KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > wizards > CommonGeneralFinishVisualPanel


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  * CommonGeneralFinishVisualPanel.java
21  *
22  */

23
24 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards;
25
26 import org.openide.util.NbBundle;
27 import java.util.ResourceBundle JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import javax.swing.*;
30 import javax.swing.event.ChangeListener JavaDoc;
31
32 import org.netbeans.modules.j2ee.sun.sunresources.beans.Field;
33 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup;
34 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants;
35 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper;
36
37 /** A single panel for a wizard - the GUI portion.
38  * Code reused from Appserver common API module
39  
40  *
41  */

42 public class CommonGeneralFinishVisualPanel extends javax.swing.JPanel JavaDoc implements ChangeListener JavaDoc, WS70WizardConstants {
43     
44     /** The wizard panel descriptor associated with this GUI panel.
45      * If you need to fire state changes or something similar, you can
46      * use this handle to do so.
47      */

48     
49     public static final String JavaDoc TYPE_EXTERNAL_RESOURCE = "_EXTERNAL"; //NOI18N
50
public static final String JavaDoc TYPE_MAIL_RESOURCE = "_MAIL"; //NOI18N
51
public static final String JavaDoc TYPE_CUSTOM_RESOURCE = "_CUSTOM"; //NOI18N
52
public static final String JavaDoc TYPE_JDBC_RESOURCE = "_JDBC"; //NOI18N
53

54     protected ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.Bundle"); //NOI18N
55

56     protected final CommonGeneralFinishPanel panel;
57     protected FieldGroup[] groups;
58     protected int fieldSize;
59     protected ResourceConfigHelper helper;
60     protected String JavaDoc panelType = TYPE_MAIL_RESOURCE;
61     protected ArrayList JavaDoc beans = new ArrayList JavaDoc();
62     protected boolean createNewResource = false;
63     
64     // Variables declaration - general attributes
65
protected javax.swing.JTextArea JavaDoc descriptionTextArea = null;
66     protected javax.swing.JPanel JavaDoc jPanel1[] = null;
67     protected javax.swing.JLabel JavaDoc jLabels[] = null;
68     protected javax.swing.JComponent JavaDoc jFields[] = null;
69     protected Field fields[] = null;
70     protected String JavaDoc resourceName;
71     protected boolean showGroupTitle = false;
72     
73     // Variable declaration - choice
74
private javax.swing.JPanel JavaDoc jPanel0;
75     private boolean firstTime = true;
76     private int y = 0;
77     // used in case of JDBC resource only
78
private String JavaDoc[] dbVendors;
79     
80     /** Create the wizard panel and set up some basic properties. */
81     public CommonGeneralFinishVisualPanel(CommonGeneralFinishPanel panel, FieldGroup[] groups, String JavaDoc panelType) {
82         this.firstTime = true;
83         this.panel = panel;
84         this.helper = panel.getHelper();
85         this.resourceName = panel.getResourceName();
86         setFieldGroups(groups);
87         if (groups.length > 1)
88             this.showGroupTitle = true;
89         
90         setLayout(new java.awt.GridBagLayout JavaDoc());
91         initDescriptionComponent();
92         
93             
94         setPanelType(panelType);
95         initComponents();
96
97         refreshFields();
98         // Provide a name in the title bar.
99
setName(NbBundle.getMessage(CommonGeneralFinishVisualPanel.class, "TITLE_" + groups[0].getName())); //NOI18N
100
getAccessibleContext().setAccessibleName(bundle.getString("TITLE_" + groups[0].getName()));
101         String JavaDoc a11yDesc = null;
102         if(panelType==TYPE_CUSTOM_RESOURCE){
103             a11yDesc = WS70WizardConstants.__CustomResource;
104         }else if(panelType==TYPE_MAIL_RESOURCE){
105             a11yDesc = WS70WizardConstants.__MailResource;
106         }if(panelType==TYPE_EXTERNAL_RESOURCE){
107             a11yDesc = WS70WizardConstants.__ExternalJndiResource;
108         }if(panelType==TYPE_JDBC_RESOURCE){
109             a11yDesc = WS70WizardConstants.__JdbcResource;
110         }
111         getAccessibleContext().setAccessibleDescription(bundle.getString(a11yDesc+"_Description"));
112         this.firstTime = false;
113     }
114     
115     public void setFieldGroups(FieldGroup[] groups) {
116         this.groups = groups;
117         fieldSize = 0;
118         for (int i = 0; i < groups.length; i++) {
119             fieldSize += groups[i].sizeField();
120         }
121     }
122     
123     /** This method is called from within the constructor to
124      * initialize the form.
125      * WARNING: Do NOT modify this code. The content of this method is
126      * always regenerated by the Form Editor.
127      */

128     private void initComponents() {
129         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
130
131         int gap = 0;
132         int itemHeight = 28;
133         if (fieldSize < 6) {
134             itemHeight = 42;
135             gap = 7;
136         }
137         int i = 0;
138         jPanel1 = new JPanel[groups.length];
139         fields = new Field[fieldSize];
140         jLabels = new JLabel[fieldSize];
141         jFields = new JComponent[fieldSize];
142       
143       for (int j = 0; j < groups.length; j++) {
144         if (showGroupTitle) {
145             JLabel label = new JLabel();
146             label.setText(bundle.getString("LBL_GROUP_" + groups[j].getName())); //NOI18N
147
label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_GROUP_" + groups[j].getName() + "A11yDesc")); //NOI18N
148
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149             gridBagConstraints.gridx = 0;
150             gridBagConstraints.gridy = this.y; this.y++;
151             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
152             gridBagConstraints.ipadx = 0;
153             gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 11);
154             add(label, gridBagConstraints);
155         }
156         
157         Field[] flds = groups[j].getField();
158         int size = flds.length;
159         jPanel1[j] = new javax.swing.JPanel JavaDoc();
160         jPanel1[j].setLayout(new java.awt.GridBagLayout JavaDoc());
161         
162         //Fixing Issue# 80007
163
int panelWidth = (int)jPanel1[j].getMaximumSize().getWidth();
164         jPanel1[j].setMaximumSize(new java.awt.Dimension JavaDoc(panelWidth, itemHeight * size));
165         jPanel1[j].setMinimumSize(new java.awt.Dimension JavaDoc(panelWidth, itemHeight * size));
166         jPanel1[j].setPreferredSize(new java.awt.Dimension JavaDoc(panelWidth, itemHeight * size));
167         
168
169         for (int k = 0; k < size; k++) {
170             fields[i] = flds[k];
171             JLabel jLabel = new JLabel();
172             jLabel.setText(bundle.getString("LBL_" + fields[i].getName())); //NOI18N
173
jLabel.setDisplayedMnemonic(bundle.getString("LBL_" + fields[i].getName() + "_Mnemonic").charAt(0)); //NOI18N
174
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175             gridBagConstraints.gridx = 0;
176             gridBagConstraints.gridy = k;
177             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
178             gridBagConstraints.ipadx = 0;
179             gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 12, gap, 0);
180             jLabels[i] = jLabel;
181             jPanel1[j].add(jLabels[i], gridBagConstraints);
182             
183             if (FieldHelper.isList(fields[i])) {
184                 JComboBox jComboBox = new JComboBox();
185                 jLabel.setLabelFor(jComboBox);
186                 jComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ToolTip_" + fields[i].getName()));
187                 String JavaDoc tags[] = FieldHelper.getTags(fields[i]);
188                 boolean isVendorField = false;
189                 if(this.getPanelType()==this.TYPE_JDBC_RESOURCE&& fields[i].getName().equals(__DatabaseVendor)){
190                     Field vendorField = FieldHelper.getField(groups[0], __DatabaseVendor);
191                     tags = FieldHelper.getTags(vendorField);
192                     dbVendors = FieldHelper.getTags(vendorField);
193                     isVendorField = true;
194                 }
195                 for (int h = 0; h < tags.length; h++) {
196                     if(isVendorField){
197                         jComboBox.addItem(bundle.getString("DBVendor_" + tags[h])); //NOI18N
198
}else{
199                         jComboBox.addItem(tags[h]);
200                     }
201                 }
202                 final int index = i;
203                 jComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
204                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
205                         jComboBoxActionPerformed(evt, index);
206                     }
207                 });
208                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209                 gridBagConstraints.gridx = 1;
210                 gridBagConstraints.gridy = k;
211                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 20, gap, 0);
213                 gridBagConstraints.weightx = 1.0;
214                 jFields[i] = jComboBox;
215                 jPanel1[j].add(jComboBox, gridBagConstraints);
216             } else {
217                 JTextField jTextField = new JTextField();
218                 jTextField.setText("jTextField1"); //NOI18N
219
jLabel.setLabelFor(jTextField);
220                 jTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ToolTip_" + fields[i].getName()));
221                 jTextField.setToolTipText(bundle.getString("ToolTip_" + fields[i].getName())); //NOI18N
222

223                 //Fixing Issue# 80007
224
//jTextField.setMinimumSize(new java.awt.Dimension(340, 21));
225
//jTextField.setPreferredSize(new java.awt.Dimension(340, 21));
226
final int index = i;
227                 /*
228                 jTextField.addActionListener(new java.awt.event.ActionListener() {
229                     public void actionPerformed(java.awt.event.ActionEvent evt) {
230                         jTextField1ActionPerformed(evt, index);
231                     }
232                 });
233                  */

234                 jTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
235                     public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
236                         jTextField1KeyReleased(evt, index);
237                     }
238                 });
239                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
240                 gridBagConstraints.gridx = 1;
241                 gridBagConstraints.gridy = k;
242                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
243                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 20, gap, 0);
244                 gridBagConstraints.weightx = 1.0;
245                 jFields[i] = jTextField;
246                 jPanel1[j].add(jTextField, gridBagConstraints);
247             }
248             i++;
249         }
250         
251         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
252         gridBagConstraints.gridx = 0;
253         gridBagConstraints.gridy = this.y; this.y++;
254         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
255         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 10, 11);
256         jPanel1[j].setBorder(new javax.swing.border.EtchedBorder JavaDoc());
257         add(jPanel1[j], gridBagConstraints);
258       }
259     }
260     
261     private void initDescriptionComponent() {
262         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
263         
264         descriptionTextArea = new javax.swing.JTextArea JavaDoc();
265         descriptionTextArea.setEditable(false);
266         descriptionTextArea.setFont(javax.swing.UIManager.getFont("Label.font")); //NOI18N
267
descriptionTextArea.setText(bundle.getString(this.resourceName + "_Description")); //NOI18N
268
descriptionTextArea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground")); //NOI18N
269
descriptionTextArea.setRequestFocusEnabled(false);
270         descriptionTextArea.setEnabled(false);
271         descriptionTextArea.setOpaque(false);
272         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
273         gridBagConstraints.gridx = 0;
274         gridBagConstraints.gridy = this.y; this.y++;
275         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
276         gridBagConstraints.weightx = 1.0;
277         gridBagConstraints.weighty = 0.0;
278         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 20, 11);
279         add(descriptionTextArea, gridBagConstraints);
280     }
281     
282
283     
284     protected String JavaDoc getPanelType() {
285         return panelType;
286     }
287     
288     protected void setPanelType(String JavaDoc type) {
289         this.panelType = type;
290     }
291     
292
293     public void stateChanged(final javax.swing.event.ChangeEvent JavaDoc p1) {
294     }
295
296     public boolean createNew() {
297         return createNewResource;
298     }
299     
300     public void refreshFields() {
301         ResourceConfigData data = this.helper.getData();
302         for (int i = 0; i < jFields.length; i++) {
303             String JavaDoc item;
304             if (FieldHelper.isList(fields[i])) {
305                 item = (String JavaDoc)((JComboBox)jFields[i]).getSelectedItem();
306             } else {
307                 item = (String JavaDoc)((JTextField)jFields[i]).getText();
308             }
309             String JavaDoc fieldName = fields[i].getName();
310             Object JavaDoc value = data.get(fieldName);
311             if (value == null) {
312                 value = FieldHelper.getDefaultValue(fields[i]);
313                 data.set(fieldName, value);
314             }
315             String JavaDoc val = (String JavaDoc)value;
316             if (!item.equals(val)) {
317                 if (FieldHelper.isList(fields[i])) {
318                     ((JComboBox)jFields[i]).setSelectedItem(val);
319                 } else {
320                     ((JTextField)jFields[i]).setText(val);
321                 }
322             }
323          }
324     }
325     
326     private void jComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt, int index) {
327         ResourceConfigData data = this.helper.getData();
328         String JavaDoc item = (String JavaDoc)((JComboBox)jFields[index]).getSelectedItem();
329         int selectedIndex = ((JComboBox)jFields[index]).getSelectedIndex();
330         String JavaDoc fieldName = fields[index].getName();
331         
332         if(this.getPanelType()==this.TYPE_JDBC_RESOURCE && fieldName.equals(__DatabaseVendor)){
333             for(int i=0;i<fields.length;i++){
334                 String JavaDoc fname = fields[i].getName();
335                 if(fname.equals(WS70WizardConstants.__DatasourceClassname)){
336                     Field dsField = FieldHelper.getField(groups[0], __DatasourceClassname);
337                     String JavaDoc classVal = FieldHelper.getConditionalFieldValue(dsField, dbVendors[selectedIndex]);
338                     ((JTextField)jFields[i]).setText(classVal);
339                     data.setString(fname, classVal);
340                 }
341             }
342         }else{
343             String JavaDoc val = data.getString(fieldName);
344             if (!item.equals(val))
345                 data.setString(fieldName, item);
346         }
347     }
348     
349     private void jTextField1KeyReleased(java.awt.event.KeyEvent JavaDoc evt, int index) {
350         ResourceConfigData data = this.helper.getData();
351         String JavaDoc item = (String JavaDoc)((JTextField)jFields[index]).getText();
352         String JavaDoc fieldName = fields[index].getName();
353         String JavaDoc val = data.getString(fieldName);
354         if (FieldHelper.isInt(fields[index])) {
355             try {
356                 Integer.parseInt(item);
357             } catch (NumberFormatException JavaDoc ex) {
358                 JOptionPane.showMessageDialog(this, bundle.getString("MSG_NotNumber")); //NOI18N
359
if (val == null || val.length() == 0)
360                     val = FieldHelper.getDefaultValue(fields[index]);
361                 ((JTextField)jFields[index]).setText(val);
362                 return;
363             }
364         }
365         String JavaDoc jLabel = (String JavaDoc)this.jLabels[index].getText();
366         //if (!item.equals(val) && !jLabel.equals(bundle.getString("LBL_" + __JndiName)) ) { // don't save jndi name here or it will break 'duplicate jndi name validation' in edit mode
367
if (!item.equals(val) && jLabel.equals(bundle.getString("LBL_" + __JndiName)) ) {
368             item = item + data.getTargetFile();
369             data.setString(fieldName, item);
370         }
371         if (!item.equals(val)){
372             data.setString(fieldName, item);
373             //panel.fireChangeEvent();
374
}
375         panel.fireChangeEvent();
376     }
377     
378     public CommonGeneralFinishVisualPanel setFirstTime(boolean first) {
379         this.firstTime = first;
380         return this;
381     }
382     
383     public void initData() {
384         refreshFields();
385     }
386     
387      public void setHelper(ResourceConfigHelper helper){
388         this.helper = helper;
389         this.helper.getData().setString("jndi-name", helper.getData().getTargetFile()); //NOI18N
390
refreshFields();
391     }
392 }
393
Popular Tags