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.tree.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.gui.action.AbstractColumbaAction;
028: import org.columba.core.resourceloader.ImageLoader;
029: import org.columba.mail.folder.IMailFolder;
030: import org.columba.mail.folder.imap.IMAPFolder;
031: import org.columba.mail.folder.imap.IMAPRootFolder;
032: import org.columba.mail.gui.config.subscribe.SubscribeDialog;
033: import org.columba.mail.gui.frame.MailFrameMediator;
034: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
035: import org.columba.mail.util.MailResourceLoader;
036:
037: /**
038: * @author frd
039: *
040: * To change this generated comment go to Window>Preferences>Java>Code
041: * Generation>Code and Comments
042: */
043: public class SubscribeFolderAction extends AbstractColumbaAction
044: implements ISelectionListener {
045: private IMAPRootFolder rootFolder;
046:
047: public SubscribeFolderAction(IFrameMediator frameMediator) {
048: super (frameMediator, MailResourceLoader.getString("menu",
049: "mainframe", "menu_folder_subscribe"));
050:
051: // tooltip text
052: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
053: "menu", "mainframe", "menu_folder_subscribe")
054: .replaceAll("&", ""));
055:
056: // shortcut key
057: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
058: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
059: | ActionEvent.SHIFT_MASK));
060:
061: setEnabled(false);
062:
063: ((MailFrameMediator) frameMediator)
064: .registerTreeSelectionListener(this );
065: }
066:
067: /*
068: * (non-Javadoc)
069: *
070: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
071: */
072: public void actionPerformed(ActionEvent evt) {
073: new SubscribeDialog(getFrameMediator().getView().getFrame(),
074: rootFolder);
075: }
076:
077: /*
078: * (non-Javadoc)
079: *
080: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
081: */
082: public void selectionChanged(SelectionChangedEvent e) {
083: if (((TreeSelectionChangedEvent) e).getSelected().length > 0) {
084: IMailFolder selected = ((TreeSelectionChangedEvent) e)
085: .getSelected()[0];
086:
087: if (selected instanceof IMAPFolder) {
088: rootFolder = (IMAPRootFolder) ((IMAPFolder) selected)
089: .getRootFolder();
090: setEnabled(true);
091: } else if (selected instanceof IMAPRootFolder) {
092: rootFolder = (IMAPRootFolder) selected;
093: setEnabled(true);
094: } else {
095: setEnabled(false);
096: }
097: } else {
098: setEnabled(false);
099: }
100: }
101: }
|