KickJava   Java API By Example, From Geeks To Geeks.

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


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 upAction is the action when you pressing the up key (not on NUM-PAD). If
40  * you do so, the previouseMessage up your key is selected and shown in the
41  * message-view. If no more message up your key, then nothing changed.
42  */

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

63     public void actionPerformed(ActionEvent JavaDoc arg0) {
64         LOG.info("action up performed");
65
66         // getting last selection
67
IMailFolderCommandReference r = ((MailFrameMediator) frameController)
68                 .getTableSelection();
69         IMailFolderCommandReference ref = r;
70         LOG.info("folderCommandRef: " + ref);
71
72         // getting current uid
73
Object JavaDoc[] uids = ref.getUids();
74         LOG.info("curr uids: " + uids);
75
76         // at any time i get here uids of length 0. If this is so we should
77
// return and do nothing
78
if (uids.length == 0) {
79             return;
80         }
81
82         // getting current node (under the selection)
83
DefaultMutableTreeNode JavaDoc currNode = (DefaultMutableTreeNode JavaDoc) tableController
84                 .getMessageNode(uids[0]);
85         LOG.info("currNode: " + currNode);
86
87         // getting prev node
88
DefaultMutableTreeNode JavaDoc prevNode = currNode.getPreviousNode();
89         LOG.info("prevNode: " + prevNode);
90
91         Object JavaDoc[] prevUids = new Object JavaDoc[1];
92         prevUids[0] = ((MessageNode) prevNode).getUid();
93         LOG.info("prevUids: " + prevUids);
94         ref.setUids(prevUids);
95
96         // check if the node is not null
97
IMessageNode[] nodes = new MessageNode[prevUids.length];
98
99         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()).setLastSelection(prevUids[0]);
120
121             tableController.makeSelectedRowVisible();
122
123             MailFolderCommandReference refNew = new MailFolderCommandReference(
124                     ref.getSourceFolder(), prevUids);
125
126             // view the message under the new node
127
CommandProcessor.getInstance().addOp(
128                     new ViewMessageCommand(this.frameController, refNew));
129         }
130     }
131 }
Popular Tags