01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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.tree.action;
17:
18: import java.awt.event.ActionEvent;
19: import java.awt.event.KeyEvent;
20:
21: import javax.swing.KeyStroke;
22:
23: import org.columba.api.gui.frame.IFrameMediator;
24: import org.columba.api.selection.ISelectionListener;
25: import org.columba.api.selection.SelectionChangedEvent;
26: import org.columba.core.gui.action.AbstractColumbaAction;
27: import org.columba.mail.command.MailFolderCommandReference;
28: import org.columba.mail.config.IFolderItem;
29: import org.columba.mail.folder.IMailFolder;
30: import org.columba.mail.folder.IMailbox;
31: import org.columba.mail.gui.config.folder.FolderOptionsDialog;
32: import org.columba.mail.gui.frame.AbstractMailFrameController;
33: import org.columba.mail.gui.frame.MailFrameMediator;
34: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
35: import org.columba.mail.util.MailResourceLoader;
36:
37: /**
38: * Action used to popup a folder renaming dialog to the user.
39: *
40: * @author Frederik
41: */
42: public class RenameFolderAction extends AbstractColumbaAction implements
43: ISelectionListener {
44: public RenameFolderAction(IFrameMediator frameMediator) {
45: super (frameMediator, MailResourceLoader.getString("menu",
46: "mainframe", "menu_folder_renamefolder"));
47:
48: // tooltip text
49: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
50: "menu", "mainframe", "menu_folder_renamefolder")
51: .replaceAll("&", ""));
52:
53: // shortcut key
54: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(
55: KeyEvent.VK_F2, 0));
56:
57: setEnabled(false);
58:
59: ((MailFrameMediator) frameMediator)
60: .registerTreeSelectionListener(this );
61: }
62:
63: public void actionPerformed(ActionEvent evt) {
64: MailFolderCommandReference r = (MailFolderCommandReference) ((AbstractMailFrameController) frameMediator)
65: .getTreeSelection();
66:
67: new FolderOptionsDialog((IMailbox) r.getSourceFolder(), true,
68: (AbstractMailFrameController) frameMediator);
69: }
70:
71: public void selectionChanged(SelectionChangedEvent evt) {
72: if (((TreeSelectionChangedEvent) evt).getSelected().length > 0
73: && ((TreeSelectionChangedEvent) evt).getSelected()[0] instanceof IMailbox) {
74: IMailFolder folder = ((TreeSelectionChangedEvent) evt)
75: .getSelected()[0];
76:
77: if ((folder != null) && folder instanceof IMailbox) {
78: IFolderItem item = folder.getConfiguration();
79:
80: if (item.getString("property", "accessrights").equals(
81: "user")) {
82: setEnabled(true);
83: } else {
84: setEnabled(false);
85: }
86: }
87: } else {
88: setEnabled(false);
89: }
90: }
91: }
|