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.command.CommandProcessor;
028: import org.columba.core.gui.action.AbstractColumbaAction;
029: import org.columba.mail.command.IMailFolderCommandReference;
030: import org.columba.mail.folder.IMailFolder;
031: import org.columba.mail.folder.RootFolder;
032: import org.columba.mail.folder.command.ExpungeFolderCommand;
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:
044: public class ExpungeFolderAction extends AbstractColumbaAction
045: implements ISelectionListener {
046: public ExpungeFolderAction(IFrameMediator frameMediator) {
047: super (frameMediator, MailResourceLoader.getString("menu",
048: "mainframe", "menu_folder_expungefolder"));
049:
050: // tooltip text
051: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
052: "menu", "mainframe", "menu_folder_expungefolder")
053: .replaceAll("&", ""));
054:
055: // shortcut key
056: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,
057: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
058: | ActionEvent.SHIFT_MASK));
059:
060: setEnabled(false);
061:
062: ((MailFrameMediator) frameMediator)
063: .registerTreeSelectionListener(this );
064: }
065:
066: /*
067: * (non-Javadoc)
068: *
069: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
070: */
071: public void actionPerformed(ActionEvent evt) {
072: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
073: .getTreeSelection();
074: ExpungeFolderCommand c = new ExpungeFolderCommand(r);
075:
076: CommandProcessor.getInstance().addOp(c);
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
083: */
084: public void selectionChanged(SelectionChangedEvent e) {
085: if (((TreeSelectionChangedEvent) e).getSelected().length > 0) {
086: IMailFolder folder = ((TreeSelectionChangedEvent) e)
087: .getSelected()[0];
088:
089: if (folder != null) {
090: if (folder instanceof RootFolder) {
091: setEnabled(false);
092: } else {
093:
094: setEnabled(true);
095: }
096:
097: }
098: } else {
099: setEnabled(false);
100: }
101: }
102: }
|