KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > filter > plugins > FolderChooserActionRow


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.config.filter.plugins;
19
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22
23 import javax.swing.JButton JavaDoc;
24
25 import org.columba.api.gui.frame.IFrameMediator;
26 import org.columba.core.filter.FilterAction;
27 import org.columba.mail.folder.IMailFolder;
28 import org.columba.mail.folder.IMailbox;
29 import org.columba.mail.gui.config.filter.ActionList;
30 import org.columba.mail.gui.tree.FolderTreeModel;
31 import org.columba.mail.gui.tree.util.SelectFolderDialog;
32 import org.columba.mail.gui.tree.util.TreeNodeList;
33
34 public class FolderChooserActionRow extends DefaultActionRow implements
35         ActionListener JavaDoc {
36     private JButton JavaDoc treePathButton;
37
38     public FolderChooserActionRow(IFrameMediator mediator, ActionList list,
39             FilterAction action) {
40         super(mediator, list, action);
41
42     }
43
44     public void updateComponents(boolean b) {
45         super.updateComponents(b);
46
47         if (b) {
48             String JavaDoc uid = filterAction.getUid();
49             IMailbox folder = (IMailbox) FolderTreeModel.getInstance()
50                     .getFolder(uid);
51             if (folder == null) {
52                 // couldn't find folder associated with this uid
53
// -> open the select folder dialog
54
promptUserForFolder();
55             } else {
56
57                 String JavaDoc treePath = folder.getTreePath();
58
59                 treePathButton.setText(treePath);
60             }
61         } else {
62             String JavaDoc treePath = treePathButton.getText();
63             TreeNodeList list = new TreeNodeList(treePath);
64             IMailbox folder = (IMailbox) FolderTreeModel
65                     .getInstance().getFolder(list);
66
67             if (folder == null) {
68                 // user didn't select any folder
69
// -> make Inbox the default folder
70
folder = (IMailbox) FolderTreeModel.getInstance()
71                         .getFolder("101");
72             }
73
74             String JavaDoc uid = folder.getId();
75             filterAction.setUid(uid);
76         }
77     }
78
79     public void initComponents() {
80         super.initComponents();
81
82         treePathButton = new JButton JavaDoc();
83
84         // treePathButton.setMargin(new Insets(0,0,0,0));
85
treePathButton.addActionListener(this);
86         treePathButton.setActionCommand("TREEPATH");
87
88         addComponent(treePathButton);
89     }
90
91     public void actionPerformed(ActionEvent JavaDoc e) {
92         String JavaDoc action = e.getActionCommand();
93
94         if (action.equals("TREEPATH")) {
95             promptUserForFolder();
96         }
97     }
98
99     private void promptUserForFolder() {
100         SelectFolderDialog dialog = new SelectFolderDialog(getMediator());
101
102         if (dialog.success()) {
103             IMailFolder folder = (IMailFolder) dialog.getSelectedFolder();
104
105             String JavaDoc treePath = folder.getTreePath();
106
107             treePathButton.setText(treePath);
108         }
109     }
110 }
Popular Tags