View Javadoc

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   *     Copyright 2004 Stephen Cowx
28   *
29   *     Licensed under the Apache License, Version 2.0 (the "License");
30   *     you may not use this file except in compliance with the License.
31   *     You may obtain a copy of the License at
32   *
33   *     http://www.apache.org/licenses/LICENSE-2.0
34   *
35   *     Unless required by applicable law or agreed to in writing, software
36   *     distributed under the License is distributed on an "AS IS" BASIS,
37   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38   *     See the License for the specific language governing permissions and
39   *     limitations under the License.
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          //There will alwyas be at least one - "Configure new driver..."
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 }