KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > table > action > DownAction


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.table.action;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.util.logging.Logger JavaDoc;
20
21 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
22
23 import org.columba.api.gui.frame.IFrameMediator;
24 import org.columba.core.command.CommandProcessor;
25 import org.columba.core.gui.action.AbstractColumbaAction;
26 import org.columba.mail.command.IMailFolderCommandReference;
27 import org.columba.mail.command.MailFolderCommandReference;
28 import org.columba.mail.folder.IMailbox;
29 import org.columba.mail.gui.frame.MailFrameMediator;
30 import org.columba.mail.gui.frame.TableViewOwner;
31 import org.columba.mail.gui.message.command.ViewMessageCommand;
32 import org.columba.mail.gui.table.IMessageNode;
33 import org.columba.mail.gui.table.ITableController;
34 import org.columba.mail.gui.table.model.MessageNode;
35
36 /**
37  * @author waffel
38  *
39  * The downAction is the action when you pressing the down key (not on NUM-PAD).
40  * If you do so, the nextMessage down your key is selected and shown in the
41  * message-view. If no more message down your key, then nothing changed.
42  */

43
44 public class DownAction extends AbstractColumbaAction {
45
46     /** JDK 1.4+ logging framework logger, used for logging. */
47     private static final Logger JavaDoc LOG = Logger
48             .getLogger("org.columba.mail.gui.table.action");
49
50     ITableController tableController;
51
52     IFrameMediator frameController;
53
54     public DownAction(IFrameMediator frameController) {
55         super(frameController, "DownAction");
56         this.tableController = ((TableViewOwner) frameController)
57                 .getTableController();
58         this.frameController = frameController;
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
65      */

66     public void actionPerformed(ActionEvent JavaDoc arg0) {
67         LOG.info("action down performed");
68
69         // getting last selection
70
IMailFolderCommandReference r = ((MailFrameMediator) frameController)
71                 .getTableSelection();
72
73         // getting current uid
74
Object JavaDoc[] uids = r.getUids();
75         LOG.info("curr uids: " + uids);
76
77         // getting current node (under the selection)
78
DefaultMutableTreeNode JavaDoc currNode = (DefaultMutableTreeNode JavaDoc) tableController
79                 .getMessageNode(uids[0]);
80         LOG.info("currNode: " + currNode);
81
82         // getting next node
83
DefaultMutableTreeNode JavaDoc nextNode = currNode.getNextNode();
84
85         // if next node is null (the end of the list) return
86
if (nextNode == null) {
87             return;
88         }
89
90         LOG.info("nextNode: " + nextNode);
91
92         // getting from the next node the uid
93
Object JavaDoc[] nextUids = new Object JavaDoc[1];
94         nextUids[0] = ((MessageNode) nextNode).getUid();
95         LOG.info("prevUids: " + nextUids);
96
97         // and set this to the actual ref
98
r.setUids(nextUids);
99
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()).setLastSelection(nextUids[0]);
124
125             tableController.makeSelectedRowVisible();
126
127             MailFolderCommandReference refNew = new MailFolderCommandReference(
128                     r.getSourceFolder(), nextUids);
129
130             // view the message under the new node
131
CommandProcessor.getInstance().addOp(
132                     new ViewMessageCommand(frameController, refNew));
133         }
134     }
135 }
136
Popular Tags