1 package org.columba.mail.gui.config.filter.plugins; 19 20 import java.awt.GridBagConstraints ; 21 import java.awt.GridBagLayout ; 22 import java.awt.Insets ; 23 24 import javax.swing.JComponent ; 25 import javax.swing.JPanel ; 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 panel; 41 42 protected IFilterAction filterAction; 43 44 protected GridBagLayout gridbag = new GridBagLayout (); 45 46 protected GridBagConstraints c = new GridBagConstraints (); 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 (); 63 64 initComponents(); 65 66 updateComponents(true); 67 68 } 69 70 public JPanel getContentPane() { 71 return panel; 72 } 73 74 public void updateComponents(boolean b) { 75 if (b) { 76 String name = (String ) filterAction.getAction(); 77 comboMenu.setText(name); 78 } else { 79 String name = (String ) 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 [] ids = pluginHandler.getPluginIdList(); 101 for (String element : ids) { 102 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 (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 component) { 123 c.gridx = ++count; 124 gridbag.setConstraints(component, c); 125 panel.add(component); 126 } 127 128 133 public IFilterAction getFilterAction() { 134 return filterAction; 135 } 136 137 143 public void setFilterAction(IFilterAction filterAction) { 144 this.filterAction = filterAction; 145 } 146 147 150 public IFrameMediator getMediator() { 151 return mediator; 152 } 153 } | Popular Tags |