KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > ParametersPicker


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
21 package org.netbeans.modules.form;
22
23 import java.awt.event.ItemEvent JavaDoc;
24 import java.awt.event.ItemListener JavaDoc;
25 import java.beans.*;
26 import java.util.*;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29
30 import org.openide.awt.Mnemonics;
31 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.Utilities;
34 import org.openide.ErrorManager;
35 import org.openide.DialogDescriptor;
36
37 /** The ParametersPicker is a panel which allows to enter a method parameter data.
38  *
39  * @author Ian Formanek
40  */

41 public class ParametersPicker extends javax.swing.JPanel JavaDoc implements EnhancedCustomPropertyEditor {
42
43     static final long serialVersionUID =1116033799965380000L;
44     
45     private boolean previousValue = false;
46         
47     /** Initializes the Form */
48     public ParametersPicker(FormModel formModel, Class JavaDoc requiredType) {
49         this.formModel = formModel;
50         this.requiredType = requiredType;
51         initComponents();
52
53         javax.swing.ButtonGroup JavaDoc bg = new javax.swing.ButtonGroup JavaDoc();
54         bg.add(valueButton);
55         bg.add(beanButton);
56         bg.add(propertyButton);
57         bg.add(methodButton);
58         bg.add(codeButton);
59
60         if ((!requiredType.isPrimitive()) &&
61             (!requiredType.equals(String JavaDoc.class))) {
62             valueButton.setEnabled(false);
63             propertyButton.setSelected(true);
64         }
65
66         // localize components
67
paramLabel.setLabelFor(this);
68         propertyLabel.setText(FormUtils.getBundleString("CTL_CW_NoProperty")); // NOI18N
69
methodLabel.setText(FormUtils.getBundleString("CTL_CW_NoMethod")); // NOI18N
70

71         Mnemonics.setLocalizedText(valueButton, FormUtils.getBundleString("CTL_CW_Value")); // NOI18N
72
Mnemonics.setLocalizedText(beanButton, FormUtils.getBundleString("CTL_CW_Bean")); // NOI18N
73
Mnemonics.setLocalizedText(propertyButton, FormUtils.getBundleString("CTL_CW_Property")); // NOI18N
74
Mnemonics.setLocalizedText(methodButton, FormUtils.getBundleString("CTL_CW_Method")); // NOI18N
75
Mnemonics.setLocalizedText(codeButton, FormUtils.getBundleString("CTL_CW_UserCode")); // NOI18N
76

77         beansList = new ArrayList();
78         for (RADComponent radComp : formModel.getAllComponents()) {
79             if (requiredType.isAssignableFrom(radComp.getBeanClass()))
80                 beansList.add(radComp);
81         }
82         if (beansList.size() > 0) {
83             Collections.sort(beansList, new ComponentComparator());
84
85             beanCombo.addItem(FormUtils.getBundleString("CTL_CW_SelectBean")); // NOI18N
86
for (Iterator it = beansList.iterator(); it.hasNext(); ) {
87                 RADComponent radComp = (RADComponent) it.next();
88                 if (radComp == formModel.getTopRADComponent())
89                     beanCombo.addItem(
90                         FormUtils.getBundleString("CTL_FormTopContainerName")); // NOI18N
91
else
92                     beanCombo.addItem(radComp.getName());
93             }
94
95             beanCombo.addItemListener(new ItemListener JavaDoc() {
96                 public void itemStateChanged(ItemEvent JavaDoc evt) {
97                     int index = beanCombo.getSelectedIndex();
98                     if (index == 0) {
99                         selectedComponent = null;
100                     } else {
101                         selectedComponent =(RADComponent)beansList.get(index - 1);
102                     }
103                     fireStateChange();
104                 }
105             }
106                                       );
107         }
108         else beanButton.setEnabled(false); // no beans on the form are of the required type
109

110         updateParameterTypes();
111             
112         HelpCtx.setHelpIDString(this, "gui.source.modifying.property"); // NOI18N
113

114         valueButton.getAccessibleContext().setAccessibleDescription(
115             FormUtils.getBundleString("ACSD_CTL_CW_Value")); // NOI18N
116
beanButton.getAccessibleContext().setAccessibleDescription(
117             FormUtils.getBundleString("ACSD_CTL_CW_Bean")); // NOI18N
118
propertyButton.getAccessibleContext().setAccessibleDescription(
119             FormUtils.getBundleString("ACSD_CTL_CW_Property")); // NOI18N
120
methodButton.getAccessibleContext().setAccessibleDescription(
121             FormUtils.getBundleString("ACSD_CTL_CW_Method")); // NOI18N
122
codeButton.getAccessibleContext().setAccessibleDescription(
123             FormUtils.getBundleString("ACSD_CTL_CW_UserCode")); // NOI18N
124

125         valueField.getAccessibleContext().setAccessibleName(valueButton.getText());
126         valueField.getAccessibleContext().setAccessibleDescription(
127             FormUtils.getBundleString("ACSD_CTL_CW_ValueField")); // NOI18N
128
beanCombo.getAccessibleContext().setAccessibleName(beanButton.getText());
129         beanCombo.getAccessibleContext().setAccessibleDescription(
130             FormUtils.getBundleString("ACSD_CTL_CW_BeanCombo")); // NOI18N
131
propertyLabel.getAccessibleContext().setAccessibleName(propertyButton.getText());
132         propertyLabel.getAccessibleContext().setAccessibleDescription(
133             FormUtils.getBundleString("ACSD_CTL_CW_PropertyLabel")); // NOI18N
134
methodLabel.getAccessibleContext().setAccessibleName(methodButton.getText());
135         methodLabel.getAccessibleContext().setAccessibleDescription(
136             FormUtils.getBundleString("ACSD_CTL_CW_MethodLabel")); // NOI18N
137
codeArea.getAccessibleContext().setAccessibleName(codeButton.getText());
138         codeArea.getAccessibleContext().setAccessibleDescription(
139             FormUtils.getBundleString("ACSD_CTL_CW_UserCodeArea")); // NOI18N
140

141         propertyDetailsButton.getAccessibleContext().setAccessibleDescription(
142             FormUtils.getBundleString("ACSD_CTL_CW_PropertyButton")); // NOI18N
143
methodDetailsButton.getAccessibleContext().setAccessibleDescription(
144             FormUtils.getBundleString("ACSD_CTL_CW_MethodButton")); // NOI18N
145
getAccessibleContext().setAccessibleDescription(
146             FormUtils.getBundleString("ACSD_ParametersPicker")); // NOI18N
147
}
148     
149     public void setPropertyValue(RADConnectionPropertyEditor.RADConnectionDesignValue value, Object JavaDoc realValue) {
150         if (value == null) {
151             previousValue = realValue != null;
152             return; // can happen if starting without previously set value
153
} else {
154             previousValue = true;
155         }
156         
157         switch (value.type) {
158             case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_VALUE:
159                 valueButton.setSelected(true);
160                 valueField.setText(value.value);
161                 break;
162             case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_BEAN:
163                 beanButton.setSelected(true);
164                 selectedComponent = value.getRADComponent();
165                 int index = beansList.indexOf(selectedComponent);
166                 if (index > -1)
167                     beanCombo.setSelectedIndex(index+1);
168                 break;
169             case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_PROPERTY:
170                 propertyButton.setSelected(true);
171                 selectedComponent = value.getRADComponent();
172                 selectedProperty = value.getProperty();
173                 if (selectedComponent.getCodeExpression() == null) {
174                     propertyLabel.setText(
175                         FormUtils.getBundleString("CTL_CONNECTION_INVALID")); // NOI18N
176
}
177                 else if (selectedComponent == formModel.getTopRADComponent()) {
178                     propertyLabel.setText(selectedProperty.getName());
179                 }
180                 else {
181                     propertyLabel.setText(selectedComponent.getName() + "." + selectedProperty.getName()); // NOI18N
182
}
183                 propertyLabel.selectAll();
184                 break;
185             case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_METHOD:
186                 methodButton.setSelected(true);
187                 selectedComponent = value.getRADComponent();
188                 selectedMethod = value.getMethod();
189                 if (selectedComponent.getCodeExpression() == null) {
190                     methodLabel.setText(
191                         FormUtils.getBundleString("CTL_CONNECTION_INVALID")); // NOI18N
192
}
193                 else if (selectedComponent == formModel.getTopRADComponent()) {
194                     methodLabel.setText(selectedMethod.getName());
195                 }
196                 else {
197                     methodLabel.setText(selectedComponent.getName() + "." + selectedMethod.getName()); // NOI18N
198
}
199                 methodLabel.selectAll();
200                 break;
201             case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_CODE:
202             default:
203                 codeButton.setSelected(true);
204                 codeArea.setText(value.userCode);
205                 break;
206         }
207
208         // update enabled state
209
updateParameterTypes();
210     }
211
212     // ----------------------------------------------------------------------------------------
213
// EnhancedCustomPropertyEditor implementation
214

215     /** Get the customized property value.
216      * @return the property value
217      * @exception InvalidStateException when the custom property editor does not contain a valid property value
218      *(and thus it should not be set)
219      */

220     public Object JavaDoc getPropertyValue() throws IllegalStateException JavaDoc {
221         if (valueButton.isSelected() && !"".equals(valueField.getText())) {
222             return new RADConnectionPropertyEditor.RADConnectionDesignValue(requiredType, valueField.getText());
223         } else if (beanButton.isSelected() && selectedComponent != null) {
224             return new RADConnectionPropertyEditor.RADConnectionDesignValue(selectedComponent);
225         } else if (codeButton.isSelected() && !"".equals(codeArea.getText())) {
226             return new RADConnectionPropertyEditor.RADConnectionDesignValue(codeArea.getText());
227         } else if (propertyButton.isSelected() && selectedProperty != null) {
228             return new RADConnectionPropertyEditor.RADConnectionDesignValue(selectedComponent, selectedProperty);
229         } else if (methodButton.isSelected() && selectedMethod != null) {
230             return new RADConnectionPropertyEditor.RADConnectionDesignValue(selectedComponent, selectedMethod);
231         } else if(!previousValue) {
232             return BeanSupport.NO_VALUE;
233         }
234         
235         IllegalStateException JavaDoc exc = new IllegalStateException JavaDoc();
236         ErrorManager.getDefault().annotate(
237             exc, ErrorManager.USER, null,
238             FormUtils.getBundleString("ERR_NothingEntered"), // NOI18N
239
null, null);
240         throw exc;
241         
242     }
243
244     // ----------------------------------------------------------------------------------------
245
// end of EnhancedCustomPropertyEditor implementation
246

247     public String JavaDoc getPreviewText() {
248         if (!isFilled())
249             return FormUtils.getBundleString("CTL_CW_NotSet"); // NOI18N
250
if (codeButton.isSelected()) {
251             return FormUtils.getBundleString("CTL_CW_Code"); // NOI18N
252
}
253         return getText();
254     }
255
256     public String JavaDoc getText() {
257         if (!isFilled())
258             return FormUtils.getBundleString("CTL_CW_NotSet"); // NOI18N
259
if (valueButton.isSelected()) {
260             if (requiredType.equals(String JavaDoc.class)) {
261                 String JavaDoc s = valueField.getText();
262                 s = Utilities.replaceString(s, "\\", "\\\\"); // fixes bug 835 // NOI18N
263
s = Utilities.replaceString(s, "\"", "\\\""); // NOI18N
264
return "\""+s+"\""; // NOI18N
265
}
266             else
267                 return(valueField.getText() != null) ? valueField.getText() : ""; // NOI18N
268
} else if (codeButton.isSelected()) {
269             return codeArea.getText();
270         } else if (beanButton.isSelected()) {
271             if (selectedComponent == formModel.getTopRADComponent()) {
272                 return "this"; // NOI18N
273
} else {
274                 return(selectedComponent.getName());
275             }
276         } else if (propertyButton.isSelected()) {
277             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
278             if (selectedComponent != formModel.getTopRADComponent()) {
279                 sb.append(selectedComponent.getName());
280                 sb.append("."); // NOI18N
281
}
282             if (selectedProperty != null) {
283                 sb.append(selectedProperty.getReadMethod().getName());
284                 sb.append("()"); // NOI18N
285
} else {
286                 sb.append("???"); // NOI18N
287
}
288             return sb.toString();
289         } else if (methodButton.isSelected()) {
290             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
291             if (selectedComponent != formModel.getTopRADComponent()) {
292                 sb.append(selectedComponent.getName());
293                 sb.append("."); // NOI18N
294
}
295             sb.append(selectedMethod.getName()); // [FUTURE: - method parameters]
296
sb.append("()"); // NOI18N
297
return sb.toString();
298         } else return ""; // NOI18N
299
}
300
301     public boolean isFilled() {
302         if (codeButton.isSelected()) {
303             if (requiredType.equals(String JavaDoc.class)) return true;
304             else return !"".equals(codeArea.getText()); // NOI18N
305
} else if (beanButton.isSelected()) {
306             return(selectedComponent != null);
307         } else if (propertyButton.isSelected()) {
308             return(selectedProperty != null);
309         } else if (valueButton.isSelected()) {
310             if (requiredType.equals(String JavaDoc.class)) return true;
311             else return !"".equals(valueField.getText()); // NOI18N
312
} else if (methodButton.isSelected()) {
313             return(selectedMethod != null);
314         } else return false;
315     }
316
317     public synchronized void addChangeListener(ChangeListener JavaDoc l) {
318         if (listeners == null)
319             listeners = new ArrayList();
320         listeners.add(l);
321     }
322
323     public synchronized void removeListener(ChangeListener JavaDoc l) {
324         if (listeners == null)
325             return;
326         listeners.remove(l);
327     }
328
329     private synchronized void fireStateChange() {
330         if (listeners == null)
331             return;
332         ArrayList list =(ArrayList)listeners.clone();
333         ChangeEvent JavaDoc evt = new ChangeEvent JavaDoc(this);
334         for (Iterator it = list.iterator(); it.hasNext();)
335             ((ChangeListener JavaDoc)it.next()).stateChanged(evt);
336     }
337
338     /** This method is called from within the constructor to
339      * initialize the form.
340      * WARNING: Do NOT modify this code. The content of this method is
341      * always regenerated by the FormEditor.
342      */

343     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
344
private void initComponents() {
345         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
346
347         valueButton = new javax.swing.JRadioButton JavaDoc();
348         valueField = new javax.swing.JTextField JavaDoc();
349         beanButton = new javax.swing.JRadioButton JavaDoc();
350         beanCombo = new javax.swing.JComboBox JavaDoc();
351         propertyButton = new javax.swing.JRadioButton JavaDoc();
352         propertyLabel = new javax.swing.JTextField JavaDoc();
353         propertyDetailsButton = new javax.swing.JButton JavaDoc();
354         methodButton = new javax.swing.JRadioButton JavaDoc();
355         methodLabel = new javax.swing.JTextField JavaDoc();
356         methodDetailsButton = new javax.swing.JButton JavaDoc();
357         codeButton = new javax.swing.JRadioButton JavaDoc();
358         codeScrollPane = new javax.swing.JScrollPane JavaDoc();
359         codeArea = FormEditor.createCodeEditorPane(formModel);
360         paramLabel = new javax.swing.JLabel JavaDoc();
361
362         setLayout(new java.awt.GridBagLayout JavaDoc());
363
364         valueButton.setText("Value:");
365         valueButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
366             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
367                 typeButtonPressed(evt);
368             }
369         });
370
371         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
372         gridBagConstraints.gridx = 0;
373         gridBagConstraints.gridy = 1;
374         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
375         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
376         add(valueButton, gridBagConstraints);
377
378         valueField.addCaretListener(new javax.swing.event.CaretListener JavaDoc() {
379             public void caretUpdate(javax.swing.event.CaretEvent JavaDoc evt) {
380                 updateState(evt);
381             }
382         });
383
384         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
385         gridBagConstraints.gridx = 1;
386         gridBagConstraints.gridy = 1;
387         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
388         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
389         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
390         add(valueField, gridBagConstraints);
391
392         beanButton.setText("Bean:");
393         beanButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
394             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
395                 typeButtonPressed(evt);
396             }
397         });
398
399         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
400         gridBagConstraints.gridx = 0;
401         gridBagConstraints.gridy = 2;
402         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
403         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
404         add(beanButton, gridBagConstraints);
405
406         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
407         gridBagConstraints.gridx = 1;
408         gridBagConstraints.gridy = 2;
409         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
410         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
411         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
412         add(beanCombo, gridBagConstraints);
413
414         propertyButton.setText("Property:");
415         propertyButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
416             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
417                 typeButtonPressed(evt);
418             }
419         });
420
421         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
422         gridBagConstraints.gridx = 0;
423         gridBagConstraints.gridy = 3;
424         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
425         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
426         add(propertyButton, gridBagConstraints);
427
428         propertyLabel.setEditable(false);
429         propertyLabel.setText(FormUtils.getBundleString("CTL_CW_NoProperty"));
430         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
431         gridBagConstraints.gridx = 1;
432         gridBagConstraints.gridy = 3;
433         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
434         gridBagConstraints.weightx = 1.0;
435         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
436         add(propertyLabel, gridBagConstraints);
437
438         propertyDetailsButton.setText("...");
439         propertyDetailsButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
440             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
441                 propertyDetailsButtonActionPerformed(evt);
442             }
443         });
444
445         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
446         gridBagConstraints.gridx = 2;
447         gridBagConstraints.gridy = 3;
448         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
449         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
450         add(propertyDetailsButton, gridBagConstraints);
451
452         methodButton.setText("Method Call:");
453         methodButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
454             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
455                 typeButtonPressed(evt);
456             }
457         });
458
459         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
460         gridBagConstraints.gridx = 0;
461         gridBagConstraints.gridy = 4;
462         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
463         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
464         add(methodButton, gridBagConstraints);
465
466         methodLabel.setEditable(false);
467         methodLabel.setText(FormUtils.getBundleString("CTL_CW_NoMethod"));
468         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
469         gridBagConstraints.gridx = 1;
470         gridBagConstraints.gridy = 4;
471         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
472         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
473         add(methodLabel, gridBagConstraints);
474
475         methodDetailsButton.setText("...");
476         methodDetailsButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
477             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
478                 methodDetailsButtonActionPerformed(evt);
479             }
480         });
481
482         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
483         gridBagConstraints.gridx = 2;
484         gridBagConstraints.gridy = 4;
485         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
486         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
487         add(methodDetailsButton, gridBagConstraints);
488
489         codeButton.setText("User Code:");
490         codeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
491             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
492                 typeButtonPressed(evt);
493             }
494         });
495
496         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
497         gridBagConstraints.gridx = 0;
498         gridBagConstraints.gridy = 5;
499         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
500         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
501         add(codeButton, gridBagConstraints);
502
503         codeArea.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
504             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
505                 codeAreaMouseClicked(evt);
506             }
507         });
508         codeArea.addCaretListener(new javax.swing.event.CaretListener JavaDoc() {
509             public void caretUpdate(javax.swing.event.CaretEvent JavaDoc evt) {
510                 updateState(evt);
511             }
512         });
513
514         codeScrollPane.setViewportView(codeArea);
515
516         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
517         gridBagConstraints.gridx = 1;
518         gridBagConstraints.gridy = 5;
519         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
520         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
521         gridBagConstraints.weightx = 1.0;
522         gridBagConstraints.weighty = 1.0;
523         add(codeScrollPane, gridBagConstraints);
524
525         paramLabel.setText(FormUtils.getBundleString("CTL_CW_GetParametersFrom"));
526         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
527         gridBagConstraints.gridx = 0;
528         gridBagConstraints.gridy = 0;
529         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
530         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
531         add(paramLabel, gridBagConstraints);
532
533     }// </editor-fold>//GEN-END:initComponents
534

535     private void codeAreaMouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_codeAreaMouseClicked
536
if (!codeButton.isSelected())
537             codeButton.doClick();
538     }//GEN-LAST:event_codeAreaMouseClicked
539

540     private void methodDetailsButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_methodDetailsButtonActionPerformed
541
MethodPicker picker = new MethodPicker(formModel, null, requiredType);
542         picker.setSelectedComponent(selectedComponent);
543         picker.setSelectedMethod(selectedMethod);
544
545         String JavaDoc title = FormUtils.getFormattedBundleString(
546             "CTL_FMT_CW_SelectMethod", // NOI18N
547
new Object JavaDoc[] { Utilities.getShortClassName(requiredType) });
548
549         final DialogDescriptor dd = new DialogDescriptor(picker, title);
550         dd.setValid(picker.isPickerValid());
551         picker.addPropertyChangeListener("pickerValid", new PropertyChangeListener() { // NOI18N
552
public void propertyChange(PropertyChangeEvent evt2) {
553                 dd.setValid(((Boolean JavaDoc)evt2.getNewValue()).booleanValue());
554             }
555         });
556         java.awt.Dialog JavaDoc dialog = org.openide.DialogDisplayer.getDefault().createDialog(dd);
557         dialog.setVisible(true);
558
559         if (dd.getValue() == DialogDescriptor.OK_OPTION) {
560             selectedComponent = picker.getSelectedComponent();
561         
562         MethodPicker.MethodPickerItem selectedItem = picker.getSelectedMethod();
563         selectedMethod = selectedItem.getMethodDescriptor();
564         if(selectedMethod==null) {
565         switchToCodeArea(selectedItem.getMethodName());
566         return;
567         }
568                     
569             methodLabel.setEnabled(true);
570             if (selectedComponent == formModel.getTopRADComponent()) {
571                 methodLabel.setText(selectedMethod.getName());
572             } else {
573                 methodLabel.setText(selectedComponent.getName() + "." + selectedMethod.getName()); // NOI18N
574
}
575             methodLabel.repaint();
576             fireStateChange();
577         }
578     }//GEN-LAST:event_methodDetailsButtonActionPerformed
579

580     private void updateState(javax.swing.event.CaretEvent JavaDoc evt) {//GEN-FIRST:event_updateState
581
fireStateChange();
582         codeArea.getCaret().setVisible(codeButton.isSelected() && codeArea.hasFocus());
583     }//GEN-LAST:event_updateState
584

585     private void propertyDetailsButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_propertyDetailsButtonActionPerformed
586
if (propertyPicker == null) {
587             propertyPicker = new PropertyPicker(formModel, null, requiredType);
588         }
589         propertyPicker.setSelectedComponent(selectedComponent);
590         propertyPicker.setSelectedProperty(selectedProperty);
591         
592         String JavaDoc title = FormUtils.getFormattedBundleString(
593             "CTL_FMT_CW_SelectProperty", // NOI18N
594
new Object JavaDoc[] { Utilities.getShortClassName(requiredType) });
595         
596         final DialogDescriptor dd = new DialogDescriptor(propertyPicker, title);
597         dd.setValid(propertyPicker.isPickerValid());
598         propertyPicker.addPropertyChangeListener("pickerValid", new PropertyChangeListener() { // NOI18N
599
public void propertyChange(PropertyChangeEvent evt2) {
600                 dd.setValid(((Boolean JavaDoc)evt2.getNewValue()).booleanValue());
601             }
602         });
603         java.awt.Dialog JavaDoc dialog = org.openide.DialogDisplayer.getDefault().createDialog(dd);
604         dialog.setVisible(true);
605         
606         if (dd.getValue() == DialogDescriptor.OK_OPTION) {
607             selectedComponent = propertyPicker.getSelectedComponent();
608         
609         PropertyPicker.PropertyPickerItem selectedItem = propertyPicker.getSelectedProperty();
610         selectedProperty = selectedItem.getPropertyDescriptor();
611         if(selectedProperty == null) {
612         switchToCodeArea(selectedItem.getReadMethodName());
613         return;
614         }
615         
616             propertyLabel.setEnabled(true);
617             if (selectedComponent == formModel.getTopRADComponent()) {
618                 propertyLabel.setText(selectedProperty.getName());
619             } else {
620                 propertyLabel.setText(selectedComponent.getName() + "." + selectedProperty.getName()); // NOI18N
621
}
622             propertyLabel.repaint();
623             fireStateChange();
624         }
625     }//GEN-LAST:event_propertyDetailsButtonActionPerformed
626

627     private void switchToCodeArea(String JavaDoc text) {
628     codeArea.setText(text);
629     codeButton.setSelected(true);
630     updateParameterTypes();
631     }
632     
633     private void typeButtonPressed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_typeButtonPressed
634
updateParameterTypes();
635         if (beanButton.isSelected()) {
636             beanCombo.requestFocus();
637         } else if (codeButton.isSelected()) {
638             codeArea.requestFocus();
639         } else if (propertyButton.isSelected()) {
640             propertyDetailsButton.requestFocus();
641         } else if (methodButton.isSelected()) {
642             methodDetailsButton.requestFocus();
643         } else if (valueButton.isSelected()) {
644             valueField.requestFocus();
645         }
646     }//GEN-LAST:event_typeButtonPressed
647

648     private void updateParameterTypes() {
649         valueField.setEnabled(valueButton.isSelected());
650         beanCombo.setEnabled(beanButton.isSelected());
651         if (!propertyButton.isSelected())
652             propertyLabel.setText(FormUtils.getBundleString("CTL_CW_NoProperty")); // NOI18N
653
propertyLabel.setEnabled(propertyButton.isSelected());
654         propertyLabel.repaint();
655         propertyDetailsButton.setEnabled(propertyButton.isSelected());
656
657         if (!methodButton.isSelected())
658             methodLabel.setText(FormUtils.getBundleString("CTL_CW_NoMethod")); // NOI18N
659
methodLabel.setEnabled(methodButton.isSelected());
660         methodLabel.repaint();
661         methodDetailsButton.setEnabled(methodButton.isSelected());
662         codeArea.setEnabled(codeButton.isSelected());
663         //codeArea.setEditable(codeButton.isSelected());
664
codeArea.getCaret().setVisible(codeButton.isSelected() && codeArea.hasFocus());
665         fireStateChange();
666     }
667     
668     // Variables declaration - do not modify//GEN-BEGIN:variables
669
private javax.swing.JRadioButton JavaDoc beanButton;
670     private javax.swing.JComboBox JavaDoc beanCombo;
671     private javax.swing.JEditorPane JavaDoc codeArea;
672     private javax.swing.JRadioButton JavaDoc codeButton;
673     private javax.swing.JScrollPane JavaDoc codeScrollPane;
674     private javax.swing.JRadioButton JavaDoc methodButton;
675     private javax.swing.JButton JavaDoc methodDetailsButton;
676     private javax.swing.JTextField JavaDoc methodLabel;
677     private javax.swing.JLabel JavaDoc paramLabel;
678     private javax.swing.JRadioButton JavaDoc propertyButton;
679     private javax.swing.JButton JavaDoc propertyDetailsButton;
680     private javax.swing.JTextField JavaDoc propertyLabel;
681     private javax.swing.JRadioButton JavaDoc valueButton;
682     private javax.swing.JTextField JavaDoc valueField;
683     // End of variables declaration//GEN-END:variables
684

685     private FormModel formModel;
686     private Class JavaDoc requiredType;
687
688     private PropertyPicker propertyPicker;
689
690     private ArrayList listeners;
691     private RADComponent selectedComponent;
692     private PropertyDescriptor selectedProperty;
693     private MethodDescriptor selectedMethod;
694
695     private java.util.List JavaDoc beansList;
696
697     // -------
698

699     static class ComponentComparator implements Comparator {
700         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
701             RADComponent comp1 = (RADComponent) o1;
702             RADComponent comp2 = (RADComponent) o2;
703             if (comp1 == comp2)
704                 return 0;
705
706             RADComponent topComp = comp1.getFormModel().getTopRADComponent();
707             if (comp1 == topComp)
708                 return -1;
709             if (comp2 == topComp)
710                 return 1;
711
712             return comp1.getName().compareTo(comp2.getName());
713         }
714     }
715 }
716
Popular Tags