001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.table.action;
017:
018: import java.awt.event.ActionEvent;
019: import java.util.logging.Logger;
020:
021: import javax.swing.tree.DefaultMutableTreeNode;
022:
023: import org.columba.api.gui.frame.IFrameMediator;
024: import org.columba.core.command.CommandProcessor;
025: import org.columba.core.gui.action.AbstractColumbaAction;
026: import org.columba.mail.command.IMailFolderCommandReference;
027: import org.columba.mail.command.MailFolderCommandReference;
028: import org.columba.mail.folder.IMailbox;
029: import org.columba.mail.gui.frame.MailFrameMediator;
030: import org.columba.mail.gui.frame.TableViewOwner;
031: import org.columba.mail.gui.message.command.ViewMessageCommand;
032: import org.columba.mail.gui.table.IMessageNode;
033: import org.columba.mail.gui.table.ITableController;
034: import org.columba.mail.gui.table.model.MessageNode;
035:
036: /**
037: * @author waffel
038: *
039: * The upAction is the action when you pressing the up key (not on NUM-PAD). If
040: * you do so, the previouseMessage up your key is selected and shown in the
041: * message-view. If no more message up your key, then nothing changed.
042: */
043: public class UpAction extends AbstractColumbaAction {
044:
045: /** JDK 1.4+ logging framework logger, used for logging. */
046: private static final Logger LOG = Logger
047: .getLogger("org.columba.mail.gui.table.action");
048:
049: ITableController tableController;
050:
051: IFrameMediator frameController;
052:
053: public UpAction(IFrameMediator frameController) {
054: super (frameController, "UpAction");
055: this .tableController = ((TableViewOwner) frameController)
056: .getTableController();
057: this .frameController = frameController;
058: }
059:
060: /**
061: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
062: */
063: public void actionPerformed(ActionEvent arg0) {
064: LOG.info("action up performed");
065:
066: // getting last selection
067: IMailFolderCommandReference r = ((MailFrameMediator) frameController)
068: .getTableSelection();
069: IMailFolderCommandReference ref = r;
070: LOG.info("folderCommandRef: " + ref);
071:
072: // getting current uid
073: Object[] uids = ref.getUids();
074: LOG.info("curr uids: " + uids);
075:
076: // at any time i get here uids of length 0. If this is so we should
077: // return and do nothing
078: if (uids.length == 0) {
079: return;
080: }
081:
082: // getting current node (under the selection)
083: DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) tableController
084: .getMessageNode(uids[0]);
085: LOG.info("currNode: " + currNode);
086:
087: // getting prev node
088: DefaultMutableTreeNode prevNode = currNode.getPreviousNode();
089: LOG.info("prevNode: " + prevNode);
090:
091: Object[] prevUids = new Object[1];
092: prevUids[0] = ((MessageNode) prevNode).getUid();
093: LOG.info("prevUids: " + prevUids);
094: ref.setUids(prevUids);
095:
096: // check if the node is not null
097: IMessageNode[] nodes = new MessageNode[prevUids.length];
098:
099: for (int i = 0; i < prevUids.length; i++) {
100: nodes[i] = tableController.getMessageNode(prevUids[i]);
101: }
102:
103: boolean node_ok = true;
104:
105: for (int i = 0; i < nodes.length; i++) {
106: if (nodes[i] == null) {
107: node_ok = false;
108:
109: break;
110: }
111: }
112:
113: // if the node is not null
114: if (node_ok) {
115: // select it
116: tableController.setSelected(prevUids);
117:
118: // saving the last selection for the current folder
119: ((IMailbox) ref.getSourceFolder())
120: .setLastSelection(prevUids[0]);
121:
122: tableController.makeSelectedRowVisible();
123:
124: MailFolderCommandReference refNew = new MailFolderCommandReference(
125: ref.getSourceFolder(), prevUids);
126:
127: // view the message under the new node
128: CommandProcessor.getInstance()
129: .addOp(
130: new ViewMessageCommand(
131: this.frameController, refNew));
132: }
133: }
134: }
|