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.core.resourceloader.ImageLoader;
030: import org.columba.mail.command.IMailFolderCommandReference;
031: import org.columba.mail.folder.IMailFolder;
032: import org.columba.mail.gui.frame.MailFrameMediator;
033: import org.columba.mail.gui.tree.command.CreateSubFolderCommand;
034: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
035: import org.columba.mail.gui.tree.util.CreateFolderDialog;
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 CreateSubFolderAction extends AbstractColumbaAction
045: implements ISelectionListener {
046: public CreateSubFolderAction(IFrameMediator frameMediator) {
047: super (frameMediator, MailResourceLoader.getString("menu",
048: "mainframe", "menu_folder_newfolder"));
049:
050: // tooltip text
051: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
052: "menu", "mainframe", "menu_folder_newfolder")
053: .replaceAll("&", ""));
054:
055: // icons
056: putValue(SMALL_ICON, ImageLoader.getSmallIcon("folder-new.png"));
057: putValue(LARGE_ICON, ImageLoader.getIcon("folder-new.png"));
058:
059: // shortcut key
060: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N,
061: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
062: | ActionEvent.SHIFT_MASK));
063:
064: setEnabled(false);
065:
066: ((MailFrameMediator) frameMediator)
067: .registerTreeSelectionListener(this );
068: }
069:
070: /*
071: * (non-Javadoc)
072: *
073: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
074: */
075: public void actionPerformed(ActionEvent evt) {
076: IMailFolderCommandReference selection = ((MailFrameMediator) getFrameMediator())
077: .getTreeSelection();
078:
079: CreateFolderDialog dialog = new CreateFolderDialog(
080: getFrameMediator(), ((IMailFolder) selection
081: .getSourceFolder()).getSelectionTreePath());
082:
083: String name;
084:
085: if (dialog.success()) {
086: // ok pressed
087: selection.setSourceFolder(dialog.getSelected());
088: selection.setFolderName(dialog.getName());
089: selection.setFolderType(dialog.getType());
090:
091: CommandProcessor.getInstance().addOp(
092: new CreateSubFolderCommand(selection));
093: }
094: }
095:
096: /*
097: * (non-Javadoc)
098: *
099: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
100: */
101: public void selectionChanged(SelectionChangedEvent e) {
102: TreeSelectionChangedEvent ev = (TreeSelectionChangedEvent) e;
103:
104: if (ev.getSelected() != null && ev.getSelected().length == 1
105: && ev.getSelected()[0] != null
106: && ev.getSelected()[0].getAllowsChildren()) {
107: setEnabled(true);
108: } else {
109: setEnabled(false);
110: }
111: }
112: }
|