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 previous 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 PreviousUnreadMessageAction extends AbstractColumbaAction
048: implements ISelectionListener {
049: public PreviousUnreadMessageAction(IFrameMediator frameMediator) {
050: super (frameMediator, MailResourceLoader.getString("menu",
051: "mainframe", "menu_view_prevunreadmessage"));
052:
053: // tooltip text
054: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
055: "menu", "mainframe",
056: "menu_view_prevunreadmessage_tooltip").replaceAll("&",
057: ""));
058:
059: // shortcut key
060: //putValue(ACCELERATOR_KEY,
061: // KeyStroke.getKeyStroke(KeyEvent.VK_BRACELEFT, 0));
062:
063: //setEnabled(false);
064:
065: // uncomment to enable action
066:
067: /*
068: * ((MailFrameMediator)
069: * frameMediator).registerTableSelectionListener(this);
070: */
071: }
072:
073: /**
074: *
075: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
076: */
077: public void actionPerformed(ActionEvent evt) {
078: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
079: .getTableSelection();
080: ITableController table = ((TableViewOwner) getFrameMediator())
081: .getTableController();
082: if (table == null)
083: return;
084:
085: if (r == null)
086: return;
087:
088: IMessageNode[] nodes = table.getSelectedNodes();
089: if (nodes.length == 0)
090: return;
091:
092: MessageNode node = (MessageNode) nodes[0];
093: MessageNode previousNode = node;
094: boolean seen = true;
095: while (seen) {
096: previousNode = (MessageNode) previousNode.getPreviousNode();
097: if (previousNode == null)
098: return;
099:
100: IColumbaHeader h = previousNode.getHeader();
101: seen = h.getFlags().getSeen();
102: }
103:
104: // necessary for the message-frame only
105: r.setUids(new Object[] { previousNode.getUid() });
106: ((MailFrameMediator) getFrameMediator()).setTableSelection(r);
107: CommandProcessor.getInstance().addOp(
108: new ViewMessageCommand(getFrameMediator(), r));
109:
110: // select message in message list
111: table.setSelected(new Object[] { previousNode.getUid() });
112: }
113:
114: /**
115: *
116: * @see org.columba.core.gui.util.ISelectionListener#connectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
117: */
118: public void selectionChanged(SelectionChangedEvent e) {
119: setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
120: }
121: }
|