KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > tree > action > RenameFolderAction


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.tree.action;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.awt.event.KeyEvent JavaDoc;
20
21 import javax.swing.KeyStroke JavaDoc;
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", "mainframe",
46                 "menu_folder_renamefolder"));
47
48         // tooltip text
49
putValue(SHORT_DESCRIPTION, MailResourceLoader.getString("menu",
50                 "mainframe", "menu_folder_renamefolder").replaceAll("&", ""));
51
52         // shortcut key
53
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
54
55         setEnabled(false);
56
57         ((MailFrameMediator) frameMediator).registerTreeSelectionListener(this);
58     }
59
60     public void actionPerformed(ActionEvent JavaDoc evt) {
61         MailFolderCommandReference r = (MailFolderCommandReference) ((AbstractMailFrameController) frameMediator)
62                 .getTreeSelection();
63
64         new FolderOptionsDialog((IMailbox) r.getSourceFolder(), true,
65                 (AbstractMailFrameController) frameMediator);
66     }
67
68     public void selectionChanged(SelectionChangedEvent evt) {
69         if (((TreeSelectionChangedEvent) evt).getSelected().length > 0
70                 && ((TreeSelectionChangedEvent) evt).getSelected()[0] instanceof IMailbox) {
71             IMailFolder folder = ((TreeSelectionChangedEvent) evt)
72                     .getSelected()[0];
73
74             if ((folder != null) && folder instanceof IMailbox) {
75                 IFolderItem item = folder.getConfiguration();
76
77                 if (item.getString("property", "accessrights").equals("user")) {
78                     setEnabled(true);
79                 } else {
80                     setEnabled(false);
81                 }
82             }
83         } else {
84             setEnabled(false);
85         }
86     }
87 }
88
Popular Tags