1 27 package com.genimen.djeneric.tools.modeler.extenteditor; 28 29 import java.awt.BorderLayout ; 30 import java.awt.Color ; 31 import java.awt.Dimension ; 32 import java.awt.event.ActionEvent ; 33 import java.awt.event.FocusEvent ; 34 import java.awt.event.KeyEvent ; 35 import java.awt.event.MouseAdapter ; 36 import java.awt.event.MouseEvent ; 37 import java.util.ArrayList ; 38 import java.util.Arrays ; 39 40 import javax.swing.DefaultComboBoxModel ; 41 import javax.swing.JButton ; 42 import javax.swing.JCheckBox ; 43 import javax.swing.JComboBox ; 44 import javax.swing.JComponent ; 45 import javax.swing.JLabel ; 46 import javax.swing.JOptionPane ; 47 import javax.swing.JPanel ; 48 import javax.swing.JPopupMenu ; 49 import javax.swing.JScrollPane ; 50 import javax.swing.JTabbedPane ; 51 import javax.swing.JTable ; 52 import javax.swing.JTextArea ; 53 import javax.swing.JTextField ; 54 import javax.swing.JToolTip ; 55 56 import com.genimen.djeneric.language.Messages; 57 import com.genimen.djeneric.repository.DjExtent; 58 import com.genimen.djeneric.repository.DjPackage; 59 import com.genimen.djeneric.repository.DjPersistenceManager; 60 import com.genimen.djeneric.repository.DjSession; 61 import com.genimen.djeneric.repository.exceptions.CatalogException; 62 import com.genimen.djeneric.repository.exceptions.DjenericException; 63 import com.genimen.djeneric.tools.modeler.ModelEditor; 64 import com.genimen.djeneric.tools.modeler.diagrammer.ExtentViewer; 65 import com.genimen.djeneric.ui.DjCloseable; 66 import com.genimen.djeneric.ui.DjFocusMeLater; 67 import com.genimen.djeneric.ui.DjMultiLineToolTip; 68 import com.genimen.djeneric.ui.DjPropertyPathCompleter; 69 import com.genimen.djeneric.ui.DjStatusListener; 70 import com.genimen.djeneric.ui.DjTable; 71 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 72 import com.genimen.djeneric.ui.Util; 73 import com.genimen.djeneric.util.DjLogger; 74 import com.genimen.djeneric.util.DjString; 75 76 public class ExtentEditor extends JPanel implements DjStatusListener, DjCloseable 77 { 78 private static final long serialVersionUID = 1L; 79 BorderLayout borderLayout1 = new BorderLayout (); 80 JPanel jPanel1 = new JPanel (); 81 BorderLayout borderLayout2 = new BorderLayout (); 82 JPanel jPanel2 = new JPanel (); 83 JLabel jLabel1 = new JLabel (); 84 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 85 JLabel jLabel2 = new JLabel (); 86 JLabel jLabel3 = new JLabel (); 87 JPanel jPanel3 = new JPanel (); 88 JPanel jPanel4 = new JPanel (); 89 BorderLayout borderLayout3 = new BorderLayout (); 90 JTextField _edtName = new JTextField (); 91 JTextField _edtAlias = new JTextField (); 92 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 93 JTextField _edtObjectType = new JTextField (); 94 JPanel jPanel5 = new JPanel (); 95 BorderLayout borderLayout4 = new BorderLayout (); 96 JScrollPane _scrProperties = new JScrollPane (); 97 DjTable _grdProperties = new DjTable(); 98 PropertyTableModel _propertyModel; 99 RelationTableModel _relationModel; 100 101 JPanel jPanel8 = new JPanel (); 102 JPanel jPanel9 = new JPanel (); 103 BorderLayout borderLayout5 = new BorderLayout (); 104 JButton _butAccept = new JButton (); 105 JButton _butCancel = new JButton (); 106 DjExtent _extent; 107 DjExtent _scratchExtent; 108 ModelEditor _editor; 109 JTabbedPane _tabs = new JTabbedPane (); 110 JScrollPane _scrRelations = new JScrollPane (); 111 DjTable _grdRelations = new DjTable(); 112 JScrollPane _scrDescription = new JScrollPane (); 113 JTextArea _edtDescription = new JTextArea (); 114 JPopupMenu jPopupMenu1 = new JPopupMenu (); 115 JPanel jPanel11 = new JPanel (); 116 JTextField _edtTitle = new JTextField (); 117 JTextField _edtPlural = new JTextField (); 118 DjVerticalFlowLayout verticalFlowLayout4 = new DjVerticalFlowLayout(); 119 DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout(); 120 JLabel jLabel6 = new JLabel (); 121 JPanel jPanel7 = new JPanel (); 122 JLabel jLabel5 = new JLabel (); 123 JPanel jPanel6 = new JPanel (); 124 JLabel jLabel4 = new JLabel (); 125 JTextField _edtSingular = new JTextField (); 126 JPanel jPanel12 = new JPanel (); 127 BorderLayout borderLayout6 = new BorderLayout (); 128 JPanel jPanel13 = new JPanel (); 129 JPanel jPanel14 = new JPanel (); 130 DjVerticalFlowLayout verticalFlowLayout5 = new DjVerticalFlowLayout(); 131 DjVerticalFlowLayout verticalFlowLayout6 = new DjVerticalFlowLayout(); 132 BorderLayout borderLayout7 = new BorderLayout (); 133 ExtentViewer _extentViewer; 134 boolean _modelsModified = false; 135 JLabel jLabel7 = new JLabel (); 136 JTextField _edtDescriptorExpression = new JTextField () 137 { 138 private static final long serialVersionUID = 1L; 139 140 public JToolTip createToolTip() 141 { 142 DjMultiLineToolTip tip = new DjMultiLineToolTip(); 143 tip.setComponent(this); 144 return tip; 145 } 146 }; 147 JLabel jLabel8 = new JLabel (); 148 JComboBox _cbbSuper = new JComboBox (); 149 DefaultComboBoxModel _superModel; 150 JButton _butUp = new JButton (); 151 JButton _butDelete = new JButton (); 152 JButton _butDown = new JButton (); 153 JButton _butBottom = new JButton (); 154 JButton _butFirst = new JButton (); 155 JPanel jPanel10 = new JPanel (); 156 JButton _butCreate = new JButton (); 157 JButton _butApply = new JButton (); 158 JLabel jLabel9 = new JLabel (); 159 JCheckBox _chkLarge = new JCheckBox (); 160 JLabel _lblTransient = new JLabel (); 161 JCheckBox _chkTransient = new JCheckBox (); 162 JComboBox _cbbPackage = new JComboBox (); 163 JLabel _lblPackage = new JLabel (); 164 DjPackage _defaultPackage = new DjPackage("Default"); 165 166 public ExtentEditor(ModelEditor editor, ExtentViewer extentViewer) 167 { 168 _extent = extentViewer.getExtent(); 169 _extentViewer = extentViewer; 170 _scratchExtent = (DjExtent) _extent.clone(); 171 172 _editor = editor; 173 174 try 175 { 176 ArrayList extents = new ArrayList (); 177 extents.add(Messages.getString("global.none")); 178 extents.addAll(editor.getPersistenceManager().getExtentsAsArrayList()); 179 extents.remove(extentViewer.getExtent()); 180 181 _superModel = new DefaultComboBoxModel (extents.toArray(new Object [0])); 182 _cbbSuper.setModel(_superModel); 183 if (_scratchExtent.getSuper() == null) 184 { 185 _cbbSuper.setSelectedIndex(0); 186 } 187 else 188 { 189 _cbbSuper.setSelectedItem(_scratchExtent.getSuper()); 190 } 191 192 ArrayList packages = new ArrayList (); 193 packages.add(_defaultPackage); 194 packages.addAll(Arrays.asList(editor.getPersistenceManager().getPackages())); 195 _cbbPackage.setModel(new DefaultComboBoxModel (packages.toArray())); 196 197 jbInit(); 198 199 _superModel = new DefaultComboBoxModel (extents.toArray(new Object [0])); 200 201 _edtName.setText(_scratchExtent.getName()); 202 _edtDescriptorExpression.setText(_scratchExtent.getDescriptorExpression()); 203 _edtAlias.setText(_scratchExtent.getInternalCode()); 204 _edtObjectType.setText(_scratchExtent.getObjectType()); 205 _edtDescription.setText(_scratchExtent.getDescription()); 206 _edtTitle.setText(_scratchExtent.getTitle()); 207 _edtSingular.setText(_scratchExtent.getNameSingular()); 208 _edtPlural.setText(_scratchExtent.getNamePlural()); 209 _edtDescription.setText(_scratchExtent.getDescription()); 210 _chkLarge.setSelected(_scratchExtent.isLarge()); 211 _chkTransient.setSelected(_scratchExtent.isTransient()); 212 213 DjPackage current = _scratchExtent.getPackage(); 214 if (current == null) current = _defaultPackage; 215 216 _cbbPackage.setSelectedItem(current); 217 218 _scrProperties.addMouseListener(new MouseAdapter () 219 { 220 public void mouseClicked(MouseEvent e) 221 { 222 doubleClick(e, _grdProperties); 223 } 224 }); 225 _scrRelations.addMouseListener(new MouseAdapter () 226 { 227 public void mouseClicked(MouseEvent e) 228 { 229 doubleClick(e, _grdRelations); 230 } 231 }); 232 _butAccept.setEnabled(_editor.isModelLocked()); 233 _butApply.setEnabled(_editor.isModelLocked()); 234 _butCreate.setEnabled(_editor.isModelLocked()); 235 _butDelete.setEnabled(_editor.isModelLocked()); 236 tableFirst(_grdProperties); 237 tableFirst(_grdRelations); 238 DjPropertyPathCompleter ppc = new DjPropertyPathCompleter(_scratchExtent, _edtDescriptorExpression); 239 ppc.addStatusListener(this); 240 validateDescriptorExpression(); 241 } 242 catch (Exception ex) 243 { 244 JOptionPane.showMessageDialog(this, ex.getMessage()); 245 _editor.closeCloseable(this); 246 DjLogger.log(ex); 247 } 248 } 249 250 public void requestFocus() 251 { 252 _edtName.requestFocus(); 253 } 254 255 public void notifyNewExtent() 256 { 257 _edtName.setText(""); 258 _edtAlias.setText(""); 259 _edtPlural.setText(""); 260 _edtSingular.setText(""); 261 _edtObjectType.setText(""); 262 _edtTitle.setText(""); 263 264 } 265 266 void jbInit() throws Exception 267 { 268 _propertyModel = new PropertyTableModel(_editor.getPersistenceManager(), _scratchExtent); 269 _propertyModel.setEditable(_editor.isModelLocked()); 270 _relationModel = new RelationTableModel(_editor.getPersistenceManager(), _scratchExtent); 271 _propertyModel.setEditable(_editor.isModelLocked()); 272 273 this.setLayout(borderLayout1); 274 jPanel1.setLayout(borderLayout2); 275 jLabel1.setText(Messages.getString("global.Alias")); 276 jPanel2.setLayout(verticalFlowLayout1); 277 jLabel2.setText(Messages.getString("global.Name")); 278 jLabel3.setText(Messages.getString("ExtentEditor.ObjectType")); 279 jPanel3.setLayout(borderLayout3); 280 jPanel4.setLayout(verticalFlowLayout2); 281 _edtObjectType.setMinimumSize(new Dimension (126, 21)); 282 _edtObjectType.setPreferredSize(new Dimension (190, 21)); 283 _edtObjectType.setToolTipText(Messages.getString("ExtentEditor.NameOfClass")); 284 _edtObjectType.addKeyListener(new java.awt.event.KeyAdapter () 285 { 286 public void keyReleased(KeyEvent e) 287 { 288 applyPluralAndObjectType(e); 289 } 290 }); 291 jPanel5.setLayout(borderLayout4); 292 jPanel8.setLayout(borderLayout5); 293 _butAccept.setText(Messages.getString("ExtentEditor.Accept")); 294 _butAccept.addActionListener(new java.awt.event.ActionListener () 295 { 296 public void actionPerformed(ActionEvent e) 297 { 298 _butAccept_actionPerformed(e); 299 } 300 }); 301 _butCancel.setText(Messages.getString("global.Cancel")); 302 _butCancel.addActionListener(new java.awt.event.ActionListener () 303 { 304 public void actionPerformed(ActionEvent e) 305 { 306 _butCancel_actionPerformed(e); 307 } 308 }); 309 _edtAlias.setPreferredSize(new Dimension (190, 21)); 310 _edtAlias.setToolTipText(Messages.getString("ExtentEditor.ShortIDCode")); 311 _edtName.setPreferredSize(new Dimension (190, 21)); 312 _edtName.setToolTipText(Messages.getString("ExtentEditor.TheNameOfExtent")); 313 _edtDescriptorExpression.setFont(new java.awt.Font ("Monospaced", 0, 12)); 314 _edtDescriptorExpression.setPreferredSize(new Dimension (450, 21)); 315 _edtDescriptorExpression.setToolTipText(Messages.getString("global.Descriptor")); 316 _edtDescriptorExpression.addKeyListener(new java.awt.event.KeyAdapter () 317 { 318 public void keyReleased(KeyEvent e) 319 { 320 _edtDescriptorExpression_keyReleased(e); 321 } 322 }); 323 _grdProperties.setModel(_propertyModel); 324 _grdRelations.setModel(_relationModel); 325 _edtDescription.setFont(new java.awt.Font ("Monospaced", 0, 12)); 326 _edtDescription.setWrapStyleWord(false); 327 _edtTitle.setPreferredSize(new Dimension (190, 21)); 328 _edtTitle.setToolTipText(Messages.getString("ExtentEditor.Title1")); 329 _edtPlural.setPreferredSize(new Dimension (190, 21)); 330 _edtPlural.setToolTipText(Messages.getString("ExtentEditor.TitleForList")); 331 _edtPlural.addKeyListener(new java.awt.event.KeyAdapter () 332 { 333 public void keyReleased(KeyEvent e) 334 { 335 applyPluralAndObjectType(e); 336 } 337 }); 338 verticalFlowLayout4.setHorizontalFill(false); 339 jLabel6.setText(Messages.getString("ExtentEditor.Plural")); 340 jPanel7.setLayout(verticalFlowLayout4); 341 jLabel5.setText(Messages.getString("ExtentEditor.Singular")); 342 jPanel6.setLayout(verticalFlowLayout3); 343 jLabel4.setText(Messages.getString("global.Title")); 344 _edtSingular.setPreferredSize(new Dimension (190, 21)); 345 _edtSingular.setToolTipText(Messages.getString("ExtentEditor.TitleForSingle")); 346 jPanel12.setLayout(borderLayout6); 347 jPanel13.setLayout(verticalFlowLayout5); 348 jPanel14.setLayout(verticalFlowLayout6); 349 jPanel11.setLayout(borderLayout7); 350 jLabel7.setText(Messages.getString("ExtentEditor.DescriptorExpr")); 351 jLabel8.setText(Messages.getString("global.Super")); 352 _cbbSuper.addActionListener(new java.awt.event.ActionListener () 353 { 354 public void actionPerformed(ActionEvent e) 355 { 356 _cbbSuper_actionPerformed(e); 357 } 358 }); 359 _cbbSuper.setPreferredSize(new Dimension (130, 21)); 360 _cbbSuper.setToolTipText(Messages.getString("ExtentEditor.ExtentToInherit")); 361 _butUp.setPreferredSize(new Dimension (24, 24)); 362 _butUp.setIcon(ModelEditor.getImageIcon("up.gif")); 363 _butUp.setToolTipText(Messages.getString("global.PreviousInList")); 364 _butUp.addActionListener(new java.awt.event.ActionListener () 366 { 367 public void actionPerformed(ActionEvent e) 368 { 369 _butUp_actionPerformed(e); 370 } 371 }); 372 _butDelete.addActionListener(new java.awt.event.ActionListener () 373 { 374 public void actionPerformed(ActionEvent e) 375 { 376 _butDelete_actionPerformed(e); 377 } 378 }); 379 _butDelete.setToolTipText(Messages.getString("global.DeleteCtrl")); 381 _butDelete.setIcon(ModelEditor.getImageIcon("delete.gif")); 382 _butDelete.setPreferredSize(new Dimension (24, 24)); 383 _butDown.addActionListener(new java.awt.event.ActionListener () 384 { 385 public void actionPerformed(ActionEvent e) 386 { 387 _butDown_actionPerformed(e); 388 } 389 }); 390 _butDown.setToolTipText(Messages.getString("global.NextInList")); 392 _butDown.setIcon(ModelEditor.getImageIcon("down.gif")); 393 _butDown.setPreferredSize(new Dimension (24, 24)); 394 _butBottom.setPreferredSize(new Dimension (24, 24)); 395 _butBottom.setIcon(ModelEditor.getImageIcon("bottom.gif")); 396 _butBottom.setToolTipText(Messages.getString("global.LastInList")); 397 _butBottom.addActionListener(new java.awt.event.ActionListener () 399 { 400 public void actionPerformed(ActionEvent e) 401 { 402 _butBottom_actionPerformed(e); 403 } 404 }); 405 _butFirst.setPreferredSize(new Dimension (24, 24)); 406 _butFirst.setIcon(ModelEditor.getImageIcon("top.gif")); 407 _butFirst.setToolTipText(Messages.getString("global.FirstInList")); 408 _butFirst.addActionListener(new java.awt.event.ActionListener () 410 { 411 public void actionPerformed(ActionEvent e) 412 { 413 _butFirst_actionPerformed(e); 414 } 415 }); 416 _butCreate.setPreferredSize(new Dimension (24, 24)); 417 _butCreate.setIcon(ModelEditor.getImageIcon("new.gif")); 418 _butCreate.setToolTipText(Messages.getString("global.CreateCtrl")); 419 _butCreate.addActionListener(new java.awt.event.ActionListener () 421 { 422 public void actionPerformed(ActionEvent e) 423 { 424 _butCreate_actionPerformed(e); 425 } 426 }); 427 _butApply.setPreferredSize(new Dimension (24, 24)); 428 _butApply.setIcon(ModelEditor.getImageIcon("save.gif")); 429 _butApply.setToolTipText(Messages.getString("global.ApplyAll")); 431 _butApply.addActionListener(new java.awt.event.ActionListener () 432 { 433 public void actionPerformed(ActionEvent e) 434 { 435 _butApply_actionPerformed(e); 436 } 437 }); 438 _scrDescription.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 439 _scrDescription.setAutoscrolls(true); 440 jLabel9.setToolTipText(""); 441 jLabel9.setText(Messages.getString("ExtentEditor.LargeComplex")); 442 _chkLarge.setPreferredSize(new Dimension (190, 21)); 443 _chkLarge.setToolTipText(Messages.getString("ExtentEditor.ComplexDescr")); 444 _chkLarge.setText(""); 445 _lblTransient.setText(Messages.getString("ExtentEditor.Transient")); 446 _chkTransient.setToolTipText(Messages.getString("ExtentEditor.TransientDescr")); 447 _chkTransient.setText(""); 448 _lblPackage.setText(Messages.getString("ExtentEditor.Package")); 449 jPanel2.add(jLabel2, null); 450 jPanel2.add(jLabel8, null); 451 jPanel2.add(jLabel1, null); 452 jPanel2.add(_lblPackage, null); 453 jPanel2.add(jLabel3, null); 454 jPanel2.add(jLabel9, null); 455 jPanel1.add(jPanel3, BorderLayout.CENTER); 456 jPanel3.add(jPanel4, BorderLayout.WEST); 457 jPanel4.add(_edtName, null); 458 jPanel4.add(_cbbSuper, null); 459 jPanel4.add(_edtAlias, null); 460 jPanel4.add(_cbbPackage, null); 461 jPanel4.add(_edtObjectType, null); 462 jPanel4.add(_chkLarge, null); 463 jPanel3.add(jPanel5, BorderLayout.CENTER); 464 jPanel5.add(jPanel11, BorderLayout.WEST); 465 jPanel7.add(_edtTitle, null); 466 jPanel7.add(_edtSingular, null); 467 jPanel7.add(_edtPlural, null); 468 jPanel7.add(_edtDescriptorExpression, null); 469 jPanel7.add(_chkTransient, null); 470 jPanel5.add(jPanel12, BorderLayout.CENTER); 471 jPanel12.add(jPanel13, BorderLayout.WEST); 472 jPanel12.add(jPanel14, BorderLayout.CENTER); 473 jPanel11.add(jPanel6, BorderLayout.WEST); 474 jPanel6.add(jLabel4, null); 475 jPanel6.add(jLabel5, null); 476 jPanel6.add(jLabel6, null); 477 jPanel6.add(jLabel7, null); 478 jPanel6.add(_lblTransient, null); 479 jPanel11.add(jPanel7, BorderLayout.CENTER); 480 this.add(jPanel1, BorderLayout.NORTH); 481 jPanel1.add(jPanel2, BorderLayout.WEST); 482 this.add(jPanel8, BorderLayout.SOUTH); 483 jPanel8.add(jPanel9, BorderLayout.EAST); 484 jPanel9.add(_butCancel, null); 485 jPanel9.add(_butAccept, null); 486 jPanel8.add(jPanel10, BorderLayout.WEST); 487 jPanel10.add(_butApply, null); 488 jPanel10.add(_butUp, null); 489 jPanel10.add(_butDown, null); 490 jPanel10.add(_butFirst, null); 491 jPanel10.add(_butBottom, null); 492 jPanel10.add(_butCreate, null); 493 jPanel10.add(_butDelete, null); 494 this.add(_tabs, BorderLayout.CENTER); 495 _tabs.add(_scrProperties, Messages.getString("ExtentEditor.Properties")); 496 _scrProperties.getViewport().add(_grdProperties, null); 497 _tabs.add(_scrRelations, Messages.getString("ExtentEditor.RelationsWithMaster")); 498 _tabs.add(_scrDescription, Messages.getString("ExtentEditor.ExtentDescription")); 499 _scrRelations.getViewport().add(_grdRelations, null); 500 _scrDescription.getViewport().add(_edtDescription, null); 501 502 _propertyModel.addStatusListener(this); 503 _relationModel.addStatusListener(this); 504 Util.sizeButtons(jPanel9); 505 Util.sizeLabels(jPanel2); 506 Util.sizeLabels(jPanel6); 507 } 508 509 public DjExtent getExtent() 510 { 511 return _extent; 512 } 513 514 public boolean isModified() 515 { 516 return !(stringsAreEqual(_edtDescriptorExpression.getText(), _extent.getDescriptorExpression()) 517 && stringsAreEqual(_edtName.getText(), _extent.getName()) 518 && stringsAreEqual(_edtAlias.getText(), _extent.getInternalCode()) 519 && stringsAreEqual(_edtObjectType.getText(), _extent.getObjectType()) 520 && stringsAreEqual(_edtTitle.getText(), _extent.getTitle()) 521 && stringsAreEqual(_edtSingular.getText(), _extent.getNameSingular()) 522 && stringsAreEqual(_edtPlural.getText(), _extent.getNamePlural()) 523 && stringsAreEqual(_edtDescription.getText(), _extent.getDescription()) 524 && _chkLarge.isSelected() == _extent.isLarge() && _chkTransient.isSelected() == _extent.isTransient() && !_modelsModified); 525 } 526 527 boolean stringsAreEqual(String str1, String str2) 528 { 529 if (str1 == null) str1 = ""; 530 if (str2 == null) str2 = ""; 531 532 return str1.equals(str2); 533 } 534 535 void updateSuperExtent() 536 { 537 Object superExtent = _cbbSuper.getSelectedItem(); 538 if (!(superExtent instanceof DjExtent)) _scratchExtent.setSuper(null); 539 else _scratchExtent.setSuper((DjExtent) superExtent); 540 541 _propertyModel.fireTableStructureChanged(); 542 } 543 544 void apply() throws Exception 545 { 546 defaultFields(); 547 548 _propertyModel.autoAdjustMappings(); 549 _scratchExtent.setName(_edtName.getText().trim()); 550 _scratchExtent.setDescriptorExpression(_edtDescriptorExpression.getText().trim()); 551 _scratchExtent.setAlias(_edtAlias.getText().trim()); 552 _scratchExtent.setInternalCode(_edtAlias.getText().trim()); 553 _scratchExtent.setObjectType(_edtObjectType.getText().trim()); 554 _scratchExtent.setTitle(_edtTitle.getText().trim()); 555 _scratchExtent.setNameSingular(_edtSingular.getText().trim()); 556 _scratchExtent.setNamePlural(_edtPlural.getText().trim()); 557 _scratchExtent.setDescription(_edtDescription.getText().trim()); 558 _scratchExtent.setLarge(_chkLarge.isSelected()); 559 _scratchExtent.setTransient(_chkTransient.isSelected()); 560 561 DjPackage pack = (DjPackage) _cbbPackage.getSelectedItem(); 562 if (pack == _defaultPackage) pack = null; 563 _scratchExtent.setPackage(pack); 564 565 updateSuperExtent(); 566 567 _scratchExtent.validate(_editor.getPersistenceManager(), false); 568 569 DjSession session = null; 570 try 571 { 572 session = _editor.getPersistenceManager().createSession(); 573 574 if (!_scratchExtent.getAlias().equals(_extent.getAlias())) 575 { 576 boolean isEmpty = true; 577 578 try 579 { 580 isEmpty = _extent.isEmpty(session); 581 } 582 catch (DjenericException de) 583 { 584 DjLogger.log(de); 585 setStatusMessage(Messages.getString("ExtentEditor.CouldNotDetermineContentsAliasUnchecked"), false); 586 } 587 588 if (!isEmpty) 589 { 590 _edtAlias.setText(_extent.getAlias()); 591 throw new Exception (Messages.getString("ExtentEditor.DataFound")); 592 } 593 } 594 } 595 finally 596 { 597 if (session != null) session.close(); 598 } 599 600 _scratchExtent.copyInto(_extent); 601 _editor.getPersistenceManager().rebuildDependancies(); 602 _extent.sortProperties(); 603 604 _editor.validateModel(false); 607 608 _editor.fixInvalidReferences(); 609 _editor.setStatusMessage(Messages.getString("ExtentEditor.ChangesApplied")); 610 _editor.getPersistenceManager().rebuildDependancies(); 611 _modelsModified = false; 612 } 613 614 void _butApply_actionPerformed(ActionEvent e) 615 { 616 DjExtent temp = null; 617 try 618 { 619 temp = (DjExtent) _extent.clone(); 620 apply(); 621 } 622 catch (Exception x) 623 { 624 try 625 { 626 if (temp != null) temp.copyInto(_extent); 627 } 628 catch (Exception x2) 629 { 630 DjLogger.log(x2); 631 } 634 _editor.setStatusMessage(x); 635 } 636 } 637 638 void _butAccept_actionPerformed(ActionEvent e) 639 { 640 DjExtent temp = null; 641 try 642 { 643 temp = (DjExtent) _extent.clone(); 644 apply(); 645 _editor.closeCloseable(this); 646 } 647 catch (Exception x) 648 { 649 try 650 { 651 if (temp != null) temp.copyInto(_extent); 652 } 653 catch (Exception x2) 654 { 655 } 658 _editor.setStatusMessage(x); 659 } 660 661 } 662 663 void _butCancel_actionPerformed(ActionEvent e) 664 { 665 if (canClose()) _editor.closeCloseable(this); 666 } 667 668 public boolean canClose() 669 { 670 if (!isModified()) return true; 671 int result = JOptionPane.showOptionDialog(this, Messages.getString("ExtentEditor.DiscardChanges"), Messages 672 .getString("global.CloseEditor"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, 673 new String []{Messages.getString("global.Discard"), 674 Messages.getString("global.Cancel")}, null); 675 return result == 0; 676 } 677 678 public boolean close() 679 { 680 _editor.closeCloseable(this); 681 return true; 682 } 683 684 public void doubleClick(MouseEvent e, DjTable table) 685 { 686 table.requestFocus(); 687 if (e.getClickCount() < 2) return; 688 689 try 690 { 691 table.insertRow(); 692 } 693 catch (Exception x) 694 { 695 _editor.setStatusMessage(x); 696 } 697 } 698 699 public void setStatusMessage(String msg, boolean isInformative) 700 { 701 _editor.setStatusMessage(msg, isInformative); 702 } 703 704 public void setStatusMessage(Throwable t) 705 { 706 _editor.setStatusMessage(t); 707 } 708 709 public void notifyModified() 710 { 711 _modelsModified = true; 712 } 713 714 void _cbbSuper_actionPerformed(ActionEvent e) 715 { 716 updateSuperExtent(); 717 } 718 719 void _field_focusGained(FocusEvent e) 720 { 721 if (e.getComponent() instanceof JComponent ) 722 { 723 JComponent comp = DjFocusMeLater.getNeededComponent((JComponent ) e.getComponent()); 724 if (comp instanceof JTextField ) 725 { 726 JTextField tf = (JTextField ) e.getComponent(); 727 tf.selectAll(); 728 } 729 } 730 } 731 732 void defaultFields() 733 { 734 if (_edtAlias.getText().trim().length() == 0) 735 { 736 StringBuffer alias = new StringBuffer (_edtName.getText()); 737 if (alias.length() > DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH) 738 { 739 int i = 0; 740 while (i < alias.length()) 741 { 742 if ("aAeEiIoOuU".indexOf(alias.charAt(i)) != -1) alias.deleteCharAt(i); 743 else i++; 744 } 745 if (alias.length() > DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH) 746 { 747 alias = new StringBuffer (alias.substring(0, DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH)); 748 } 749 if (alias.length() == 0) 750 { 751 alias = new StringBuffer (_edtName.getText().trim() 752 .substring(0, DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH)); 753 } 754 } 755 _edtAlias.setText(alias.toString()); 756 } 757 758 String title = DjString.initCapNoLowerCase(_edtName.getText().trim()); 759 760 if (_edtObjectType.getText().trim().length() == 0) _edtObjectType.setText(title); 761 762 String suffix = "s"; 763 if (title.endsWith(suffix)) suffix = ""; 764 if (_edtPlural.getText().trim().length() == 0) _edtPlural.setText(title + suffix); 765 if (_edtSingular.getText().trim().length() == 0) _edtSingular.setText(title); 766 if (_edtTitle.getText().trim().length() == 0) _edtTitle.setText(title); 767 applyPluralAndObjectType(null); 768 } 769 770 private void tableFirst(JTable table) 771 { 772 if (table.getRowCount() <= 0) return; 773 774 table.setRowSelectionInterval(0, 0); 775 } 776 777 private void tableBottom(JTable table) 778 { 779 int row = table.getRowCount() - 1; 780 if (row != -1) table.setRowSelectionInterval(row, row); 781 } 782 783 private void tableUp(JTable table) 784 { 785 int row = table.getSelectedRow(); 786 if (row > 0) table.setRowSelectionInterval(row - 1, row - 1); 787 } 788 789 private void tableDown(JTable table) 790 { 791 int row = table.getSelectedRow(); 792 if (row < table.getRowCount() - 1) table.setRowSelectionInterval(row + 1, row + 1); 793 } 794 795 void _butDown_actionPerformed(ActionEvent e) 796 { 797 if (_tabs.getSelectedComponent() == _scrProperties) tableDown(_grdProperties); 798 else if (_tabs.getSelectedComponent() == _scrRelations) tableDown(_grdRelations); 799 } 800 801 void _butDelete_actionPerformed(ActionEvent e) 802 { 803 try 804 { 805 if (_tabs.getSelectedComponent() == _scrProperties) _grdProperties.deleteRow(); 806 else if (_tabs.getSelectedComponent() == _scrRelations) _grdRelations.deleteRow(); 807 } 808 catch (Exception x) 809 { 810 setStatusMessage(x.getMessage(), false); 811 } 812 } 813 814 void _butBottom_actionPerformed(ActionEvent e) 815 { 816 if (_tabs.getSelectedComponent() == _scrProperties) tableBottom(_grdProperties); 817 else if (_tabs.getSelectedComponent() == _scrRelations) tableBottom(_grdRelations); 818 } 819 820 void _butFirst_actionPerformed(ActionEvent e) 821 { 822 if (_tabs.getSelectedComponent() == _scrProperties) tableFirst(_grdProperties); 823 else if (_tabs.getSelectedComponent() == _scrRelations) tableFirst(_grdRelations); 824 } 825 826 void _butCreate_actionPerformed(ActionEvent e) 827 { 828 try 829 { 830 if (_tabs.getSelectedComponent() == _scrProperties) _grdProperties.insertRow(); 831 else if (_tabs.getSelectedComponent() == _scrRelations) _grdRelations.insertRow(); 832 } 833 catch (Exception x) 834 { 835 setStatusMessage(x.getMessage(), false); 836 } 837 } 838 839 void _butUp_actionPerformed(ActionEvent e) 840 { 841 if (_tabs.getSelectedComponent() == _scrProperties) tableUp(_grdProperties); 842 else if (_tabs.getSelectedComponent() == _scrRelations) tableUp(_grdRelations); 843 } 844 845 void applyPluralAndObjectType(KeyEvent e) 846 { 847 _scratchExtent.setNamePlural(_edtPlural.getText()); 848 _scratchExtent.setObjectType(_edtObjectType.getText()); 849 } 850 851 void _edtDescriptorExpression_keyReleased(KeyEvent e) 852 { 853 validateDescriptorExpression(); 854 } 855 856 protected void validateDescriptorExpression() 857 { 858 try 859 { 860 _scratchExtent.setDescriptorExpression(_edtDescriptorExpression.getText()); 861 _scratchExtent.validateDescriptorExpression(); 862 _edtDescriptorExpression.setForeground(Color.black); 863 } 864 catch (CatalogException ce) 865 { 866 _edtDescriptorExpression.setForeground(Color.red); 867 } 868 } 869 } | Popular Tags |