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