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:
20: import org.columba.api.gui.frame.IFrameMediator;
21: import org.columba.api.selection.ISelectionListener;
22: import org.columba.api.selection.SelectionChangedEvent;
23: import org.columba.core.command.CommandProcessor;
24: import org.columba.core.gui.action.AbstractColumbaAction;
25: import org.columba.core.resourceloader.ImageLoader;
26: import org.columba.mail.command.MailFolderCommandReference;
27: import org.columba.mail.folder.IMailFolder;
28: import org.columba.mail.folder.IMailbox;
29: import org.columba.mail.gui.config.folder.FolderOptionsDialog;
30: import org.columba.mail.gui.frame.AbstractMailFrameController;
31: import org.columba.mail.gui.frame.MailFrameMediator;
32: import org.columba.mail.gui.tree.command.MailboxSizeCommand;
33: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
34: import org.columba.mail.util.MailResourceLoader;
35:
36: /**
37: * Opens AbstractMessageFolder Options Dialog.
38: *
39: * @author fdietz
40: */
41: public class FolderOptionsAction extends AbstractColumbaAction
42: implements ISelectionListener {
43: /**
44: * @param frameMediator
45: * @param name
46: */
47: public FolderOptionsAction(IFrameMediator frameMediator) {
48: super (frameMediator, MailResourceLoader.getString("menu",
49: "mainframe", "menu_folder_folderoptions"));
50:
51: // icon for menu
52: // putValue(SMALL_ICON, ImageLoader
53: // .getSmallImageIcon("16_configure_folder.png"));
54:
55: setEnabled(false);
56:
57: ((MailFrameMediator) frameMediator)
58: .registerTreeSelectionListener(this );
59: }
60:
61: /*
62: * (non-Javadoc)
63: *
64: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
65: */
66: public void actionPerformed(ActionEvent evt) {
67: // it is safe here to cast to AbstractMailFrameControlller
68: MailFolderCommandReference r = (MailFolderCommandReference) ((AbstractMailFrameController) frameMediator)
69: .getTreeSelection();
70:
71: // only use the first selected folder
72: IMailFolder folder = (IMailFolder) r.getSourceFolder();
73:
74: // cast to Folder
75: FolderOptionsDialog dialog = new FolderOptionsDialog(
76: (IMailbox) folder, true,
77: (AbstractMailFrameController) frameMediator);
78:
79: // calculate mailbox size in background worker
80: CommandProcessor.getInstance().addOp(
81: new MailboxSizeCommand(r, dialog));
82: }
83:
84: public void selectionChanged(SelectionChangedEvent e) {
85: IMailFolder[] r = ((TreeSelectionChangedEvent) e).getSelected();
86:
87: if ((r.length > 0) && r[0] instanceof IMailbox) {
88: setEnabled(true);
89: } else {
90: setEnabled(false);
91: }
92: }
93: }
|