View Javadoc

1   package com.explosion.expfmodules.rdbmsconn.connectwizard.screens;
2   
3   import java.awt.BorderLayout;
4   import java.awt.GridBagConstraints;
5   import java.awt.GridBagLayout;
6   import java.awt.Insets;
7   import java.util.HashMap;
8   import java.util.List;
9   import java.util.Map;
10  
11  import javax.swing.JDialog;
12  import javax.swing.JEditorPane;
13  import javax.swing.JPanel;
14  import javax.swing.text.html.HTMLEditorKit;
15  
16  import com.explosion.expfmodules.rdbmsconn.DriverDescriptorManager;
17  import com.explosion.expfmodules.rdbmsconn.RdbmsConnConstants;
18  import com.explosion.expfmodules.wizard.StepDefinition;
19  import com.explosion.expfmodules.wizard.standard.PreferenceDataItem;
20  import com.explosion.expfmodules.wizard.standard.view.StandardStepView;
21  import com.explosion.expfmodules.wizard.standard.view.WizardBasePanel;
22  import com.explosion.utilities.GeneralConstants;
23  import com.explosion.utilities.preferences.Preference;
24  import com.explosion.utilities.preferences.PreferenceChangeEvent;
25  import com.explosion.utilities.preferences.PreferenceChangeListener;
26  import com.explosion.utilities.preferences.editandrender.form.ChoicePreferenceEditorAndRenderer;
27  import com.explosion.utilities.preferences.editandrender.form.FormBasedPreferenceRendererAndEditor;
28  import com.explosion.utilities.preferences.editandrender.form.ListChoicePreferenceEditorAndRenderer;
29  import com.explosion.utilities.preferences.groups.PreferenceGroup;
30  
31  
32  /* =============================================================================
33   *       
34   *     Copyright 2004 Stephen Cowx
35   *
36   *     Licensed under the Apache License, Version 2.0 (the "License");
37   *     you may not use this file except in compliance with the License.
38   *     You may obtain a copy of the License at
39   *
40   *     http://www.apache.org/licenses/LICENSE-2.0
41   *
42   *     Unless required by applicable law or agreed to in writing, software
43   *     distributed under the License is distributed on an "AS IS" BASIS,
44   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45   *     See the License for the specific language governing permissions and
46   *     limitations under the License.
47   * 
48   * =============================================================================
49   */
50  
51  /***
52   * @author Stephen Cowx
53   * Created on 21-Feb-2005
54   */
55  public class DriverCreateScreen extends StandardStepView implements PreferenceChangeListener
56  {
57  	private JDialog helpDialog;
58      private static org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(DriverCreateScreen.class);
59      private StepDefinition stepDefinition = null;
60      private FormBasedPreferenceRendererAndEditor filesEditor;
61      private FormBasedPreferenceRendererAndEditor classnameEditor;
62      private FormBasedPreferenceRendererAndEditor namespaceAwareEditor;
63      private FormBasedPreferenceRendererAndEditor useQuotesEditor;
64      
65      /***
66       * @see com.explosion.expfmodules.wizard.StepView#init(com.explosion.expfmodules.wizard.StepDefinition, java.awt.Component)
67       * @param stepDefinition
68       * @param parent
69       */
70      public void init(StepDefinition stepDefinition) throws Exception 
71      {
72      	Map store = new HashMap();
73      	DriverDescriptorManager manager = new DriverDescriptorManager(new HashMap());
74      	PreferenceGroup group = manager.createGroup("New driver");
75      	
76      	Preference files = group.getPreference(RdbmsConnConstants.DRVR_LOCATION);
77      	Preference classname = group.getPreference(RdbmsConnConstants.DRVR_NAME);
78      	Preference namespaceaware = group.getPreference(RdbmsConnConstants.DRVR_DB_SUPPORTS_NAMESPACES);
79      	Preference useQuotes = group.getPreference(RdbmsConnConstants.DRVR_USE_QUOTES_WITH_IDENTIFERS);
80      	
81      	PreferenceDataItem a = ((PreferenceDataItem) stepDefinition.getDataItems().get(RdbmsConnConstants.DRVR_LOCATION));
82      	PreferenceDataItem b = ((PreferenceDataItem) stepDefinition.getDataItems().get(RdbmsConnConstants.DRVR_NAME));
83      	PreferenceDataItem c = ((PreferenceDataItem) stepDefinition.getDataItems().get(RdbmsConnConstants.DRVR_DB_SUPPORTS_NAMESPACES));
84      	PreferenceDataItem d = ((PreferenceDataItem) stepDefinition.getDataItems().get(RdbmsConnConstants.DRVR_USE_QUOTES_WITH_IDENTIFERS));
85      	
86      	a.setPreference(files);
87      	b.setPreference(classname);
88      	c.setPreference(namespaceaware);
89      	d.setPreference(useQuotes);
90      	
91      	files.addPreferenceChangeListener(this);
92      	
93      	this.removeAll();
94      	this.stepDefinition = stepDefinition;
95      	JPanel inputPanel = new JPanel();
96      	JPanel helpAndDisplayPanel = new JPanel();
97      	
98      	List list = stepDefinition.getOrderedDataItems();
99      	inputPanel.removeAll();
100     	inputPanel.setLayout(new GridBagLayout());
101     	
102     	filesEditor = FormBasedPreferenceRendererAndEditor.getEditorForType(files.getType(),this.getUltimateParent(),files, a.getAttributes());
103     	inputPanel.add(	filesEditor			, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
104     	
105     	classnameEditor = FormBasedPreferenceRendererAndEditor.getEditorForType(classname.getType(),this.getUltimateParent(),classname, b.getAttributes());
106     	inputPanel.add(	classnameEditor		, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
107     	
108     	namespaceAwareEditor = FormBasedPreferenceRendererAndEditor.getEditorForType(namespaceaware.getType(),this.getUltimateParent(),namespaceaware, c.getAttributes());
109     	inputPanel.add(	namespaceAwareEditor, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
110     	
111     	useQuotesEditor = FormBasedPreferenceRendererAndEditor.getEditorForType(useQuotes.getType(),this.getUltimateParent(),useQuotes, d.getAttributes());
112     	inputPanel.add(	useQuotesEditor		, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
113     	
114     	JEditorPane name = new JEditorPane();
115     	name.setEditorKit(new HTMLEditorKit());
116     	name.setText(WizardBasePanel.FONT + stepDefinition.getName());
117     	name.setFont(GeneralConstants.DEFAULT_WINDOW_FONT);
118     	name.setOpaque(false);
119     	name.setEditable(false);		  
120     	
121     	JEditorPane notes = new JEditorPane();
122     	notes.setEditorKit(new HTMLEditorKit());
123     	notes.setText(WizardBasePanel.FONT + stepDefinition.getNotes());
124     	notes.setFont(GeneralConstants.DEFAULT_WINDOW_FONT);
125     	notes.setOpaque(false);
126     	notes.setEditable(false);
127     	
128     	helpAndDisplayPanel.removeAll();
129     	helpAndDisplayPanel.setLayout(new BorderLayout());
130     	helpAndDisplayPanel.add(name, BorderLayout.NORTH);
131     	helpAndDisplayPanel.add(notes, BorderLayout.CENTER);
132     	
133     	this.setLayout(new BorderLayout());
134     	this.add(helpAndDisplayPanel,BorderLayout.NORTH);
135     	this.add(inputPanel,BorderLayout.CENTER);
136     	
137     	stepDefinition.getWizard().getWizardDataValues().put("driver_descriptor",group);
138     }
139     
140     
141 	/***
142 	 * Resets the driverclassname list box with the correct values
143 	 */
144 	public void preferenceChanged(PreferenceChangeEvent preferenceChangeEvent) {
145 		if (classnameEditor instanceof ListChoicePreferenceEditorAndRenderer)
146 		   ((ListChoicePreferenceEditorAndRenderer) classnameEditor).choicesUpdated();
147 		else if (classnameEditor instanceof ChoicePreferenceEditorAndRenderer)
148 			   ((ChoicePreferenceEditorAndRenderer) classnameEditor).choicesUpdated();
149 		
150 	}
151 }