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.Toolkit;
019: import java.awt.event.ActionEvent;
020: import java.awt.event.KeyEvent;
021:
022: import javax.swing.KeyStroke;
023:
024: import org.columba.api.gui.frame.IFrameMediator;
025: import org.columba.api.selection.ISelectionListener;
026: import org.columba.api.selection.SelectionChangedEvent;
027: import org.columba.core.command.CommandProcessor;
028: import org.columba.core.gui.action.AbstractColumbaAction;
029: import org.columba.mail.command.IMailFolderCommandReference;
030: import org.columba.mail.command.MailFolderCommandReference;
031: import org.columba.mail.folder.IMailFolder;
032: import org.columba.mail.folder.command.CopyMessageCommand;
033: import org.columba.mail.gui.frame.MailFrameMediator;
034: import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
035: import org.columba.mail.gui.tree.util.SelectFolderDialog;
036: import org.columba.mail.resourceloader.MailImageLoader;
037: import org.columba.mail.util.MailResourceLoader;
038:
039: /**
040: * @author frd
041: *
042: * To change this generated comment go to Window>Preferences>Java>Code
043: * Generation>Code and Comments
044: */
045: public class CopyMessageAction extends AbstractColumbaAction implements
046: ISelectionListener {
047: public CopyMessageAction(IFrameMediator frameMediator) {
048: super (frameMediator, MailResourceLoader.getString("menu",
049: "mainframe", "menu_message_copy"));
050:
051: // toolbar text
052: putValue(TOOLBAR_NAME, MailResourceLoader.getString("menu",
053: "mainframe", "menu_message_copy_toolbar"));
054:
055: // tooltip text
056: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
057: "menu", "mainframe", "menu_message_copy_tooltip")
058: .replaceAll("&", ""));
059:
060: // icons
061: putValue(SMALL_ICON, MailImageLoader
062: .getSmallIcon("message-copy.png"));
063: putValue(LARGE_ICON, MailImageLoader
064: .getIcon("message-copy.png"));
065:
066: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
067: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
068: | ActionEvent.SHIFT_MASK));
069:
070: // disable toolbar text
071: setShowToolBarText(false);
072:
073: setEnabled(false);
074:
075: ((MailFrameMediator) frameMediator)
076: .registerTableSelectionListener(this );
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
083: */
084: public void actionPerformed(ActionEvent evt) {
085: SelectFolderDialog dialog = new SelectFolderDialog(
086: getFrameMediator());
087:
088: if (dialog.success()) {
089: IMailFolder destFolder = (IMailFolder) dialog
090: .getSelectedFolder();
091:
092: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
093: .getTableSelection();
094: IMailFolderCommandReference result = new MailFolderCommandReference(
095: r.getSourceFolder(), destFolder);
096: result.setUids(r.getUids());
097:
098: CopyMessageCommand c = new CopyMessageCommand(result);
099:
100: CommandProcessor.getInstance().addOp(c);
101: }
102: }
103:
104: /*
105: * (non-Javadoc)
106: *
107: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
108: */
109: public void selectionChanged(SelectionChangedEvent e) {
110: setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
111: }
112: }
|