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.util.HelpCtx;
052: import org.openide.util.Utilities;
053: import org.openide.ErrorManager;
054: import org.openide.DialogDescriptor;
055:
056: /** The ParametersPicker is a panel which allows to enter a method parameter data.
057: *
058: * @author Ian Formanek
059: */
060: public class ParametersPicker extends javax.swing.JPanel {
061:
062: static final long serialVersionUID = 1116033799965380000L;
063:
064: /** Initializes the Form */
065: public ParametersPicker(FormModel formModel, Class requiredType) {
066: initComponents();
067: this .requiredType = requiredType;
068: this .formModel = formModel;
069:
070: javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup();
071: bg.add(valueButton);
072: bg.add(beanButton);
073: bg.add(propertyButton);
074: bg.add(methodButton);
075: bg.add(codeButton);
076:
077: if ((!requiredType.isPrimitive())
078: && (!requiredType.equals(String.class))) {
079: valueButton.setEnabled(false);
080: propertyButton.setSelected(true);
081: }
082:
083: // localize components
084: paramLabel.setText(FormUtils
085: .getBundleString("CTL_CW_GetParametersFrom")); // NOI18N
086: paramLabel.setLabelFor(this );
087: valueButton.setText(FormUtils.getBundleString("CTL_CW_Value")); // NOI18N
088: beanButton.setText(FormUtils.getBundleString("CTL_CW_Bean")); // NOI18N
089: propertyButton.setText(FormUtils
090: .getBundleString("CTL_CW_Property")); // NOI18N
091: propertyLabel.setText(FormUtils
092: .getBundleString("CTL_CW_NoProperty")); // NOI18N
093: methodButton
094: .setText(FormUtils.getBundleString("CTL_CW_Method")); // NOI18N
095: methodLabel.setText(FormUtils
096: .getBundleString("CTL_CW_NoMethod")); // NOI18N
097: codeButton
098: .setText(FormUtils.getBundleString("CTL_CW_UserCode")); // NOI18N
099:
100: valueButton.setMnemonic(FormUtils.getBundleString(
101: "CTL_CW_Value_Mnemonic").charAt(0)); // NOI18N
102: beanButton.setMnemonic(FormUtils.getBundleString(
103: "CTL_CW_Bean_Mnemonic").charAt(0)); // NOI18N
104: propertyButton.setMnemonic(FormUtils.getBundleString(
105: "CTL_CW_Property_Mnemonic").charAt(0)); // NOI18N
106: methodButton.setMnemonic(FormUtils.getBundleString(
107: "CTL_CW_Method_Mnemonic").charAt(0)); // NOI18N
108: codeButton.setMnemonic(FormUtils.getBundleString(
109: "CTL_CW_UserCode_Mnemonic").charAt(0)); // NOI18N
110:
111: beansList = new ArrayList();
112: for (Iterator it = formModel.getMetaComponents().iterator(); it
113: .hasNext();) {
114: RADComponent radComp = (RADComponent) it.next();
115: if (requiredType.isAssignableFrom(radComp.getBeanClass()))
116: beansList.add(radComp);
117: }
118: if (beansList.size() > 0) {
119: Collections.sort(beansList, new ComponentComparator());
120:
121: beanCombo.addItem(FormUtils
122: .getBundleString("CTL_CW_SelectBean")); // NOI18N
123: for (Iterator it = beansList.iterator(); it.hasNext();) {
124: RADComponent radComp = (RADComponent) it.next();
125: if (radComp == formModel.getTopRADComponent())
126: beanCombo
127: .addItem(FormUtils
128: .getBundleString("CTL_FormTopContainerName")); // NOI18N
129: else
130: beanCombo.addItem(radComp.getName());
131: }
132:
133: beanCombo.addItemListener(new ItemListener() {
134: public void itemStateChanged(ItemEvent evt) {
135: int index = beanCombo.getSelectedIndex();
136: if (index == 0) {
137: selectedComponent = null;
138: } else {
139: selectedComponent = (RADComponent) beansList
140: .get(index - 1);
141: }
142: fireStateChange();
143: }
144: });
145: } else
146: beanButton.setEnabled(false); // no beans on the form are of the required type
147:
148: codeArea.setContentType("text/x-java"); // allow syntax coloring // NOI18N
149:
150: updateParameterTypes();
151: currentFilledState = isFilled();
152:
153: HelpCtx.setHelpIDString(this , "gui.source.modifying.property"); // NOI18N
154:
155: valueButton.getAccessibleContext().setAccessibleDescription(
156: FormUtils.getBundleString("ACSD_CTL_CW_Value")); // NOI18N
157: beanButton.getAccessibleContext().setAccessibleDescription(
158: FormUtils.getBundleString("ACSD_CTL_CW_Bean")); // NOI18N
159: propertyButton.getAccessibleContext().setAccessibleDescription(
160: FormUtils.getBundleString("ACSD_CTL_CW_Property")); // NOI18N
161: methodButton.getAccessibleContext().setAccessibleDescription(
162: FormUtils.getBundleString("ACSD_CTL_CW_Method")); // NOI18N
163: codeButton.getAccessibleContext().setAccessibleDescription(
164: FormUtils.getBundleString("ACSD_CTL_CW_UserCode")); // NOI18N
165:
166: valueField.getAccessibleContext().setAccessibleName(
167: valueButton.getText());
168: valueField.getAccessibleContext().setAccessibleDescription(
169: FormUtils.getBundleString("ACSD_CTL_CW_ValueField")); // NOI18N
170: beanCombo.getAccessibleContext().setAccessibleName(
171: beanButton.getText());
172: beanCombo.getAccessibleContext().setAccessibleDescription(
173: FormUtils.getBundleString("ACSD_CTL_CW_BeanCombo")); // NOI18N
174: propertyLabel.getAccessibleContext().setAccessibleName(
175: propertyButton.getText());
176: propertyLabel.getAccessibleContext().setAccessibleDescription(
177: FormUtils.getBundleString("ACSD_CTL_CW_PropertyLabel")); // NOI18N
178: methodLabel.getAccessibleContext().setAccessibleName(
179: methodButton.getText());
180: methodLabel.getAccessibleContext().setAccessibleDescription(
181: FormUtils.getBundleString("ACSD_CTL_CW_MethodLabel")); // NOI18N
182: codeArea.getAccessibleContext().setAccessibleName(
183: codeButton.getText());
184: codeArea.getAccessibleContext().setAccessibleDescription(
185: FormUtils.getBundleString("ACSD_CTL_CW_UserCodeArea")); // NOI18N
186:
187: propertyDetailsButton
188: .getAccessibleContext()
189: .setAccessibleDescription(
190: FormUtils
191: .getBundleString("ACSD_CTL_CW_PropertyButton")); // NOI18N
192: methodDetailsButton
193: .getAccessibleContext()
194: .setAccessibleDescription(
195: FormUtils
196: .getBundleString("ACSD_CTL_CW_MethodButton")); // NOI18N
197: getAccessibleContext().setAccessibleDescription(
198: FormUtils.getBundleString("ACSD_ParametersPicker")); // NOI18N
199: }
200:
201: public void setPropertyValue(
202: RADConnectionPropertyEditor.RADConnectionDesignValue value) {
203: if (value == null)
204: return; // can happen if starting without previously set value
205:
206: switch (value.type) {
207: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_VALUE:
208: valueButton.setSelected(true);
209: valueField.setText(value.value);
210: break;
211: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_BEAN:
212: beanButton.setSelected(true);
213: selectedComponent = value.getRADComponent();
214: int index = beansList.indexOf(selectedComponent);
215: if (index > -1)
216: beanCombo.setSelectedIndex(index + 1);
217: break;
218: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_PROPERTY:
219: propertyButton.setSelected(true);
220: selectedComponent = value.getRADComponent();
221: selectedProperty = value.getProperty();
222: if (selectedComponent.getCodeExpression() == null) {
223: propertyLabel.setText(FormUtils
224: .getBundleString("CTL_CONNECTION_INVALID")); // NOI18N
225: } else if (selectedComponent == formModel
226: .getTopRADComponent()) {
227: propertyLabel.setText(selectedProperty.getName());
228: } else {
229: propertyLabel.setText(selectedComponent.getName() + "."
230: + selectedProperty.getName()); // NOI18N
231: }
232: propertyLabel.selectAll();
233: break;
234: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_METHOD:
235: methodButton.setSelected(true);
236: selectedComponent = value.getRADComponent();
237: selectedMethod = value.getMethod();
238: if (selectedComponent.getCodeExpression() == null) {
239: methodLabel.setText(FormUtils
240: .getBundleString("CTL_CONNECTION_INVALID")); // NOI18N
241: } else if (selectedComponent == formModel
242: .getTopRADComponent()) {
243: methodLabel.setText(selectedMethod.getName());
244: } else {
245: methodLabel.setText(selectedComponent.getName() + "."
246: + selectedMethod.getName()); // NOI18N
247: }
248: methodLabel.selectAll();
249: break;
250: case RADConnectionPropertyEditor.RADConnectionDesignValue.TYPE_CODE:
251: default:
252: codeButton.setSelected(true);
253: codeArea.setText(value.userCode);
254: break;
255: }
256:
257: // update enabled state
258: updateParameterTypes();
259: }
260:
261: /** Get the customized property value.
262: * @return the property value
263: * @exception InvalidStateException when the custom property editor does not contain a valid property value
264: *(and thus it should not be set)
265: */
266: public Object getPropertyValue() throws IllegalStateException {
267: if (!isFilled()) {
268: IllegalStateException exc = new IllegalStateException();
269: ErrorManager.getDefault().annotate(exc, ErrorManager.USER,
270: null,
271: FormUtils.getBundleString("ERR_NothingEntered"), // NOI18N
272: null, null);
273: throw exc;
274: }
275:
276: if (valueButton.isSelected()) {
277: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
278: requiredType, valueField.getText());
279: } else if (beanButton.isSelected()) {
280: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
281: selectedComponent);
282: } else if (codeButton.isSelected()) {
283: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
284: codeArea.getText());
285: } else if (propertyButton.isSelected()) {
286: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
287: selectedComponent, selectedProperty);
288: } else if (methodButton.isSelected()) {
289: return new RADConnectionPropertyEditor.RADConnectionDesignValue(
290: selectedComponent, selectedMethod);
291: } else
292: return null;
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();
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: ArrayList list = (ArrayList) listeners.clone();
387: ChangeEvent evt = new ChangeEvent(this );
388: for (Iterator it = list.iterator(); it.hasNext();)
389: ((ChangeListener) it.next()).stateChanged(evt);
390: }
391:
392: /** This method is called from within the constructor to
393: * initialize the form.
394: * WARNING: Do NOT modify this code. The content of this method is
395: * always regenerated by the FormEditor.
396: */
397: private void initComponents() {//GEN-BEGIN:initComponents
398: java.awt.GridBagConstraints gridBagConstraints;
399:
400: valueButton = new javax.swing.JRadioButton();
401: valueField = new javax.swing.JTextField();
402: beanButton = new javax.swing.JRadioButton();
403: beanCombo = new javax.swing.JComboBox();
404: propertyButton = new javax.swing.JRadioButton();
405: propertyLabel = new javax.swing.JTextField();
406: propertyDetailsButton = new javax.swing.JButton();
407: methodButton = new javax.swing.JRadioButton();
408: methodLabel = new javax.swing.JTextField();
409: methodDetailsButton = new javax.swing.JButton();
410: codeButton = new javax.swing.JRadioButton();
411: codeScrollPane = new javax.swing.JScrollPane();
412: codeArea = new javax.swing.JEditorPane();
413: paramLabel = new javax.swing.JLabel();
414:
415: setLayout(new java.awt.GridBagLayout());
416:
417: valueButton.setSelected(true);
418: valueButton.setText(FormUtils.getBundleString("CTL_CW_Value"));
419: valueButton
420: .addActionListener(new java.awt.event.ActionListener() {
421: public void actionPerformed(
422: java.awt.event.ActionEvent evt) {
423: typeButtonPressed(evt);
424: }
425: });
426:
427: gridBagConstraints = new java.awt.GridBagConstraints();
428: gridBagConstraints.gridx = 0;
429: gridBagConstraints.gridy = 1;
430: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
431: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
432: add(valueButton, gridBagConstraints);
433:
434: valueField
435: .addCaretListener(new javax.swing.event.CaretListener() {
436: public void caretUpdate(
437: javax.swing.event.CaretEvent evt) {
438: updateState(evt);
439: }
440: });
441:
442: gridBagConstraints = new java.awt.GridBagConstraints();
443: gridBagConstraints.gridx = 1;
444: gridBagConstraints.gridy = 1;
445: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
446: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
447: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
448: add(valueField, gridBagConstraints);
449:
450: beanButton.setText(FormUtils.getBundleString("CTL_CW_Bean"));
451: beanButton
452: .addActionListener(new java.awt.event.ActionListener() {
453: public void actionPerformed(
454: java.awt.event.ActionEvent evt) {
455: typeButtonPressed(evt);
456: }
457: });
458:
459: gridBagConstraints = new java.awt.GridBagConstraints();
460: gridBagConstraints.gridx = 0;
461: gridBagConstraints.gridy = 2;
462: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
463: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
464: add(beanButton, gridBagConstraints);
465:
466: gridBagConstraints = new java.awt.GridBagConstraints();
467: gridBagConstraints.gridx = 1;
468: gridBagConstraints.gridy = 2;
469: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
470: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
471: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
472: add(beanCombo, gridBagConstraints);
473:
474: propertyButton.setText(FormUtils
475: .getBundleString("CTL_CW_Property"));
476: propertyButton
477: .addActionListener(new java.awt.event.ActionListener() {
478: public void actionPerformed(
479: java.awt.event.ActionEvent evt) {
480: typeButtonPressed(evt);
481: }
482: });
483:
484: gridBagConstraints = new java.awt.GridBagConstraints();
485: gridBagConstraints.gridx = 0;
486: gridBagConstraints.gridy = 3;
487: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
488: gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
489: add(propertyButton, gridBagConstraints);
490:
491: propertyLabel.setEditable(false);
492: propertyLabel.setText(FormUtils
493: .getBundleString("CTL_CW_NoProperty"));
494: gridBagConstraints = new java.awt.GridBagConstraints();
495: gridBagConstraints.gridx = 1;
496: gridBagConstraints.gridy = 3;
497: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
498: gridBagConstraints.weightx = 1.0;
499: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
500: add(propertyLabel, gridBagConstraints);
501:
502: propertyDetailsButton.setText("...");
503: propertyDetailsButton
504: .addActionListener(new java.awt.event.ActionListener() {
505: public void actionPerformed(
506: java.awt.event.ActionEvent evt) {
507: propertyDetailsButtonActionPerformed(evt);
508: }
509: });
510:
511: gridBagConstraints = new java.awt.GridBagConstraints();
512: gridBagConstraints.gridx = 2;
513: gridBagConstraints.gridy = 3;
514: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
515: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
516: add(propertyDetailsButton, gridBagConstraints);
517:
518: methodButton.setText(FormUtils
519: .getBundleString("CTL_CW_MethodCall"));
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
562: .setText(FormUtils.getBundleString("CTL_CW_UserCode"));
563: codeButton
564: .addActionListener(new java.awt.event.ActionListener() {
565: public void actionPerformed(
566: java.awt.event.ActionEvent evt) {
567: typeButtonPressed(evt);
568: }
569: });
570:
571: gridBagConstraints = new java.awt.GridBagConstraints();
572: gridBagConstraints.gridx = 0;
573: gridBagConstraints.gridy = 5;
574: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
575: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
576: add(codeButton, gridBagConstraints);
577:
578: codeArea
579: .addCaretListener(new javax.swing.event.CaretListener() {
580: public void caretUpdate(
581: javax.swing.event.CaretEvent evt) {
582: updateState(evt);
583: }
584: });
585:
586: codeArea.addMouseListener(new java.awt.event.MouseAdapter() {
587: public void mouseClicked(java.awt.event.MouseEvent evt) {
588: codeAreaMouseClicked(evt);
589: }
590: });
591:
592: codeScrollPane.setViewportView(codeArea);
593:
594: gridBagConstraints = new java.awt.GridBagConstraints();
595: gridBagConstraints.gridx = 1;
596: gridBagConstraints.gridy = 5;
597: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
598: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
599: gridBagConstraints.weightx = 1.0;
600: gridBagConstraints.weighty = 1.0;
601: add(codeScrollPane, gridBagConstraints);
602:
603: paramLabel.setText("label1");
604: gridBagConstraints = new java.awt.GridBagConstraints();
605: gridBagConstraints.gridx = 0;
606: gridBagConstraints.gridy = 0;
607: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
608: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
609: add(paramLabel, gridBagConstraints);
610:
611: }//GEN-END:initComponents
612:
613: private void codeAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_codeAreaMouseClicked
614: if (!codeButton.isSelected())
615: codeButton.doClick();
616: }//GEN-LAST:event_codeAreaMouseClicked
617:
618: private void methodDetailsButtonActionPerformed(
619: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_methodDetailsButtonActionPerformed
620: MethodPicker picker = new MethodPicker(formModel, null,
621: requiredType);
622: picker.setSelectedComponent(selectedComponent);
623: picker.setSelectedMethod(selectedMethod);
624:
625: String title = FormUtils.getFormattedBundleString(
626: "CTL_FMT_CW_SelectMethod", // NOI18N
627: new Object[] { Utilities
628: .getShortClassName(requiredType) });
629:
630: final DialogDescriptor dd = new DialogDescriptor(picker, title);
631: dd.setValid(picker.isPickerValid());
632: picker.addPropertyChangeListener("pickerValid",
633: new PropertyChangeListener() { // NOI18N
634: public void propertyChange(PropertyChangeEvent evt2) {
635: dd.setValid(((Boolean) evt2.getNewValue())
636: .booleanValue());
637: }
638: });
639: java.awt.Dialog dialog = org.openide.DialogDisplayer
640: .getDefault().createDialog(dd);
641: dialog.show();
642:
643: if (dd.getValue() == DialogDescriptor.OK_OPTION) {
644: selectedComponent = picker.getSelectedComponent();
645: selectedMethod = picker.getSelectedMethod();
646: methodLabel.setEnabled(true);
647: if (selectedComponent == formModel.getTopRADComponent()) {
648: methodLabel.setText(selectedMethod.getName());
649: } else {
650: methodLabel.setText(selectedComponent.getName() + "."
651: + selectedMethod.getName()); // NOI18N
652: }
653: methodLabel.repaint();
654: fireStateChange();
655: }
656: }//GEN-LAST:event_methodDetailsButtonActionPerformed
657:
658: private void updateState(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_updateState
659: fireStateChange();
660: codeArea.getCaret().setVisible(
661: codeButton.isSelected() && codeArea.hasFocus());
662: }//GEN-LAST:event_updateState
663:
664: private void propertyDetailsButtonActionPerformed(
665: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propertyDetailsButtonActionPerformed
666: if (propertyPicker == null) {
667: propertyPicker = new PropertyPicker(formModel, null,
668: requiredType);
669: }
670: propertyPicker.setSelectedComponent(selectedComponent);
671: propertyPicker.setSelectedProperty(selectedProperty);
672:
673: String title = FormUtils.getFormattedBundleString(
674: "CTL_FMT_CW_SelectProperty", // NOI18N
675: new Object[] { Utilities
676: .getShortClassName(requiredType) });
677:
678: final DialogDescriptor dd = new DialogDescriptor(
679: propertyPicker, title);
680: dd.setValid(propertyPicker.isPickerValid());
681: propertyPicker.addPropertyChangeListener("pickerValid",
682: new PropertyChangeListener() { // NOI18N
683: public void propertyChange(PropertyChangeEvent evt2) {
684: dd.setValid(((Boolean) evt2.getNewValue())
685: .booleanValue());
686: }
687: });
688: java.awt.Dialog dialog = org.openide.DialogDisplayer
689: .getDefault().createDialog(dd);
690: dialog.show();
691:
692: if (dd.getValue() == DialogDescriptor.OK_OPTION) {
693: selectedComponent = propertyPicker.getSelectedComponent();
694: selectedProperty = propertyPicker.getSelectedProperty();
695: propertyLabel.setEnabled(true);
696: if (selectedComponent == formModel.getTopRADComponent()) {
697: propertyLabel.setText(selectedProperty.getName());
698: } else {
699: propertyLabel.setText(selectedComponent.getName() + "."
700: + selectedProperty.getName()); // NOI18N
701: }
702: propertyLabel.repaint();
703: fireStateChange();
704: }
705: }//GEN-LAST:event_propertyDetailsButtonActionPerformed
706:
707: private void typeButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typeButtonPressed
708: updateParameterTypes();
709: if (beanButton.isSelected()) {
710: beanCombo.requestFocus();
711: } else if (codeButton.isSelected()) {
712: codeArea.requestFocus();
713: } else if (propertyButton.isSelected()) {
714: propertyDetailsButton.requestFocus();
715: } else if (methodButton.isSelected()) {
716: methodDetailsButton.requestFocus();
717: } else if (valueButton.isSelected()) {
718: valueField.requestFocus();
719: }
720: }//GEN-LAST:event_typeButtonPressed
721:
722: private void updateParameterTypes() {
723: valueField.setEnabled(valueButton.isSelected());
724: beanCombo.setEnabled(beanButton.isSelected());
725: if (!propertyButton.isSelected())
726: propertyLabel.setText(FormUtils
727: .getBundleString("CTL_CW_NoProperty")); // NOI18N
728: propertyLabel.setEnabled(propertyButton.isSelected());
729: propertyLabel.repaint();
730: propertyDetailsButton.setEnabled(propertyButton.isSelected());
731:
732: if (!methodButton.isSelected())
733: methodLabel.setText(FormUtils
734: .getBundleString("CTL_CW_NoMethod")); // NOI18N
735: methodLabel.setEnabled(methodButton.isSelected());
736: methodLabel.repaint();
737: methodDetailsButton.setEnabled(methodButton.isSelected());
738: codeArea.setEnabled(codeButton.isSelected());
739: //codeArea.setEditable(codeButton.isSelected());
740: codeArea.getCaret().setVisible(
741: codeButton.isSelected() && codeArea.hasFocus());
742: fireStateChange();
743: }
744:
745: // Variables declaration - do not modify//GEN-BEGIN:variables
746: private javax.swing.JTextField propertyLabel;
747: private javax.swing.JTextField methodLabel;
748: private javax.swing.JRadioButton codeButton;
749: private javax.swing.JRadioButton methodButton;
750: private javax.swing.JTextField valueField;
751: private javax.swing.JEditorPane codeArea;
752: private javax.swing.JRadioButton beanButton;
753: private javax.swing.JButton propertyDetailsButton;
754: private javax.swing.JComboBox beanCombo;
755: private javax.swing.JScrollPane codeScrollPane;
756: private javax.swing.JLabel paramLabel;
757: private javax.swing.JRadioButton valueButton;
758: private javax.swing.JButton methodDetailsButton;
759: private javax.swing.JRadioButton propertyButton;
760: // End of variables declaration//GEN-END:variables
761:
762: private FormModel formModel;
763: private Class requiredType;
764:
765: private PropertyPicker propertyPicker;
766:
767: private ArrayList listeners;
768: private boolean currentFilledState;
769: private RADComponent selectedComponent;
770: private PropertyDescriptor selectedProperty;
771: private MethodDescriptor selectedMethod;
772:
773: private java.util.List beansList;
774:
775: // -------
776:
777: static class ComponentComparator implements Comparator {
778: public int compare(Object o1, Object o2) {
779: RADComponent comp1 = (RADComponent) o1;
780: RADComponent comp2 = (RADComponent) o2;
781: if (comp1 == comp2)
782: return 0;
783:
784: RADComponent topComp = comp1.getFormModel()
785: .getTopRADComponent();
786: if (comp1 == topComp)
787: return -1;
788: if (comp2 == topComp)
789: return 1;
790:
791: return comp1.getName().compareTo(comp2.getName());
792: }
793: }
794: }
|