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:
019: package org.columba.addressbook.gui.dialog.importfilter;
020:
021: import java.awt.BorderLayout;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.Insets;
025: import java.lang.reflect.Method;
026:
027: import javax.swing.JComponent;
028: import javax.swing.JList;
029: import javax.swing.JPanel;
030: import javax.swing.JScrollPane;
031: import javax.swing.event.ListSelectionEvent;
032: import javax.swing.event.ListSelectionListener;
033:
034: import net.javaprog.ui.wizard.AbstractStep;
035: import net.javaprog.ui.wizard.DataModel;
036: import net.javaprog.ui.wizard.DefaultDataLookup;
037:
038: import org.columba.addressbook.folder.importfilter.DefaultAddressbookImporter;
039: import org.columba.addressbook.util.AddressbookResourceLoader;
040: import org.columba.api.plugin.IExtension;
041: import org.columba.api.plugin.IExtensionHandler;
042: import org.columba.core.gui.base.MultiLineLabel;
043:
044: class PluginStep extends AbstractStep implements ListSelectionListener {
045: protected DataModel data;
046:
047: private MultiLineLabel descriptionLabel;
048:
049: private IExtensionHandler pluginHandler;
050:
051: public PluginStep(DataModel data) {
052: super (AddressbookResourceLoader.getString("dialog",
053: "addressbookimport", "plugin"),
054: AddressbookResourceLoader.getString("dialog",
055: "addressbookimport", "plugin_description"));
056: this .data = data;
057: pluginHandler = (IExtensionHandler) data
058: .getData("Plugin.handler");
059: }
060:
061: protected JComponent createComponent() {
062: JList list = new JList(pluginHandler.getPluginIdList());
063: list.setCellRenderer(new PluginListCellRenderer());
064:
065: descriptionLabel = new MultiLineLabel("description");
066:
067: JComponent component = new JPanel(new BorderLayout());
068: component.setLayout(new BorderLayout(0, 30));
069: component.add(new MultiLineLabel(
070: AddressbookResourceLoader.getString("dialog",
071: "addressbookimport", "plugin_text")),
072: BorderLayout.NORTH);
073:
074: JPanel middlePanel = new JPanel();
075: middlePanel.setAlignmentX(1);
076:
077: GridBagLayout layout = new GridBagLayout();
078: middlePanel.setLayout(layout);
079:
080: Method method = null;
081:
082: try {
083: method = list.getClass()
084: .getMethod("getSelectedValue", null);
085: } catch (NoSuchMethodException nsme) {
086: }
087:
088: data.registerDataLookup("Plugin.ID", new DefaultDataLookup(
089: list, method, null));
090: list.addListSelectionListener(this );
091: list.setSelectedIndex(0);
092:
093: JScrollPane scrollPane = new JScrollPane(list);
094: scrollPane
095: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
096:
097: // scrollPane.setPreferredSize( new Dimension(200,200) );
098: GridBagConstraints c = new GridBagConstraints();
099: c.anchor = GridBagConstraints.NORTHWEST;
100: c.gridx = 0;
101: c.fill = GridBagConstraints.BOTH;
102: c.weightx = 0.4;
103:
104: // c.gridwidth = GridBagConstraints.RELATIVE;
105: c.weighty = 1.0;
106: layout.setConstraints(scrollPane, c);
107: middlePanel.add(scrollPane);
108:
109: c.gridwidth = GridBagConstraints.REMAINDER;
110: c.weightx = 0.6;
111: c.gridx = 1;
112: c.anchor = GridBagConstraints.NORTHWEST;
113: c.insets = new Insets(0, 10, 0, 0);
114:
115: JScrollPane scrollPane2 = new JScrollPane(descriptionLabel);
116:
117: scrollPane2
118: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
119: layout.setConstraints(scrollPane2, c);
120: middlePanel.add(scrollPane2);
121: component.add(middlePanel);
122:
123: return component;
124: }
125:
126: public void valueChanged(ListSelectionEvent event) {
127: try {
128: // adjust description field
129: IExtension extension = pluginHandler
130: .getExtension((String) data.getData("Plugin.ID"));
131:
132: DefaultAddressbookImporter importer = (DefaultAddressbookImporter) extension
133: .instanciateExtension(null);
134:
135: String description = importer.getDescription();
136: descriptionLabel.setText(description);
137: } catch (Exception e) {
138: e.printStackTrace();
139: ((JList) event.getSource()).clearSelection();
140: }
141: }
142:
143: public void prepareRendering() {
144: }
145: }
|