KickJava   Java API By Example, From Geeks To Geeks.

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


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.GridBagConstraints JavaDoc;
21 import java.awt.GridBagLayout JavaDoc;
22 import java.awt.Insets JavaDoc;
23
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26
27 import org.columba.api.gui.frame.IFrameMediator;
28 import org.columba.api.plugin.IExtensionHandler;
29 import org.columba.api.plugin.IExtensionInterface;
30 import org.columba.api.plugin.PluginHandlerNotFoundException;
31 import org.columba.core.filter.FilterAction;
32 import org.columba.core.filter.IFilterAction;
33 import org.columba.core.gui.base.ComboMenu;
34 import org.columba.core.gui.dialog.ErrorDialog;
35 import org.columba.core.plugin.PluginManager;
36 import org.columba.mail.gui.config.filter.ActionList;
37 import org.columba.mail.plugin.IExtensionHandlerKeys;
38
39 public class DefaultActionRow implements IExtensionInterface {
40     protected JPanel JavaDoc panel;
41
42     protected IFilterAction filterAction;
43
44     protected GridBagLayout JavaDoc gridbag = new GridBagLayout JavaDoc();
45
46     protected GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
47
48     protected ActionList actionList;
49
50     protected int count;
51
52     private IFrameMediator mediator;
53
54     private ComboMenu comboMenu;
55
56     public DefaultActionRow(IFrameMediator mediator, ActionList list,
57             IFilterAction action) {
58         this.filterAction = action;
59         this.actionList = list;
60         this.mediator = mediator;
61
62         panel = new JPanel JavaDoc();
63
64         initComponents();
65
66         updateComponents(true);
67
68     }
69
70     public JPanel JavaDoc getContentPane() {
71         return panel;
72     }
73
74     public void updateComponents(boolean b) {
75         if (b) {
76             String JavaDoc name = (String JavaDoc) filterAction.getAction();
77             comboMenu.setText(name);
78         } else {
79             String JavaDoc name = (String JavaDoc) comboMenu.getText();
80             filterAction.setAction(name);
81         }
82     }
83
84     public void initComponents() {
85         panel.removeAll();
86
87         panel.setLayout(gridbag);
88
89         IExtensionHandler pluginHandler = null;
90
91         try {
92             pluginHandler = PluginManager
93                     .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_MAIL_FILTERACTION);
94         } catch (PluginHandlerNotFoundException ex) {
95             ErrorDialog.createDialog(ex.getMessage(), ex);
96         }
97
98         
99         comboMenu = new ComboMenu();
100         String JavaDoc[] ids = pluginHandler.getPluginIdList();
101         for (String JavaDoc element : ids) {
102             // TODO localize filter action names
103
comboMenu.addMenuItem(element, element);
104         }
105         
106         comboMenu.setText(filterAction.getAction());
107         comboMenu.addItemListener(actionList);
108
109         c.fill = GridBagConstraints.VERTICAL;
110         c.weightx = 1.0;
111         c.insets = new Insets JavaDoc(2, 2, 2, 2);
112         c.gridx = 0;
113         c.anchor = GridBagConstraints.WEST;
114         c.gridwidth = 1;
115
116         gridbag.setConstraints(comboMenu, c);
117         panel.add(comboMenu);
118
119         count = 0;
120     }
121
122     public void addComponent(JComponent JavaDoc component) {
123         c.gridx = ++count;
124         gridbag.setConstraints(component, c);
125         panel.add(component);
126     }
127
128     /**
129      * Returns the filterAction.
130      *
131      * @return FilterAction
132      */

133     public IFilterAction getFilterAction() {
134         return filterAction;
135     }
136
137     /**
138      * Sets the filterAction.
139      *
140      * @param filterAction
141      * The filterAction to set
142      */

143     public void setFilterAction(IFilterAction filterAction) {
144         this.filterAction = filterAction;
145     }
146
147     /**
148      * @return Returns the mediator.
149      */

150     public IFrameMediator getMediator() {
151         return mediator;
152     }
153 }
Popular Tags