KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 import org.columba.api.gui.frame.IFrameMediator;
21 import org.columba.api.selection.ISelectionListener;
22 import org.columba.api.selection.SelectionChangedEvent;
23 import org.columba.core.command.CommandProcessor;
24 import org.columba.core.gui.action.AbstractColumbaAction;
25 import org.columba.core.resourceloader.IconKeys;
26 import org.columba.core.resourceloader.ImageLoader;
27 import org.columba.mail.command.IMailFolderCommandReference;
28 import org.columba.mail.gui.frame.MailFrameMediator;
29 import org.columba.mail.gui.frame.TableViewOwner;
30 import org.columba.mail.gui.message.command.ViewMessageCommand;
31 import org.columba.mail.gui.table.IMessageNode;
32 import org.columba.mail.gui.table.ITableController;
33 import org.columba.mail.gui.table.model.MessageNode;
34 import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
35 import org.columba.mail.util.MailResourceLoader;
36
37 /**
38  * Select previous message in message list.
39  *
40  * <p>
41  * Note that this action is also used in the message-frame (frame without
42  * folder tree and without message list), which depends on the parent frame
43  * for referencing messages.
44  *
45  * @see org.columba.mail.gui.messageframe.MessageFrameController
46  *
47  * @author fdietz
48  */

49 public class PreviousMessageAction extends AbstractColumbaAction implements
50         ISelectionListener {
51     public PreviousMessageAction(IFrameMediator frameMediator) {
52         super(frameMediator, MailResourceLoader.getString("menu", "mainframe",
53                 "menu_view_prevmessage"));
54
55         // tooltip text
56
putValue(SHORT_DESCRIPTION, MailResourceLoader.getString("menu",
57                 "mainframe", "menu_view_prevmessage_tooltip").replaceAll("&",
58                 ""));
59
60         // icons
61
putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.GO_PREVIOUS));
62         putValue(SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.GO_PREVIOUS));
63
64         // shortcut key
65
//putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("B"));
66

67         // disable toolbar text
68
setShowToolBarText(false);
69
70         //setEnabled(false);
71

72         // uncomment to enable action
73

74         /*
75          * ((MailFrameMediator)
76          * frameMediator).registerTableSelectionListener(this);
77          */

78     }
79
80     /**
81      *
82      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
83      */

84     public void actionPerformed(ActionEvent JavaDoc evt) {
85         IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
86                 .getTableSelection();
87         ITableController table = ((TableViewOwner) getFrameMediator())
88                 .getTableController();
89         if ( table == null ) return;
90         
91         if (r == null)
92             return;
93
94         IMessageNode[] nodes = table.getSelectedNodes();
95         if (nodes.length == 0)
96             return;
97
98         MessageNode node = (MessageNode) nodes[0];
99         MessageNode previousNode = (MessageNode) node.getPreviousNode();
100         if (previousNode == null)
101             return;
102
103         // necessary for the message-frame only
104
r.setUids(new Object JavaDoc[] { previousNode.getUid() });
105         ((MailFrameMediator) getFrameMediator()).setTableSelection(r);
106         CommandProcessor.getInstance().addOp(new ViewMessageCommand(
107                 getFrameMediator(), r));
108
109         // select message in message list
110
table.setSelected(new Object JavaDoc[] { previousNode.getUid() });
111     }
112
113     /**
114      *
115      * @see org.columba.core.gui.util.ISelectionListener#connectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
116      */

117     public void selectionChanged(SelectionChangedEvent e) {
118         setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
119     }
120 }
Popular Tags