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.JComponent;
025: import javax.swing.JPanel;
026:
027: import org.columba.api.gui.frame.IFrameMediator;
028: import org.columba.api.plugin.IExtensionHandler;
029: import org.columba.api.plugin.IExtensionInterface;
030: import org.columba.api.plugin.PluginHandlerNotFoundException;
031: import org.columba.core.filter.FilterAction;
032: import org.columba.core.filter.IFilterAction;
033: import org.columba.core.gui.base.ComboMenu;
034: import org.columba.core.gui.dialog.ErrorDialog;
035: import org.columba.core.plugin.PluginManager;
036: import org.columba.mail.gui.config.filter.ActionList;
037: import org.columba.mail.plugin.IExtensionHandlerKeys;
038:
039: public class DefaultActionRow implements IExtensionInterface {
040: protected JPanel panel;
041:
042: protected IFilterAction filterAction;
043:
044: protected GridBagLayout gridbag = new GridBagLayout();
045:
046: protected GridBagConstraints c = new GridBagConstraints();
047:
048: protected ActionList actionList;
049:
050: protected int count;
051:
052: private IFrameMediator mediator;
053:
054: private ComboMenu comboMenu;
055:
056: public DefaultActionRow(IFrameMediator mediator, ActionList list,
057: IFilterAction action) {
058: this .filterAction = action;
059: this .actionList = list;
060: this .mediator = mediator;
061:
062: panel = new JPanel();
063:
064: initComponents();
065:
066: updateComponents(true);
067:
068: }
069:
070: public JPanel getContentPane() {
071: return panel;
072: }
073:
074: public void updateComponents(boolean b) {
075: if (b) {
076: String name = (String) filterAction.getAction();
077: comboMenu.setText(name);
078: } else {
079: String name = (String) comboMenu.getText();
080: filterAction.setAction(name);
081: }
082: }
083:
084: public void initComponents() {
085: panel.removeAll();
086:
087: panel.setLayout(gridbag);
088:
089: IExtensionHandler pluginHandler = null;
090:
091: try {
092: pluginHandler = PluginManager
093: .getInstance()
094: .getExtensionHandler(
095: IExtensionHandlerKeys.ORG_COLUMBA_MAIL_FILTERACTION);
096: } catch (PluginHandlerNotFoundException ex) {
097: ErrorDialog.createDialog(ex.getMessage(), ex);
098: }
099:
100: comboMenu = new ComboMenu();
101: String[] ids = pluginHandler.getPluginIdList();
102: for (String element : ids) {
103: // TODO localize filter action names
104: comboMenu.addMenuItem(element, element);
105: }
106:
107: comboMenu.setText(filterAction.getAction());
108: comboMenu.addItemListener(actionList);
109:
110: c.fill = GridBagConstraints.VERTICAL;
111: c.weightx = 1.0;
112: c.insets = new Insets(2, 2, 2, 2);
113: c.gridx = 0;
114: c.anchor = GridBagConstraints.WEST;
115: c.gridwidth = 1;
116:
117: gridbag.setConstraints(comboMenu, c);
118: panel.add(comboMenu);
119:
120: count = 0;
121: }
122:
123: public void addComponent(JComponent component) {
124: c.gridx = ++count;
125: gridbag.setConstraints(component, c);
126: panel.add(component);
127: }
128:
129: /**
130: * Returns the filterAction.
131: *
132: * @return FilterAction
133: */
134: public IFilterAction getFilterAction() {
135: return filterAction;
136: }
137:
138: /**
139: * Sets the filterAction.
140: *
141: * @param filterAction
142: * The filterAction to set
143: */
144: public void setFilterAction(IFilterAction filterAction) {
145: this .filterAction = filterAction;
146: }
147:
148: /**
149: * @return Returns the mediator.
150: */
151: public IFrameMediator getMediator() {
152: return mediator;
153: }
154: }
|