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:
020: import org.columba.api.gui.frame.IFrameMediator;
021: import org.columba.api.selection.ISelectionListener;
022: import org.columba.api.selection.SelectionChangedEvent;
023: import org.columba.core.command.CommandProcessor;
024: import org.columba.core.gui.action.AbstractColumbaAction;
025: import org.columba.mail.command.IMailFolderCommandReference;
026: import org.columba.mail.gui.frame.MailFrameMediator;
027: import org.columba.mail.gui.frame.TableViewOwner;
028: import org.columba.mail.gui.message.command.ViewMessageCommand;
029: import org.columba.mail.gui.table.IMessageNode;
030: import org.columba.mail.gui.table.ITableController;
031: import org.columba.mail.gui.table.model.MessageNode;
032: import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
033: import org.columba.mail.message.IColumbaHeader;
034: import org.columba.mail.util.MailResourceLoader;
035:
036: /**
037: * Select next unread message in message list.
038: * <p>
039: * Note that this action is also used in the message-frame (frame without
040: * folder tree and without message list), which depends on the parent frame
041: * for referencing messages.
042: *
043: * @see org.columba.mail.gui.messageframe.MessageFrameController
044: *
045: * @author fdietz
046: */
047: public class NextUnreadMessageAction extends AbstractColumbaAction
048: implements ISelectionListener {
049: /**
050: * @param frameMediator
051: * @param name
052: * @param longDescription
053: * @param actionCommand
054: * @param small_icon
055: * @param big_icon
056: * @param mnemonic
057: * @param keyStroke
058: */
059: public NextUnreadMessageAction(IFrameMediator frameMediator) {
060: super (frameMediator, MailResourceLoader.getString("menu",
061: "mainframe", "menu_view_nextunreadmessage"));
062:
063: // tooltip text
064: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
065: "menu", "mainframe",
066: "menu_view_nextunreadmessage_tooltip").replaceAll("&",
067: ""));
068:
069: // Shortcut key
070: //putValue(ACCELERATOR_KEY,
071: // KeyStroke.getKeyStroke(KeyEvent.VK_BRACELEFT,0));
072:
073: //setEnabled(false);
074:
075: // uncomment to enable action
076:
077: /*
078: * ( ( AbstractMailFrameController) frameMediator)
079: * .registerTableSelectionListener( this);
080: */
081: }
082:
083: /**
084: *
085: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
086: */
087: public void actionPerformed(ActionEvent evt) {
088: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
089: .getTableSelection();
090:
091: ITableController table = ((TableViewOwner) getFrameMediator())
092: .getTableController();
093: if (table == null)
094: return;
095:
096: if (r == null)
097: return;
098:
099: IMessageNode[] nodes = table.getSelectedNodes();
100: if (nodes.length == 0)
101: return;
102:
103: MessageNode node = (MessageNode) nodes[0];
104: MessageNode nextNode = node;
105: boolean seen = true;
106: while (seen) {
107: nextNode = (MessageNode) nextNode.getNextNode();
108: if (nextNode == null)
109: return;
110:
111: IColumbaHeader h = nextNode.getHeader();
112: seen = h.getFlags().getSeen();
113: }
114:
115: // necessary for the message-frame only
116: r.setUids(new Object[] { nextNode.getUid() });
117: ((MailFrameMediator) getFrameMediator()).setTableSelection(r);
118: CommandProcessor.getInstance().addOp(
119: new ViewMessageCommand(getFrameMediator(), r));
120: // select message in message list
121: table.setSelected(new Object[] { nextNode.getUid() });
122: }
123:
124: /**
125: *
126: * @see org.columba.core.gui.util.ISelectionListener#connectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
127: */
128: public void selectionChanged(SelectionChangedEvent e) {
129: setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
130: }
131: }
|