1 19 package org.netbeans.modules.db.sql.visualeditor.querybuilder; 20 21 import java.awt.Dialog ; 22 import java.awt.event.ActionListener ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.Dimension ; 25 26 import javax.swing.JTextArea ; 27 import javax.swing.JTextField ; 28 import javax.swing.JRadioButton ; 29 import javax.swing.JComboBox ; 30 import javax.swing.JLabel ; 31 import javax.swing.ButtonGroup ; 32 import javax.swing.JPanel ; 33 import javax.swing.border.EtchedBorder ; 34 35 import org.openide.util.NbBundle; 36 import org.openide.util.HelpCtx ; 37 import org.openide.NotifyDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.DialogDescriptor; 40 41 45 public class AddQueryParameterDlg extends JPanel { 46 47 49 50 public static final int RET_CANCEL = 0; 51 52 53 public static final int RET_OK = 1; 54 55 private String _columnName = "<Column Name>"; 57 private Dialog dialog; 58 private final int WIDTH = 400; 59 private final int HEIGHT = 280; 60 61 62 64 67 public AddQueryParameterDlg() { 68 this(true, "<Column Name>"); } 70 71 76 77 public AddQueryParameterDlg(boolean modal, String columnName) { 78 79 initComponents(); 80 valueTxtField.setSelectionEnd(valueTxtField.getText().length()); 83 parmTxtField.setSelectionStart(0); 84 parmTxtField.setSelectionEnd(parmTxtField.getText().length()); 85 86 ActionListener listener = new ActionListener () { 87 88 public void actionPerformed (ActionEvent evt) { 89 Object o = evt.getSource(); 90 if (o == NotifyDescriptor.CANCEL_OPTION) { 91 returnStatus = RET_CANCEL; 92 } else if (o == NotifyDescriptor.OK_OPTION) { 93 returnStatus = RET_OK; 95 } } 97 }; 98 99 DialogDescriptor dlg = 101 new DialogDescriptor(this, 102 NbBundle.getMessage(AddQueryParameterDlg.class, 103 "ADD_QUERY_CRITERIA_TITLE"), modal, listener); 105 106 dlg.setHelpCtx ( 107 new HelpCtx( "projrave_ui_elements_dialogs_add_query_criteria" ) ); 109 setColumnName(columnName); 110 dialog = DialogDisplayer.getDefault().createDialog(dlg); 111 dialog.setVisible(true); 112 } 113 114 public void setColumnName (String columnName) { 115 _columnName = columnName; 116 dispColumnNameLbl.setText(_columnName); 117 } 118 119 public String getCriteria () { 120 121 StringBuffer criteriaStringBuffer = new StringBuffer (); 122 123 String comboBoxString = (String ) comparisonComboBox.getSelectedItem(); 124 125 if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "EQUALS") ) ) { criteriaStringBuffer.append ("="); } 128 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "LESS_THAN") ) ) { criteriaStringBuffer.append ("<"); } 131 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "LESS_THAN_EQUALS") ) ) { criteriaStringBuffer.append ("<="); } 134 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "GREATER_THAN") ) ) { criteriaStringBuffer.append (">"); } 137 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "GREATER_THAN_EQUALS") ) ) { criteriaStringBuffer.append (">="); } 140 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "NOT_EQUALS") ) ) { criteriaStringBuffer.append ("<>"); } 143 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "LIKE") ) ) { criteriaStringBuffer.append ("LIKE"); } 146 else if (comboBoxString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "IN") ) ) { criteriaStringBuffer.append ("IN"); } 149 criteriaStringBuffer.append (" "); 152 if ( parmRadioBtn.isSelected() ) { 154 criteriaStringBuffer.append ((String ) parmTxtField.getText()); 155 } else if ( valueRadioBtn.isSelected() ) 156 criteriaStringBuffer.append ((String ) valueTxtField.getText()); 157 158 161 162 return ( criteriaStringBuffer.toString() ); 163 } 164 165 166 167 public int getReturnStatus() { 168 return returnStatus; 169 } 170 171 private void updateLabel ( String comparisonString ) { 172 212 213 if (comparisonString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "LIKE") ) ) { comparisonHintLbl.setText ( 215 NbBundle.getMessage(AddQueryParameterDlg.class, 216 "HINT_LIKE") ); } 218 else if (comparisonString.equals (NbBundle.getMessage(AddQueryParameterDlg.class, "IN") ) ) { comparisonHintLbl.setText ( 221 NbBundle.getMessage(AddQueryParameterDlg.class, 222 "HINT_IN") ); } 224 else { 225 comparisonHintLbl.setText ( " " ); } 227 228 } 229 230 235 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 237 238 buttonGroup1 = new ButtonGroup (); 239 mainPanel = new JPanel (); 240 columnNameLbl = new JLabel (); 241 dispColumnNameLbl = new JLabel (); 242 comparisonLbl = new JLabel (); 243 comparisonHintLbl = new JLabel (); 244 comparisonComboBox = new JComboBox (); 245 radioButtonPanel = new JPanel (); 246 valueRadioBtn = new JRadioButton (); 247 parmRadioBtn = new JRadioButton (); 248 valueTxtField = new JTextField (); 249 valueTxtFieldLbl = new JLabel (); 250 parmTxtField = new JTextField (); 251 parmTxtFieldLbl = new JLabel (); 252 253 fillerLbl = new JLabel (); 257 258 setLayout(new java.awt.GridBagLayout ()); 259 260 mainPanel.setLayout(new java.awt.GridBagLayout ()); 261 262 getAccessibleContext().setAccessibleName( 263 NbBundle.getMessage(AddQueryParameterDlg.class, "ADD_QUERY_CRITERIA_a11yName")); 264 getAccessibleContext().setAccessibleDescription( 265 NbBundle.getMessage(AddQueryParameterDlg.class, "ADD_QUERY_CRITERIA_a11yDescription")); 266 267 instructions = new JTextArea ( 269 NbBundle.getMessage(AddQueryParameterDlg.class, "QUERY_INSTRUCTIONS") ); instructions.setLineWrap(true); 271 instructions.setWrapStyleWord(true); 272 instructions.setEditable(false); 273 instructions.setBorder(new EtchedBorder (EtchedBorder.LOWERED)); 274 instructions.setFocusable(false); 275 gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 278 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 281 gridBagConstraints.weightx = 1.0; 282 gridBagConstraints.insets = new java.awt.Insets (0, 0, 10, 0); 283 mainPanel.add(instructions, gridBagConstraints); 284 285 columnNameLbl.setText ( 286 NbBundle.getMessage(AddQueryParameterDlg.class, "COLUMN_NAME") ); columnNameLbl.getAccessibleContext().setAccessibleDescription( 288 NbBundle.getMessage(AddQueryParameterDlg.class, "COLUMN_NAME_a11yDescription")); 289 columnNameLbl.setDisplayedMnemonic(NbBundle.getMessage(AddQueryParameterDlg.class, "COLUMN_NAME_Mnemonic").charAt(0)); 290 291 gridBagConstraints = new java.awt.GridBagConstraints (); 292 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 293 gridBagConstraints.gridx = 0; 294 gridBagConstraints.gridy = 1; 295 mainPanel.add(columnNameLbl, gridBagConstraints); 296 297 dispColumnNameLbl.setText(_columnName); 300 gridBagConstraints = new java.awt.GridBagConstraints (); 301 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 0); 302 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 303 gridBagConstraints.weightx = 1.0; 304 gridBagConstraints.gridx = 1; 305 gridBagConstraints.gridy = 1; 306 mainPanel.add(dispColumnNameLbl, gridBagConstraints); 307 308 comparisonLbl.setLabelFor(comparisonComboBox); 309 comparisonLbl.setText( 310 NbBundle.getMessage(AddQueryParameterDlg.class, "COMPARISON") ); comparisonLbl.getAccessibleContext().setAccessibleDescription( 312 NbBundle.getMessage(AddQueryParameterDlg.class, "COMPARISON_a11yDescription")); 313 comparisonLbl.setDisplayedMnemonic(NbBundle.getMessage(AddQueryParameterDlg.class, "COMPARISON_Mnemonic").charAt(0)); 314 315 gridBagConstraints = new java.awt.GridBagConstraints (); 316 gridBagConstraints.gridx = 0; 317 gridBagConstraints.gridy = 2; 318 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 319 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 320 mainPanel.add(comparisonLbl, gridBagConstraints); 321 322 comparisonComboBox.addActionListener ( 323 new java.awt.event.ActionListener () { 324 public void actionPerformed(java.awt.event.ActionEvent evt) { 325 JComboBox cb = (JComboBox )evt.getSource(); 326 String comparisonString = (String )cb.getSelectedItem(); 327 updateLabel(comparisonString); 328 } 329 }); 330 331 comparisonComboBox.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddQueryParameterDlg.class, "COMPARISON_a11yDescription")); 332 333 comparisonComboBox.setModel( 334 new javax.swing.DefaultComboBoxModel ( 335 new String [] { 336 NbBundle.getMessage(AddQueryParameterDlg.class, "EQUALS"), NbBundle.getMessage(AddQueryParameterDlg.class, "LESS_THAN"), NbBundle.getMessage(AddQueryParameterDlg.class, "LESS_THAN_EQUALS"), NbBundle.getMessage(AddQueryParameterDlg.class, "GREATER_THAN"), NbBundle.getMessage(AddQueryParameterDlg.class, "GREATER_THAN_EQUALS"), NbBundle.getMessage(AddQueryParameterDlg.class, "NOT_EQUALS"), NbBundle.getMessage(AddQueryParameterDlg.class, "LIKE"), NbBundle.getMessage(AddQueryParameterDlg.class, "IN"), })); 353 gridBagConstraints = new java.awt.GridBagConstraints (); 354 gridBagConstraints.gridx = 1; 355 gridBagConstraints.gridy = 2; 356 gridBagConstraints.insets = new java.awt.Insets (6, 10, 0, 0); 357 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 358 gridBagConstraints.weightx = 1.0; 359 mainPanel.add(comparisonComboBox, gridBagConstraints); 360 361 radioButtonPanel.setLayout(new java.awt.GridBagLayout ()); 362 363 valueRadioBtn.setSelected(true); 364 valueRadioBtn.setMnemonic (NbBundle.getMessage(AddQueryParameterDlg.class, "VALUE_Mnemonic").charAt(0)); 365 valueRadioBtn.getAccessibleContext().setAccessibleDescription( 366 NbBundle.getMessage(AddQueryParameterDlg.class, "VALUE_RADIO_BUTTON_a11yDescription")); 367 valueRadioBtn.setText( 368 NbBundle.getMessage(AddQueryParameterDlg.class, "VALUE") ); buttonGroup1.add(valueRadioBtn); 370 valueRadioBtn.addActionListener(new java.awt.event.ActionListener () { 371 public void actionPerformed(java.awt.event.ActionEvent evt) { 372 valueRadioBtnActionPerformed(evt); 373 } 374 }); 375 376 gridBagConstraints = new java.awt.GridBagConstraints (); 377 gridBagConstraints.gridwidth = 2; 378 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 379 radioButtonPanel.add(valueRadioBtn, gridBagConstraints); 380 381 parmRadioBtn.setMnemonic (NbBundle.getMessage(AddQueryParameterDlg.class, "PARAMETER_Mnemonic").charAt(0)); 382 parmRadioBtn.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddQueryParameterDlg.class, "PARAMETER_RADIO_BUTTON_a11yDescription")); 383 parmRadioBtn.setText( 384 NbBundle.getMessage(AddQueryParameterDlg.class, "PARAMETER") ); buttonGroup1.add(parmRadioBtn); 386 parmRadioBtn.addActionListener(new java.awt.event.ActionListener () { 387 public void actionPerformed(java.awt.event.ActionEvent evt) { 388 parmRadioBtnActionPerformed(evt); 389 } 390 }); 391 392 gridBagConstraints = new java.awt.GridBagConstraints (); 393 gridBagConstraints.gridx = 0; 394 gridBagConstraints.gridy = 2; 395 gridBagConstraints.gridwidth = 2; 396 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 397 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 398 radioButtonPanel.add(parmRadioBtn, gridBagConstraints); 399 400 valueTxtField.setHorizontalAlignment(JTextField.TRAILING); 401 valueTxtField.setText("0"); valueTxtField.getAccessibleContext().setAccessibleName( 403 NbBundle.getMessage(AddQueryParameterDlg.class, "VALUE_a11yName")); 404 valueTxtField.getAccessibleContext().setAccessibleDescription( 405 NbBundle.getMessage(AddQueryParameterDlg.class, "VALUE_a11yDescription")); 406 valueTxtFieldLbl.setText( 407 NbBundle.getMessage(AddQueryParameterDlg.class, "VALUE_label")); 408 valueTxtFieldLbl.setLabelFor(valueTxtField); 409 gridBagConstraints = new java.awt.GridBagConstraints (); 410 gridBagConstraints.gridx = 2; 411 gridBagConstraints.gridy = 0; 412 gridBagConstraints.gridwidth = 2; 413 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 414 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 0); 415 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 416 gridBagConstraints.weightx = 1.0; 417 radioButtonPanel.add(valueTxtField, gridBagConstraints); 418 419 comparisonHintLbl.setHorizontalAlignment(JTextField.LEADING); 420 comparisonHintLbl.setText(" "); gridBagConstraints = new java.awt.GridBagConstraints (); 422 gridBagConstraints.gridx = 2; 423 gridBagConstraints.gridy = 1; 424 gridBagConstraints.gridwidth = 2; 425 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 426 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 0); 427 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 428 gridBagConstraints.weightx = 1.0; 429 radioButtonPanel.add(comparisonHintLbl, gridBagConstraints); 430 431 parmTxtField.setText("?"); parmTxtField.getAccessibleContext().setAccessibleName( 433 NbBundle.getMessage(AddQueryParameterDlg.class, "PARAMETER_a11yName")); 434 parmTxtField.getAccessibleContext().setAccessibleDescription( 435 NbBundle.getMessage(AddQueryParameterDlg.class, "PARAMETER_a11yDescription")); 436 parmTxtFieldLbl.setText( 437 NbBundle.getMessage(AddQueryParameterDlg.class, "PARAMETER_label")); 438 parmTxtFieldLbl.setLabelFor(parmTxtField); 439 gridBagConstraints = new java.awt.GridBagConstraints (); 444 gridBagConstraints.gridx = 2; 445 gridBagConstraints.gridy = 2; 446 gridBagConstraints.gridwidth = 2; 447 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 448 gridBagConstraints.insets = new java.awt.Insets (6, 10, 0, 0); 449 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 450 gridBagConstraints.weightx = 1.0; 451 radioButtonPanel.add(parmTxtField, gridBagConstraints); 452 453 gridBagConstraints = new java.awt.GridBagConstraints (); 456 gridBagConstraints.gridx = 3; 457 gridBagConstraints.gridy = 3; 458 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 459 gridBagConstraints.insets = new java.awt.Insets (6, 10, 0, 0); 460 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 461 gridBagConstraints.weightx = 1.0; 462 464 gridBagConstraints = new java.awt.GridBagConstraints (); 467 gridBagConstraints.gridx = 1; 468 gridBagConstraints.gridy = 2; 469 gridBagConstraints.gridwidth = 2; 470 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 471 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 472 474 fillerLbl.setText(" "); gridBagConstraints = new java.awt.GridBagConstraints (); 476 gridBagConstraints.gridx = 0; 477 gridBagConstraints.gridy = 3; 478 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 479 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 480 gridBagConstraints.weighty = 1.0; 481 radioButtonPanel.add(fillerLbl, gridBagConstraints); 482 483 gridBagConstraints = new java.awt.GridBagConstraints (); 484 gridBagConstraints.gridx = 0; 485 gridBagConstraints.gridy = 4; 486 gridBagConstraints.gridwidth = 2; 487 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 488 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 489 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 490 gridBagConstraints.weightx = 1.0; 491 gridBagConstraints.weighty = 1.0; 492 mainPanel.add(radioButtonPanel, gridBagConstraints); 493 494 gridBagConstraints = new java.awt.GridBagConstraints (); 495 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 496 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 10); 497 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 498 gridBagConstraints.weightx = 1.0; 499 gridBagConstraints.weighty = 1.0; 500 mainPanel.setPreferredSize(new Dimension (WIDTH, HEIGHT)); 502 add(mainPanel, gridBagConstraints); 503 } 505 506 private void parmRadioBtnActionPerformed(java.awt.event.ActionEvent evt) { enableDlgControls(); 509 } 511 512 private void valueRadioBtnActionPerformed(java.awt.event.ActionEvent evt) { enableDlgControls(); 515 } 517 518 private void enableDlgControls() { 519 boolean parmSelected = parmRadioBtn.isSelected(); 520 parmTxtField.setEnabled(parmSelected); 521 parmTxtField.repaint(); 522 valueTxtField.setEnabled(!parmSelected); 526 valueTxtField.repaint(); 527 } 528 529 private ButtonGroup buttonGroup1; 531 private JLabel columnNameLbl; 532 private JComboBox comparisonComboBox; 533 private JLabel comparisonLbl; 534 private JLabel comparisonHintLbl; 535 private JLabel dispColumnNameLbl; 538 private JLabel fillerLbl; 539 private JPanel mainPanel; 540 private JRadioButton parmRadioBtn; 541 private JPanel radioButtonPanel; 542 private JRadioButton valueRadioBtn; 543 private JTextField valueTxtField; 544 private JLabel valueTxtFieldLbl; 545 private JTextField parmTxtField; 546 private JLabel parmTxtFieldLbl; 547 548 private JTextArea instructions; 549 550 552 private int returnStatus = RET_CANCEL; 553 } 554 | Popular Tags |