1 19 package org.columba.mail.gui.config.mailboximport; 20 21 import java.awt.BorderLayout ; 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.Insets ; 25 import java.lang.reflect.Method ; 26 27 import javax.swing.JComponent ; 28 import javax.swing.JList ; 29 import javax.swing.JPanel ; 30 import javax.swing.JScrollPane ; 31 import javax.swing.event.ListSelectionEvent ; 32 import javax.swing.event.ListSelectionListener ; 33 34 import net.javaprog.ui.wizard.AbstractStep; 35 import net.javaprog.ui.wizard.DataModel; 36 import net.javaprog.ui.wizard.DefaultDataLookup; 37 38 import org.columba.api.plugin.IExtension; 39 import org.columba.api.plugin.IExtensionHandler; 40 import org.columba.api.plugin.PluginException; 41 import org.columba.core.gui.base.MultiLineLabel; 42 import org.columba.core.logging.Logging; 43 import org.columba.mail.folder.mailboximport.AbstractMailboxImporter; 44 import org.columba.mail.util.MailResourceLoader; 45 46 class PluginStep extends AbstractStep implements ListSelectionListener { 47 protected DataModel data; 48 49 protected MultiLineLabel descriptionLabel; 50 51 private IExtensionHandler pluginHandler; 52 53 public PluginStep(DataModel data) { 54 super( 55 MailResourceLoader.getString("dialog", "mailboximport", 56 "plugin"), MailResourceLoader.getString("dialog", 57 "mailboximport", "plugin_description")); 58 this.data = data; 59 pluginHandler = (IExtensionHandler) data.getData("Plugin.handler"); 60 } 61 62 protected JComponent createComponent() { 63 descriptionLabel = new MultiLineLabel("description"); 64 65 JList list = new JList (pluginHandler.getPluginIdList()); 66 list.setCellRenderer(new PluginListCellRenderer()); 67 68 JComponent component = new JPanel (new BorderLayout (0, 30)); 69 component.add(new MultiLineLabel(MailResourceLoader.getString("dialog", 70 "mailboximport", "plugin_text")), BorderLayout.NORTH); 71 72 JPanel middlePanel = new JPanel (); 73 middlePanel.setAlignmentX(1); 74 75 GridBagLayout layout = new GridBagLayout (); 76 middlePanel.setLayout(layout); 77 78 Method method = null; 79 try { 80 method = list.getClass().getMethod("getSelectedValue", null); 81 } catch (NoSuchMethodException nsme) { 82 } 83 data.registerDataLookup("Plugin.ID", new DefaultDataLookup(list, 84 method, null)); 85 list.addListSelectionListener(this); 86 list.setSelectedIndex(0); 87 88 JScrollPane scrollPane = new JScrollPane (list); 89 scrollPane 90 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 91 92 GridBagConstraints c = new GridBagConstraints (); 93 c.anchor = GridBagConstraints.NORTHWEST; 94 c.gridx = 0; 95 c.fill = GridBagConstraints.BOTH; 96 c.weightx = 0.4; 97 98 c.weighty = 1.0; 100 layout.setConstraints(scrollPane, c); 101 middlePanel.add(scrollPane); 102 103 c.gridwidth = GridBagConstraints.REMAINDER; 104 c.weightx = 0.6; 105 c.gridx = 1; 106 c.anchor = GridBagConstraints.NORTHWEST; 107 c.insets = new Insets (0, 10, 0, 0); 108 109 JScrollPane scrollPane2 = new JScrollPane (descriptionLabel); 110 scrollPane2 111 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 112 113 layout.setConstraints(scrollPane2, c); 114 middlePanel.add(scrollPane2); 115 component.add(middlePanel); 116 117 return component; 118 } 119 120 public void valueChanged(ListSelectionEvent event) { 121 AbstractMailboxImporter importer; 123 try { 124 IExtension extension = pluginHandler.getExtension((String ) data 125 .getData("Plugin.ID")); 126 127 importer = (AbstractMailboxImporter) extension 128 .instanciateExtension(null); 129 String description = importer.getDescription(); 130 descriptionLabel.setText(description); 131 } catch (PluginException e) { 132 if (Logging.DEBUG) { 133 e.printStackTrace(); 134 } 135 } 136 } 137 138 public void prepareRendering() { 139 } 140 } 141 | Popular Tags |