1 30 package com.genimen.djeneric.tools.modeler.userperspective; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.FlowLayout ; 35 import java.awt.event.ActionEvent ; 36 import java.awt.event.KeyEvent ; 37 import java.awt.event.MouseEvent ; 38 import java.util.ArrayList ; 39 import java.util.Collections ; 40 import java.util.Iterator ; 41 42 import javax.swing.DefaultComboBoxModel ; 43 import javax.swing.JButton ; 44 import javax.swing.JCheckBox ; 45 import javax.swing.JLabel ; 46 import javax.swing.JList ; 47 import javax.swing.JOptionPane ; 48 import javax.swing.JPanel ; 49 import javax.swing.JScrollPane ; 50 import javax.swing.JTabbedPane ; 51 import javax.swing.JTable ; 52 import javax.swing.JTextField ; 53 import javax.swing.JTree ; 54 import javax.swing.event.TreeExpansionEvent ; 55 import javax.swing.event.TreeSelectionEvent ; 56 import javax.swing.tree.DefaultMutableTreeNode ; 57 import javax.swing.tree.DefaultTreeModel ; 58 import javax.swing.tree.ExpandVetoException ; 59 import javax.swing.tree.TreeNode ; 60 import javax.swing.tree.TreePath ; 61 62 import com.genimen.djeneric.language.Messages; 63 import com.genimen.djeneric.repository.DjExtent; 64 import com.genimen.djeneric.repository.DjRelation; 65 import com.genimen.djeneric.repository.exceptions.DjenericException; 66 import com.genimen.djeneric.structure.EditorDefinition; 67 import com.genimen.djeneric.structure.ExtentUsage; 68 import com.genimen.djeneric.structure.RelationDescriptor; 69 import com.genimen.djeneric.structure.RelationUsage; 70 import com.genimen.djeneric.tools.modeler.ModelEditor; 71 import com.genimen.djeneric.ui.DjCloseable; 72 import com.genimen.djeneric.ui.DjCloseableCloser; 73 import com.genimen.djeneric.ui.DjTable; 74 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 75 import com.genimen.djeneric.ui.Util; 76 import com.genimen.djeneric.util.DjLogger; 77 import com.genimen.djeneric.util.DjStringComparator; 78 79 84 public class EditorEditorPanel extends JPanel implements DjCloseable 85 { 86 private static final long serialVersionUID = 1L; 87 BorderLayout borderLayout1 = new BorderLayout (); 88 ExtentUsageNode _root; 89 DefaultTreeModel _treeModel; 90 ExtentNodeRenderer _treeCellRendrer = new ExtentNodeRenderer(); 91 92 ViewEditor _viewEditor; 93 ModelEditor _modelEditor; 94 JPanel jPanel5 = new JPanel (); 95 JPanel jPanel4 = new JPanel (); 96 DjVerticalFlowLayout verticalFlowLayout = new DjVerticalFlowLayout(); 97 JPanel jPanel1 = new JPanel (); 98 JCheckBox _chkEditAllowed = new JCheckBox (); 99 JScrollPane jScrollPane5 = new JScrollPane (); 100 JScrollPane _scrProperties = new JScrollPane (); 101 JScrollPane jScrollPane3 = new JScrollPane (); 102 JPanel jPanel11 = new JPanel (); 103 JButton _butAdd = new JButton (); 104 BorderLayout borderLayout10 = new BorderLayout (); 105 JCheckBox _chkInsertAllowed = new JCheckBox (); 106 JButton _butDown = new JButton (); 107 BorderLayout borderLayout9 = new BorderLayout (); 108 BorderLayout borderLayout6 = new BorderLayout (); 109 JButton _butDelete = new JButton (); 110 JButton _butUp = new JButton (); 111 JLabel jLabel6 = new JLabel (); 112 JLabel jLabel4 = new JLabel (); 113 JTextField _edtNodeTitle = new JTextField (); 114 JLabel _lblExtentName = new JLabel (); 115 JTree _tree = new JTree (); 116 JList _lstExtents = new JList (); 117 JPanel jPanel2 = new JPanel (); 118 JPanel jPanel6 = new JPanel (); 119 BorderLayout borderLayout4 = new BorderLayout (); 120 JPanel jPanel7 = new JPanel (); 121 JPanel jPanel8 = new JPanel (); 122 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 123 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 124 DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout(); 125 DjTable _tabProperties = new DjTable(); 126 PropertyUsageTableModel _emptyModel = new PropertyUsageTableModel(null); 127 JPanel jPanel3 = new JPanel (); 128 BorderLayout borderLayout2 = new BorderLayout (); 129 DjVerticalFlowLayout verticalFlowLayout4 = new DjVerticalFlowLayout(); 130 JCheckBox _chkMultiRow = new JCheckBox (); 131 JPanel jPanel9 = new JPanel (); 132 JCheckBox _chkDeleteAllowed = new JCheckBox (); 133 JPanel jPanel12 = new JPanel (); 134 DjVerticalFlowLayout verticalFlowLayout5 = new DjVerticalFlowLayout(); 135 JLabel jLabel1 = new JLabel (); 136 JTextField _edtRowsDisplayed = new JTextField (); 137 JPanel jPanel13 = new JPanel (); 138 BorderLayout borderLayout3 = new BorderLayout (); 139 JPanel jPanel14 = new JPanel (); 140 JButton _butAddAll = new JButton (); 141 JLabel jLabel2 = new JLabel (); 142 JTextField _edtNodeId = new JTextField (); 143 JTabbedPane _tabs = new JTabbedPane (); 144 BorderLayout borderLayout8 = new BorderLayout (); 145 JPanel jPanel20 = new JPanel (); 146 BorderLayout borderLayout13 = new BorderLayout (); 147 JPanel _pnlEditorStructure = new JPanel (); 148 ScriptEditorPanel _pnlScript; 149 JPanel jPanel10 = new JPanel (); 150 FlowLayout flowLayout1 = new FlowLayout (); 151 JButton _butOk = new JButton (); 152 JButton _butCancel = new JButton (); 153 DjCloseableCloser _closer; 154 EditorDefinition _currentEditorDefinition; 155 EditorDefinition _scratchEditorDefinition; 156 JPanel jPanel15 = new JPanel (); 157 JLabel jLabel3 = new JLabel (); 158 BorderLayout borderLayout5 = new BorderLayout (); 159 JTextField _edtEditorName = new JTextField (); 160 JPanel jPanel16 = new JPanel (); 161 BorderLayout borderLayout7 = new BorderLayout (); 162 JPanel jPanel17 = new JPanel (); 163 JPanel jPanel18 = new JPanel (); 164 DjVerticalFlowLayout verticalFlowLayout6 = new DjVerticalFlowLayout(); 165 DjVerticalFlowLayout verticalFlowLayout7 = new DjVerticalFlowLayout(); 166 JLabel jLabel5 = new JLabel (); 167 JCheckBox _chkCustomEditor = new JCheckBox (); 168 JTextField _edtCustomClassName = new JTextField (); 169 JPanel jPanel19 = new JPanel (); 170 BorderLayout borderLayout11 = new BorderLayout (); 171 172 175 public EditorEditorPanel(DjCloseableCloser closer, ViewEditor viewEditor, EditorDefinition editorDef) 176 { 177 try 178 { 179 _currentEditorDefinition = editorDef; 180 181 EditorDefinition scratch = (EditorDefinition) editorDef.clone(); 182 _closer = closer; 183 _modelEditor = viewEditor.getModelEditor(); 184 _viewEditor = viewEditor; 185 186 _pnlScript = new ScriptEditorPanel(); 187 _pnlScript.setScriptType(ScriptEditorPanel.SCRIPT_TYPE_EMBEDDED); 188 _pnlScript.setPersistenceManager(_modelEditor.getPersistenceManager()); 189 _pnlScript.setOkCancelButtonVisible(false); 190 191 jbInit(); 192 193 _butAdd.setIcon(ModelEditor.getImageIcon("add.gif")); 194 _butDelete.setIcon(ModelEditor.getImageIcon("remove.gif")); 195 _butUp.setIcon(ModelEditor.getImageIcon("up.gif")); 196 _butDown.setIcon(ModelEditor.getImageIcon("down.gif")); 197 _tree.putClientProperty("JTree.lineStyle", "Angled"); 198 199 setSelectedEditor(scratch); 200 201 _pnlScript.setScriptDefinition(scratch.getScriptDefinition()); 204 } 205 catch (Exception ex) 206 { 207 JOptionPane.showMessageDialog(this, ex.getMessage()); 208 DjLogger.log(ex); 209 } 210 } 211 212 public EditorDefinition getCurrentEditorDefinition() 213 { 214 return _currentEditorDefinition; 215 } 216 217 void jbInit() throws Exception 218 { 219 this.setLayout(borderLayout1); 220 jPanel5.setLayout(verticalFlowLayout2); 221 jPanel4.setLayout(borderLayout10); 222 jPanel1.setLayout(borderLayout9); 223 jScrollPane5.setPreferredSize(new Dimension (300, 131)); 224 jScrollPane3.setPreferredSize(new Dimension (320, 100)); 225 jPanel11.setLayout(borderLayout6); 226 _butAdd.setPreferredSize(new Dimension (24, 24)); 227 _butAdd.setToolTipText(Messages.getString("EditorEditorPanel.CreateDetailBasedOn")); 228 _butAdd.addActionListener(new java.awt.event.ActionListener () 229 { 230 public void actionPerformed(ActionEvent e) 231 { 232 _butAdd_actionPerformed(e); 233 } 234 }); 235 _butDown.setPreferredSize(new Dimension (24, 24)); 236 _butDown.setToolTipText(Messages.getString("global.MoveDown")); 237 _butDown.addActionListener(new java.awt.event.ActionListener () 238 { 239 public void actionPerformed(ActionEvent e) 240 { 241 _butDown_actionPerformed(e); 242 } 243 }); 244 _butDelete.setPreferredSize(new Dimension (24, 24)); 245 _butDelete.setToolTipText(Messages.getString("EditorEditorPanel.RemoveDetail")); 246 _butDelete.addActionListener(new java.awt.event.ActionListener () 247 { 248 public void actionPerformed(ActionEvent e) 249 { 250 _butDelete_actionPerformed(e); 251 } 252 }); 253 _butUp.setPreferredSize(new Dimension (24, 24)); 254 _butUp.setToolTipText(Messages.getString("global.MoveUp")); 255 _butUp.addActionListener(new java.awt.event.ActionListener () 256 { 257 public void actionPerformed(ActionEvent e) 258 { 259 _butUp_actionPerformed(e); 260 } 261 }); 262 jLabel6.setText(Messages.getString("global.Extent")); 263 jLabel4.setText(Messages.getString("global.Title")); 264 _tree.setCellRenderer(_treeCellRendrer); 265 _tree.setShowsRootHandles(false); 266 _tree.addTreeWillExpandListener(new javax.swing.event.TreeWillExpandListener () 267 { 268 public void treeWillExpand(TreeExpansionEvent e) 269 { 270 } 271 272 public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException 273 { 274 _tree_treeWillCollapse(e); 275 } 276 }); 277 _tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener () 278 { 279 public void valueChanged(TreeSelectionEvent e) 280 { 281 _tree_valueChanged(e); 282 } 283 }); 284 _tree.setAutoscrolls(true); 285 _lstExtents.addMouseListener(new java.awt.event.MouseAdapter () 286 { 287 public void mouseClicked(MouseEvent e) 288 { 289 _lstExtents_mouseClicked(e); 290 } 291 }); 292 _chkEditAllowed.addActionListener(new java.awt.event.ActionListener () 293 { 294 public void actionPerformed(ActionEvent e) 295 { 296 _chkEditAllowed_actionPerformed(e); 297 } 298 }); 299 _chkInsertAllowed.addActionListener(new java.awt.event.ActionListener () 300 { 301 public void actionPerformed(ActionEvent e) 302 { 303 _chkInsertAllowed_actionPerformed(e); 304 } 305 }); 306 jPanel2.setLayout(verticalFlowLayout3); 307 jPanel6.setLayout(borderLayout4); 308 jPanel7.setLayout(verticalFlowLayout1); 309 jPanel8.setLayout(verticalFlowLayout); 310 _chkEditAllowed.setText(Messages.getString("global.EditAllowed")); 311 _chkInsertAllowed.setText(Messages.getString("global.Insertallowed")); 312 _tabProperties.setAutoCreateColumnsFromModel(false); 313 _tabProperties.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 314 _scrProperties.addMouseListener(new java.awt.event.MouseAdapter () 315 { 316 public void mouseClicked(MouseEvent e) 317 { 318 _scrProperties_mouseClicked(e); 319 } 320 }); 321 _edtNodeTitle.addKeyListener(new java.awt.event.KeyAdapter () 322 { 323 public void keyReleased(KeyEvent e) 324 { 325 _edtNodeTitle_keyReleased(e); 326 } 327 }); 328 jPanel3.setLayout(borderLayout2); 329 _chkMultiRow.addActionListener(new java.awt.event.ActionListener () 330 { 331 public void actionPerformed(ActionEvent e) 332 { 333 _chkMultiRow_actionPerformed(e); 334 } 335 }); 336 _chkMultiRow.setText(Messages.getString("EditorEditorPanel.MultiRow")); 337 jPanel9.setLayout(verticalFlowLayout4); 338 _chkDeleteAllowed.addActionListener(new java.awt.event.ActionListener () 339 { 340 public void actionPerformed(ActionEvent e) 341 { 342 _chkDeleteAllowed_actionPerformed(e); 343 } 344 }); 345 _chkDeleteAllowed.setText(Messages.getString("global.DeleteAllowed")); 346 jPanel12.setLayout(verticalFlowLayout5); 347 jLabel1.setText(" "); 348 _edtRowsDisplayed.setPreferredSize(new Dimension (40, 21)); 349 _edtRowsDisplayed.setToolTipText(Messages.getString("EditorEditorPanel.RowsDsp")); 350 _edtRowsDisplayed.setText("5"); 351 _edtRowsDisplayed.addKeyListener(new java.awt.event.KeyAdapter () 352 { 353 public void keyReleased(KeyEvent e) 354 { 355 _edtRowsDisplayed_keyReleased(e); 356 } 357 }); 358 verticalFlowLayout5.setHorizontalFill(false); 359 jPanel13.setLayout(borderLayout3); 360 _butAddAll.setText(Messages.getString("EditorEditorPanel.AddAll")); 361 _butAddAll.addActionListener(new java.awt.event.ActionListener () 362 { 363 public void actionPerformed(ActionEvent e) 364 { 365 _butAddAll_actionPerformed(e); 366 } 367 }); 368 jLabel2.setText(Messages.getString("global.ID")); 369 _edtNodeId.addKeyListener(new java.awt.event.KeyAdapter () 370 { 371 public void keyReleased(KeyEvent e) 372 { 373 _edtNodeId_keyReleased(e); 374 } 375 }); 376 _pnlEditorStructure.setLayout(borderLayout8); 377 _scrProperties.setPreferredSize(new Dimension (10, 10)); 378 jPanel20.setLayout(borderLayout13); 379 jPanel10.setLayout(flowLayout1); 380 flowLayout1.setAlignment(FlowLayout.RIGHT); 381 _butOk.setText(Messages.getString("global.Ok")); 382 _butOk.addActionListener(new java.awt.event.ActionListener () 383 { 384 public void actionPerformed(ActionEvent e) 385 { 386 _butOk_actionPerformed(e); 387 } 388 }); 389 _butCancel.setText(Messages.getString("global.Cancel")); 390 _butCancel.addActionListener(new java.awt.event.ActionListener () 391 { 392 public void actionPerformed(ActionEvent e) 393 { 394 _butCancel_actionPerformed(e); 395 } 396 }); 397 jPanel15.setLayout(borderLayout5); 398 jLabel3.setText(Messages.getString("EditorEditorPanel.EditorName") + " "); 399 jPanel16.setLayout(borderLayout7); 400 jPanel18.setLayout(verticalFlowLayout7); 401 jPanel17.setLayout(verticalFlowLayout6); 402 _edtEditorName.setPreferredSize(new Dimension (4, 21)); 403 jLabel5.setText(Messages.getString("EditorEditorPanel.CustomImplementation")); 404 _chkCustomEditor.setText(""); 405 _chkCustomEditor.addActionListener(new java.awt.event.ActionListener () 406 { 407 public void actionPerformed(ActionEvent e) 408 { 409 _chkCustomEditor_actionPerformed(e); 410 } 411 }); 412 _edtCustomClassName.setPreferredSize(new Dimension (63, 21)); 413 _edtCustomClassName.setToolTipText(Messages.getString("EditorEditorPanel.ImplementObjectEditor")); 414 _edtCustomClassName.setText(""); 415 jPanel19.setLayout(borderLayout11); 416 _chkCustomEditor.setToolTipText(Messages.getString("EditorEditorPanel.UseCustomizedEditorClass")); 417 _chkCustomEditor.setText(""); 418 jPanel7.add(jLabel6, null); 419 jPanel7.add(jLabel2, null); 420 jPanel7.add(jLabel4, null); 421 _tabs.add(_pnlEditorStructure, Messages.getString("EditorEditorPanel.EditorStructure")); 422 _tabs.add(_pnlScript, Messages.getString("EditorEditorPanel.Script")); 423 this.add(jPanel16, BorderLayout.SOUTH); 424 jPanel16.add(jPanel14, BorderLayout.EAST); 425 _pnlEditorStructure.add(jPanel20, BorderLayout.NORTH); 426 jPanel20.add(jScrollPane3, BorderLayout.WEST); 427 jPanel20.add(jPanel1, BorderLayout.CENTER); 428 jScrollPane3.getViewport().add(_tree, null); 429 jPanel4.add(jPanel3, BorderLayout.CENTER); 430 jPanel6.add(jPanel8, BorderLayout.CENTER); 431 jPanel8.add(_lblExtentName, null); 432 jPanel8.add(_edtNodeId, null); 433 jPanel8.add(_edtNodeTitle, null); 434 jPanel6.add(jPanel7, BorderLayout.WEST); 435 jPanel4.add(jPanel2, BorderLayout.WEST); 436 jPanel2.add(_chkEditAllowed, null); 437 jPanel2.add(_chkInsertAllowed, null); 438 jPanel4.add(jPanel6, BorderLayout.NORTH); 439 jPanel9.add(_chkDeleteAllowed, null); 440 jPanel9.add(_chkMultiRow, null); 441 jPanel3.add(jPanel12, BorderLayout.CENTER); 442 jPanel12.add(jLabel1, null); 443 jPanel12.add(_edtRowsDisplayed, null); 444 jPanel3.add(jPanel9, BorderLayout.WEST); 445 this.add(_tabs, BorderLayout.CENTER); 446 _pnlEditorStructure.add(jPanel11, BorderLayout.CENTER); 447 jPanel11.add(jPanel13, BorderLayout.SOUTH); 448 jPanel14.add(_butCancel, null); 449 jPanel14.add(_butOk, null); 450 jPanel13.add(jPanel10, BorderLayout.CENTER); 451 jPanel10.add(_butAddAll, null); 452 jPanel11.add(_scrProperties, BorderLayout.CENTER); 453 jPanel11.add(jPanel4, BorderLayout.NORTH); 454 _scrProperties.getViewport().add(_tabProperties, null); 455 jPanel1.add(jScrollPane5, BorderLayout.CENTER); 456 jPanel1.add(jPanel5, BorderLayout.WEST); 457 jScrollPane5.getViewport().add(_lstExtents, null); 458 jPanel5.add(_butAdd, null); 459 jPanel5.add(_butDelete, null); 460 jPanel5.add(_butUp, null); 461 jPanel5.add(_butDown, null); 462 jPanel20.add(jPanel15, BorderLayout.NORTH); 463 jPanel15.add(jPanel17, BorderLayout.WEST); 464 jPanel17.add(jLabel3, null); 465 jPanel17.add(jLabel5, null); 466 jPanel15.add(jPanel18, BorderLayout.CENTER); 467 jPanel18.add(_edtEditorName, null); 468 jPanel18.add(jPanel19, null); 469 jPanel19.add(_chkCustomEditor, BorderLayout.WEST); 470 jPanel19.add(_edtCustomClassName, BorderLayout.CENTER); 471 472 Util.sizeLabels(jPanel12, false); 473 Util.sizeLabels(jPanel17, false); 474 Util.sizeLabels(jPanel16, false); 475 Util.sizeLabels(jPanel2, false); 476 Util.sizeLabels(jPanel9, false); 477 Util.sizeButtons(this); 478 } 479 480 485 public ExtentUsageNode[] getSelectedNodes() 486 { 487 if (_tree.getSelectionPath() == null) return new ExtentUsageNode[0]; 488 ArrayList result = new ArrayList (10); 489 490 TreePath [] tp = _tree.getSelectionPaths(); 491 492 for (int qq = 0; qq < tp.length; qq++) 493 { 494 DefaultMutableTreeNode node = (DefaultMutableTreeNode ) (tp[qq].getLastPathComponent()); 495 if (node instanceof ExtentUsageNode) result.add(node); 496 } 497 return (ExtentUsageNode[]) result.toArray(new ExtentUsageNode[0]); 498 } 499 500 void enableEditors(boolean b) 501 { 502 _chkDeleteAllowed.setEnabled(b); 503 _chkEditAllowed.setEnabled(b); 504 _chkInsertAllowed.setEnabled(b); 505 _chkMultiRow.setEnabled(b); 506 _butAdd.setEnabled(b); 507 _butDelete.setEnabled(b); 508 _butDown.setEnabled(b); 509 _butUp.setEnabled(b); 510 _edtNodeTitle.setEnabled(b); 511 _edtNodeId.setEnabled(b); 512 _edtRowsDisplayed.setEnabled(b); 513 } 514 515 void _tree_valueChanged(TreeSelectionEvent e) 516 { 517 ExtentUsageNode[] sels = getSelectedNodes(); 518 String title = ""; 519 String id = ""; 520 ArrayList result = new ArrayList (); 521 522 if (sels.length > 0) 523 { 524 DjExtent theExtent = sels[0].getExtent(); 525 526 if (theExtent == null) return; 527 528 sels[0].sortPropertyUsages(); 529 530 sels[0].shouldDeleteFromStructure(_modelEditor); 531 _tabProperties.setModel(sels[0].getPropertyUsageModel()); 533 sels[0].getPropertyUsageModel().addStatusListener(_modelEditor); 534 _modelEditor.setStatusMessage(ModelEditor.OK_MSG); 535 536 _chkEditAllowed.setSelected(sels[0].isEditAllowed()); 537 _chkInsertAllowed.setSelected(sels[0].isInsertAllowed()); 538 _chkDeleteAllowed.setSelected(sels[0].isDeleteAllowed()); 539 540 if (sels[0].getExtent() != null) 541 { 542 if (sels[0].getVia() == null) _lblExtentName.setText(sels[0].getExtent().getName()); 543 else _lblExtentName.setText(sels[0].getVia().toString()); 544 } 545 else _lblExtentName.setText(""); 546 547 title = sels[0].getTitle(); 548 if (title == null) title = sels[0].toString(); 549 550 id = sels[0].getId(); 551 if (id == null) id = sels[0].toString(); 552 553 enableEditors(true); 554 555 _chkMultiRow.setSelected(sels[0].isMultiRow()); 556 _edtRowsDisplayed.setText(String.valueOf(sels[0].getRowsDisplayed())); 557 558 for (int i = 0; i < theExtent.getDetailRelationCount(); i++) 559 { 560 DjRelation rel = theExtent.getDetailRelation(i); 561 562 ArrayList lst = new ArrayList (); 563 lst.add(rel.getDetailExtent()); 564 565 DjExtent[] detailExtents = rel.getDetailExtent().getAllSpecializations(); 566 for (int d = 0; d < detailExtents.length; d++) 567 lst.add(detailExtents[d]); 568 569 Iterator it = lst.iterator(); 570 while (it.hasNext()) 571 { 572 DjExtent detail = (DjExtent) it.next(); 573 RelationDescriptor rd = new RelationDescriptor(rel, detail); 574 if (!sels[0].hasExtent(rd)) result.add(rd); 575 } 576 } 577 578 _butDelete.setEnabled(sels[0] != _root); 579 _butUp.setEnabled(sels[0] != _root); 580 _butDown.setEnabled(sels[0] != _root); 581 } 582 else _tabProperties.setModel(_emptyModel); 583 584 _edtRowsDisplayed.setEnabled(_chkMultiRow.isSelected() && _chkMultiRow.isEnabled()); 585 586 Collections.sort(result, new DjStringComparator(false)); 587 DefaultComboBoxModel mdl = new DefaultComboBoxModel (result.toArray()); 588 589 _lstExtents.setModel(mdl); 590 _edtNodeTitle.setText(title); 591 _edtNodeId.setText(id); 592 } 593 594 void _lstExtents_mouseClicked(MouseEvent e) 595 { 596 if (e.getClickCount() >= 2) _butAdd_actionPerformed(null); 597 } 598 599 void _chkEditAllowed_actionPerformed(ActionEvent e) 600 { 601 ExtentUsageNode[] sels = getSelectedNodes(); 602 if (sels.length > 0) 603 { 604 sels[0].setEditAllowed(_chkEditAllowed.isSelected()); 605 } 606 } 607 608 void _chkInsertAllowed_actionPerformed(ActionEvent e) 609 { 610 ExtentUsageNode[] sels = getSelectedNodes(); 611 if (sels.length > 0) 612 { 613 sels[0].setInsertAllowed(_chkInsertAllowed.isSelected()); 614 } 615 } 616 617 void _chkDeleteAllowed_actionPerformed(ActionEvent e) 618 { 619 ExtentUsageNode[] sels = getSelectedNodes(); 620 if (sels.length > 0) 621 { 622 sels[0].setDeleteAllowed(_chkDeleteAllowed.isSelected()); 623 } 624 } 625 626 void _butAdd_actionPerformed(ActionEvent e) 627 { 628 try 629 { 630 Object [] sels = _lstExtents.getSelectedValues(); 631 ExtentUsageNode[] nodes = getSelectedNodes(); 632 if ((sels == null) || (nodes.length == 0)) return; 633 634 ExtentUsageNode focus = null; 635 636 for (int i = 0; i < sels.length; i++) 637 { 638 if (sels[i] instanceof DjExtent) 639 { 640 focus = (ExtentUsageNode) _root.addDetail((DjExtent) sels[i]); 641 } 642 else if (sels[i] instanceof RelationDescriptor) 643 { 644 645 focus = (ExtentUsageNode) nodes[0].addDetail((RelationDescriptor) sels[i], new ExtentUsage(), true); 646 } 647 else 648 { 649 System.err.println(Messages.getString("EditorEditorPanel.UnexpectedListElementType", sels[i].getClass() 650 .getName())); 651 } 652 } 653 if (sels.length > 0) 654 { 655 _treeModel.nodeStructureChanged(nodes[0]); 656 } 657 if (focus != null) 658 { 659 focus.initPropertyUsages(); 660 nodes[0].focusChild(focus); 661 } 662 } 663 catch (Exception x) 664 { 665 DjLogger.log(x); 666 } 667 } 668 669 void _butDelete_actionPerformed(ActionEvent e) 670 { 671 try 672 { 673 ExtentUsageNode[] nodes = getSelectedNodes(); 674 if (nodes.length == 0) return; 675 ExtentUsageNode focus = null; 676 677 for (int i = 0; i < nodes.length; i++) 678 { 679 if (nodes[i] != _root) 680 { 681 if (focus == null) focus = (ExtentUsageNode) nodes[i].getNextSibling(); 682 if (focus == null) focus = (ExtentUsageNode) nodes[i].getPreviousSibling(); 683 if (focus == null) focus = (ExtentUsageNode) nodes[i].getParentExtentNode(); 684 685 nodes[i].removeFromparent(); 686 } 687 } 688 _treeModel.nodeStructureChanged(nodes[0]); 689 if (focus == _root) _tree.setSelectionPath(new TreePath (new Object []{_root})); 690 else if (focus != null) 691 { 692 if (focus.getParentExtentNode() != null) 693 { 694 focus.getParentExtentNode().focusChild(focus); 695 } 696 } 697 _tree_valueChanged(null); 698 } 699 catch (Exception x) 700 { 701 DjLogger.log(x); 702 } 703 } 704 705 void _butUp_actionPerformed(ActionEvent e) 706 { 707 ExtentUsageNode[] nodes = getSelectedNodes(); 708 if (nodes.length == 0) return; 709 for (int i = 0; i < nodes.length; i++) 710 if (nodes[i].getPreviousSibling() == null) return; 711 712 TreePath [] selected = _tree.getSelectionPaths(); 713 714 for (int i = 0; i < nodes.length; i++) 715 { 716 if (nodes[i] == _root) continue; 717 718 ExtentUsageNode parent = (ExtentUsageNode) nodes[i].getParentExtentNode(); 719 720 int childCount = parent.getChildCount(); 721 TreeNode [] list = new ExtentUsageNode[childCount]; 722 723 for (int c = 0; c < childCount; c++) 724 { 725 list[c] = parent.getChildAt(c); 726 } 727 for (int c = 1; c < childCount; c++) 728 { 729 if (list[c] == nodes[i]) 730 { 731 TreeNode temp = list[c - 1]; 732 list[c - 1] = list[c]; 733 list[c] = temp; 734 parent.getExtentUsage().moveDetailUp(c); 735 break; 736 } 737 } 738 parent.removeAllChildren(); 739 740 for (int c = 0; c < childCount; c++) 741 { 742 parent.addDetail((ExtentUsageNode) list[c]); 743 } 744 _treeModel.nodeStructureChanged(parent); 745 } 746 _tree.setSelectionPaths(selected); 747 } 748 749 void _butDown_actionPerformed(ActionEvent e) 750 { 751 ExtentUsageNode[] nodes = getSelectedNodes(); 752 if (nodes.length == 0) return; 753 for (int i = 0; i < nodes.length; i++) 754 if (nodes[i].getNextSibling() == null) return; 755 756 TreePath [] selected = _tree.getSelectionPaths(); 757 758 for (int i = nodes.length - 1; i >= 0; i--) 759 { 760 if (nodes[i] == _root) continue; 761 762 ExtentUsageNode parent = (ExtentUsageNode) nodes[i].getParentExtentNode(); 763 764 int childCount = parent.getChildCount(); 765 TreeNode [] list = new ExtentUsageNode[childCount]; 766 for (int c = 0; c < childCount; c++) 767 { 768 list[c] = parent.getChildAt(c); 769 } 770 for (int c = childCount - 2; c >= 0; c--) 771 { 772 if (list[c] == nodes[i]) 773 { 774 TreeNode temp = list[c + 1]; 775 list[c + 1] = list[c]; 776 list[c] = temp; 777 parent.getExtentUsage().moveDetailDown(c); 778 break; 779 } 780 } 781 parent.removeAllChildren(); 782 for (int c = 0; c < childCount; c++) 783 { 784 parent.addDetail((ExtentUsageNode) list[c]); 785 } 786 _treeModel.nodeStructureChanged(parent); 787 } 788 _tree.setSelectionPaths(selected); 789 } 790 791 public void setSelectedEditor(EditorDefinition editorDef) 792 { 793 _scratchEditorDefinition = editorDef; 794 795 ExtentUsage extentUsage = editorDef.getUsages(); 796 797 _edtEditorName.setText(editorDef.getName()); 798 String customClass = editorDef.getCustomEditorClass(); 799 _chkCustomEditor.setSelected(customClass != null); 800 if (customClass != null) _edtCustomClassName.setText(customClass); 801 else _edtCustomClassName.setText(""); 802 803 enableEditors(true); 804 805 _butDelete.setEnabled(false); 806 _butUp.setEnabled(false); 807 _butDown.setEnabled(false); 808 809 _root = new ExtentUsageNode(new ExtentUsage()); 810 _root.setModel(new DefaultTreeModel (_root)); 811 _root.setExtent(extentUsage.getExtent()); 812 _root.setTitle(extentUsage.getTitle()); 813 _root.setId(extentUsage.getId()); 814 815 _root.setTree(_tree); 816 817 _tabProperties.setModel(_root.getPropertyUsageModel()); 818 819 _root.setInsertAllowed(extentUsage.isInsertAllowed()); 820 _root.setDeleteAllowed(extentUsage.isDeleteAllowed()); 821 _root.setEditAllowed(extentUsage.isEditAllowed()); 822 823 _treeModel = _root.getModel(); 824 _tree.setModel(_treeModel); 825 _treeModel.nodeStructureChanged(_root); 826 827 createSubTree(_root, extentUsage); 828 829 expandTree(); 830 _tree.setSelectionPath(new TreePath (_root.getPath())); 831 832 synchCustomClassStuff(); 833 _pnlScript.setEditorDefinition(editorDef); 834 } 835 836 public void createSubTree(ExtentNode extentNode, ExtentUsage extentUsage) 837 { 838 extentNode.setExtentUsage(extentUsage); 839 for (int i = 0; i < extentUsage.getDetailRelationCount(); i++) 840 { 841 RelationUsage ru = extentUsage.getDetailRelation(i); 842 RelationDescriptor rdesc = new RelationDescriptor(extentUsage.getDetailRelation(i).getRelation()); 843 844 ExtentNode detail = extentNode.addDetail(rdesc, ru.getDetail(), false); 848 createSubTree(detail, ru.getDetail()); 850 } 851 } 852 853 public void clear() 854 { 855 _root = new ExtentUsageNode(new ExtentUsage()); 856 _root.setModel(new DefaultTreeModel (_root)); 857 _treeModel = _root.getModel(); 858 _treeModel.nodeStructureChanged(_root); 859 _tree.setModel(_treeModel); 860 861 enableEditors(false); 862 } 863 864 void _chkMultiRow_actionPerformed(ActionEvent e) 865 { 866 ExtentUsageNode[] sels = getSelectedNodes(); 867 if (sels.length > 0) 868 { 869 sels[0].setMultiRow(_chkMultiRow.isSelected()); 870 } 871 _edtRowsDisplayed.setEnabled(_chkMultiRow.isSelected()); 872 } 873 874 877 public void expandTree() 878 { 879 int row = 0; 880 while (row < _tree.getRowCount()) 881 { 882 _tree.expandRow(row++); 883 } 884 } 885 886 void _scrProperties_mouseClicked(MouseEvent e) 887 { 888 doubleClick(e, _tabProperties); 889 } 890 891 899 public void doubleClick(MouseEvent e, DjTable table) 900 { 901 table.requestFocus(); 902 if (e.getClickCount() < 2) return; 903 904 try 905 { 906 table.insertRow(); 907 } 908 catch (Exception x) 909 { 910 _modelEditor.setStatusMessage(x); 911 } 912 913 } 914 915 void _edtNodeTitle_keyReleased(KeyEvent e) 916 { 917 ExtentUsageNode[] sels = getSelectedNodes(); 918 if (sels.length > 0) 919 { 920 String title = _edtNodeTitle.getText().trim(); 921 if (!title.equals(sels[0].getTitle())) 922 { 923 sels[0].setTitle(title); 924 _treeModel.nodeChanged(sels[0]); 925 } 926 } 927 } 928 929 void _edtRowsDisplayed_keyReleased(KeyEvent e) 930 { 931 ExtentUsageNode[] sels = getSelectedNodes(); 932 if (sels.length > 0) 933 { 934 try 935 { 936 int rows = Integer.parseInt(_edtRowsDisplayed.getText().trim()); 937 if (sels[0].getRowsDisplayed() != rows) 938 { 939 sels[0].setRowsDisplayed(rows); 940 } 941 } 942 catch (Exception x) 943 { 944 } 946 _treeModel.nodeChanged(sels[0]); 947 } 948 } 949 950 void _butAddAll_actionPerformed(ActionEvent e) 951 { 952 addAllProperties(); 953 } 954 955 public void addAllProperties() 956 { 957 try 958 { 959 while (_tabProperties.insertRow() != -1); 960 } 961 catch (Exception x) 962 { 963 DjLogger.log(x); 964 } 965 } 966 967 void _edtNodeId_keyReleased(KeyEvent e) 968 { 969 ExtentUsageNode[] sels = getSelectedNodes(); 970 if (sels.length > 0) 971 { 972 if (!_edtNodeId.getText().equals(sels[0].getId())) 973 { 974 sels[0].setId(_edtNodeId.getText()); 975 _treeModel.nodeChanged(sels[0]); 976 } 977 } 978 979 } 980 981 void _butOk_actionPerformed(ActionEvent e) 982 { 983 if (!_pnlScript.apply(false)) return; 984 985 copyFieldsToScratch(false); 986 987 try 988 { 989 _scratchEditorDefinition.validate(); 990 991 _currentEditorDefinition.copyFrom(_scratchEditorDefinition); 992 close(); 993 } 994 catch (DjenericException dje) 995 { 996 _modelEditor.setStatusMessage(dje); 997 } 998 } 999 1000 private void copyFieldsToScratch(boolean ignoreErrors) 1001 { 1002 String name = _edtEditorName.getText().trim(); 1003 if (name.length() == 0) name = Messages.getString("EditorEditorPanel.Unnamed"); 1004 1005 _scratchEditorDefinition.setName(name); 1006 1007 String className = _edtCustomClassName.getText().trim(); 1008 if (className.length() == 0) className = null; 1009 if (!_chkCustomEditor.isSelected()) className = null; 1010 _scratchEditorDefinition.setCustomEditorClass(className); 1011 1012 _pnlScript.apply(ignoreErrors); 1013 } 1014 1015 void _butCancel_actionPerformed(ActionEvent e) 1016 { 1017 if (canClose()) close(); 1018 } 1019 1020 public boolean canClose() 1021 { 1022 copyFieldsToScratch(true); 1023 1024 if (_scratchEditorDefinition.equals(_currentEditorDefinition)) return true; 1025 1026 int result = JOptionPane.showOptionDialog(this, Messages.getString("EditorEditorPanel.DiscardChanges1"), Messages 1027 .getString("global.DiscardChanges"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, 1028 new String []{Messages.getString("global.Discard"), 1029 Messages.getString("global.Cancel")}, null); 1030 return result == 0; 1031 } 1032 1033 public boolean close() 1034 { 1035 _closer.closeCloseable(this); 1036 return true; 1037 } 1038 1039 void _chkCustomEditor_actionPerformed(ActionEvent e) 1040 { 1041 synchCustomClassStuff(); 1042 if (_chkCustomEditor.isSelected()) _edtCustomClassName.requestFocus(); 1043 } 1044 1045 private void synchCustomClassStuff() 1046 { 1047 _edtCustomClassName.setEnabled(_chkCustomEditor.isSelected()); 1048 } 1049 1050 void _tree_treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException 1051 { 1052 throw new ExpandVetoException (e); 1053 } 1054 1055} | Popular Tags |