1 19 20 21 package org.netbeans.modules.form; 22 23 import java.awt.event.ItemEvent ; 24 import java.awt.event.ItemListener ; 25 import java.beans.*; 26 import java.util.*; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 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 41 public class ParametersPicker extends javax.swing.JPanel implements EnhancedCustomPropertyEditor { 42 43 static final long serialVersionUID =1116033799965380000L; 44 45 private boolean previousValue = false; 46 47 48 public ParametersPicker(FormModel formModel, Class requiredType) { 49 this.formModel = formModel; 50 this.requiredType = requiredType; 51 initComponents(); 52 53 javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup (); 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 .class))) { 62 valueButton.setEnabled(false); 63 propertyButton.setSelected(true); 64 } 65 66 paramLabel.setLabelFor(this); 68 propertyLabel.setText(FormUtils.getBundleString("CTL_CW_NoProperty")); methodLabel.setText(FormUtils.getBundleString("CTL_CW_NoMethod")); 71 Mnemonics.setLocalizedText(valueButton, FormUtils.getBundleString("CTL_CW_Value")); Mnemonics.setLocalizedText(beanButton, FormUtils.getBundleString("CTL_CW_Bean")); Mnemonics.setLocalizedText(propertyButton, FormUtils.getBundleString("CTL_CW_Property")); Mnemonics.setLocalizedText(methodButton, FormUtils.getBundleString("CTL_CW_Method")); Mnemonics.setLocalizedText(codeButton, FormUtils.getBundleString("CTL_CW_UserCode")); 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")); 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")); else 92 beanCombo.addItem(radComp.getName()); 93 } 94 95 beanCombo.addItemListener(new ItemListener () { 96 public void itemStateChanged(ItemEvent 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); 110 updateParameterTypes(); 111 112 HelpCtx.setHelpIDString(this, "gui.source.modifying.property"); 114 valueButton.getAccessibleContext().setAccessibleDescription( 115 FormUtils.getBundleString("ACSD_CTL_CW_Value")); beanButton.getAccessibleContext().setAccessibleDescription( 117 FormUtils.getBundleString("ACSD_CTL_CW_Bean")); propertyButton.getAccessibleContext().setAccessibleDescription( 119 FormUtils.getBundleString("ACSD_CTL_CW_Property")); methodButton.getAccessibleContext().setAccessibleDescription( 121 FormUtils.getBundleString("ACSD_CTL_CW_Method")); codeButton.getAccessibleContext().setAccessibleDescription( 123 FormUtils.getBundleString("ACSD_CTL_CW_UserCode")); 125 valueField.getAccessibleContext().setAccessibleName(valueButton.getText()); 126 valueField.getAccessibleContext().setAccessibleDescription( 127 FormUtils.getBundleString("ACSD_CTL_CW_ValueField")); beanCombo.getAccessibleContext().setAccessibleName(beanButton.getText()); 129 beanCombo.getAccessibleContext().setAccessibleDescription( 130 FormUtils.getBundleString("ACSD_CTL_CW_BeanCombo")); propertyLabel.getAccessibleContext().setAccessibleName(propertyButton.getText()); 132 propertyLabel.getAccessibleContext().setAccessibleDescription( 133 FormUtils.getBundleString("ACSD_CTL_CW_PropertyLabel")); methodLabel.getAccessibleContext().setAccessibleName(methodButton.getText()); 135 methodLabel.getAccessibleContext().setAccessibleDescription( 136 FormUtils.getBundleString("ACSD_CTL_CW_MethodLabel")); codeArea.getAccessibleContext().setAccessibleName(codeButton.getText()); 138 codeArea.getAccessibleContext().setAccessibleDescription( 139 FormUtils.getBundleString("ACSD_CTL_CW_UserCodeArea")); 141 propertyDetailsButton.getAccessibleContext().setAccessibleDescription( 142 FormUtils.getBundleString("ACSD_CTL_CW_PropertyButton")); methodDetailsButton.getAccessibleContext().setAccessibleDescription( 144 FormUtils.getBundleString("ACSD_CTL_CW_MethodButton")); getAccessibleContext().setAccessibleDescription( 146 FormUtils.getBundleString("ACSD_ParametersPicker")); } 148 149 public void setPropertyValue(RADConnectionPropertyEditor.RADConnectionDesignValue value, Object realValue) { 150 if (value == null) { 151 previousValue = realValue != null; 152 return; } 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")); } 177 else if (selectedComponent == formModel.getTopRADComponent()) { 178 propertyLabel.setText(selectedProperty.getName()); 179 } 180 else { 181 propertyLabel.setText(selectedComponent.getName() + "." + selectedProperty.getName()); } 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")); } 193 else if (selectedComponent == formModel.getTopRADComponent()) { 194 methodLabel.setText(selectedMethod.getName()); 195 } 196 else { 197 methodLabel.setText(selectedComponent.getName() + "." + selectedMethod.getName()); } 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 updateParameterTypes(); 210 } 211 212 215 220 public Object getPropertyValue() throws IllegalStateException { 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 exc = new IllegalStateException (); 236 ErrorManager.getDefault().annotate( 237 exc, ErrorManager.USER, null, 238 FormUtils.getBundleString("ERR_NothingEntered"), null, null); 240 throw exc; 241 242 } 243 244 247 public String getPreviewText() { 248 if (!isFilled()) 249 return FormUtils.getBundleString("CTL_CW_NotSet"); if (codeButton.isSelected()) { 251 return FormUtils.getBundleString("CTL_CW_Code"); } 253 return getText(); 254 } 255 256 public String getText() { 257 if (!isFilled()) 258 return FormUtils.getBundleString("CTL_CW_NotSet"); if (valueButton.isSelected()) { 260 if (requiredType.equals(String .class)) { 261 String s = valueField.getText(); 262 s = Utilities.replaceString(s, "\\", "\\\\"); s = Utilities.replaceString(s, "\"", "\\\""); return "\""+s+"\""; } 266 else 267 return(valueField.getText() != null) ? valueField.getText() : ""; } else if (codeButton.isSelected()) { 269 return codeArea.getText(); 270 } else if (beanButton.isSelected()) { 271 if (selectedComponent == formModel.getTopRADComponent()) { 272 return "this"; } else { 274 return(selectedComponent.getName()); 275 } 276 } else if (propertyButton.isSelected()) { 277 StringBuffer sb = new StringBuffer (); 278 if (selectedComponent != formModel.getTopRADComponent()) { 279 sb.append(selectedComponent.getName()); 280 sb.append("."); } 282 if (selectedProperty != null) { 283 sb.append(selectedProperty.getReadMethod().getName()); 284 sb.append("()"); } else { 286 sb.append("???"); } 288 return sb.toString(); 289 } else if (methodButton.isSelected()) { 290 StringBuffer sb = new StringBuffer (); 291 if (selectedComponent != formModel.getTopRADComponent()) { 292 sb.append(selectedComponent.getName()); 293 sb.append("."); } 295 sb.append(selectedMethod.getName()); sb.append("()"); return sb.toString(); 298 } else return ""; } 300 301 public boolean isFilled() { 302 if (codeButton.isSelected()) { 303 if (requiredType.equals(String .class)) return true; 304 else return !"".equals(codeArea.getText()); } 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 .class)) return true; 311 else return !"".equals(valueField.getText()); } else if (methodButton.isSelected()) { 313 return(selectedMethod != null); 314 } else return false; 315 } 316 317 public synchronized void addChangeListener(ChangeListener l) { 318 if (listeners == null) 319 listeners = new ArrayList(); 320 listeners.add(l); 321 } 322 323 public synchronized void removeListener(ChangeListener 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 evt = new ChangeEvent (this); 334 for (Iterator it = list.iterator(); it.hasNext();) 335 ((ChangeListener )it.next()).stateChanged(evt); 336 } 337 338 343 private void initComponents() { 345 java.awt.GridBagConstraints gridBagConstraints; 346 347 valueButton = new javax.swing.JRadioButton (); 348 valueField = new javax.swing.JTextField (); 349 beanButton = new javax.swing.JRadioButton (); 350 beanCombo = new javax.swing.JComboBox (); 351 propertyButton = new javax.swing.JRadioButton (); 352 propertyLabel = new javax.swing.JTextField (); 353 propertyDetailsButton = new javax.swing.JButton (); 354 methodButton = new javax.swing.JRadioButton (); 355 methodLabel = new javax.swing.JTextField (); 356 methodDetailsButton = new javax.swing.JButton (); 357 codeButton = new javax.swing.JRadioButton (); 358 codeScrollPane = new javax.swing.JScrollPane (); 359 codeArea = FormEditor.createCodeEditorPane(formModel); 360 paramLabel = new javax.swing.JLabel (); 361 362 setLayout(new java.awt.GridBagLayout ()); 363 364 valueButton.setText("Value:"); 365 valueButton.addActionListener(new java.awt.event.ActionListener () { 366 public void actionPerformed(java.awt.event.ActionEvent evt) { 367 typeButtonPressed(evt); 368 } 369 }); 370 371 gridBagConstraints = new java.awt.GridBagConstraints (); 372 gridBagConstraints.gridx = 0; 373 gridBagConstraints.gridy = 1; 374 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 375 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 376 add(valueButton, gridBagConstraints); 377 378 valueField.addCaretListener(new javax.swing.event.CaretListener () { 379 public void caretUpdate(javax.swing.event.CaretEvent evt) { 380 updateState(evt); 381 } 382 }); 383 384 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 0, 5, 0); 390 add(valueField, gridBagConstraints); 391 392 beanButton.setText("Bean:"); 393 beanButton.addActionListener(new java.awt.event.ActionListener () { 394 public void actionPerformed(java.awt.event.ActionEvent evt) { 395 typeButtonPressed(evt); 396 } 397 }); 398 399 gridBagConstraints = new java.awt.GridBagConstraints (); 400 gridBagConstraints.gridx = 0; 401 gridBagConstraints.gridy = 2; 402 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 403 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 404 add(beanButton, gridBagConstraints); 405 406 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 0, 5, 0); 412 add(beanCombo, gridBagConstraints); 413 414 propertyButton.setText("Property:"); 415 propertyButton.addActionListener(new java.awt.event.ActionListener () { 416 public void actionPerformed(java.awt.event.ActionEvent evt) { 417 typeButtonPressed(evt); 418 } 419 }); 420 421 gridBagConstraints = new java.awt.GridBagConstraints (); 422 gridBagConstraints.gridx = 0; 423 gridBagConstraints.gridy = 3; 424 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 425 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (0, 0, 5, 5); 436 add(propertyLabel, gridBagConstraints); 437 438 propertyDetailsButton.setText("..."); 439 propertyDetailsButton.addActionListener(new java.awt.event.ActionListener () { 440 public void actionPerformed(java.awt.event.ActionEvent evt) { 441 propertyDetailsButtonActionPerformed(evt); 442 } 443 }); 444 445 gridBagConstraints = new java.awt.GridBagConstraints (); 446 gridBagConstraints.gridx = 2; 447 gridBagConstraints.gridy = 3; 448 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 449 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 450 add(propertyDetailsButton, gridBagConstraints); 451 452 methodButton.setText("Method Call:"); 453 methodButton.addActionListener(new java.awt.event.ActionListener () { 454 public void actionPerformed(java.awt.event.ActionEvent evt) { 455 typeButtonPressed(evt); 456 } 457 }); 458 459 gridBagConstraints = new java.awt.GridBagConstraints (); 460 gridBagConstraints.gridx = 0; 461 gridBagConstraints.gridy = 4; 462 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 463 gridBagConstraints.insets = new java.awt.Insets (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 (); 469 gridBagConstraints.gridx = 1; 470 gridBagConstraints.gridy = 4; 471 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 472 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 5); 473 add(methodLabel, gridBagConstraints); 474 475 methodDetailsButton.setText("..."); 476 methodDetailsButton.addActionListener(new java.awt.event.ActionListener () { 477 public void actionPerformed(java.awt.event.ActionEvent evt) { 478 methodDetailsButtonActionPerformed(evt); 479 } 480 }); 481 482 gridBagConstraints = new java.awt.GridBagConstraints (); 483 gridBagConstraints.gridx = 2; 484 gridBagConstraints.gridy = 4; 485 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 486 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 487 add(methodDetailsButton, gridBagConstraints); 488 489 codeButton.setText("User Code:"); 490 codeButton.addActionListener(new java.awt.event.ActionListener () { 491 public void actionPerformed(java.awt.event.ActionEvent evt) { 492 typeButtonPressed(evt); 493 } 494 }); 495 496 gridBagConstraints = new java.awt.GridBagConstraints (); 497 gridBagConstraints.gridx = 0; 498 gridBagConstraints.gridy = 5; 499 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 500 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 501 add(codeButton, gridBagConstraints); 502 503 codeArea.addMouseListener(new java.awt.event.MouseAdapter () { 504 public void mouseClicked(java.awt.event.MouseEvent evt) { 505 codeAreaMouseClicked(evt); 506 } 507 }); 508 codeArea.addCaretListener(new javax.swing.event.CaretListener () { 509 public void caretUpdate(javax.swing.event.CaretEvent evt) { 510 updateState(evt); 511 } 512 }); 513 514 codeScrollPane.setViewportView(codeArea); 515 516 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (); 527 gridBagConstraints.gridx = 0; 528 gridBagConstraints.gridy = 0; 529 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 530 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 531 add(paramLabel, gridBagConstraints); 532 533 } 535 private void codeAreaMouseClicked(java.awt.event.MouseEvent evt) { if (!codeButton.isSelected()) 537 codeButton.doClick(); 538 } 540 private void methodDetailsButtonActionPerformed(java.awt.event.ActionEvent evt) { MethodPicker picker = new MethodPicker(formModel, null, requiredType); 542 picker.setSelectedComponent(selectedComponent); 543 picker.setSelectedMethod(selectedMethod); 544 545 String title = FormUtils.getFormattedBundleString( 546 "CTL_FMT_CW_SelectMethod", new Object [] { Utilities.getShortClassName(requiredType) }); 548 549 final DialogDescriptor dd = new DialogDescriptor(picker, title); 550 dd.setValid(picker.isPickerValid()); 551 picker.addPropertyChangeListener("pickerValid", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt2) { 553 dd.setValid(((Boolean )evt2.getNewValue()).booleanValue()); 554 } 555 }); 556 java.awt.Dialog 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()); } 575 methodLabel.repaint(); 576 fireStateChange(); 577 } 578 } 580 private void updateState(javax.swing.event.CaretEvent evt) { fireStateChange(); 582 codeArea.getCaret().setVisible(codeButton.isSelected() && codeArea.hasFocus()); 583 } 585 private void propertyDetailsButtonActionPerformed(java.awt.event.ActionEvent evt) { if (propertyPicker == null) { 587 propertyPicker = new PropertyPicker(formModel, null, requiredType); 588 } 589 propertyPicker.setSelectedComponent(selectedComponent); 590 propertyPicker.setSelectedProperty(selectedProperty); 591 592 String title = FormUtils.getFormattedBundleString( 593 "CTL_FMT_CW_SelectProperty", new Object [] { Utilities.getShortClassName(requiredType) }); 595 596 final DialogDescriptor dd = new DialogDescriptor(propertyPicker, title); 597 dd.setValid(propertyPicker.isPickerValid()); 598 propertyPicker.addPropertyChangeListener("pickerValid", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt2) { 600 dd.setValid(((Boolean )evt2.getNewValue()).booleanValue()); 601 } 602 }); 603 java.awt.Dialog 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()); } 622 propertyLabel.repaint(); 623 fireStateChange(); 624 } 625 } 627 private void switchToCodeArea(String text) { 628 codeArea.setText(text); 629 codeButton.setSelected(true); 630 updateParameterTypes(); 631 } 632 633 private void typeButtonPressed(java.awt.event.ActionEvent evt) { 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 } 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")); 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")); methodLabel.setEnabled(methodButton.isSelected()); 660 methodLabel.repaint(); 661 methodDetailsButton.setEnabled(methodButton.isSelected()); 662 codeArea.setEnabled(codeButton.isSelected()); 663 codeArea.getCaret().setVisible(codeButton.isSelected() && codeArea.hasFocus()); 665 fireStateChange(); 666 } 667 668 private javax.swing.JRadioButton beanButton; 670 private javax.swing.JComboBox beanCombo; 671 private javax.swing.JEditorPane codeArea; 672 private javax.swing.JRadioButton codeButton; 673 private javax.swing.JScrollPane codeScrollPane; 674 private javax.swing.JRadioButton methodButton; 675 private javax.swing.JButton methodDetailsButton; 676 private javax.swing.JTextField methodLabel; 677 private javax.swing.JLabel paramLabel; 678 private javax.swing.JRadioButton propertyButton; 679 private javax.swing.JButton propertyDetailsButton; 680 private javax.swing.JTextField propertyLabel; 681 private javax.swing.JRadioButton valueButton; 682 private javax.swing.JTextField valueField; 683 685 private FormModel formModel; 686 private Class 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 beansList; 696 697 699 static class ComponentComparator implements Comparator { 700 public int compare(Object o1, Object 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 |