001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.tree.action;
019:
020: import java.awt.Toolkit;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.KeyEvent;
023:
024: import javax.swing.KeyStroke;
025:
026: import org.columba.api.gui.frame.IFrameMediator;
027: import org.columba.api.selection.ISelectionListener;
028: import org.columba.api.selection.SelectionChangedEvent;
029: import org.columba.core.gui.action.AbstractColumbaAction;
030: import org.columba.core.resourceloader.ImageLoader;
031: import org.columba.mail.command.MailFolderCommandReference;
032: import org.columba.mail.folder.FolderFactory;
033: import org.columba.mail.folder.IMailFolder;
034: import org.columba.mail.folder.virtual.VirtualFolder;
035: import org.columba.mail.gui.config.search.SearchFrame;
036: import org.columba.mail.gui.frame.AbstractMailFrameController;
037: import org.columba.mail.gui.frame.MailFrameMediator;
038: import org.columba.mail.gui.tree.FolderTreeModel;
039: import org.columba.mail.gui.tree.selection.TreeSelectionChangedEvent;
040: import org.columba.mail.gui.tree.util.CreateFolderDialog;
041: import org.columba.mail.util.MailResourceLoader;
042:
043: /**
044: * @author frd
045: *
046: * To change this generated comment go to Window>Preferences>Java>Code
047: * Generation>Code and Comments
048: */
049: public class CreateVirtualFolderAction extends AbstractColumbaAction
050: implements ISelectionListener {
051:
052: public CreateVirtualFolderAction(IFrameMediator frameMediator) {
053: super (frameMediator, MailResourceLoader.getString("menu",
054: "mainframe", "menu_folder_newvirtualfolder"));
055:
056: // tooltip text
057: putValue(SHORT_DESCRIPTION, MailResourceLoader.getString(
058: "menu", "mainframe", "menu_folder_newvirtualfolder")
059: .replaceAll("&", ""));
060:
061: // icons
062: putValue(SMALL_ICON, ImageLoader
063: .getSmallIcon("folder-saved-search.png"));
064: putValue(LARGE_ICON, ImageLoader
065: .getIcon("folder-saved-search.png"));
066:
067: // shortcut key
068: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
069: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
070: | ActionEvent.SHIFT_MASK));
071:
072: setEnabled(false);
073:
074: ((MailFrameMediator) frameMediator)
075: .registerTreeSelectionListener(this );
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
082: */
083: public void actionPerformed(ActionEvent evt) {
084: CreateFolderDialog dialog = new CreateFolderDialog(
085: getFrameMediator(), null);
086:
087: String name;
088:
089: if (dialog.success()) {
090: // ok pressed
091: name = dialog.getName();
092:
093: try {
094: MailFolderCommandReference r = (MailFolderCommandReference) ((AbstractMailFrameController) getFrameMediator())
095: .getTreeSelection();
096:
097: VirtualFolder vfolder = (VirtualFolder) FolderFactory
098: .getInstance()
099: .createVirtualFolder(
100: (IMailFolder) r.getSourceFolder(), name);
101:
102: FolderTreeModel.getInstance().nodeStructureChanged(
103: (IMailFolder) r.getSourceFolder());
104:
105: // set parent folder uid
106: vfolder.getConfiguration().setString("property",
107: "source_uid", r.getSourceFolder().getId());
108:
109: // open search dialog
110: new SearchFrame(
111: (AbstractMailFrameController) frameMediator,
112: vfolder);
113: } catch (Exception ex) {
114: ex.printStackTrace();
115: }
116: } else {
117: // cancel pressed
118: return;
119: }
120: }
121:
122: /*
123: * (non-Javadoc)
124: *
125: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
126: */
127: public void selectionChanged(SelectionChangedEvent e) {
128: if (((TreeSelectionChangedEvent) e).getSelected().length > 0) {
129: setEnabled(true);
130: } else {
131: setEnabled(false);
132: }
133: }
134: }
|