KickJava   Java API By Example, From Geeks To Geeks.

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


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.Toolkit JavaDoc;
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.KeyEvent JavaDoc;
21
22 import javax.swing.KeyStroke JavaDoc;
23
24 import org.columba.api.gui.frame.IFrameMediator;
25 import org.columba.api.selection.ISelectionListener;
26 import org.columba.api.selection.SelectionChangedEvent;
27 import org.columba.core.command.CommandProcessor;
28 import org.columba.core.gui.action.AbstractColumbaAction;
29 import org.columba.mail.command.IMailFolderCommandReference;
30 import org.columba.mail.command.MailFolderCommandReference;
31 import org.columba.mail.folder.IMailFolder;
32 import org.columba.mail.folder.command.CopyMessageCommand;
33 import org.columba.mail.gui.frame.MailFrameMediator;
34 import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
35 import org.columba.mail.gui.tree.util.SelectFolderDialog;
36 import org.columba.mail.resourceloader.MailImageLoader;
37 import org.columba.mail.util.MailResourceLoader;
38
39 /**
40  * @author frd
41  *
42  * To change this generated comment go to Window>Preferences>Java>Code
43  * Generation>Code and Comments
44  */

45 public class CopyMessageAction extends AbstractColumbaAction implements
46         ISelectionListener {
47     public CopyMessageAction(IFrameMediator frameMediator) {
48         super(frameMediator, MailResourceLoader.getString("menu", "mainframe",
49                 "menu_message_copy"));
50
51         // toolbar text
52
putValue(TOOLBAR_NAME, MailResourceLoader.getString("menu",
53                 "mainframe", "menu_message_copy_toolbar"));
54
55         // tooltip text
56
putValue(SHORT_DESCRIPTION, MailResourceLoader.getString("menu",
57                 "mainframe", "menu_message_copy_tooltip").replaceAll("&", ""));
58
59         // icons
60
putValue(SMALL_ICON, MailImageLoader.getSmallIcon("message-copy.png"));
61         putValue(LARGE_ICON, MailImageLoader.getIcon("message-copy.png"));
62
63         putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
64                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | ActionEvent.SHIFT_MASK));
65
66         // disable toolbar text
67
setShowToolBarText(false);
68
69         setEnabled(false);
70
71         ((MailFrameMediator) frameMediator)
72                 .registerTableSelectionListener(this);
73     }
74
75     /*
76      * (non-Javadoc)
77      *
78      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
79      */

80     public void actionPerformed(ActionEvent JavaDoc evt) {
81         SelectFolderDialog dialog = new SelectFolderDialog(getFrameMediator());
82
83         if (dialog.success()) {
84             IMailFolder destFolder = (IMailFolder) dialog.getSelectedFolder();
85
86             IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
87                     .getTableSelection();
88             IMailFolderCommandReference result = new MailFolderCommandReference(
89                     r.getSourceFolder(), destFolder);
90             result.setUids(r.getUids());
91
92             CopyMessageCommand c = new CopyMessageCommand(result);
93
94             CommandProcessor.getInstance().addOp(c);
95         }
96     }
97
98     /*
99      * (non-Javadoc)
100      *
101      * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
102      */

103     public void selectionChanged(SelectionChangedEvent e) {
104         setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
105     }
106 }
Popular Tags