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.core.resourceloader.IconKeys;
026: import org.columba.core.resourceloader.ImageLoader;
027: import org.columba.mail.command.IMailFolderCommandReference;
028: import org.columba.mail.gui.frame.MailFrameMediator;
029: import org.columba.mail.gui.frame.TableViewOwner;
030: import org.columba.mail.gui.message.command.ViewMessageCommand;
031: import org.columba.mail.gui.table.IMessageNode;
032: import org.columba.mail.gui.table.ITableController;
033: import org.columba.mail.gui.table.model.MessageNode;
034: import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
035: import org.columba.mail.util.MailResourceLoader;
036:
037: /**
038: * Select next message in message list.
039: * <p>
040: * Note that this action is also used in the message-frame (frame without
041: * folder tree and without message list), which depends on the parent frame
042: * for referencing messages.
043: *
044: * @see org.columba.mail.gui.messageframe.MessageFrameController
045: *
046: * @author fdietz
047: */
048: public class NextMessageAction extends AbstractColumbaAction implements
049: ISelectionListener {
050: public NextMessageAction(IFrameMediator frameMediator) {
051: super (frameMediator, MailResourceLoader.getString("menu",
052: "mainframe", "menu_view_nextmessage"));
053:
054: // tooltip text
055: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
056: "menu", "mainframe", "menu_view_nextmessage_tooltip")
057: .replaceAll("&", ""));
058:
059: // icons
060: putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.GO_NEXT));
061: putValue(SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.GO_NEXT));
062:
063: // shortcut key
064: //putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, 0));
065:
066: // disable toolbar text
067: setShowToolBarText(false);
068:
069: //setEnabled(false);
070:
071: // uncomment to enable action
072:
073: /*
074: * ((MailFrameMediator)
075: * frameMediator).registerTableSelectionListener(this);
076: */
077: }
078:
079: /**
080: *
081: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
082: */
083: public void actionPerformed(ActionEvent evt) {
084: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
085: .getTableSelection();
086:
087: ITableController table = ((TableViewOwner) getFrameMediator())
088: .getTableController();
089: if (table == null)
090: return;
091:
092: if (r == null)
093: return;
094:
095: IMessageNode[] nodes = table.getSelectedNodes();
096: if (nodes.length == 0)
097: return;
098:
099: MessageNode node = (MessageNode) nodes[0];
100: MessageNode nextNode = (MessageNode) node.getNextNode();
101: if (nextNode == null)
102: return;
103:
104: // necessary for the message-frame only
105: r.setUids(new Object[] { nextNode.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[] { nextNode.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: }
|