001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form;
043:
044: import java.awt.event.ItemEvent;
045: import java.awt.event.ItemListener;
046: import java.beans.*;
047: import java.util.*;
048: import javax.swing.event.ChangeEvent;
049: import javax.swing.event.ChangeListener;
050:
051: import org.openide.awt.Mnemonics;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.Utilities;
054: import org.openide.ErrorManager;
055: import org.openide.DialogDescriptor;
056:
057: /** The ParametersPicker is a panel which allows to enter a method parameter data.
058: *
059: * @author Ian Formanek
060: */
061: public class ParametersPicker extends javax.swing.JPanel {
062:
063: static final long serialVersionUID = 1116033799965380000L;
064:
065: private boolean previousValue = false;
066:
067: /**
068: * Initializes the Form.
069: *
070: * @param formModel form model.
071: * @param requiredType type of the parameter.
072: */
073: public ParametersPicker(FormModel formModel, Class requiredType) {
074: this .formModel = formModel;
075: this .requiredType = requiredType;
076: initComponents();
077:
078: javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup();
079: bg.add(valueButton);
080: bg.add(beanButton);
081: bg.add(propertyButton);
082: bg.add(methodButton);
083: bg.add(codeButton);
084:
085: if ((!requiredType.isPrimitive())
086: && (!requiredType.equals(String.class))) {
087: valueButton.setEnabled(false);
088: propertyButton.setSelected(true);
089: }
090:
091: // localize components
092: paramLabel.setLabelFor(this );
093: propertyLabel.setText(FormUtils
094: .getBundleString("CTL_CW_NoProperty")); // NOI18N
095: methodLabel.setText(FormUtils
096: .getBundleString("CTL_CW_NoMethod")); // NOI18N
097:
098: Mnemonics.setLocalizedText(valueButton, FormUtils
099: .getBundleString("CTL_CW_Value")); // NOI18N
100: Mnemonics.setLocalizedText(beanButton, FormUtils
101: .getBundleString("CTL_CW_Bean")); // NOI18N
102: Mnemonics.setLocalizedText(propertyButton, FormUtils
103: .getBundleString("CTL_CW_Property")); // NOI18N
104: Mnemonics.setLocalizedText(methodButton, FormUtils
105: .getBundleString("CTL_CW_Method")); // NOI18N
106: Mnemonics.setLocalizedText(codeButton, FormUtils
107: .getBundleString("CTL_CW_UserCode")); // NOI18N
108:
109: beansList = new ArrayList<RADComponent>();
110: for (RADComponent radComp : formModel.getAllComponents()) {
111: if (this .requiredType.isAssignableFrom(radComp
112: .getBeanClass()))
113: beansList.add(radComp);
114: }
115: if (beansList.size() > 0) {
116: Collections.sort(beansList, new ComponentComparator());
117:
118: beanCombo.addItem(FormUtils
119: .getBundleString("CTL_CW_SelectBean")); // NOI18N
120: for (Iterator it = beansList.iterator(); it.hasNext();) {
121: RADComponent radComp = (RADComponent) it.next();
122: if (radComp == formModel.getTopRADComponent())
123: beanCombo
124: .addItem(FormUtils
125: .getBundleString("CTL_FormTopContainerName")); // NOI18N
126: else
127: beanCombo.addItem(radComp.getName());
128: }
129:
130: beanCombo.addItemListener(new ItemListener() {
131: public void itemStateChanged(ItemEvent evt) {
132: int index = beanCombo.getSelectedIndex();
133: if (index == 0) {
134: selectedComponent = null;
135: } else {
136: selectedComponent = beansList.get(index - 1);
137: }
138: fireStateChange();
139: }
140: });
141: } else
142: beanButton.setEnabled(false); // no beans on the form are of the required type
143:
144: updateParameterTypes();
145:
146: HelpCtx.setHelpIDString(this , "gui.source.modifying.property"); // NOI18N
147:
148: valueButton.getAccessibleContext().setAccessibleDescription(
149: FormUtils.getBundleString("ACSD_CTL_CW_Value")); // NOI18N
150: beanButton.getAccessibleContext().setAccessibleDescription(
151: FormUtils.getBundleString("ACSD_CTL_CW_Bean")); // NOI18N
152: propertyButton.getAccessibleContext().setAccessibleDescription(
153: FormUtils.getBundleString("ACSD_CTL_CW_Property")); // NOI18N
154: methodButton.getAccessibleContext().setAccessibleDescription(
155: FormUtils.getBundleString("ACSD_CTL_CW_Method")); // NOI18N
156: codeButton.getAccessibleContext().setAccessibleDescription(
157: FormUtils.getBundleString("ACSD_CTL_CW_UserCode")); // NOI18N
158:
159: valueField.getAccessibleContext().setAccessibleName(
160: valueButton.getText());
161: valueField.getAccessibleContext().setAccessibleDescription(
162: FormUtils.getBundleString("ACSD_CTL_CW_ValueField")); // NOI18N
163: beanCombo.getAccessibleContext().setAccessibleName(
164: beanButton.getText());
165: beanCombo.getAccessibleContext().setAccessibleDescription(
166: FormUtils.getBundleString("ACSD_CTL_CW_BeanCombo")); // NOI18N
167: propertyLabel.getAccessibleContext().setAccessibleName(
168: propertyButton.getText());
169: propertyLabel.getAccessibleContext().setAccessibleDescription(
170: FormUtils.getBundleString("ACSD_CTL_CW_PropertyLabel")); // NOI18N
171: methodLabel.getAccessibleContext().setAccessibleName(
172: methodButton.getText());
173: methodLabel.getAccessibleContext().setAccessibleDescription(
174: FormUtils.getBundleString("ACSD_CTL_CW_MethodLabel")); // NOI18N
175: codeArea.getAccessibleContext().setAccessibleName(
176: codeButton.getText());
177: codeArea.getAccessibleContext().setAccessibleDescription(
178: FormUtils.getBundleString("ACSD_CTL_CW_UserCodeArea")); // NOI18N
179:
180: propertyDetailsButton
181: .getAccessibleContext()
182: .setAccessibleDescription(
183: FormUtils
184: .getBundleString("ACSD_CTL_CW_PropertyButton")); // NOI18N
185: methodDetailsButton
186: .getAccessibleContext()
187: .setAccessibleDescription(
188: FormUtils
189: .getBundleString("ACSD_CTL_CW_MethodButton")); // NOI18N
190: getAccessibleContext().setAccessibleDescription(
191: FormUtils.getBundleString("ACSD_ParametersPicker")); // NOI18N
192: }
193:
194: public void setPropertyValue(
195: RADConnectionPropertyEditor.RADConnectionDesignValue value,
196: Object realValue) {
197: if (value == null) {
198: previousValue = realValue != null;
199: return; // can happen if starting without previously set value
200: } else {
201: previousValue = true;
202: }
203:
204: switch (value.type) {
205: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_VALUE:
206: valueButton.setSelected(true);
207: valueField.setText(value.value);
208: break;
209: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_BEAN:
210: beanButton.setSelected(true);
211: selectedComponent = value.getRADComponent();
212: int index = beansList.indexOf(selectedComponent);
213: if (index > -1)
214: beanCombo.setSelectedIndex(index + 1);
215: break;
216: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_PROPERTY:
217: propertyButton.setSelected(true);
218: selectedComponent = value.getRADComponent();
219: selectedProperty = value.getProperty();
220: if (selectedComponent.getCodeExpression() == null) {
221: propertyLabel.setText(FormUtils
222: .getBundleString("CTL_CONNECTION_INVALID")); // NOI18N
223: } else if (selectedComponent == formModel
224: .getTopRADComponent()) {
225: propertyLabel.setText(selectedProperty.getName());
226: } else {
227: propertyLabel.setText(selectedComponent.getName() + "."
228: + selectedProperty.getName()); // NOI18N
229: }
230: propertyLabel.selectAll();
231: break;
232: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_METHOD:
233: methodButton.setSelected(true);
234: selectedComponent = value.getRADComponent();
235: selectedMethod = value.getMethod();
236: if (selectedComponent.getCodeExpression() == null) {
237: methodLabel.setText(FormUtils
238: .getBundleString("CTL_CONNECTION_INVALID")); // NOI18N
239: } else if (selectedComponent == formModel
240: .getTopRADComponent()) {
241: methodLabel.setText(selectedMethod.getName());
242: } else {
243: methodLabel.setText(selectedComponent.getName() + "."
244: + selectedMethod.getName()); // NOI18N
245: }
246: methodLabel.selectAll();
247: break;
248: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_CODE:
249: default:
250: codeButton.setSelected(true);
251: codeArea.setText(value.userCode);
252: break;
253: }
254:
255: // update enabled state
256: updateParameterTypes();
257: }
258:
259: /** Get the customized property value.
260: * @return the property value
261: * @exception IllegalStateException when the custom property editor does not contain a valid property value
262: *(and thus it should not be set)
263: */
264: public Object getPropertyValue() throws IllegalStateException {
265: if (valueButton.isSelected()
266: && !"".equals(valueField.getText())) {
267: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
268: requiredType, valueField.getText());
269: } else if (beanButton.isSelected() && selectedComponent != null) {
270: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
271: selectedComponent);
272: } else if (codeButton.isSelected()
273: && !"".equals(codeArea.getText())) {
274: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
275: codeArea.getText());
276: } else if (propertyButton.isSelected()
277: && selectedProperty != null) {
278: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
279: selectedComponent, selectedProperty);
280: } else if (methodButton.isSelected() && selectedMethod != null) {
281: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
282: selectedComponent, selectedMethod);
283: } else if (!previousValue) {
284: return BeanSupport.NO_VALUE;
285: }
286:
287: IllegalStateException exc = new IllegalStateException();
288: ErrorManager.getDefault().annotate(exc, ErrorManager.USER,
289: null, FormUtils.getBundleString("ERR_NothingEntered"), // NOI18N
290: null, null);
291: throw exc;
292:
293: }
294:
295: public String getPreviewText() {
296: if (!isFilled())
297: return FormUtils.getBundleString("CTL_CW_NotSet"); // NOI18N
298: if (codeButton.isSelected()) {
299: return FormUtils.getBundleString("CTL_CW_Code"); // NOI18N
300: }
301: return getText();
302: }
303:
304: public String getText() {
305: if (!isFilled())
306: return FormUtils.getBundleString("CTL_CW_NotSet"); // NOI18N
307: if (valueButton.isSelected()) {
308: if (requiredType.equals(String.class)) {
309: String s = valueField.getText();
310: s = Utilities.replaceString(s, "\\", "\\\\"); // fixes bug 835 // NOI18N
311: s = Utilities.replaceString(s, "\"", "\\\""); // NOI18N
312: return "\"" + s + "\""; // NOI18N
313: } else
314: return (valueField.getText() != null) ? valueField
315: .getText() : ""; // NOI18N
316: } else if (codeButton.isSelected()) {
317: return codeArea.getText();
318: } else if (beanButton.isSelected()) {
319: if (selectedComponent == formModel.getTopRADComponent()) {
320: return "this"; // NOI18N
321: } else {
322: return (selectedComponent.getName());
323: }
324: } else if (propertyButton.isSelected()) {
325: StringBuffer sb = new StringBuffer();
326: if (selectedComponent != formModel.getTopRADComponent()) {
327: sb.append(selectedComponent.getName());
328: sb.append("."); // NOI18N
329: }
330: if (selectedProperty != null) {
331: sb.append(selectedProperty.getReadMethod().getName());
332: sb.append("()"); // NOI18N
333: } else {
334: sb.append("???"); // NOI18N
335: }
336: return sb.toString();
337: } else if (methodButton.isSelected()) {
338: StringBuffer sb = new StringBuffer();
339: if (selectedComponent != formModel.getTopRADComponent()) {
340: sb.append(selectedComponent.getName());
341: sb.append("."); // NOI18N
342: }
343: sb.append(selectedMethod.getName()); // [FUTURE: - method parameters]
344: sb.append("()"); // NOI18N
345: return sb.toString();
346: } else
347: return ""; // NOI18N
348: }
349:
350: public boolean isFilled() {
351: if (codeButton.isSelected()) {
352: if (requiredType.equals(String.class))
353: return true;
354: else
355: return !"".equals(codeArea.getText()); // NOI18N
356: } else if (beanButton.isSelected()) {
357: return (selectedComponent != null);
358: } else if (propertyButton.isSelected()) {
359: return (selectedProperty != null);
360: } else if (valueButton.isSelected()) {
361: if (requiredType.equals(String.class))
362: return true;
363: else
364: return !"".equals(valueField.getText()); // NOI18N
365: } else if (methodButton.isSelected()) {
366: return (selectedMethod != null);
367: } else
368: return false;
369: }
370:
371: public synchronized void addChangeListener(ChangeListener l) {
372: if (listeners == null)
373: listeners = new ArrayList<ChangeListener>();
374: listeners.add(l);
375: }
376:
377: public synchronized void removeListener(ChangeListener l) {
378: if (listeners == null)
379: return;
380: listeners.remove(l);
381: }
382:
383: private synchronized void fireStateChange() {
384: if (listeners == null)
385: return;
386: List<ChangeListener> list = new ArrayList<ChangeListener>(
387: listeners);
388: ChangeEvent evt = new ChangeEvent(this );
389: for (Iterator<ChangeListener> it = list.iterator(); it
390: .hasNext();)
391: it.next().stateChanged(evt);
392: }
393:
394: /** This method is called from within the constructor to
395: * initialize the form.
396: * WARNING: Do NOT modify this code. The content of this method is
397: * always regenerated by the FormEditor.
398: */
399: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
400: private void initComponents() {
401: java.awt.GridBagConstraints gridBagConstraints;
402:
403: valueButton = new javax.swing.JRadioButton();
404: valueField = new javax.swing.JTextField();
405: beanButton = new javax.swing.JRadioButton();
406: beanCombo = new javax.swing.JComboBox();
407: propertyButton = new javax.swing.JRadioButton();
408: propertyLabel = new javax.swing.JTextField();
409: propertyDetailsButton = new javax.swing.JButton();
410: methodButton = new javax.swing.JRadioButton();
411: methodLabel = new javax.swing.JTextField();
412: methodDetailsButton = new javax.swing.JButton();
413: codeButton = new javax.swing.JRadioButton();
414: codeScrollPane = new javax.swing.JScrollPane();
415: codeArea = FormEditor.createCodeEditorPane(formModel);
416: paramLabel = new javax.swing.JLabel();
417:
418: setLayout(new java.awt.GridBagLayout());
419:
420: valueButton.setText("Value:");
421: valueButton
422: .addActionListener(new java.awt.event.ActionListener() {
423: public void actionPerformed(
424: java.awt.event.ActionEvent evt) {
425: typeButtonPressed(evt);
426: }
427: });
428:
429: gridBagConstraints = new java.awt.GridBagConstraints();
430: gridBagConstraints.gridx = 0;
431: gridBagConstraints.gridy = 1;
432: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
433: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
434: add(valueButton, gridBagConstraints);
435:
436: valueField
437: .addCaretListener(new javax.swing.event.CaretListener() {
438: public void caretUpdate(
439: javax.swing.event.CaretEvent evt) {
440: updateState(evt);
441: }
442: });
443:
444: gridBagConstraints = new java.awt.GridBagConstraints();
445: gridBagConstraints.gridx = 1;
446: gridBagConstraints.gridy = 1;
447: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
448: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
449: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
450: add(valueField, gridBagConstraints);
451:
452: beanButton.setText("Bean:");
453: beanButton
454: .addActionListener(new java.awt.event.ActionListener() {
455: public void actionPerformed(
456: java.awt.event.ActionEvent evt) {
457: typeButtonPressed(evt);
458: }
459: });
460:
461: gridBagConstraints = new java.awt.GridBagConstraints();
462: gridBagConstraints.gridx = 0;
463: gridBagConstraints.gridy = 2;
464: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
465: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
466: add(beanButton, gridBagConstraints);
467:
468: gridBagConstraints = new java.awt.GridBagConstraints();
469: gridBagConstraints.gridx = 1;
470: gridBagConstraints.gridy = 2;
471: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
472: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
473: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
474: add(beanCombo, gridBagConstraints);
475:
476: propertyButton.setText("Property:");
477: propertyButton
478: .addActionListener(new java.awt.event.ActionListener() {
479: public void actionPerformed(
480: java.awt.event.ActionEvent evt) {
481: typeButtonPressed(evt);
482: }
483: });
484:
485: gridBagConstraints = new java.awt.GridBagConstraints();
486: gridBagConstraints.gridx = 0;
487: gridBagConstraints.gridy = 3;
488: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
489: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
490: add(propertyButton, gridBagConstraints);
491:
492: propertyLabel.setEditable(false);
493: propertyLabel.setText(FormUtils
494: .getBundleString("CTL_CW_NoProperty"));
495: gridBagConstraints = new java.awt.GridBagConstraints();
496: gridBagConstraints.gridx = 1;
497: gridBagConstraints.gridy = 3;
498: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
499: gridBagConstraints.weightx = 1.0;
500: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
501: add(propertyLabel, gridBagConstraints);
502:
503: propertyDetailsButton.setText("...");
504: propertyDetailsButton
505: .addActionListener(new java.awt.event.ActionListener() {
506: public void actionPerformed(
507: java.awt.event.ActionEvent evt) {
508: propertyDetailsButtonActionPerformed(evt);
509: }
510: });
511:
512: gridBagConstraints = new java.awt.GridBagConstraints();
513: gridBagConstraints.gridx = 2;
514: gridBagConstraints.gridy = 3;
515: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
516: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
517: add(propertyDetailsButton, gridBagConstraints);
518:
519: methodButton.setText("Method Call:");
520: methodButton
521: .addActionListener(new java.awt.event.ActionListener() {
522: public void actionPerformed(
523: java.awt.event.ActionEvent evt) {
524: typeButtonPressed(evt);
525: }
526: });
527:
528: gridBagConstraints = new java.awt.GridBagConstraints();
529: gridBagConstraints.gridx = 0;
530: gridBagConstraints.gridy = 4;
531: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
532: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
533: add(methodButton, gridBagConstraints);
534:
535: methodLabel.setEditable(false);
536: methodLabel.setText(FormUtils
537: .getBundleString("CTL_CW_NoMethod"));
538: gridBagConstraints = new java.awt.GridBagConstraints();
539: gridBagConstraints.gridx = 1;
540: gridBagConstraints.gridy = 4;
541: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
542: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
543: add(methodLabel, gridBagConstraints);
544:
545: methodDetailsButton.setText("...");
546: methodDetailsButton
547: .addActionListener(new java.awt.event.ActionListener() {
548: public void actionPerformed(
549: java.awt.event.ActionEvent evt) {
550: methodDetailsButtonActionPerformed(evt);
551: }
552: });
553:
554: gridBagConstraints = new java.awt.GridBagConstraints();
555: gridBagConstraints.gridx = 2;
556: gridBagConstraints.gridy = 4;
557: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
558: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
559: add(methodDetailsButton, gridBagConstraints);
560:
561: codeButton.setText("User Code:");
562: codeButton
563: .addActionListener(new java.awt.event.ActionListener() {
564: public void actionPerformed(
565: java.awt.event.ActionEvent evt) {
566: typeButtonPressed(evt);
567: }
568: });
569:
570: gridBagConstraints = new java.awt.GridBagConstraints();
571: gridBagConstraints.gridx = 0;
572: gridBagConstraints.gridy = 5;
573: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
574: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
575: add(codeButton, gridBagConstraints);
576:
577: codeArea.addMouseListener(new java.awt.event.MouseAdapter() {
578: public void mouseClicked(java.awt.event.MouseEvent evt) {
579: codeAreaMouseClicked(evt);
580: }
581: });
582: codeArea
583: .addCaretListener(new javax.swing.event.CaretListener() {
584: public void caretUpdate(
585: javax.swing.event.CaretEvent evt) {
586: updateState(evt);
587: }
588: });
589:
590: codeScrollPane.setViewportView(codeArea);
591:
592: gridBagConstraints = new java.awt.GridBagConstraints();
593: gridBagConstraints.gridx = 1;
594: gridBagConstraints.gridy = 5;
595: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
596: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
597: gridBagConstraints.weightx = 1.0;
598: gridBagConstraints.weighty = 1.0;
599: add(codeScrollPane, gridBagConstraints);
600:
601: paramLabel.setText(FormUtils
602: .getBundleString("CTL_CW_GetParametersFrom"));
603: gridBagConstraints = new java.awt.GridBagConstraints();
604: gridBagConstraints.gridx = 0;
605: gridBagConstraints.gridy = 0;
606: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
607: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
608: add(paramLabel, gridBagConstraints);
609:
610: }// </editor-fold>//GEN-END:initComponents
611:
612: private void codeAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_codeAreaMouseClicked
613: if (!codeButton.isSelected())
614: codeButton.doClick();
615: }//GEN-LAST:event_codeAreaMouseClicked
616:
617: private void methodDetailsButtonActionPerformed(
618: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_methodDetailsButtonActionPerformed
619: MethodPicker picker = new MethodPicker(formModel, null,
620: requiredType);
621: picker.setSelectedComponent(selectedComponent);
622: picker.setSelectedMethod(selectedMethod);
623:
624: String title = FormUtils.getFormattedBundleString(
625: "CTL_FMT_CW_SelectMethod", // NOI18N
626: new Object[] { Utilities
627: .getShortClassName(requiredType) });
628:
629: final DialogDescriptor dd = new DialogDescriptor(picker, title);
630: dd.setValid(picker.isPickerValid());
631: picker.addPropertyChangeListener("pickerValid",
632: new PropertyChangeListener() { // NOI18N
633: public void propertyChange(PropertyChangeEvent evt2) {
634: dd.setValid(((Boolean) evt2.getNewValue())
635: .booleanValue());
636: }
637: });
638: java.awt.Dialog dialog = org.openide.DialogDisplayer
639: .getDefault().createDialog(dd);
640: dialog.setVisible(true);
641:
642: if (dd.getValue() == DialogDescriptor.OK_OPTION) {
643: selectedComponent = picker.getSelectedComponent();
644:
645: MethodPicker.MethodPickerItem selectedItem = picker
646: .getSelectedMethod();
647: selectedMethod = selectedItem.getMethodDescriptor();
648: if (selectedMethod == null) {
649: switchToCodeArea(selectedItem.getMethodName());
650: return;
651: }
652:
653: methodLabel.setEnabled(true);
654: if (selectedComponent == formModel.getTopRADComponent()) {
655: methodLabel.setText(selectedMethod.getName());
656: } else {
657: methodLabel.setText(selectedComponent.getName() + "."
658: + selectedMethod.getName()); // NOI18N
659: }
660: methodLabel.repaint();
661: fireStateChange();
662: }
663: }//GEN-LAST:event_methodDetailsButtonActionPerformed
664:
665: private void updateState(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_updateState
666: fireStateChange();
667: codeArea.getCaret().setVisible(
668: codeButton.isSelected() && codeArea.hasFocus());
669: }//GEN-LAST:event_updateState
670:
671: private void propertyDetailsButtonActionPerformed(
672: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propertyDetailsButtonActionPerformed
673: if (propertyPicker == null) {
674: propertyPicker = new PropertyPicker(formModel, null,
675: requiredType);
676: }
677: propertyPicker.setSelectedComponent(selectedComponent);
678: propertyPicker.setSelectedProperty(selectedProperty);
679:
680: String title = FormUtils.getFormattedBundleString(
681: "CTL_FMT_CW_SelectProperty", // NOI18N
682: new Object[] { Utilities
683: .getShortClassName(requiredType) });
684:
685: final DialogDescriptor dd = new DialogDescriptor(
686: propertyPicker, title);
687: dd.setValid(propertyPicker.isPickerValid());
688: propertyPicker.addPropertyChangeListener("pickerValid",
689: new PropertyChangeListener() { // NOI18N
690: public void propertyChange(PropertyChangeEvent evt2) {
691: dd.setValid(((Boolean) evt2.getNewValue())
692: .booleanValue());
693: }
694: });
695: java.awt.Dialog dialog = org.openide.DialogDisplayer
696: .getDefault().createDialog(dd);
697: dialog.setVisible(true);
698:
699: if (dd.getValue() == DialogDescriptor.OK_OPTION) {
700: selectedComponent = propertyPicker.getSelectedComponent();
701:
702: PropertyPicker.PropertyPickerItem selectedItem = propertyPicker
703: .getSelectedProperty();
704: selectedProperty = selectedItem.getPropertyDescriptor();
705: if (selectedProperty == null) {
706: switchToCodeArea(selectedItem.getReadMethodName());
707: return;
708: }
709:
710: propertyLabel.setEnabled(true);
711: if (selectedComponent == formModel.getTopRADComponent()) {
712: propertyLabel.setText(selectedProperty.getName());
713: } else {
714: propertyLabel.setText(selectedComponent.getName() + "."
715: + selectedProperty.getName()); // NOI18N
716: }
717: propertyLabel.repaint();
718: fireStateChange();
719: }
720: }//GEN-LAST:event_propertyDetailsButtonActionPerformed
721:
722: private void switchToCodeArea(String text) {
723: codeArea.setText(text);
724: codeButton.setSelected(true);
725: updateParameterTypes();
726: }
727:
728: private void typeButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typeButtonPressed
729: updateParameterTypes();
730: if (beanButton.isSelected()) {
731: beanCombo.requestFocus();
732: } else if (codeButton.isSelected()) {
733: codeArea.requestFocus();
734: } else if (propertyButton.isSelected()) {
735: propertyDetailsButton.requestFocus();
736: } else if (methodButton.isSelected()) {
737: methodDetailsButton.requestFocus();
738: } else if (valueButton.isSelected()) {
739: valueField.requestFocus();
740: }
741: }//GEN-LAST:event_typeButtonPressed
742:
743: private void updateParameterTypes() {
744: valueField.setEnabled(valueButton.isSelected());
745: beanCombo.setEnabled(beanButton.isSelected());
746: if (!propertyButton.isSelected())
747: propertyLabel.setText(FormUtils
748: .getBundleString("CTL_CW_NoProperty")); // NOI18N
749: propertyLabel.setEnabled(propertyButton.isSelected());
750: propertyLabel.repaint();
751: propertyDetailsButton.setEnabled(propertyButton.isSelected());
752:
753: if (!methodButton.isSelected())
754: methodLabel.setText(FormUtils
755: .getBundleString("CTL_CW_NoMethod")); // NOI18N
756: methodLabel.setEnabled(methodButton.isSelected());
757: methodLabel.repaint();
758: methodDetailsButton.setEnabled(methodButton.isSelected());
759: codeArea.setEnabled(codeButton.isSelected());
760: //codeArea.setEditable(codeButton.isSelected());
761: codeArea.getCaret().setVisible(
762: codeButton.isSelected() && codeArea.hasFocus());
763: fireStateChange();
764: }
765:
766: // Variables declaration - do not modify//GEN-BEGIN:variables
767: private javax.swing.JRadioButton beanButton;
768: private javax.swing.JComboBox beanCombo;
769: private javax.swing.JEditorPane codeArea;
770: private javax.swing.JRadioButton codeButton;
771: private javax.swing.JScrollPane codeScrollPane;
772: private javax.swing.JRadioButton methodButton;
773: private javax.swing.JButton methodDetailsButton;
774: private javax.swing.JTextField methodLabel;
775: private javax.swing.JLabel paramLabel;
776: private javax.swing.JRadioButton propertyButton;
777: private javax.swing.JButton propertyDetailsButton;
778: private javax.swing.JTextField propertyLabel;
779: private javax.swing.JRadioButton valueButton;
780: private javax.swing.JTextField valueField;
781: // End of variables declaration//GEN-END:variables
782:
783: private FormModel formModel;
784: private Class<?> requiredType;
785:
786: private PropertyPicker propertyPicker;
787:
788: private List<ChangeListener> listeners;
789: private RADComponent selectedComponent;
790: private PropertyDescriptor selectedProperty;
791: private MethodDescriptor selectedMethod;
792:
793: private java.util.List<RADComponent> beansList;
794:
795: // -------
796:
797: static class ComponentComparator implements
798: Comparator<RADComponent> {
799: public int compare(RADComponent comp1, RADComponent comp2) {
800: if (comp1 == comp2)
801: return 0;
802:
803: RADComponent topComp = comp1.getFormModel()
804: .getTopRADComponent();
805: if (comp1 == topComp)
806: return -1;
807: if (comp2 == topComp)
808: return 1;
809:
810: return comp1.getName().compareTo(comp2.getName());
811: }
812: }
813: }
|