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.GridBagConstraints;
021: import java.awt.GridBagLayout;
022: import java.awt.Insets;
023:
024: import javax.swing.JButton;
025: import javax.swing.JComponent;
026: import javax.swing.JPanel;
027:
028: import org.columba.api.plugin.IExtensionHandler;
029: import org.columba.api.plugin.IExtensionInterface;
030: import org.columba.core.filter.FilterCriteria;
031: import org.columba.core.gui.base.ComboMenu;
032: import org.columba.mail.gui.config.filter.CriteriaList;
033:
034: public class DefaultCriteriaRow implements IExtensionInterface {
035:
036: protected FilterCriteria criteria;
037:
038: protected CriteriaList criteriaList;
039:
040: protected JPanel panel;
041:
042: protected JButton removeButton;
043:
044: protected GridBagLayout gridbag = new GridBagLayout();
045:
046: protected GridBagConstraints c = new GridBagConstraints();
047:
048: IExtensionHandler pluginHandler;
049:
050: protected int count;
051:
052: private ComboMenu comboMenu;
053:
054: public DefaultCriteriaRow(IExtensionHandler pluginHandler,
055: CriteriaList criteriaList, FilterCriteria c) {
056: this .pluginHandler = pluginHandler;
057:
058: this .criteria = c;
059: this .criteriaList = criteriaList;
060:
061: panel = new JPanel();
062:
063: initComponents();
064:
065: updateComponents(true);
066:
067: }
068:
069: public void updateComponents(boolean b) {
070: if (b) {
071: String conditionString = criteria.getTypeString();
072:
073: comboMenu.setText(conditionString);
074:
075: } else {
076:
077: String conditionString = comboMenu.getText();
078: criteria.setTypeString(conditionString);
079:
080: }
081: }
082:
083: public void initComponents() {
084: panel.setLayout(gridbag);
085:
086: comboMenu = new ComboMenu();
087: String[] ids = pluginHandler.getPluginIdList();
088: for (String element : ids) {
089: // TODO localize filter action names
090: comboMenu.addMenuItem(element, element);
091: }
092: comboMenu.setText(criteria.getTypeString());
093: comboMenu.addItemListener(criteriaList);
094:
095: c.fill = GridBagConstraints.VERTICAL;
096: c.weightx = 1.0;
097: c.insets = new Insets(2, 2, 2, 2);
098: c.gridx = 0;
099: c.anchor = GridBagConstraints.WEST;
100: c.gridwidth = 1;
101:
102: gridbag.setConstraints(comboMenu, c);
103:
104: panel.add(comboMenu);
105:
106: count = 0;
107: }
108:
109: public JPanel getContentPane() {
110: return panel;
111: }
112:
113: public void addComponent(JComponent component) {
114: c.gridx = ++count;
115: gridbag.setConstraints(component, c);
116: panel.add(component);
117: }
118:
119: /**
120: * Returns the criteria.
121: *
122: * @return FilterCriteria
123: */
124: public FilterCriteria getCriteria() {
125: return criteria;
126: }
127:
128: /**
129: * Returns the pluginHandler.
130: *
131: * @return AbstractPluginHandler
132: */
133: public IExtensionHandler getPluginHandler() {
134: return pluginHandler;
135: }
136:
137: /**
138: * Sets the pluginHandler.
139: *
140: * @param pluginHandler
141: * The pluginHandler to set
142: */
143: public void setPluginHandler(IExtensionHandler pluginHandler) {
144: this.pluginHandler = pluginHandler;
145: }
146:
147: }
|