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 downAction is the action when you pressing the down key (not on NUM-PAD).
040: * If you do so, the nextMessage down your key is selected and shown in the
041: * message-view. If no more message down your key, then nothing changed.
042: */
043:
044: public class DownAction extends AbstractColumbaAction {
045:
046: /** JDK 1.4+ logging framework logger, used for logging. */
047: private static final Logger LOG = Logger
048: .getLogger("org.columba.mail.gui.table.action");
049:
050: ITableController tableController;
051:
052: IFrameMediator frameController;
053:
054: public DownAction(IFrameMediator frameController) {
055: super (frameController, "DownAction");
056: this .tableController = ((TableViewOwner) frameController)
057: .getTableController();
058: this .frameController = frameController;
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
065: */
066: public void actionPerformed(ActionEvent arg0) {
067: LOG.info("action down performed");
068:
069: // getting last selection
070: IMailFolderCommandReference r = ((MailFrameMediator) frameController)
071: .getTableSelection();
072:
073: // getting current uid
074: Object[] uids = r.getUids();
075: LOG.info("curr uids: " + uids);
076:
077: // getting current node (under the selection)
078: DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) tableController
079: .getMessageNode(uids[0]);
080: LOG.info("currNode: " + currNode);
081:
082: // getting next node
083: DefaultMutableTreeNode nextNode = currNode.getNextNode();
084:
085: // if next node is null (the end of the list) return
086: if (nextNode == null) {
087: return;
088: }
089:
090: LOG.info("nextNode: " + nextNode);
091:
092: // getting from the next node the uid
093: Object[] nextUids = new Object[1];
094: nextUids[0] = ((MessageNode) nextNode).getUid();
095: LOG.info("prevUids: " + nextUids);
096:
097: // and set this to the actual ref
098: r.setUids(nextUids);
099:
100: // check if the node is not null
101: IMessageNode[] nodes = new MessageNode[nextUids.length];
102:
103: for (int i = 0; i < nextUids.length; i++) {
104: nodes[i] = tableController.getMessageNode(nextUids[i]);
105: }
106:
107: boolean node_ok = true;
108:
109: for (int i = 0; i < nodes.length; i++) {
110: if (nodes[i] == null) {
111: node_ok = false;
112:
113: break;
114: }
115: }
116:
117: // if the node is not null
118: if (node_ok) {
119: // select it
120: tableController.setSelected(nextUids);
121:
122: // saving the last selection for the current folder
123: ((IMailbox) r.getSourceFolder())
124: .setLastSelection(nextUids[0]);
125:
126: tableController.makeSelectedRowVisible();
127:
128: MailFolderCommandReference refNew = new MailFolderCommandReference(
129: r.getSourceFolder(), nextUids);
130:
131: // view the message under the new node
132: CommandProcessor.getInstance().addOp(
133: new ViewMessageCommand(frameController, refNew));
134: }
135: }
136: }
|