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.event.ActionEvent;
019:
020: import javax.swing.JOptionPane;
021:
022: import org.columba.api.gui.frame.IFrameMediator;
023: import org.columba.api.selection.ISelectionListener;
024: import org.columba.api.selection.SelectionChangedEvent;
025: import org.columba.core.command.CommandProcessor;
026: import org.columba.core.gui.action.AbstractColumbaAction;
027: import org.columba.core.gui.frame.FrameManager;
028: import org.columba.core.resourceloader.ImageLoader;
029: import org.columba.mail.command.IMailFolderCommandReference;
030: import org.columba.mail.config.IFolderItem;
031: import org.columba.mail.folder.IMailFolder;
032: import org.columba.mail.folder.IMailbox;
033: import org.columba.mail.folder.command.RemoveFolderCommand;
034: import org.columba.mail.gui.frame.MailFrameMediator;
035: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
036: import org.columba.mail.util.MailResourceLoader;
037:
038: /**
039: * @author frd
040: *
041: * To change this generated comment go to Window>Preferences>Java>Code
042: * Generation>Code and Comments
043: */
044: public class RemoveFolderAction extends AbstractColumbaAction implements
045: ISelectionListener {
046: public RemoveFolderAction(IFrameMediator frameMediator) {
047: super (frameMediator, MailResourceLoader.getString("menu",
048: "mainframe", "menu_folder_removefolder"));
049:
050: // tooltip text
051: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
052: "menu", "mainframe", "menu_folder_removefolder")
053: .replaceAll("&", ""));
054:
055: // icons
056: // putValue(SMALL_ICON, ImageLoader.getIcon("folder_delete.png"));
057: // putValue(LARGE_ICON, ImageLoader.getIcon("folder_delete.png"));
058:
059: setEnabled(false);
060:
061: ((MailFrameMediator) frameMediator)
062: .registerTreeSelectionListener(this );
063: }
064:
065: /*
066: * (non-Javadoc)
067: *
068: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
069: */
070: public void actionPerformed(ActionEvent evt) {
071: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
072: .getTreeSelection();
073: IMailFolder folder = (IMailFolder) r.getSourceFolder();
074:
075: if (!folder.isLeaf()) {
076: // warn user
077: JOptionPane.showMessageDialog(FrameManager.getInstance()
078: .getActiveFrame(),
079: "Your can only remove leaf folders!");
080:
081: return;
082: } else {
083: // warn user in any other cases
084: int n = JOptionPane.showConfirmDialog(null,
085: MailResourceLoader.getString("tree", "tree",
086: "folder_warning"), MailResourceLoader
087: .getString("tree", "tree",
088: "folder_warning_title"),
089: JOptionPane.YES_NO_OPTION);
090:
091: if (n == JOptionPane.NO_OPTION) {
092: return;
093: }
094: }
095:
096: CommandProcessor.getInstance()
097: .addOp(new RemoveFolderCommand(r));
098: }
099:
100: /*
101: * (non-Javadoc)
102: *
103: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
104: */
105: public void selectionChanged(SelectionChangedEvent e) {
106: if (((TreeSelectionChangedEvent) e).getSelected().length == 1) {
107: IMailFolder folder = ((TreeSelectionChangedEvent) e)
108: .getSelected()[0];
109:
110: if (folder instanceof IMailbox) {
111: IFolderItem item = folder.getConfiguration();
112:
113: if (item.getString("property", "accessrights").equals(
114: "user")) {
115: setEnabled(true);
116: } else {
117: setEnabled(false);
118: }
119: }
120: } else {
121: setEnabled(false);
122: }
123: }
124: }
|