KickJava   Java API By Example, From Geeks To Geeks.

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


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.mail.command.IMailFolderCommandReference;
26 import org.columba.mail.gui.frame.MailFrameMediator;
27 import org.columba.mail.gui.frame.TableViewOwner;
28 import org.columba.mail.gui.message.command.ViewMessageCommand;
29 import org.columba.mail.gui.table.IMessageNode;
30 import org.columba.mail.gui.table.ITableController;
31 import org.columba.mail.gui.table.model.MessageNode;
32 import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
33 import org.columba.mail.message.IColumbaHeader;
34 import org.columba.mail.util.MailResourceLoader;
35
36 /**
37  * Select next unread message in message list.
38  * <p>
39  * Note that this action is also used in the message-frame (frame without
40  * folder tree and without message list), which depends on the parent frame
41  * for referencing messages.
42  *
43  * @see org.columba.mail.gui.messageframe.MessageFrameController
44  *
45  * @author fdietz
46  */

47 public class NextUnreadMessageAction extends AbstractColumbaAction implements
48         ISelectionListener {
49     /**
50      * @param frameMediator
51      * @param name
52      * @param longDescription
53      * @param actionCommand
54      * @param small_icon
55      * @param big_icon
56      * @param mnemonic
57      * @param keyStroke
58      */

59     public NextUnreadMessageAction(IFrameMediator frameMediator) {
60         super(frameMediator, MailResourceLoader.getString("menu", "mainframe",
61                 "menu_view_nextunreadmessage"));
62
63         // tooltip text
64
putValue(SHORT_DESCRIPTION, MailResourceLoader.getString("menu",
65                 "mainframe", "menu_view_nextunreadmessage_tooltip").replaceAll(
66                 "&", ""));
67
68         // Shortcut key
69
//putValue(ACCELERATOR_KEY,
70
// KeyStroke.getKeyStroke(KeyEvent.VK_BRACELEFT,0));
71

72         //setEnabled(false);
73

74         // uncomment to enable action
75

76         /*
77          * ( ( AbstractMailFrameController) frameMediator)
78          * .registerTableSelectionListener( this);
79          */

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

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

126     public void selectionChanged(SelectionChangedEvent e) {
127         setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
128     }
129 }
Popular Tags