1 package com.explosion.expfmodules.rdbmsconn.connectwizard.screens;
2
3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.util.Vector;
6
7 import javax.swing.JEditorPane;
8 import javax.swing.JList;
9 import javax.swing.JPanel;
10 import javax.swing.JScrollPane;
11 import javax.swing.event.ListSelectionEvent;
12 import javax.swing.event.ListSelectionListener;
13 import javax.swing.text.html.HTMLEditorKit;
14
15 import com.explosion.expfmodules.rdbmsconn.RdbmsConnModuleManager;
16 import com.explosion.expfmodules.wizard.StepDefinition;
17 import com.explosion.expfmodules.wizard.standard.PreferenceDataItem;
18 import com.explosion.expfmodules.wizard.standard.view.StandardStepView;
19 import com.explosion.expfmodules.wizard.standard.view.WizardBasePanel;
20 import com.explosion.utilities.GeneralConstants;
21 import com.explosion.utilities.exception.ExceptionManagerFactory;
22 import com.explosion.utilities.preferences.Preference;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 /***
45 * @author Stephen Cowx
46 * Created on 21-Feb-2005
47 */
48 public class DriverChoiceScreen extends StandardStepView
49 {
50
51 private static org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(DriverChoiceScreen.class);
52 private JList comboBox = null;
53 private String[] driverList = null;
54 private StepDefinition stepDefinition = null;
55
56 /***
57 * @see com.explosion.expfmodules.wizard.StepView#init(com.explosion.expfmodules.wizard.StepDefinition, java.awt.Component)
58 * @param stepDefinition
59 * @param parent
60 */
61 public void init(StepDefinition stepDefinition)
62 {
63 this.removeAll();
64 JPanel inputPanel = new JPanel();
65 JPanel helpAndDisplayPanel = new JPanel();
66
67 log.debug("Called init");
68
69 if (driverList == null)
70 {
71 Vector drivers = RdbmsConnModuleManager.instance().getDriverDescriptorManager().getIdentifiers();
72 driverList = new String[drivers.size()+1];
73 driverList[0] = "Configure new driver...";
74 for (int i=1;i-1<drivers.size();i++)
75 {
76 driverList[i] = drivers.elementAt(i-1).toString();
77 }
78 }
79
80 this.stepDefinition = stepDefinition;
81 comboBox = new JList(driverList);
82
83 comboBox.setSelectedIndex(0);
84
85 try
86 {
87 PreferenceDataItem item = (PreferenceDataItem) stepDefinition.getDataItems().get("driver");
88 Preference pref = item.getPreference();
89 pref.setValue(comboBox.getSelectedValue());
90 stepDefinition.getDataItems().put("driver", item);
91 }
92 catch (Exception e1)
93 {
94 ExceptionManagerFactory.getExceptionManager().manageException(e1,"Exception caught while setting value of preference");
95 }
96
97 comboBox.addListSelectionListener(new ListSelectionListener(){
98 public void valueChanged(ListSelectionEvent e) {
99 choiceUpdated();
100 }
101 });
102
103 inputPanel.add(new JScrollPane(comboBox), FlowLayout.LEFT);
104
105 JEditorPane name = new JEditorPane();
106 name.setEditorKit(new HTMLEditorKit());
107 name.setText(WizardBasePanel.FONT + stepDefinition.getName());
108 name.setFont(GeneralConstants.DEFAULT_WINDOW_FONT);
109 name.setOpaque(false);
110 name.setEditable(false);
111
112 JEditorPane notes = new JEditorPane();
113 notes.setEditorKit(new HTMLEditorKit());
114 notes.setText(WizardBasePanel.FONT + stepDefinition.getNotes());
115 notes.setFont(GeneralConstants.DEFAULT_WINDOW_FONT);
116 notes.setOpaque(false);
117 notes.setEditable(false);
118
119 helpAndDisplayPanel.removeAll();
120 helpAndDisplayPanel.setLayout(new BorderLayout());
121 helpAndDisplayPanel.add(name, BorderLayout.NORTH);
122 helpAndDisplayPanel.add(notes, BorderLayout.CENTER);
123
124 this.setLayout(new BorderLayout());
125 this.add(helpAndDisplayPanel,BorderLayout.NORTH);
126 this.add(inputPanel,BorderLayout.CENTER);
127 }
128
129 /***
130 * @throws Exception
131 */
132 private void choiceUpdated() {
133 log.debug("choiceUpdated");
134 try {
135 PreferenceDataItem item = (PreferenceDataItem) stepDefinition.getDataItems().get("driver");
136 Preference pref = item.getPreference();
137 pref.setValue(comboBox.getSelectedValue());
138 } catch (Exception e) {
139 ExceptionManagerFactory.getExceptionManager().manageException(e, "Exception caught while updating preference.");
140 }
141 }
142
143 }