KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > mailboximport > PluginStep


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18

19 package org.columba.mail.gui.config.mailboximport;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JScrollPane JavaDoc;
31 import javax.swing.event.ListSelectionEvent JavaDoc;
32 import javax.swing.event.ListSelectionListener JavaDoc;
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 JavaDoc {
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 JavaDoc createComponent() {
63         descriptionLabel = new MultiLineLabel("description");
64
65         JList JavaDoc list = new JList JavaDoc(pluginHandler.getPluginIdList());
66         list.setCellRenderer(new PluginListCellRenderer());
67
68         JComponent JavaDoc component = new JPanel JavaDoc(new BorderLayout JavaDoc(0, 30));
69         component.add(new MultiLineLabel(MailResourceLoader.getString("dialog",
70                 "mailboximport", "plugin_text")), BorderLayout.NORTH);
71
72         JPanel JavaDoc middlePanel = new JPanel JavaDoc();
73         middlePanel.setAlignmentX(1);
74
75         GridBagLayout JavaDoc layout = new GridBagLayout JavaDoc();
76         middlePanel.setLayout(layout);
77
78         Method JavaDoc method = null;
79         try {
80             method = list.getClass().getMethod("getSelectedValue", null);
81         } catch (NoSuchMethodException JavaDoc nsme) {
82         }
83         data.registerDataLookup("Plugin.ID", new DefaultDataLookup(list,
84                 method, null));
85         list.addListSelectionListener(this);
86         list.setSelectedIndex(0);
87
88         JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(list);
89         scrollPane
90                 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
91
92         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
93         c.anchor = GridBagConstraints.NORTHWEST;
94         c.gridx = 0;
95         c.fill = GridBagConstraints.BOTH;
96         c.weightx = 0.4;
97
98         // c.gridwidth = GridBagConstraints.RELATIVE;
99
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 JavaDoc(0, 10, 0, 0);
108
109         JScrollPane JavaDoc scrollPane2 = new JScrollPane JavaDoc(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 JavaDoc event) {
121         // adjust description field
122
AbstractMailboxImporter importer;
123         try {
124             IExtension extension = pluginHandler.getExtension((String JavaDoc) data
125                     .getData("Plugin.ID"));
126
127             importer = (AbstractMailboxImporter) extension
128                     .instanciateExtension(null);
129             String JavaDoc 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