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.config.filter.plugins;
019:
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022:
023: import javax.swing.JButton;
024:
025: import org.columba.api.gui.frame.IFrameMediator;
026: import org.columba.core.filter.FilterAction;
027: import org.columba.mail.folder.IMailFolder;
028: import org.columba.mail.folder.IMailbox;
029: import org.columba.mail.gui.config.filter.ActionList;
030: import org.columba.mail.gui.tree.FolderTreeModel;
031: import org.columba.mail.gui.tree.util.SelectFolderDialog;
032: import org.columba.mail.gui.tree.util.TreeNodeList;
033:
034: public class FolderChooserActionRow extends DefaultActionRow implements
035: ActionListener {
036: private JButton treePathButton;
037:
038: public FolderChooserActionRow(IFrameMediator mediator,
039: ActionList list, FilterAction action) {
040: super (mediator, list, action);
041:
042: }
043:
044: public void updateComponents(boolean b) {
045: super .updateComponents(b);
046:
047: if (b) {
048: String uid = filterAction.getUid();
049: IMailbox folder = (IMailbox) FolderTreeModel.getInstance()
050: .getFolder(uid);
051: if (folder == null) {
052: // couldn't find folder associated with this uid
053: // -> open the select folder dialog
054: promptUserForFolder();
055: } else {
056:
057: String treePath = folder.getTreePath();
058:
059: treePathButton.setText(treePath);
060: }
061: } else {
062: String treePath = treePathButton.getText();
063: TreeNodeList list = new TreeNodeList(treePath);
064: IMailbox folder = (IMailbox) FolderTreeModel.getInstance()
065: .getFolder(list);
066:
067: if (folder == null) {
068: // user didn't select any folder
069: // -> make Inbox the default folder
070: folder = (IMailbox) FolderTreeModel.getInstance()
071: .getFolder("101");
072: }
073:
074: String uid = folder.getId();
075: filterAction.setUid(uid);
076: }
077: }
078:
079: public void initComponents() {
080: super .initComponents();
081:
082: treePathButton = new JButton();
083:
084: // treePathButton.setMargin(new Insets(0,0,0,0));
085: treePathButton.addActionListener(this );
086: treePathButton.setActionCommand("TREEPATH");
087:
088: addComponent(treePathButton);
089: }
090:
091: public void actionPerformed(ActionEvent e) {
092: String action = e.getActionCommand();
093:
094: if (action.equals("TREEPATH")) {
095: promptUserForFolder();
096: }
097: }
098:
099: private void promptUserForFolder() {
100: SelectFolderDialog dialog = new SelectFolderDialog(
101: getMediator());
102:
103: if (dialog.success()) {
104: IMailFolder folder = (IMailFolder) dialog
105: .getSelectedFolder();
106:
107: String treePath = folder.getTreePath();
108:
109: treePathButton.setText(treePath);
110: }
111: }
112: }
|