1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.sql.*; 23 import java.awt.*; 24 import java.awt.event.*; 25 import java.util.*; 26 import java.beans.*; 27 import javax.swing.*; 28 import javax.swing.border.*; 29 import javax.swing.text.JTextComponent ; 30 import org.netbeans.api.db.explorer.DatabaseException; 31 import org.openide.*; 32 import org.openide.util.NbBundle; 33 import org.netbeans.lib.ddl.impl.*; 34 import org.netbeans.lib.ddl.util.*; 35 import org.netbeans.modules.db.util.*; 36 import org.netbeans.modules.db.explorer.infos.*; 37 import org.netbeans.modules.db.explorer.nodes.*; 38 import org.openide.awt.Mnemonics; 39 40 public class AddTableColumnDialog { 41 boolean result = false; 42 Dialog dialog = null; 43 Specification spec; 44 Map ixmap; 45 Map ix_uqmap; 46 String colname = null; 47 transient private static final String tempStr = new String (); 48 JTextField colnamefield, colsizefield, colscalefield, defvalfield; 49 JTextArea checkfield; 50 JComboBox coltypecombo, idxcombo; 51 JCheckBox pkcheckbox, ixcheckbox, checkcheckbox, nullcheckbox, uniquecheckbox; 52 DataModel dmodel = new DataModel(); 53 private ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); 55 public AddTableColumnDialog(final Specification spe, final DatabaseNodeInfo nfo) throws DatabaseException { 56 spec = spe; 57 try { 58 JLabel label; 59 JPanel pane = new JPanel(); 60 pane.setBorder(new EmptyBorder(new Insets(12, 12, 5, 11))); 61 GridBagLayout layout = new GridBagLayout(); 62 GridBagConstraints con; 63 pane.setLayout (layout); 64 65 TextFieldListener fldlistener = new TextFieldListener(dmodel); 66 IntegerFieldListener intfldlistener = new IntegerFieldListener(dmodel); 67 68 70 label = new JLabel(); 71 Mnemonics.setLocalizedText(label, bundle.getString("AddTableColumnName")); label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnNameA11yDesc")); 73 con = new GridBagConstraints (); 74 con.gridx = 0; 75 con.gridy = 0; 76 con.gridwidth = 1; 77 con.gridheight = 1; 78 con.anchor = GridBagConstraints.WEST; 79 con.insets = new java.awt.Insets (0, 0, 0, 0); 80 con.weightx = 0.0; 81 con.weighty = 0.0; 82 pane.add(label, con); 83 84 con = new GridBagConstraints (); 85 con.gridx = 1; 86 con.gridy = 0; 87 con.gridwidth = 3; 88 con.gridheight = 1; 89 con.fill = GridBagConstraints.HORIZONTAL; 90 con.insets = new java.awt.Insets (0, 12, 0, 0); 91 con.weightx = 1.0; 92 con.weighty = 0.0; 93 colnamefield = new JTextField(35); 94 colnamefield.setName(ColumnItem.NAME); 95 colnamefield.addFocusListener(fldlistener); 96 colnamefield.setToolTipText(bundle.getString("ACS_AddTableColumnNameTextFieldA11yDesc")); 97 colnamefield.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnNameTextFieldA11yName")); 98 label.setLabelFor(colnamefield); 99 pane.add(colnamefield, con); 100 101 103 Map tmap = spec.getTypeMap(); 104 Vector ttab = new Vector(tmap.size()); 105 Iterator iter = tmap.keySet().iterator(); 106 while (iter.hasNext()) { 107 String iterkey = (String )iter.next(); 108 String iterval = (String )tmap.get(iterkey); 109 ttab.add(new TypeElement(iterkey, iterval)); 110 } 111 112 ColumnItem item = new ColumnItem(); 113 item.setProperty(ColumnItem.TYPE, ttab.elementAt(0)); 114 dmodel.addRow(item); 115 116 label = new JLabel(); 117 Mnemonics.setLocalizedText(label, bundle.getString("AddTableColumnType")); label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnTypeA11yDesc")); 119 con = new GridBagConstraints (); 120 con.gridx = 0; 121 con.gridy = 1; 122 con.gridwidth = 1; 123 con.gridheight = 1; 124 con.anchor = GridBagConstraints.WEST; 125 con.insets = new java.awt.Insets (12, 0, 0, 0); 126 con.weightx = 0.0; 127 con.weighty = 0.0; 128 pane.add(label, con); 129 130 con = new GridBagConstraints (); 131 con.gridx = 1; 132 con.gridy = 1; 133 con.gridwidth = 3; 134 con.gridheight = 1; 135 con.fill = GridBagConstraints.HORIZONTAL; 136 con.insets = new java.awt.Insets (12, 12, 0, 0); 137 con.weightx = 1.0; 138 con.weighty = 0.0; 139 coltypecombo = new JComboBox(ttab); 140 coltypecombo.addActionListener(new ComboBoxListener(dmodel)); 141 coltypecombo.setName(ColumnItem.TYPE); 142 coltypecombo.setToolTipText(bundle.getString("ACS_AddTableColumnTypeComboBoxA11yDesc")); 143 coltypecombo.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnTypeComboBoxA11yName")); 144 label.setLabelFor(coltypecombo); 145 pane.add(coltypecombo, con); 146 147 149 label = new JLabel(); 150 Mnemonics.setLocalizedText(label, bundle.getString("AddTableColumnSize")); label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnSizeA11yDesc")); 152 con = new GridBagConstraints (); 153 con.gridx = 0; 154 con.gridy = 2; 155 con.gridwidth = 1; 156 con.gridheight = 1; 157 con.anchor = GridBagConstraints.WEST; 158 con.insets = new java.awt.Insets (12, 0, 0, 0); 159 con.weightx = 0.0; 160 con.weighty = 0.0; 161 pane.add(label, con); 162 163 con = new GridBagConstraints (); 164 con.gridx = 1; 165 con.gridy = 2; 166 con.gridwidth = 1; 167 con.gridheight = 1; 168 con.fill = GridBagConstraints.HORIZONTAL; 169 con.insets = new java.awt.Insets (12, 12, 0, 0); 170 con.weightx = 1.0; 171 con.weighty = 0.0; 172 colsizefield = new ValidableTextField(new TextFieldValidator.integer()); 173 colsizefield.setName(ColumnItem.SIZE); 174 colsizefield.addFocusListener(intfldlistener); 175 colsizefield.setToolTipText(bundle.getString("ACS_AddTableColumnSizeTextFieldA11yDesc")); 176 colsizefield.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnSizeTextFieldA11yName")); 177 label.setLabelFor(colsizefield); 178 pane.add(colsizefield, con); 179 180 182 label = new JLabel(); 183 Mnemonics.setLocalizedText(label, bundle.getString("AddTableColumnScale")); label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnScaleA11yDesc")); 185 con = new GridBagConstraints (); 186 con.gridx = 2; 187 con.gridy = 2; 188 con.gridwidth = 1; 189 con.gridheight = 1; 190 con.anchor = GridBagConstraints.WEST; 191 con.insets = new java.awt.Insets (12, 12, 0, 0); 192 con.weightx = 0.0; 193 con.weighty = 0.0; 194 pane.add(label, con); 195 196 con = new GridBagConstraints (); 197 con.gridx = 3; 198 con.gridy = 2; 199 con.gridwidth = 1; 200 con.gridheight = 1; 201 con.fill = GridBagConstraints.HORIZONTAL; 202 con.insets = new java.awt.Insets (12, 12, 0, 0); 203 con.weightx = 1.0; 204 con.weighty = 0.0; 205 colscalefield = new ValidableTextField(new TextFieldValidator.integer()); 206 colscalefield.setName(ColumnItem.SCALE); 207 colscalefield.addFocusListener(intfldlistener); 208 colscalefield.setToolTipText(bundle.getString("ACS_AddTableColumnScaleTextFieldA11yDesc")); 209 colscalefield.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnScaleTextFieldA11yName")); 210 label.setLabelFor(colscalefield); 211 pane.add(colscalefield, con); 212 213 215 label = new JLabel(); 216 Mnemonics.setLocalizedText(label, bundle.getString("AddTableColumnDefault")); label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnDefaultA11yDesc")); 218 con = new GridBagConstraints (); 219 con.gridx = 0; 220 con.gridy = 3; 221 con.gridwidth = 1; 222 con.gridheight = 1; 223 con.anchor = GridBagConstraints.WEST; 224 con.insets = new java.awt.Insets (12, 0, 0, 0); 225 con.weightx = 0.0; 226 con.weighty = 0.0; 227 pane.add(label, con); 228 229 con = new GridBagConstraints (); 230 con.gridx = 1; 231 con.gridy = 3; 232 con.gridwidth = 3; 233 con.gridheight = 1; 234 con.fill = GridBagConstraints.HORIZONTAL; 235 con.insets = new java.awt.Insets (12, 12, 0, 0); 236 con.weightx = 1.0; 237 con.weighty = 0.0; 238 defvalfield = new JTextField(35); 239 defvalfield.setName(ColumnItem.DEFVAL); 240 defvalfield.addFocusListener(fldlistener); 241 defvalfield.setToolTipText(bundle.getString("ACS_AddTableColumnDefaultTextFieldA11yDesc")); 242 defvalfield.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnDefaultTextFieldA11yName")); 243 label.setLabelFor(defvalfield); 244 layout.setConstraints(defvalfield, con); 245 pane.add(defvalfield); 246 247 249 JPanel subpane = new JPanel(); 250 subpane.setBorder(new TitledBorder(bundle.getString("AddTableColumnConstraintsTitle"))); GridBagLayout sublayout = new GridBagLayout(); 252 subpane.setLayout(sublayout); 253 254 ActionListener cbxlistener = new CheckBoxListener(dmodel); 255 256 con = new GridBagConstraints (); 257 con.gridx = 0; 258 con.gridy = 0; 259 con.gridwidth = 1; 260 con.gridheight = 1; 261 con.anchor = GridBagConstraints.WEST; 262 con.insets = new java.awt.Insets (0, 0, 0, 0); 263 con.weightx = 0.0; 264 con.weighty = 0.0; 265 pkcheckbox = new JCheckBox(); 266 Mnemonics.setLocalizedText(pkcheckbox, bundle.getString("AddTableColumnConstraintPKTitle")); pkcheckbox.setName(ColumnItem.PRIMARY_KEY); 268 pkcheckbox.addActionListener(cbxlistener); 269 pkcheckbox.setToolTipText(bundle.getString("ACS_AddTableColumnConstraintPKTitleA11yDesc")); 270 subpane.add(pkcheckbox, con); 271 272 con = new GridBagConstraints (); 273 con.gridx = 1; 274 con.gridy = 0; 275 con.gridwidth = 1; 276 con.gridheight = 1; 277 con.anchor = GridBagConstraints.WEST; 278 con.insets = new java.awt.Insets (0, 12, 0, 0); 279 con.weightx = 0.0; 280 con.weighty = 0.0; 281 uniquecheckbox = new JCheckBox(); 282 Mnemonics.setLocalizedText(uniquecheckbox, bundle.getString("AddTableColumnConstraintUniqueTitle")); uniquecheckbox.setName(ColumnItem.UNIQUE); 284 uniquecheckbox.addActionListener(cbxlistener); 285 uniquecheckbox.setToolTipText(bundle.getString("ACS_AddTableColumnConstraintUniqueTitleA11yDesc")); 286 subpane.add(uniquecheckbox, con); 287 288 con = new GridBagConstraints (); 289 con.gridx = 2; 290 con.gridy = 0; 291 con.gridwidth = 1; 292 con.gridheight = 1; 293 con.anchor = GridBagConstraints.WEST; 294 con.insets = new java.awt.Insets (0, 12, 0, 0); 295 con.weightx = 0.0; 296 con.weighty = 0.0; 297 nullcheckbox = new JCheckBox(); 298 Mnemonics.setLocalizedText(nullcheckbox, bundle.getString("AddTableColumnConstraintNullTitle")); nullcheckbox.setName(ColumnItem.NULLABLE); 300 nullcheckbox.addActionListener(cbxlistener); 301 nullcheckbox.setToolTipText(bundle.getString("ACS_AddTableColumnConstraintNullTitleA11yDesc")); 302 subpane.add(nullcheckbox, con); 303 304 306 con = new GridBagConstraints (); 307 con.gridx = 0; 308 con.gridy = 4; 309 con.gridwidth = 4; 310 con.gridheight = 1; 311 con.fill = GridBagConstraints.HORIZONTAL; 312 con.insets = new java.awt.Insets (12, 0, 0, 0); 313 con.weightx = 1.0; 314 con.weighty = 0.0; 315 pane.add(subpane, con); 316 317 boolean isPK = false; 319 try { 320 String table = (String )nfo.get(DatabaseNode.TABLE); 321 DriverSpecification drvSpec = nfo.getDriverSpecification(); 322 323 drvSpec.getPrimaryKeys(table); 324 ResultSet rs = drvSpec.getResultSet(); 325 326 if( rs != null ) { 327 if(rs.next()) 328 isPK = true; 329 rs.close(); 330 } 331 332 } catch (Exception e) { 333 org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, e); 334 } 335 336 338 con = new GridBagConstraints (); 339 con.gridx = 0; 340 con.gridy = 5; 341 con.gridwidth = 1; 342 con.gridheight = 1; 343 con.anchor = GridBagConstraints.NORTHWEST; 344 con.insets = new java.awt.Insets (12, 0, 0, 0); 345 con.weightx = 0.0; 346 con.weighty = 0.0; 347 ixcheckbox = new JCheckBox(); 348 Mnemonics.setLocalizedText(ixcheckbox, bundle.getString("AddTableColumnIndexName")); ixcheckbox.setName(ColumnItem.INDEX); 350 ixcheckbox.addActionListener(cbxlistener); 351 ixcheckbox.setToolTipText(bundle.getString("ACS_AddTableColumnIndexNameA11yDesc")); 352 pane.add(ixcheckbox, con); 353 354 try { 355 String table = (String )nfo.get(DatabaseNode.TABLE); 356 DriverSpecification drvSpec = nfo.getDriverSpecification(); 357 358 drvSpec.getIndexInfo(table, false, true); 359 ResultSet rs = drvSpec.getResultSet(); 360 HashMap rset = new HashMap(); 361 362 ixmap = new HashMap(); 363 ix_uqmap = new HashMap(); 364 String ixname; 365 while (rs.next()) { 366 rset = drvSpec.getRow(); 367 ixname = (String ) rset.get(new Integer (6)); 368 if (ixname != null) { 369 Vector ixcols = (Vector)ixmap.get(ixname); 370 if (ixcols == null) { 371 ixcols = new Vector(); 372 ixmap.put(ixname,ixcols); 373 boolean uq = !Boolean.valueOf( (String )rset.get( new Integer (4) ) ).booleanValue(); 374 if(uq) 375 ix_uqmap.put( ixname, ColumnItem.UNIQUE ); 376 } 377 378 ixcols.add((String ) rset.get(new Integer (9))); 379 } 380 rset.clear(); 381 } 382 rs.close(); 383 } catch (SQLException sqle) { 384 DatabaseException dbe = new DatabaseException(sqle.getMessage()); 385 dbe.initCause(sqle); 386 throw dbe; 387 } 388 389 con = new GridBagConstraints (); 390 con.gridx = 1; 391 con.gridy = 5; 392 con.gridwidth = 3; 393 con.gridheight = 1; 394 con.fill = GridBagConstraints.HORIZONTAL; 395 con.insets = new java.awt.Insets (12, 12, 0, 0); 396 con.weightx = 1.0; 397 con.weighty = 0.0; 398 idxcombo = new JComboBox(new Vector(ixmap.keySet())); 399 idxcombo.setToolTipText(bundle.getString("ACS_AddTableColumnIndexNameComboBoxA11yDesc")); 400 idxcombo.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnIndexNameComboBoxA11yName")); 401 idxcombo.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnIndexNameComboBoxA11yDesc")); 402 pane.add(idxcombo, con); 404 405 407 con = new GridBagConstraints (); 408 con.gridx = 0; 409 con.gridy = 6; 410 con.gridwidth = 1; 411 con.gridheight = 1; 412 con.anchor = GridBagConstraints.NORTHWEST; 413 con.insets = new java.awt.Insets (12, 0, 0, 0); 414 con.weightx = 0.0; 415 con.weighty = 0.0; 416 checkcheckbox = new JCheckBox(); 417 Mnemonics.setLocalizedText(checkcheckbox, bundle.getString("AddTableColumnConstraintCheckTitle")); checkcheckbox.setName(ColumnItem.CHECK); 419 checkcheckbox.addActionListener(cbxlistener); 420 checkcheckbox.setToolTipText(bundle.getString("ACS_AddTableColumnCheckTitleA11yDesc")); 421 pane.add(checkcheckbox, con); 422 423 con = new GridBagConstraints (); 424 con.gridx = 1; 425 con.gridy = 6; 426 con.gridwidth = 3; 427 con.gridheight = 1; 428 con.fill = GridBagConstraints.BOTH; 429 con.insets = new java.awt.Insets (12, 12, 0, 0); 430 con.weightx = 1.0; 431 con.weighty = 1.0; 432 checkfield = new JTextArea(3, 35); 433 checkfield.setName(ColumnItem.CHECK_CODE); 434 checkfield.addFocusListener(fldlistener); 435 checkfield.setToolTipText(bundle.getString("ACS_AddTableColumnCheckTextAreaA11yDesc")); 436 checkfield.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddTableColumnCheckTextAreaA11yName")); 437 checkfield.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnCheckTextAreaA11yDesc")); 438 JScrollPane spane = new JScrollPane(checkfield); 439 pane.add(spane, con); 440 441 checkcheckbox.setSelected(false); 442 checkcheckbox.setSelected(false); 443 nullcheckbox.setSelected(true); 444 uniquecheckbox.setSelected(false); 445 pkcheckbox.setEnabled(!isPK); 446 idxcombo.setEnabled(idxcombo.getItemCount()>0); 447 ixcheckbox.setEnabled(idxcombo.isEnabled()); 448 449 item.addPropertyChangeListener(new PropertyChangeListener() { 450 public void propertyChange(PropertyChangeEvent evt) { 451 String pname = evt.getPropertyName(); 452 Object nval = evt.getNewValue(); 453 if (nval instanceof Boolean ) { 454 boolean set = ((Boolean )nval).booleanValue(); 455 if (pname.equals(ColumnItem.PRIMARY_KEY)) { 456 pkcheckbox.setSelected(set); 457 } else if (pname.equals(ColumnItem.INDEX)) { 461 ixcheckbox.setSelected(set); 462 } else if (pname.equals(ColumnItem.UNIQUE)) { 463 uniquecheckbox.setSelected(set); 464 idxcombo.setEnabled(!set); 465 ixcheckbox.setEnabled(!set); 466 ixcheckbox.setSelected(set); 467 if(set) { 468 idxcombo.addItem(tempStr); 469 idxcombo.setSelectedItem(tempStr); 470 } else { 471 idxcombo.removeItem(tempStr); 472 idxcombo.setEnabled(idxcombo.getItemCount()>0); 473 ixcheckbox.setEnabled(idxcombo.isEnabled()); 474 } 475 } else if (pname.equals(ColumnItem.NULLABLE)) { 476 nullcheckbox.setSelected(set); 477 } 478 } 479 } 480 }); 481 482 ActionListener listener = new ActionListener() { 483 public void actionPerformed(ActionEvent event) { 484 if (event.getSource() == DialogDescriptor.OK_OPTION) { 485 result = validate(); 486 487 CommandBuffer cbuff = new CommandBuffer(); 488 489 if (result) { 490 try { 491 boolean use_idx = false; 492 String tablename = nfo.getTable(); 493 colname = colnamefield.getText(); 494 ColumnItem citem = (ColumnItem)dmodel.getData().elementAt(0); 495 AddColumn cmd = spec.createCommandAddColumn(tablename); 496 cmd.setObjectOwner((String )nfo.get(DatabaseNodeInfo.SCHEMA)); 497 org.netbeans.lib.ddl.impl.TableColumn col = null; 498 if (citem.isPrimaryKey()) { 499 col = (org.netbeans.lib.ddl.impl.TableColumn)cmd.createPrimaryKeyColumn(colname); 500 } else if (citem.isUnique()) { 501 col = (org.netbeans.lib.ddl.impl.TableColumn)cmd.createUniqueColumn(colname); 502 } else col = (org.netbeans.lib.ddl.impl.TableColumn)cmd.createColumn(colname); 503 if (citem.isIndexed()&&!citem.isUnique()&&!citem.isPrimaryKey()) use_idx = true; 504 col.setColumnType(Specification.getType(citem.getType().getType())); 505 col.setColumnSize(citem.getSize()); 506 col.setDecimalSize(citem.getScale()); 507 col.setNullAllowed(citem.allowsNull()); 508 if (citem.hasDefaultValue()) col.setDefaultValue(citem.getDefaultValue()); 509 510 if (citem.hasCheckConstraint()) { 511 col.setCheckCondition(citem.getCheckConstraint()); 513 } 514 cbuff.add(cmd); 515 516 if (use_idx) { 517 518 String idxname = (String )idxcombo.getSelectedItem(); 519 String isUQ = new String (); 520 if (ixmap.containsKey(idxname)) { 521 if(ix_uqmap.containsKey(idxname)) 522 isUQ = ColumnItem.UNIQUE; 523 DropIndex dropIndexCmd = spec.createCommandDropIndex(idxname); 524 dropIndexCmd.setTableName(tablename); 525 dropIndexCmd.setObjectOwner((String )nfo.get(DatabaseNodeInfo.SCHEMA)); 526 cbuff.add(dropIndexCmd); 527 } 528 529 CreateIndex xcmd = spec.createCommandCreateIndex(tablename); 530 xcmd.setIndexName(idxname); 531 xcmd.setIndexType(isUQ); 532 xcmd.setObjectOwner((String )nfo.get(DatabaseNodeInfo.SCHEMA)); 533 Enumeration enu = ((Vector)ixmap.get(idxname)).elements(); 534 while (enu.hasMoreElements()) { 535 xcmd.specifyColumn((String )enu.nextElement()); 536 } 537 xcmd.specifyColumn(citem.getName()); 538 cbuff.add(xcmd); 539 } 540 541 cbuff.execute(); 542 543 if(!cbuff.wasException()) { 545 dialog.setVisible(false); 547 dialog.dispose(); 548 } 549 551 } catch (Exception e) { 552 e.printStackTrace(); 553 } 554 } else { 555 String msg = bundle.getString("EXC_InsufficientAddColumnInfo"); 556 DialogDisplayer.getDefault().notify( 557 new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE)); 558 } 559 } 560 } 561 }; 562 563 pane.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddTableColumnDialogA11yDesc")); 564 565 DialogDescriptor descriptor = new DialogDescriptor(pane, bundle.getString("AddColumnDialogTitle"), true, listener); Object [] closingOptions = {DialogDescriptor.CANCEL_OPTION}; 569 descriptor.setClosingOptions(closingOptions); 570 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 571 dialog.setResizable(true); 572 } catch (MissingResourceException e) { 573 e.printStackTrace(); 574 } 575 } 576 577 public boolean run() { 578 if (dialog != null) dialog.setVisible(true); 579 return result; 580 } 581 582 private boolean validate() { 583 Vector cols = dmodel.getData(); 584 String colname = colnamefield.getText(); 585 if (colname == null || colname.length()<1) 586 return false; 587 588 Enumeration colse = cols.elements(); 589 while(colse.hasMoreElements()) 590 if (!((ColumnItem)colse.nextElement()).validate()) 591 return false; 592 593 return true; 594 } 595 596 public String getColumnName() { 597 return colname; 598 } 599 600 class CheckBoxListener implements ActionListener { 601 private DataModel data; 602 603 CheckBoxListener(DataModel data) { 604 this.data = data; 605 } 606 607 public void actionPerformed(ActionEvent event) { 608 JCheckBox cbx = (JCheckBox)event.getSource(); 609 String code = cbx.getName(); 610 data.setValue(cbx.isSelected() ? Boolean.TRUE : Boolean.FALSE, code, 0); 611 } 612 } 613 614 class ComboBoxListener implements ActionListener { 615 private DataModel data; 616 617 ComboBoxListener(DataModel data) { 618 this.data = data; 619 } 620 621 public void actionPerformed(ActionEvent event) { 622 JComboBox cbx = (JComboBox)event.getSource(); 623 String code = cbx.getName(); 624 data.setValue(cbx.getSelectedItem(), code, 0); 625 } 626 } 627 628 class TextFieldListener implements FocusListener { 629 private DataModel data; 630 631 TextFieldListener(DataModel data) { 632 this.data = data; 633 } 634 635 public void focusGained(FocusEvent event) { 636 } 637 638 public void focusLost(FocusEvent event) { 639 JTextComponent fld = (JTextComponent )event.getSource(); 640 String code = fld.getName(); 641 data.setValue(fld.getText(), code, 0); 642 } 643 } 644 645 class IntegerFieldListener implements FocusListener { 646 private DataModel data; 647 648 IntegerFieldListener(DataModel data) { 649 this.data = data; 650 } 651 652 public void focusGained(FocusEvent event) { 653 } 654 655 public void focusLost(FocusEvent event) { 656 JTextComponent fld = (JTextComponent )event.getSource(); 657 String code = fld.getName(); 658 String numero = fld.getText(); 659 Integer ival; 660 if (numero == null || numero.length()==0) numero = "0"; ival = new Integer (numero); 662 data.setValue(ival, code, 0); 663 } 664 } 665 } 666 | Popular Tags |