KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > CPVendorPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * CPVendorPanel.java -- synopsis.
21  *
22  */

23
24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 import java.awt.event.KeyEvent JavaDoc;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.util.Vector JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import javax.swing.JComponent JavaDoc;
33 import javax.swing.KeyStroke JavaDoc;
34 import javax.swing.ButtonGroup JavaDoc;
35 import javax.swing.event.ChangeListener JavaDoc;
36 import javax.swing.event.ListDataListener JavaDoc;
37 import javax.swing.event.DocumentListener JavaDoc;
38 import org.netbeans.api.db.explorer.ConnectionManager;
39 import org.netbeans.api.db.explorer.DatabaseConnection;
40
41 import org.openide.util.HelpCtx;
42 import org.openide.loaders.TemplateWizard;
43
44 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
45 import org.netbeans.modules.j2ee.sun.sunresources.beans.Field;
46 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
47 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
48 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper;
49 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper;
50 import org.openide.WizardDescriptor;
51 import org.openide.filesystems.FileObject;
52
53 public class CPVendorPanel extends ResourceWizardPanel implements ChangeListener JavaDoc, DocumentListener JavaDoc, ListDataListener JavaDoc {
54     
55     static final long serialVersionUID = 93474632245456421L;
56     
57     private ArrayList JavaDoc dbconns;
58     private ResourceConfigHelper helper;
59     private FieldGroup generalGroup, propGroup, vendorGroup;
60     private boolean useExistingConnection = true;
61     private String JavaDoc[] vendors;
62     private boolean firstTime = true;
63     private boolean setupValid = true;
64     
65     private static final String JavaDoc CONST_TRUE = "true"; // NOI18N
66

67     /** Creates new form DBSchemaConnectionpanel */
68     public CPVendorPanel(ResourceConfigHelper helper, Wizard wiardInfo) {
69         this.firstTime = true;
70         this.helper = helper;
71         this.generalGroup = FieldGroupHelper.getFieldGroup(wiardInfo, __General);
72         this.propGroup = FieldGroupHelper.getFieldGroup(wiardInfo, __Properties);
73         this.vendorGroup = FieldGroupHelper.getFieldGroup(wiardInfo, __PropertiesURL);
74         ButtonGroup JavaDoc bg = new ButtonGroup JavaDoc();
75         dbconns = new ArrayList JavaDoc();
76         
77         setName(bundle.getString("TITLE_ConnPoolWizardPanel_dbConn")); //NOI18N
78

79         initComponents ();
80         initAccessibility();
81         
82         nameLabel.setLabelFor(nameField);
83         nameLabel.setDisplayedMnemonic(bundle.getString("LBL_pool-name_Mnemonic").charAt(0)); //NOI18N
84
existingConnRadioButton.setMnemonic(bundle.getString("ExistingConnection_Mnemonic").charAt(0)); //NOI18N
85
newCofigRadioButton.setMnemonic(bundle.getString("NewConfiguration_Mnemonic").charAt(0)); //NOI18N
86
isXA.setMnemonic(bundle.getString("isXA_Mnemonic").charAt(0)); //NOI18N
87

88         nameComboBox.registerKeyboardAction(new ActionListener JavaDoc() {
89                 public void actionPerformed(ActionEvent JavaDoc e) {
90                     nameComboBox.requestFocus();
91                 }
92             }, KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
93
94         bg.add(existingConnRadioButton);
95         bg.add(newCofigRadioButton);
96         bg.getSelection().addChangeListener(this);
97         try{
98             DatabaseConnection[] cons = ConnectionManager.getDefault().getConnections();
99             for(int i=0; i < cons.length; i++){
100                 existingConnComboBox.addItem(cons[i].getName());
101                 dbconns.add(cons[i]);
102             }
103         }catch(Exception JavaDoc ex){
104             // Connection could not be found
105
}
106         if (existingConnComboBox.getItemCount() == 0) {
107             existingConnComboBox.insertItemAt(bundle.getString("NoConnection"), 0); //NOI18N
108
newCofigRadioButton.setSelected(true);
109         } else {
110             existingConnComboBox.insertItemAt(bundle.getString("SelectFromTheList"), 0); //NOI18N
111
existingConnRadioButton.setSelected(true);
112             setExistingConnData();
113         }
114         
115         //String vendorName = "other"; //NOI18N
116
existingConnRadioButton.setEnabled(true);
117         existingConnComboBox.setEnabled(true);
118         newCofigRadioButton.setEnabled(true);
119         nameComboBox.setEnabled(true);
120         
121         Field vendorField = FieldHelper.getField(this.generalGroup, __DatabaseVendor);
122         vendors = FieldHelper.getTags(vendorField);
123         for (int i = 0; i < vendors.length; i++) {
124             nameComboBox.addItem(bundle.getString("DBVendor_" + vendors[i])); //NOI18N
125
}
126         
127         if (nameComboBox.getItemCount() == 0)
128             nameComboBox.insertItemAt(bundle.getString("NoTemplate"), 0); //NOI18N
129
else
130             nameComboBox.insertItemAt(bundle.getString("SelectFromTheList"), 0); //NOI18N
131
nameComboBox.setSelectedIndex(0);
132         
133         existingConnComboBox.getModel().addListDataListener(this);
134         nameComboBox.getModel().addListDataListener(this);
135         isXA.setSelected(helper.getData().getString(__IsXA).equals(CONST_TRUE)); //NOI18N
136
isXA.addChangeListener(this);
137         newCofigRadioButton.addChangeListener(this);
138         
139         getAccessibleContext().setAccessibleName(bundle.getString("TITLE_ConnPoolWizardPanel_dbConn"));
140         getAccessibleContext().setAccessibleDescription(bundle.getString("TITLE_ConnPoolWizardPanel_dbConn"));
141         
142         this.firstTime = false;
143     }
144     
145     private void initAccessibility(){
146         descriptionTextArea.getAccessibleContext().setAccessibleName(bundle.getString("ACS_DescriptionA11yName")); // NOI18N
147
descriptionTextArea.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_DescriptionA11yDesc")); // NOI18N
148

149         nameLabel.getAccessibleContext().setAccessibleDescription(bundle.getString("ToolTip_pool-name")); //NOI18N
150
nameField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_pool-nameA11yDesc")); //NOI18N
151

152         existingConnRadioButton.getAccessibleContext().setAccessibleName(bundle.getString("ExistingConnection")); //NOI18N
153
existingConnRadioButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ExistingConnectionA11yDesc")); //NOI18N
154
existingConnComboBox.getAccessibleContext().setAccessibleName(bundle.getString("ACS_ExistingConnectionComboBoxA11yName")); // NOI18N
155
existingConnComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ExistingConnectionComboBoxA11yDesc")); // NOI18N
156

157         newCofigRadioButton.getAccessibleContext().setAccessibleName(bundle.getString("NewConfiguration")); //NOI18N
158
newCofigRadioButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_NewConnectionA11yDesc")); //NOI18N
159
nameComboBox.getAccessibleContext().setAccessibleName(bundle.getString("ACS_NewConnectionComboBoxA11yName")); // NOI18N
160
nameComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_NewConnectionComboBoxA11yDesc")); // NOI18N
161

162         isXA.getAccessibleContext().setAccessibleName(bundle.getString("isXA")); //NOI18N
163
isXA.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_isXA_A11yDesc")); //NOI18N
164
}
165     
166     /** This method is called from within the constructor to
167      * initialize the form.
168      * WARNING: Do NOT modify this code. The content of this method is
169      * always regenerated by the FormEditor.
170      */

171     private void initComponents() {//GEN-BEGIN:initComponents
172
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
173
174         descriptionTextArea = new javax.swing.JTextArea JavaDoc();
175         jPanel1 = new javax.swing.JPanel JavaDoc();
176         nameLabel = new javax.swing.JLabel JavaDoc();
177         nameField = new javax.swing.JTextField JavaDoc();
178         existingConnRadioButton = new javax.swing.JRadioButton JavaDoc();
179         existingConnComboBox = new javax.swing.JComboBox JavaDoc();
180         newCofigRadioButton = new javax.swing.JRadioButton JavaDoc();
181         nameComboBox = new javax.swing.JComboBox JavaDoc();
182         isXA = new javax.swing.JCheckBox JavaDoc();
183
184         setLayout(new java.awt.GridBagLayout JavaDoc());
185
186         setMaximumSize(new java.awt.Dimension JavaDoc(600, 350));
187         setMinimumSize(new java.awt.Dimension JavaDoc(600, 350));
188         setPreferredSize(new java.awt.Dimension JavaDoc(600, 350));
189         descriptionTextArea.setEditable(false);
190         descriptionTextArea.setFont(javax.swing.UIManager.getFont("Label.font"));
191         descriptionTextArea.setText(bundle.getString("Description"));
192         descriptionTextArea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
193         descriptionTextArea.setRequestFocusEnabled(false);
194         descriptionTextArea.setEnabled(false);
195         descriptionTextArea.setOpaque(false);
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 0;
198         gridBagConstraints.gridy = 0;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
200         gridBagConstraints.weightx = 1.0;
201         gridBagConstraints.weighty = 1.0;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
203         add(descriptionTextArea, gridBagConstraints);
204
205         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
206
207         nameLabel.setText(bundle.getString("LBL_pool-name"));
208         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints.gridx = 0;
210         gridBagConstraints.gridy = 0;
211         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints.weighty = 1.0;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 12, 0);
214         jPanel1.add(nameLabel, gridBagConstraints);
215
216         nameField.setText(this.helper.getData().getString(__Name));
217         nameField.setMinimumSize(new java.awt.Dimension JavaDoc(60, 21));
218         nameField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
219             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
220                 CPVendorPanel.this.nameFieldActionPerformed(evt);
221             }
222         });
223         nameField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
224             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
225                 CPVendorPanel.this.nameFieldKeyReleased(evt);
226             }
227         });
228
229         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
230         gridBagConstraints.gridx = 1;
231         gridBagConstraints.gridy = 0;
232         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
233         gridBagConstraints.weightx = 1.0;
234         gridBagConstraints.weighty = 1.0;
235         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 0);
236         jPanel1.add(nameField, gridBagConstraints);
237
238         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239         gridBagConstraints.gridx = 0;
240         gridBagConstraints.gridy = 2;
241         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
242         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 12, 20, 12);
243         add(jPanel1, gridBagConstraints);
244
245         existingConnRadioButton.setSelected(true);
246         existingConnRadioButton.setText(bundle.getString("ExistingConnection"));
247         existingConnRadioButton.setToolTipText(bundle.getString("ACS_ExistingConnectionA11yDesc"));
248         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
249         gridBagConstraints.gridx = 0;
250         gridBagConstraints.gridy = 3;
251         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
253         add(existingConnRadioButton, gridBagConstraints);
254
255         existingConnComboBox.setToolTipText(bundle.getString("ACS_ExistingConnectionComboBoxA11yDesc"));
256         existingConnComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
257             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
258                 CPVendorPanel.this.existingConnComboBoxActionPerformed(evt);
259             }
260         });
261
262         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
263         gridBagConstraints.gridx = 0;
264         gridBagConstraints.gridy = 4;
265         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
266         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 24, 0, 11);
267         add(existingConnComboBox, gridBagConstraints);
268
269         newCofigRadioButton.setText(bundle.getString("NewConfiguration"));
270         newCofigRadioButton.setToolTipText(bundle.getString("ACS_NewConnectionA11yDesc"));
271         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
272         gridBagConstraints.gridx = 0;
273         gridBagConstraints.gridy = 5;
274         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
275         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
276         add(newCofigRadioButton, gridBagConstraints);
277
278         nameComboBox.setToolTipText(bundle.getString("ACS_NewConnectionComboBoxA11yDesc"));
279         nameComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
280             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
281                 CPVendorPanel.this.nameComboBoxActionPerformed(evt);
282             }
283         });
284
285         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
286         gridBagConstraints.gridx = 0;
287         gridBagConstraints.gridy = 6;
288         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
289         gridBagConstraints.weightx = 1.0;
290         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 24, 50, 11);
291         add(nameComboBox, gridBagConstraints);
292
293         isXA.setText(bundle.getString("isXA"));
294         isXA.addActionListener(new java.awt.event.ActionListener JavaDoc() {
295             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
296                 CPVendorPanel.this.isXAActionPerformed(evt);
297             }
298         });
299
300         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
301         gridBagConstraints.gridx = 0;
302         gridBagConstraints.gridy = 7;
303         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
304         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 5, 11);
305         add(isXA, gridBagConstraints);
306
307     }//GEN-END:initComponents
308

309     private void nameFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldKeyReleased
310
// Add your handling code here:
311
ResourceConfigData data = this.helper.getData();
312         String JavaDoc value = data.getString(__Name);
313         String JavaDoc newValue = nameField.getText();
314         if (!value.equals(newValue)) {
315             this.helper.getData().setString(__Name, newValue);
316         }
317         fireChange(this);
318     }//GEN-LAST:event_nameFieldKeyReleased
319

320     private void nameFieldActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldActionPerformed
321
// Add your handling code here:
322
setResourceName();
323     }//GEN-LAST:event_nameFieldActionPerformed
324

325     public String JavaDoc getNameField() {
326         return nameField.getText();
327     }
328     
329     private void setResourceName() {
330         ResourceConfigData data = this.helper.getData();
331         String JavaDoc value = data.getString(__Name);
332         String JavaDoc newValue = nameField.getText();
333         if (!value.equals(newValue)) {
334             this.helper.getData().setString(__Name, newValue);
335             fireChange(this);
336         }
337         
338         if((this.getRootPane().getDefaultButton() != null) && (this.getRootPane().getDefaultButton().isEnabled())){
339             this.getRootPane().getDefaultButton().doClick();
340         }
341     }
342     
343     private void isXAActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_isXAActionPerformed
344
// Add your handling code here:
345
setNewConfigData(false);
346     }//GEN-LAST:event_isXAActionPerformed
347

348     private void nameComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_nameComboBoxActionPerformed
349
// Add your handling code here:
350
setNewConfigData(true);
351 /*
352         usernameTextField.setText(""); //NOI18N
353         passwordField.setText(""); //NOI18N
354         
355         data.setDriver(driverTextField.getText());
356         data.setSchema(null);
357         schemas = false;
358 */

359     }//GEN-LAST:event_nameComboBoxActionPerformed
360

361     private void setNewConfigData(boolean replaceProps) {
362         if (firstTime) {
363             return;
364         }
365         int index = nameComboBox.getSelectedIndex();
366
367         if (index > 0) {
368             if (useExistingConnection) {
369                 useExistingConnection = false;
370             }
371             ResourceConfigData data = this.helper.getData();
372             data.setString(__IsCPExisting, "false"); //NOI18N
373
String JavaDoc vendorName = vendors[index - 1];
374             String JavaDoc savedVendorName = data.getString(__DatabaseVendor);
375             String JavaDoc savedXA = data.getString(__IsXA);
376             String JavaDoc XA = isXA.isSelected()?CONST_TRUE:"false"; //NOI18N
377
boolean vendorNotChanged = vendorName.equals(savedVendorName);
378             boolean isXANotChanged = XA.equals(savedXA);
379
380             if (vendorNotChanged && isXANotChanged) {
381                 return;
382             }
383             if (!vendorNotChanged) {
384                 data.setString(__DatabaseVendor, vendorName);
385             }
386             if (!isXANotChanged) {
387                 data.setString(__IsXA, XA);
388             }
389             
390             setDataSourceClassNameAndResTypeInData(vendorName);
391             
392             if (replaceProps) {
393                 setPropertiesInData(vendorName);
394             }
395         }
396     }
397     
398     private void setDataSourceClassNameAndResTypeInData(String JavaDoc vendorName) {
399         //change datasource classname following database vendor change
400
ResourceConfigData data = this.helper.getData();
401         Field dsField;
402         if (isXA.isSelected())
403             dsField = FieldHelper.getField(this.generalGroup, __XADatasourceClassname);
404         else
405             dsField = FieldHelper.getField(this.generalGroup, __DatasourceClassname);
406         data.setString(__DatasourceClassname, FieldHelper.getConditionalFieldValue(dsField, vendorName));
407         
408         if (isXA.isSelected()) {
409             data.setString(__ResType, "javax.sql.XADataSource"); //NOI18N
410
data.setString(__IsXA, CONST_TRUE); //NOI18N
411
}else {
412             data.setString(__ResType, "javax.sql.DataSource"); //NOI18N
413
data.setString(__IsXA, "false"); //NOI18N
414
}
415     }
416     
417     private void setPropertiesInData(String JavaDoc vendorName) {
418         //change standard properties following database vendor change
419
ResourceConfigData data = this.helper.getData();
420         data.setProperties(new Vector JavaDoc());
421         Field[] propFields = this.propGroup.getField();
422         for (int i = 0; i < propFields.length; i++) {
423             String JavaDoc value = FieldHelper.getConditionalFieldValue(propFields[i], vendorName);
424             String JavaDoc name = propFields[i].getName();
425             if (name.equals(__Url) && value.length() > 0)
426                 data.addProperty(name, FieldHelper.toUrl(value));
427             else if (name.equals(__DatabaseName) && value.length() > 0)
428                 data.addProperty(name, FieldHelper.toUrl(value));
429             else if (name.equals(__User) || name.equals(__Password)) {
430                 data.addProperty(propFields[i].getName(), value);
431             }else{
432                 //All Others
433
if(value.length() > 0 && (value.equals(__NotApplicable))){
434                     data.addProperty(propFields[i].getName(), ""); //NOI18N
435
}
436             }
437         }
438     }
439         
440     
441     private void existingConnComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_existingConnComboBoxActionPerformed
442
setExistingConnData();
443     }//GEN-LAST:event_existingConnComboBoxActionPerformed
444

445     public void setExistingConnData() {
446         if(existingConnComboBox.getSelectedIndex() > 0) {
447             if (!useExistingConnection) {
448                 this.helper.getData().setResourceName(__JdbcConnectionPool);
449                 useExistingConnection = true;
450             }
451             this.helper.getData().setString(__IsCPExisting, CONST_TRUE); //NOI18N
452
DatabaseConnection dbconn = (DatabaseConnection)dbconns.get(existingConnComboBox.getSelectedIndex() - 1);
453             String JavaDoc url = dbconn.getDatabaseURL();
454             String JavaDoc user = dbconn.getUser();
455             String JavaDoc password = dbconn.getPassword();
456             String JavaDoc tmpStr = url;
457             
458             Field urlField = FieldHelper.getField(this.vendorGroup, "vendorUrls"); //NOI18N
459
String JavaDoc vendorName = FieldHelper.getOptionNameFromValue(urlField, tmpStr);
460                         
461             ResourceConfigData data = this.helper.getData();
462             data.setProperties(new Vector JavaDoc());
463             data.setString(__DatabaseVendor, vendorName);
464             
465             if (vendorName.equals("pointbase")) { //NOI18N
466
data.addProperty(__DatabaseName, dbconn.getDatabaseURL());
467             }else if(vendorName.startsWith("derby")) { //NOI18N)
468
setDerbyProps(vendorName, url);
469             }else
470                 data.addProperty(__Url, url);
471             data.addProperty(__User, user);
472             data.addProperty(__Password, password);
473             
474             setDataSourceClassNameAndResTypeInData(vendorName);
475         }
476            
477     }
478     
479     private void setDerbyProps(String JavaDoc vendorName, String JavaDoc url) {
480         //change standard properties following database vendor change
481
ResourceConfigData data = this.helper.getData();
482         data.setProperties(new Vector JavaDoc());
483         Field[] propFields = this.propGroup.getField();
484         for (int i = 0; i < propFields.length; i++) {
485             String JavaDoc value = FieldHelper.getConditionalFieldValue(propFields[i], vendorName);
486             if(value.equals(__NotApplicable)){
487                 String JavaDoc name = propFields[i].getName();
488                 if(vendorName.equals("derby_net")) {//NOI18N
489
String JavaDoc hostName = "";
490                     String JavaDoc portNumber = "";
491                     String JavaDoc databaseName = "";
492                     try{
493                         String JavaDoc workingUrl = url.substring(url.indexOf("//") + 2, url.length());
494                         if(workingUrl.indexOf(":") != -1){
495                             hostName = workingUrl.substring(0, workingUrl.indexOf(":"));
496                             if(workingUrl.indexOf("/") != -1){
497                                 portNumber = workingUrl.substring(workingUrl.indexOf(":") + 1, workingUrl.indexOf("/"));
498                                 int braceIndex = workingUrl.indexOf("[");
499                                 if(braceIndex == -1)
500                                     databaseName = workingUrl.substring(workingUrl.indexOf("/") + 1, workingUrl.length());
501                                 else
502                                     databaseName = workingUrl.substring(workingUrl.indexOf("/") + 1, braceIndex + 1).trim();
503                             }
504                         }
505                     }catch(java.lang.StringIndexOutOfBoundsException JavaDoc ex){
506                     }
507                     if (name.equals(__DerbyPortNumber)) {
508                         data.addProperty(name, portNumber);
509                     } else if (name.equals(__DerbyDatabaseName)) {
510                         data.addProperty(name, databaseName);
511                     } else if (name.equals(__ServerName)) {
512                         data.addProperty(name, hostName);
513                     }
514                 }
515             }
516         }
517     }
518     // Variables declaration - do not modify//GEN-BEGIN:variables
519
private javax.swing.JTextField JavaDoc nameField;
520     private javax.swing.JTextArea JavaDoc descriptionTextArea;
521     private javax.swing.JLabel JavaDoc nameLabel;
522     private javax.swing.JComboBox JavaDoc nameComboBox;
523     private javax.swing.JRadioButton JavaDoc newCofigRadioButton;
524     private javax.swing.JRadioButton JavaDoc existingConnRadioButton;
525     private javax.swing.JPanel JavaDoc jPanel1;
526     private javax.swing.JComboBox JavaDoc existingConnComboBox;
527     private javax.swing.JCheckBox JavaDoc isXA;
528     // End of variables declaration//GEN-END:variables
529

530 // private static final ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.Bundle"); //NOI18N
531

532     public boolean isValid() {
533         if(! setupValid){
534             setErrorMsg(bundle.getString("Err_InvalidSetup"));
535             return false;
536         }
537         setErrorMsg(bundle.getString("Empty_String"));
538         String JavaDoc name = nameField.getText();
539         if (name == null || name.length() == 0){
540             setErrorMsg(bundle.getString("Err_InvalidName"));
541             return false;
542         }else if(! ResourceUtils.isLegalResourceName(name))
543             return false;
544         else if(! ResourceUtils.isUniqueFileName(name, this.helper.getData().getTargetFileObject(), __ConnectionPoolResource)){
545             setErrorMsg(bundle.getString("Err_DuplFileName"));
546             return false;
547         }
548         
549         if (existingConnRadioButton.isSelected()) {
550             if (existingConnComboBox.getSelectedIndex() > 0)
551                 return true;
552             else
553                 setErrorMsg(bundle.getString("Err_ChooseDBConn"));
554         }else if (newCofigRadioButton.isSelected()) {
555             if (nameComboBox.getSelectedIndex() > 0)
556                 return true;
557             else
558                 setErrorMsg(bundle.getString("Err_ChooseDBVendor"));
559         }
560         
561         return false;
562     }
563
564     public void removeUpdate(final javax.swing.event.DocumentEvent JavaDoc event) {
565         fireChange(this);
566     }
567     
568     public void changedUpdate(final javax.swing.event.DocumentEvent JavaDoc event) {
569         fireChange(this);
570     }
571     
572     public void insertUpdate(final javax.swing.event.DocumentEvent JavaDoc event) {
573         fireChange(this);
574     }
575
576     public void intervalAdded(final javax.swing.event.ListDataEvent JavaDoc p1) {
577         fireChange(this);
578     }
579     
580     public void intervalRemoved(final javax.swing.event.ListDataEvent JavaDoc p1) {
581         fireChange(this);
582     }
583     
584     public void contentsChanged(final javax.swing.event.ListDataEvent JavaDoc p1) {
585         fireChange(this);
586     }
587
588     public void stateChanged(final javax.swing.event.ChangeEvent JavaDoc p1) {
589         if (firstTime) {
590             return;
591         }
592         if (p1.getSource().getClass() == javax.swing.JToggleButton.ToggleButtonModel.class) {
593             if (existingConnRadioButton.isSelected()) {
594                 //To solve a problem on Win2K only
595
if (firstTime) {
596                     return;
597                 }
598                 existingConnComboBox.setEnabled(true);
599                 nameComboBox.setEnabled(false);
600 // isXA.setEnabled(false);
601
setExistingConnData();
602             } else {
603                 existingConnComboBox.setEnabled(false);
604                 nameComboBox.setEnabled(true);
605                 setNewConfigData(true);
606             }
607         }
608         fireChange(this);
609     }
610     
611     public CPVendorPanel setFirstTime(boolean first) {
612         this.firstTime = first;
613         return this;
614     }
615
616     protected void initData() {
617         /*if (existingConnRadioButton.isSelected()) {
618             data.setExistingConn(true);
619             if(existingConnComboBox.getSelectedIndex() > 0)
620                 data.setConnectionNodeInfo((ConnectionNodeInfo) connInfos.get(existingConnComboBox.getSelectedIndex() - 1));
621             
622             data.setDriver(null);
623             data.setUrl(null);
624             data.setUsername(null);
625             data.setPassword(null);
626         } else {
627             data.setExistingConn(false);
628             data.setDriver(driverTextField.getText());
629             data.setUrl(urlTextField.getText());
630             data.setUsername(usernameTextField.getText());
631             data.setPassword(new String(passwordField.getPassword()));
632
633             data.setConnectionNodeInfo(null);
634         }*/

635     }
636     
637     public HelpCtx getHelp() {
638          return new HelpCtx("AS_Wiz_ConnPool_chooseDB"); //NOI18N
639
}
640     
641     public void readSettings(Object JavaDoc settings) {
642         this.wizDescriptor = (WizardDescriptor)settings;
643         TemplateWizard wizard = (TemplateWizard)settings;
644         String JavaDoc targetName = wizard.getTargetName();
645         if(this.helper.getData().getString(__DynamicWizPanel).equals(CONST_TRUE)){ //NOI18N
646
targetName = null;
647         }
648         FileObject setupFolder = ResourceUtils.getResourceDirectory(this.helper.getData().getTargetFileObject());
649         this.helper.getData().setTargetFileObject (setupFolder);
650         if(setupFolder != null){
651             targetName = ResourceUtils.createUniqueFileName (targetName, setupFolder, __ConnectionPoolResource);
652             this.nameField.setText (targetName);
653             this.helper.getData ().setString (__Name, targetName);
654             this.helper.getData ().setTargetFile (targetName);
655         }else
656             setupValid = false;
657     }
658     
659     public void setInitialFocus(){
660         new setFocus(nameField);
661     }
662     
663 // private boolean setupValid(){
664
// return setupValid;
665
// }
666
}
667
Popular Tags