1 14 package mondrian.gui; 15 16 import java.awt.event.ItemEvent ; 17 import java.awt.event.ItemListener ; 18 import java.awt.event.InputEvent ; 19 import java.awt.event.KeyAdapter ; 20 import java.io.StringReader ; 21 import java.io.StringWriter ; 22 import java.util.ArrayList ; 23 import java.util.EventObject ; 24 25 import javax.swing.*; 26 import javax.swing.border.EtchedBorder ; 27 import javax.swing.event.CellEditorListener ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.TreeSelectionEvent ; 30 import javax.swing.event.TreeSelectionListener ; 31 import javax.swing.table.DefaultTableModel ; 32 import javax.swing.table.TableCellRenderer ; 33 import javax.swing.table.TableCellEditor ; 34 import javax.swing.tree.TreePath ; 35 import java.awt.*; 36 import java.awt.event.ActionEvent ; 37 import java.awt.event.KeyEvent ; 38 import java.awt.event.MouseAdapter ; 39 import java.awt.event.MouseEvent ; 40 import java.io.File ; 41 import java.lang.reflect.Array ; 42 import java.lang.reflect.Field ; 43 import java.util.ResourceBundle ; 44 import javax.swing.event.TreeExpansionEvent ; 45 import javax.swing.tree.TreeCellEditor ; 46 import javax.swing.plaf.basic.BasicArrowButton ; 47 import javax.swing.tree.DefaultTreeSelectionModel ; 48 49 import org.eigenbase.xom.XOMUtil; 50 import org.eigenbase.xom.Parser; 51 import org.eigenbase.xom.NodeDef; 52 import org.eigenbase.xom.XOMException; 53 54 59 public class SchemaExplorer extends javax.swing.JPanel implements TreeSelectionListener , CellEditorListener { 60 private MondrianGuiDef.Schema schema; 61 private SchemaTreeModel model; 62 private SchemaTreeCellRenderer renderer; 63 private SchemaTreeCellEditor editor; 64 private File schemaFile; 65 private JTreeUpdater updater; 66 private final ClassLoader myClassLoader; 67 private boolean newFile; 68 private boolean dirty = false; private boolean dirtyFlag = false; private JInternalFrame parentIFrame; 71 private JDBCMetaData jdbcMetaData; 72 private boolean editModeXML = false; 73 private String errMsg = null; 74 75 76 public SchemaExplorer() { 77 myClassLoader = this.getClass().getClassLoader(); 78 initComponents(); 79 } 80 81 public SchemaExplorer(File f, JDBCMetaData jdbcMetaData, boolean newFile, JInternalFrame parentIFrame) { 82 this(); 83 84 try { 86 jEditorPaneXML = new JEditorPane(); } catch (Exception ex) { 90 ex.printStackTrace(); 91 } 92 93 jEditorPaneXML.setLayout(new java.awt.BorderLayout ()); 94 jEditorPaneXML.setEditable(false); 95 jScrollPaneXML = new JScrollPane(jEditorPaneXML); 96 jPanelXML.setLayout(new java.awt.BorderLayout ()); 98 jPanelXML.add(jScrollPaneXML, java.awt.BorderLayout.CENTER); 99 jPanelXML.add(targetLabel2, java.awt.BorderLayout.NORTH); 100 jPanelXML.add(validStatusLabel2, java.awt.BorderLayout.SOUTH); 101 jPanelXML.setMaximumSize(jPanel1.getMaximumSize()); 102 jPanelXML.setPreferredSize(jPanel1.getPreferredSize()); 103 104 106 databaseLabel.setText("Database - " +jdbcMetaData.getDbCatalogName() + " ("+ jdbcMetaData.getDatabaseProductName()+")"); 107 108 try { 109 Parser xmlParser = XOMUtil.createDefaultParser(); 110 this.schemaFile = f; 111 this.setNewFile(newFile); 112 this.parentIFrame = parentIFrame; 113 114 this.jdbcMetaData = jdbcMetaData; 115 116 if (newFile) { 117 schema = new MondrianGuiDef.Schema(); 118 schema.cubes = new MondrianGuiDef.Cube[0]; 119 schema.dimensions = new MondrianGuiDef.Dimension[0]; 120 schema.namedSets = new MondrianGuiDef.NamedSet[0]; 121 schema.roles = new MondrianGuiDef.Role[0]; 122 schema.userDefinedFunctions = new MondrianGuiDef.UserDefinedFunction[0]; 123 schema.virtualCubes = new MondrianGuiDef.VirtualCube[0]; 124 125 String sname = schemaFile.getName(); 126 int ext = sname.indexOf("."); 127 if (ext != -1) { 128 schema.name = "New "+sname.substring(0,ext); 129 } 130 } else { 131 try { 132 schema = new MondrianGuiDef.Schema(xmlParser.parse(schemaFile.toURL())); 133 } catch(XOMException ex) { 134 schema = new MondrianGuiDef.Schema(); 138 schema.cubes = new MondrianGuiDef.Cube[0]; 139 schema.dimensions = new MondrianGuiDef.Dimension[0]; 140 schema.namedSets = new MondrianGuiDef.NamedSet[0]; 141 schema.roles = new MondrianGuiDef.Role[0]; 142 schema.userDefinedFunctions = new MondrianGuiDef.UserDefinedFunction[0]; 143 schema.virtualCubes = new MondrianGuiDef.VirtualCube[0]; 144 145 System.out.println("Exception : Schema file parsing failed."+ex.getMessage()); 146 errMsg = "Parsing Error: Could not open file\n"+schemaFile+".\n"+ex.getMessage(); 147 } 148 } 149 setTitle(); 151 renderer = new SchemaTreeCellRenderer(jdbcMetaData); 153 model = new SchemaTreeModel(schema); 154 tree.setModel(model); 155 tree.setCellRenderer(renderer); 156 tree.addTreeSelectionListener(this); 157 158 JComboBox listEditor = new JComboBox( new String [] {"Join", "Table"} ); 159 listEditor.setToolTipText("select Join or Table Hierarchy"); 160 listEditor.setPreferredSize(new java.awt.Dimension (listEditor.getPreferredSize().width, 24)); 162 listEditor.addItemListener(new ItemListener () { 163 public void itemStateChanged(ItemEvent e) { 164 tree.stopEditing(); 165 TreePath tpath = tree.getSelectionPath(); if (tpath != null) { 167 TreePath parentpath = tpath.getParentPath(); 168 if (parentpath != null) { 169 refreshTree(parentpath); 170 } 171 } 172 } 173 }); 174 175 TreeCellEditor comboEditor = new DefaultCellEditor(listEditor); 176 177 editor = new SchemaTreeCellEditor(tree, renderer, comboEditor); 178 tree.setCellEditor(editor); 179 tree.setEditable(true); 180 181 182 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(jdbcMetaData); 184 spce.addCellEditorListener(this); 185 propertyTable.setDefaultEditor(Object .class, spce); 186 SchemaPropertyCellRenderer.attributeBackground = jScrollPane2.getBackground(); SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 188 propertyTable.setDefaultRenderer(Object .class, spcr); 189 190 191 203 204 208 209 } catch (Exception ex) { 210 ex.printStackTrace(); 211 } 212 } 213 214 217 private void initComponents() { 218 219 ResourceBundle resources = ResourceBundle.getBundle("mondrian.gui.resources.gui"); 220 jPanelXML = new JPanel(); 221 jScrollPaneXML = new JScrollPane(); 222 223 footer = new JPanel(); 224 databaseLabel = new javax.swing.JLabel (); 225 226 jSeparator1 = new JSeparator(); 227 jSplitPane1 = new JSplitPane(); 228 jPanel1 = new JPanel(); 229 jScrollPane2 = new JScrollPane(); 230 propertyTable = new JTable() { 235 public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) { 236 if (columnIndex == 0) { 237 AWTEvent currentEvent = EventQueue.getCurrentEvent(); 238 if(currentEvent instanceof KeyEvent ) { 239 KeyEvent ke = (KeyEvent )currentEvent; 240 int kcode = ke.getKeyCode(); 241 if (kcode == KeyEvent.VK_TAB) { 242 if ((ke.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == 243 InputEvent.SHIFT_DOWN_MASK) { 244 rowIndex -= 1; 245 if (rowIndex < 0) { 246 rowIndex = (propertyTable.getRowCount()) - 1; 247 } 248 } 249 setTableCellFocus(rowIndex); 250 return; 251 } 252 } 253 } 254 super.changeSelection(rowIndex, columnIndex, toggle, extend); 255 } 256 public void processKeyEvent(KeyEvent e) { 257 int kcode = e.getKeyCode(); 258 if (kcode == KeyEvent.VK_UP || kcode == KeyEvent.VK_DOWN) { 259 int row = propertyTable.getSelectedRow(); 260 setTableCellFocus(row); 261 return; 262 } 263 super.processKeyEvent(e); 264 } 265 }; 266 267 targetLabel = new javax.swing.JLabel (); 268 validStatusLabel = new javax.swing.JLabel (); 269 targetLabel2 = new javax.swing.JLabel (); 270 validStatusLabel2 = new javax.swing.JLabel (); 271 jPanel2 = new JPanel(); 272 jScrollPane1 = new JScrollPane(); 273 274 tree = new JTree() { 275 public String getToolTipText(MouseEvent evt) { 276 String toggleMsg = "Double click to display Join/Table selection"; 277 if (getRowForLocation(evt.getX(), evt.getY()) == -1) return null; 278 TreePath curPath = getPathForLocation(evt.getX(), evt.getY()); 279 Object o = curPath.getLastPathComponent(); 280 if (o instanceof MondrianGuiDef.Join) { 281 return toggleMsg; 282 } 283 TreePath parentPath = curPath.getParentPath(); 284 if (parentPath != null) { 285 Object po = parentPath.getLastPathComponent(); 286 if (o instanceof MondrianGuiDef.Table && 287 (po instanceof MondrianGuiDef.Hierarchy || 288 po instanceof MondrianGuiDef.Join)) { 289 return toggleMsg; 290 } 291 } 292 return null; 293 } 294 }; 295 tree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); 296 297 ToolTipManager.sharedInstance().registerComponent(tree); 298 299 jToolBar1 = new JToolBar(); 300 addCubeButton = new JButton(); 301 addDimensionButton = new JButton(); 302 addDimensionUsageButton = new JButton(); 303 addHierarchyButton = new JButton(); 304 addNamedSetButton = new JButton(); 305 addUserDefinedFunctionButton = new JButton(); 306 addRoleButton = new JButton(); 307 308 addMeasureButton = new JButton(); 309 addCalculatedMemberButton = new JButton(); 310 addLevelButton = new JButton(); 311 addPropertyButton = new JButton(); 312 313 addVirtualCubeButton = new JButton(); 314 addVirtualCubeDimensionButton = new JButton(); 315 addVirtualCubeMeasureButton = new JButton(); 316 317 cutButton = new JButton(); 318 copyButton = new JButton(); 319 pasteButton = new JButton(); 320 deleteButton = new JButton(); 321 editModeButton = new JToggleButton(); 322 323 setLayout(new BorderLayout()); 324 325 jSplitPane1.setDividerLocation(200); 326 jPanel1.setLayout(new BorderLayout()); 327 328 propertyTable.setModel(new DefaultTableModel (new Object [][] { 329 }, new String [] { "Attribute", "Value" }) { 330 Class [] types = new Class [] { java.lang.String .class, java.lang.Object .class }; 331 boolean[] canEdit = new boolean[] { false, true }; 332 333 public Class getColumnClass(int columnIndex) { 334 return types[columnIndex]; 335 } 336 337 public boolean isCellEditable(int rowIndex, int columnIndex) { 338 return canEdit[columnIndex]; 339 } 340 }); 341 342 propertyTable.getTableHeader().setFont(new Font("Dialog", Font.BOLD, 12)); 344 jScrollPane2.setViewportView(propertyTable); 345 346 jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER); 347 348 targetLabel.setFont(new Font("Dialog", 1, 14)); 349 targetLabel.setForeground((Color) UIManager.getDefaults().get("CheckBoxMenuItem.acceleratorForeground")); 350 targetLabel.setHorizontalAlignment(SwingConstants.CENTER); 351 targetLabel.setText("Schema"); 352 targetLabel.setBorder(new EtchedBorder ()); 353 jPanel3 = new JPanel(); 355 jPanel3.setLayout(new BorderLayout()); 356 BasicArrowButton arrowButtonUp = new BasicArrowButton (SwingConstants.NORTH); 357 BasicArrowButton arrowButtonDown = new BasicArrowButton (SwingConstants.SOUTH); 358 arrowButtonUp.setToolTipText("move to parent element"); 359 arrowButtonDown.setToolTipText("move to child element"); 360 arrowButtonUpAction = new AbstractAction("Arrow button up") { 361 public void actionPerformed(ActionEvent e) { 362 arrowButtonUpAction(e); 363 } 364 }; 365 arrowButtonDownAction = new AbstractAction("Arrow button down") { 366 public void actionPerformed(ActionEvent e) { 367 arrowButtonDownAction(e); 368 } 369 }; 370 arrowButtonUp.addActionListener(arrowButtonUpAction); 371 arrowButtonDown.addActionListener(arrowButtonDownAction); 372 jPanel3.add(arrowButtonDown, java.awt.BorderLayout.EAST); 373 jPanel3.add(arrowButtonUp, java.awt.BorderLayout.WEST); 374 jPanel3.add(targetLabel, java.awt.BorderLayout.CENTER); 375 376 jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH); 377 validStatusLabel.setFont(new Font("Dialog", Font.PLAIN, 12)); 378 validStatusLabel.setForeground(Color.RED); 379 validStatusLabel.setHorizontalAlignment(SwingConstants.CENTER); 380 381 jPanel1.add(validStatusLabel, java.awt.BorderLayout.SOUTH); 382 383 targetLabel2.setFont(new Font("Dialog", 1, 14)); 385 targetLabel2.setForeground((Color) UIManager.getDefaults().get("CheckBoxMenuItem.acceleratorForeground")); 386 targetLabel2.setHorizontalAlignment(SwingConstants.CENTER); 387 targetLabel2.setText("Schema"); 388 targetLabel2.setBorder(new EtchedBorder ()); 389 validStatusLabel2.setFont(new Font("Dialog", Font.PLAIN, 12)); 390 validStatusLabel2.setForeground(Color.RED); 391 validStatusLabel2.setHorizontalAlignment(SwingConstants.CENTER); 392 393 jSplitPane1.setRightComponent(jPanel1); 394 395 jPanel2.setLayout(new java.awt.BorderLayout ()); 396 397 jScrollPane1.setViewportView(tree); 398 399 jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER); 400 401 jSplitPane1.setLeftComponent(jPanel2); 402 403 404 addCube = new AbstractAction("Add cube") { 408 public void actionPerformed(ActionEvent e) { 409 addCube(e); 410 } 411 }; 412 addDimension = new AbstractAction("Add Dimension") { 413 public void actionPerformed(ActionEvent e) { 414 addDimension(e); 415 } 416 }; 417 addDimensionUsage = new AbstractAction("Add Dimension Usage") { 418 public void actionPerformed(ActionEvent e) { 419 addDimensionUsage(e); 420 } 421 }; 422 addHierarchy = new AbstractAction("Add Hierarchy") { 423 public void actionPerformed(ActionEvent e) { 424 addHierarchy(e); 425 } 426 }; 427 addNamedSet = new AbstractAction("Add Named Set") { 428 public void actionPerformed(ActionEvent e) { 429 addNamedSet(e); 430 } 431 }; 432 addMeasure = new AbstractAction("Add Measure") { 433 public void actionPerformed(ActionEvent e) { 434 addMeasure(e); 435 } 436 }; 437 addCalculatedMember = new AbstractAction("Add Calculated Measure") { 438 public void actionPerformed(ActionEvent e) { 439 addCalculatedMember(e); 440 } 441 }; 442 addUserDefinedFunction = new AbstractAction("Add User Defined Function") { 443 public void actionPerformed(ActionEvent e) { 444 addUserDefinedFunction(e); 445 } 446 }; 447 addRole = new AbstractAction("Add Role") { 448 public void actionPerformed(ActionEvent e) { 449 addRole(e); 450 } 451 }; 452 addSchemaGrant = new AbstractAction("Add Schema Grant") { 453 public void actionPerformed(ActionEvent e) { 454 addSchemaGrant(e); 455 } 456 }; 457 addCubeGrant = new AbstractAction("Add Cube Grant") { 458 public void actionPerformed(ActionEvent e) { 459 addCubeGrant(e); 460 } 461 }; 462 addDimensionGrant = new AbstractAction("Add Dimension Grant") { 463 public void actionPerformed(ActionEvent e) { 464 addDimensionGrant(e); 465 } 466 }; 467 addHierarchyGrant = new AbstractAction("Add Hierarchy Grant") { 468 public void actionPerformed(ActionEvent e) { 469 addHierarchyGrant(e); 470 } 471 }; 472 addMemberGrant = new AbstractAction("Add Member Grant") { 473 public void actionPerformed(ActionEvent e) { 474 addMemberGrant(e); 475 } 476 }; 477 478 addLevel = new AbstractAction("Add Level") { 479 public void actionPerformed(ActionEvent e) { 480 addLevel(e); 481 } 482 }; 483 addClosure = new AbstractAction("Add Closure") { 484 public void actionPerformed(ActionEvent e) { 485 addClosure(e); 486 } 487 }; 488 addKeyExp = new AbstractAction("Add Key Expression") { 489 public void actionPerformed(ActionEvent e) { 490 addKeyExp(e); 491 } 492 }; 493 addNameExp = new AbstractAction("Add Name Expression") { 494 public void actionPerformed(ActionEvent e) { 495 addNameExp(e); 496 } 497 }; 498 addOrdinalExp = new AbstractAction("Add Ordinal Expression") { 499 public void actionPerformed(ActionEvent e) { 500 addOrdinalExp(e); 501 } 502 }; 503 addParentExp = new AbstractAction("Add Parent Expression") { 504 public void actionPerformed(ActionEvent e) { 505 addParentExp(e); 506 } 507 }; 508 addMeasureExp = new AbstractAction("Add Measure Expression") { 509 public void actionPerformed(ActionEvent e) { 510 addMeasureExp(e); 511 } 512 }; 513 addSQL = new AbstractAction("Add SQL") { 514 public void actionPerformed(ActionEvent e) { 515 addSQL(e); 516 } 517 }; 518 addRelation = new AbstractAction("Add Relation") { 519 public void actionPerformed(ActionEvent e) { 520 addRelation(e); 521 } 522 }; 523 addProperty = new AbstractAction("Add Property") { 524 public void actionPerformed(ActionEvent e) { 525 addProperty(e); 526 } 527 }; 528 529 addVirtualCube = new AbstractAction("Add Virtual Cube") { 530 public void actionPerformed(ActionEvent e) { 531 addVirtualCube(e); 532 } 533 }; 534 addVirtualCubeDimension = new AbstractAction("Add Virtual Cube Dimension") { 535 public void actionPerformed(ActionEvent e) { 536 addVirtualCubeDimension(e); 537 } 538 }; 539 addVirtualCubeMeasure = new AbstractAction("Add Virtual Cube Measure") { 540 public void actionPerformed(ActionEvent e) { 541 addVirtualCubeMeasure(e); 542 } 543 }; 544 545 addAggPattern = new AbstractAction("Add Aggregate Pattern") { 546 public void actionPerformed(ActionEvent e) { 547 addAggPattern(e); 548 } 549 }; 550 addAggExclude = new AbstractAction("Add Aggregate Exclude Table") { 551 public void actionPerformed(ActionEvent e) { 552 addAggExclude(e); 553 } 554 }; 555 addAggName = new AbstractAction("Add Aggregate Name") { 556 public void actionPerformed(ActionEvent e) { 557 addAggName(e); 558 } 559 }; 560 addAggIgnoreColumn = new AbstractAction("Add Aggregate Ignore Column") { 561 public void actionPerformed(ActionEvent e) { 562 addAggIgnoreColumn(e); 563 } 564 }; 565 addAggForeignKey = new AbstractAction("Add Aggregate Foreign Key") { 566 public void actionPerformed(ActionEvent e) { 567 addAggForeignKey(e); 568 } 569 }; 570 addAggMeasure = new AbstractAction("Add Aggregate Measure") { 571 public void actionPerformed(ActionEvent e) { 572 addAggMeasure(e); 573 } 574 }; 575 addAggLevel = new AbstractAction("Add Aggregate Level") { 576 public void actionPerformed(ActionEvent e) { 577 addAggLevel(e); 578 } 579 }; 580 addAggFactCount = new AbstractAction("Add Aggregate Fact Count") { 581 public void actionPerformed(ActionEvent e) { 582 addAggFactCount(e); 583 } 584 }; 585 586 delete = new AbstractAction("Delete") { 587 public void actionPerformed(ActionEvent e) { 588 delete(e); 589 } 590 }; 591 592 editMode = new AbstractAction("EditMode") { 593 public void actionPerformed(ActionEvent e) { 594 editMode(e); 595 } 596 }; 597 598 addCubeButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addCube")))); 602 addCubeButton.setToolTipText("Add Cube"); 603 addCubeButton.addActionListener(addCube); 604 605 addDimensionButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addDimension")))); 606 addDimensionButton.setToolTipText("Add Dimension"); 607 addDimensionButton.addActionListener(addDimension); 608 609 addDimensionUsageButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addDimensionUsage")))); 610 addDimensionUsageButton.setToolTipText("Add Dimension Usage"); 611 addDimensionUsageButton.addActionListener(addDimensionUsage); 612 613 addHierarchyButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addHierarchy")))); 614 addHierarchyButton.setToolTipText("Add Hierarchy"); 615 addHierarchyButton.addActionListener(addHierarchy); 616 617 addNamedSetButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addNamedSet")))); 618 addNamedSetButton.setToolTipText("Add Named Set"); 619 addNamedSetButton.addActionListener(addNamedSet); 620 621 addUserDefinedFunctionButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addUserDefinedFunction")))); 622 addUserDefinedFunctionButton.setToolTipText("Add User defined Function"); 623 addUserDefinedFunctionButton.addActionListener(addUserDefinedFunction); 624 625 addCalculatedMemberButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addCalculatedMember")))); 626 addCalculatedMemberButton.setToolTipText("Add Calculated Member"); 627 addCalculatedMemberButton.addActionListener(addCalculatedMember); 628 629 addMeasureButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addMeasure")))); 630 addMeasureButton.setToolTipText("Add Measure"); 631 addMeasureButton.addActionListener(addMeasure); 632 633 addLevelButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addLevel")))); 634 addLevelButton.setToolTipText("Add Level"); 635 addLevelButton.addActionListener(addLevel); 636 637 addPropertyButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addProperty")))); 638 addPropertyButton.setToolTipText("Add Property"); 639 addPropertyButton.addActionListener(addProperty); 640 641 addVirtualCubeButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addVirtualCube")))); 642 addVirtualCubeButton.setToolTipText("Add Virtual Cube"); 643 addVirtualCubeButton.addActionListener(addVirtualCube); 644 645 addVirtualCubeDimensionButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addVirtualCubeDimension")))); 646 addVirtualCubeDimensionButton.setToolTipText("Add Virtual Dimension"); 647 addVirtualCubeDimensionButton.addActionListener(addVirtualCubeDimension); 648 649 addVirtualCubeMeasureButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addVirtualCubeMeasure")))); 650 addVirtualCubeMeasureButton.setToolTipText("Add Virtual Measure"); 651 addVirtualCubeMeasureButton.addActionListener(addVirtualCubeMeasure); 652 653 addRoleButton.setIcon(new ImageIcon(myClassLoader.getResource(resources.getString("addRole")))); 654 addRoleButton.setToolTipText("Add Role"); 655 addRoleButton.addActionListener(addRole); 656 657 cutButton.setIcon(new javax.swing.ImageIcon (getClass().getResource("/toolbarButtonGraphics/general/Cut24.gif"))); 658 cutButton.setToolTipText("Cut"); 659 660 copyButton.setIcon(new javax.swing.ImageIcon (getClass().getResource("/toolbarButtonGraphics/general/Copy24.gif"))); 661 copyButton.setToolTipText("Copy"); 662 663 pasteButton.setIcon(new javax.swing.ImageIcon (getClass().getResource("/toolbarButtonGraphics/general/Paste24.gif"))); 664 pasteButton.setToolTipText("Paste"); 665 666 deleteButton.setIcon(new javax.swing.ImageIcon (getClass().getResource("/toolbarButtonGraphics/general/Delete24.gif"))); 667 deleteButton.setToolTipText("Delete"); 668 deleteButton.addActionListener(delete); 669 670 editModeButton.setIcon(new javax.swing.ImageIcon (getClass().getResource("/toolbarButtonGraphics/general/Edit24.gif"))); 671 editModeButton.setToolTipText("View XML"); 672 editModeButton.addActionListener(editMode); 673 674 databaseLabel.setIcon(new javax.swing.ImageIcon (getClass().getResource("/toolbarButtonGraphics/development/Server24.gif"))); 675 676 677 jToolBar1.add(addCubeButton); 678 jToolBar1.add(addDimensionButton); 679 jToolBar1.add(addDimensionUsageButton); 680 jToolBar1.add(addHierarchyButton); 681 jToolBar1.add(addNamedSetButton); 682 jToolBar1.add(addUserDefinedFunctionButton); 683 jToolBar1.add(addCalculatedMemberButton); 684 jToolBar1.add(addMeasureButton); 685 jToolBar1.add(addLevelButton); 686 jToolBar1.add(addPropertyButton); 687 jToolBar1.addSeparator(); 688 jToolBar1.add(addVirtualCubeButton); 689 jToolBar1.add(addVirtualCubeDimensionButton); 690 jToolBar1.add(addVirtualCubeMeasureButton); 691 jToolBar1.addSeparator(); 692 jToolBar1.add(addRoleButton); 693 jToolBar1.addSeparator(); 694 695 jToolBar1.add(cutButton); 696 jToolBar1.add(copyButton); 697 jToolBar1.add(pasteButton); 698 jToolBar1.addSeparator(); 699 jToolBar1.add(deleteButton); 700 jToolBar1.addSeparator(); 701 jToolBar1.add(editModeButton); 702 703 jPopupMenu = new JPopupMenu(); 707 708 tree.addMouseListener(new PopupTrigger()); 712 tree.addKeyListener(new KeyAdapter () { 713 public void keyPressed(KeyEvent e) { 714 720 int kcode = e.getKeyCode(); 721 if (kcode == 127 || kcode == 110) { 722 delete(e); 723 } 724 } 725 }); 726 727 728 footer.setLayout(new java.awt.BorderLayout ()); 730 footer.add(databaseLabel, java.awt.BorderLayout.CENTER); 731 732 this.add(jSplitPane1, java.awt.BorderLayout.CENTER); 736 this.add(jToolBar1, java.awt.BorderLayout.NORTH); 737 this.add(footer, java.awt.BorderLayout.SOUTH); 738 739 updater = new JTreeUpdater(tree); 740 741 } 742 743 protected void arrowButtonUpAction(ActionEvent evt) { 744 TreePath tpath = tree.getSelectionPath(); 745 if (tpath != null) { 746 TreePath parentpath = tpath.getParentPath(); 747 if (parentpath != null) { 748 tree.setSelectionPath(parentpath); 749 refreshTree(parentpath); 750 } 751 } 752 } 753 754 protected void arrowButtonDownAction(ActionEvent evt) { 755 TreePath tpath = tree.getSelectionPath(); 756 if (tpath != null) { 757 Object current = tpath.getLastPathComponent(); 758 Object child = tree.getModel().getChild(current, 0); 759 if (child != null) { 760 Object [] treeObjs = new Object [30]; 761 treeObjs[0] = child; 762 treeObjs[1] = current; 763 TreePath parentpath; 765 parentpath = tpath.getParentPath(); 766 int objCnt = 2; 767 while (parentpath != null) { 768 Object po = parentpath.getLastPathComponent(); 769 treeObjs[objCnt] = po; 770 objCnt += 1; 771 parentpath = parentpath.getParentPath(); 772 } 773 Object [] nodes = new Object [objCnt]; 775 int loopCnt = objCnt - 1; 776 for (int j = 0; j < objCnt; j++) { 777 nodes[j] = treeObjs[loopCnt]; 778 loopCnt --; 779 } 780 TreePath childPath = new TreePath (nodes); 781 tree.setSelectionPath(childPath); 782 refreshTree(childPath); 783 } 784 } 785 } 786 787 792 protected void setTableCellFocus(int row) { 793 propertyTable.editCellAt(row, 1); 794 TableCellEditor editor = propertyTable.getCellEditor(row, 1); 795 Component comp = editor.getTableCellEditorComponent(propertyTable, 796 propertyTable.getValueAt(row, 1), true, row, 1); 797 } 798 799 802 protected void addCube(ActionEvent evt) { 803 MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); 804 MondrianGuiDef.Cube cube = new MondrianGuiDef.Cube(); 805 806 cube.name = ""; 808 cube.dimensions = new MondrianGuiDef.Dimension[0]; 809 cube.measures = new MondrianGuiDef.Measure[0]; 810 MondrianGuiDef.Table cfact = new MondrianGuiDef.Table("","Table",""); 811 cfact.aggExcludes = new MondrianGuiDef.AggExclude[0]; 812 cfact.aggTables = new MondrianGuiDef.AggTable[0]; 813 814 cube.fact = cfact; 815 cube.calculatedMembers = new MondrianGuiDef.CalculatedMember[0]; 816 cube.namedSets = new MondrianGuiDef.NamedSet[0]; 817 818 cube.name = getNewName("New Cube ", schema.cubes); 820 cube.cache = Boolean.TRUE; 821 cube.enabled = Boolean.TRUE; 822 NodeDef[] temp = schema.cubes; 823 schema.cubes = new MondrianGuiDef.Cube[temp.length + 1]; 824 for (int _i = 0; _i < temp.length; _i++) { 825 schema.cubes[_i] = (MondrianGuiDef.Cube) temp[_i]; 826 } 827 schema.cubes[schema.cubes.length - 1] = cube; 828 829 tree.setSelectionPath((new TreePath (model.getRoot())).pathByAddingChild(cube)); 830 refreshTree(tree.getSelectionPath()); 831 setTableCellFocus(0); 832 } 833 834 protected void addRole(ActionEvent evt) { 835 MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); 836 MondrianGuiDef.Role role = new MondrianGuiDef.Role(); 837 838 role.name = ""; 840 role.schemaGrants = new MondrianGuiDef.SchemaGrant[0]; 841 842 role.name = getNewName("New Role ", schema.roles); 844 NodeDef[] temp = schema.roles; 845 schema.roles = new MondrianGuiDef.Role[temp.length + 1]; 846 for (int _i = 0; _i < temp.length; _i++) { 847 schema.roles[_i] = (MondrianGuiDef.Role) temp[_i]; 848 } 849 schema.roles[schema.roles.length - 1] = role; 850 851 tree.setSelectionPath((new TreePath (model.getRoot())).pathByAddingChild(role)); 852 refreshTree(tree.getSelectionPath()); 853 setTableCellFocus(0); 854 } 855 856 protected void addVirtualCube(ActionEvent evt) { 857 MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); 858 MondrianGuiDef.VirtualCube cube = new MondrianGuiDef.VirtualCube(); 859 860 cube.name = ""; 862 cube.dimensions = new MondrianGuiDef.VirtualCubeDimension[0]; 863 cube.measures = new MondrianGuiDef.VirtualCubeMeasure[0]; 864 cube.calculatedMembers = new MondrianGuiDef.CalculatedMember[0]; 865 cube.enabled = Boolean.TRUE; 866 867 cube.name = getNewName("New Virtual Cube ", schema.virtualCubes); 869 NodeDef[] temp = schema.virtualCubes; 870 schema.virtualCubes = new MondrianGuiDef.VirtualCube[temp.length + 1]; 871 for (int _i = 0; _i < temp.length; _i++) { 872 schema.virtualCubes[_i] = (MondrianGuiDef.VirtualCube) temp[_i]; 873 } 874 schema.virtualCubes[schema.virtualCubes.length - 1] = cube; 875 876 tree.setSelectionPath((new TreePath (model.getRoot())).pathByAddingChild(cube)); 877 refreshTree(tree.getSelectionPath()); 878 setTableCellFocus(0); 879 } 880 881 protected void addUserDefinedFunction(ActionEvent evt) { 882 MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); 883 MondrianGuiDef.UserDefinedFunction udf = new MondrianGuiDef.UserDefinedFunction(); 884 udf.name = ""; 886 udf.name = getNewName("New Udf ", schema.userDefinedFunctions); 888 NodeDef[] temp = schema.userDefinedFunctions; 889 schema.userDefinedFunctions = new MondrianGuiDef.UserDefinedFunction[temp.length + 1]; 890 for (int _i = 0; _i < temp.length; _i++) { 891 schema.userDefinedFunctions[_i] = (MondrianGuiDef.UserDefinedFunction) temp[_i]; 892 } 893 schema.userDefinedFunctions[schema.userDefinedFunctions.length - 1] = udf; 894 tree.setSelectionPath((new TreePath (model.getRoot())).pathByAddingChild(udf)); 895 refreshTree(tree.getSelectionPath()); 896 setTableCellFocus(0); 897 } 898 899 902 private void refreshTree(TreePath path) { 903 setDirty(true); 904 if (! dirtyFlag) { 905 setDirtyFlag(true); setTitle(); 907 } 908 updater.update(); 909 tree.scrollPathToVisible(path); 910 } 911 912 915 protected void addMeasure(ActionEvent evt) { 916 TreePath tpath = tree.getSelectionPath(); 917 int parentIndex = -1; 918 Object path = null; 919 if (tpath != null) { 920 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 921 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Cube) { 922 path = tpath.getPathComponent(parentIndex); 923 break; 924 } 925 } 926 927 } 928 if (!(path instanceof MondrianGuiDef.Cube)) { 930 JOptionPane.showMessageDialog(this, "Cube not selected.", alert, JOptionPane.WARNING_MESSAGE); 931 return; 932 } 933 934 935 MondrianGuiDef.Cube cube = (MondrianGuiDef.Cube) path; 936 937 MondrianGuiDef.Measure measure = new MondrianGuiDef.Measure(); 938 measure.name = ""; 940 measure.name = getNewName("New Measure ", cube.measures); 942 measure.visible = Boolean.TRUE; 943 NodeDef[] temp = cube.measures; 944 cube.measures = new MondrianGuiDef.Measure[temp.length + 1]; 945 for (int i = 0; i < temp.length; i++) { 946 cube.measures[i] = (MondrianGuiDef.Measure) temp[i];} 947 948 cube.measures[cube.measures.length - 1] = measure; 949 950 Object [] parentPathObjs = new Object [parentIndex+1]; 951 for(int i=0; i <= parentIndex; i++) { 952 parentPathObjs[i] = tpath.getPathComponent(i) ; 953 } 954 TreePath parentPath = new TreePath (parentPathObjs); 955 tree.setSelectionPath(parentPath.pathByAddingChild(measure)); 956 957 refreshTree(tree.getSelectionPath()); 958 setTableCellFocus(0); 959 } 960 961 protected void addAggPattern(ActionEvent evt) { 962 TreePath tpath = tree.getSelectionPath(); 963 int parentIndex = -1; 964 Object path = null; 965 if (tpath != null) { 966 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 967 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Table) { 968 if (((parentIndex-1) >=0) && (tpath.getPathComponent(parentIndex-1) instanceof MondrianGuiDef.Cube)) { 969 path = tpath.getPathComponent(parentIndex); 970 break; 971 } 972 } 973 } 974 975 } 976 if (!(path instanceof MondrianGuiDef.Table)) { 978 JOptionPane.showMessageDialog(this, "Cube Fact Table not selected.", alert, JOptionPane.WARNING_MESSAGE); 979 return; 980 } 981 982 983 MondrianGuiDef.Table factTable = (MondrianGuiDef.Table) path; 984 985 MondrianGuiDef.AggPattern aggname = new MondrianGuiDef.AggPattern(); 986 aggname.pattern = ""; 988 aggname.ignorecase = Boolean.TRUE; 990 aggname.factcount = null; 991 aggname.ignoreColumns = new MondrianGuiDef.AggIgnoreColumn[0]; 992 aggname.foreignKeys = new MondrianGuiDef.AggForeignKey[0]; 993 aggname.measures = new MondrianGuiDef.AggMeasure[0]; 994 aggname.levels = new MondrianGuiDef.AggLevel[0]; 995 aggname.excludes = new MondrianGuiDef.AggExclude[0]; 996 997 NodeDef[] temp = factTable.aggTables; 998 factTable.aggTables = new MondrianGuiDef.AggTable[temp.length + 1]; 999 for (int i = 0; i < temp.length; i++) { 1000 factTable.aggTables[i] = (MondrianGuiDef.AggTable) temp[i];} 1001 1002 factTable.aggTables[factTable.aggTables.length - 1] = aggname; 1003 1004 Object [] parentPathObjs = new Object [parentIndex+1]; 1005 for(int i=0; i <= parentIndex; i++) { 1006 parentPathObjs[i] = tpath.getPathComponent(i) ; 1007 } 1008 TreePath parentPath = new TreePath (parentPathObjs); 1009 tree.setSelectionPath(parentPath.pathByAddingChild(aggname)); 1010 1011 refreshTree(tree.getSelectionPath()); 1012 setTableCellFocus(0); 1013 } 1014 1015 protected void addAggName(ActionEvent evt) { 1016 TreePath tpath = tree.getSelectionPath(); 1017 int parentIndex = -1; 1018 Object path = null; 1019 if (tpath != null) { 1020 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1021 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Table) { 1022 if (((parentIndex-1) >=0) && (tpath.getPathComponent(parentIndex-1) instanceof MondrianGuiDef.Cube)) { 1023 path = tpath.getPathComponent(parentIndex); 1024 break; 1025 } 1026 } 1027 } 1028 1029 } 1030 if (!(path instanceof MondrianGuiDef.Table)) { 1031 JOptionPane.showMessageDialog(this, "Table not selected.", alert, JOptionPane.WARNING_MESSAGE); 1032 return; 1033 } 1034 1035 MondrianGuiDef.Table factTable = (MondrianGuiDef.Table) path; 1036 1037 MondrianGuiDef.AggName aggname = new MondrianGuiDef.AggName(); 1038 aggname.name = ""; 1040 aggname.ignorecase = Boolean.TRUE; 1042 aggname.factcount = null; 1043 aggname.ignoreColumns = new MondrianGuiDef.AggIgnoreColumn[0]; 1044 aggname.foreignKeys = new MondrianGuiDef.AggForeignKey[0]; 1045 aggname.measures = new MondrianGuiDef.AggMeasure[0]; 1046 aggname.levels = new MondrianGuiDef.AggLevel[0]; 1047 1048 1049 NodeDef[] temp = factTable.aggTables; 1050 factTable.aggTables = new MondrianGuiDef.AggTable[temp.length + 1]; 1051 for (int i = 0; i < temp.length; i++) { 1052 factTable.aggTables[i] = (MondrianGuiDef.AggTable) temp[i];} 1053 1054 factTable.aggTables[factTable.aggTables.length - 1] = aggname; 1055 1056 Object [] parentPathObjs = new Object [parentIndex+1]; 1057 for(int i=0; i <= parentIndex; i++) { 1058 parentPathObjs[i] = tpath.getPathComponent(i) ; 1059 } 1060 TreePath parentPath = new TreePath (parentPathObjs); 1061 tree.setSelectionPath(parentPath.pathByAddingChild(aggname)); 1062 1063 refreshTree(tree.getSelectionPath()); 1064 setTableCellFocus(0); 1065 } 1066 1067 protected void addAggExclude(ActionEvent evt) { 1068 TreePath tpath = tree.getSelectionPath(); 1069 int parentIndex = -1; 1070 Object path = null; 1071 if (tpath != null) { 1072 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1073 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Table) { 1075 if (((parentIndex-1) >=0) && (tpath.getPathComponent(parentIndex-1) instanceof MondrianGuiDef.Cube)) { 1076 path = tpath.getPathComponent(parentIndex); 1077 break; 1078 } 1079 } else if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.AggPattern) { 1080 path = tpath.getPathComponent(parentIndex); 1082 break; 1083 1084 } 1085 } 1086 1087 } 1088 if (!(path instanceof MondrianGuiDef.Table || path instanceof MondrianGuiDef.AggPattern)) { 1090 JOptionPane.showMessageDialog(this, "Cube Fact Table or Aggregate Pattern not selected.", alert, JOptionPane.WARNING_MESSAGE); 1091 return; 1092 } 1093 1094 MondrianGuiDef.AggExclude aggexclude = new MondrianGuiDef.AggExclude(); 1095 aggexclude.pattern = ""; 1097 aggexclude.ignorecase = Boolean.TRUE; 1098 1099 if (path instanceof MondrianGuiDef.Table) { 1100 MondrianGuiDef.Table parent = (MondrianGuiDef.Table) path; 1102 NodeDef[] temp = parent.aggExcludes; 1103 parent.aggExcludes = new MondrianGuiDef.AggExclude[temp.length + 1]; 1104 for (int i = 0; i < temp.length; i++) { 1105 parent.aggExcludes[i] = (MondrianGuiDef.AggExclude) temp[i];} 1106 1107 parent.aggExcludes[parent.aggExcludes.length - 1] = aggexclude; 1108 } else { 1109 MondrianGuiDef.AggPattern parent = (MondrianGuiDef.AggPattern) path; NodeDef[] temp = parent.excludes; 1111 parent.excludes = new MondrianGuiDef.AggExclude[temp.length + 1]; 1112 for (int i = 0; i < temp.length; i++) { 1113 parent.excludes[i] = (MondrianGuiDef.AggExclude) temp[i];} 1114 1115 parent.excludes[parent.excludes.length - 1] = aggexclude; 1116 } 1117 1118 Object [] parentPathObjs = new Object [parentIndex+1]; 1119 for(int i=0; i <= parentIndex; i++) { 1120 parentPathObjs[i] = tpath.getPathComponent(i) ; 1121 } 1122 TreePath parentPath = new TreePath (parentPathObjs); 1123 tree.setSelectionPath(parentPath.pathByAddingChild(aggexclude)); 1124 1125 refreshTree(tree.getSelectionPath()); 1126 setTableCellFocus(0); 1127 } 1128 1129 protected void addAggIgnoreColumn(ActionEvent evt) { 1130 TreePath tpath = tree.getSelectionPath(); 1131 int parentIndex = -1; 1132 Object path = null; 1133 if (tpath != null) { 1134 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1135 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.AggTable) { 1136 path = tpath.getPathComponent(parentIndex); 1137 break; 1138 } 1139 } 1140 1141 } 1142 if (!(path instanceof MondrianGuiDef.AggTable)) { 1144 JOptionPane.showMessageDialog(this, "Aggregate Table not selected.", alert, JOptionPane.WARNING_MESSAGE); 1145 return; 1146 } 1147 1148 1149 MondrianGuiDef.AggTable aggTable = (MondrianGuiDef.AggTable) path; 1150 1151 MondrianGuiDef.AggIgnoreColumn aggicol = new MondrianGuiDef.AggIgnoreColumn(); 1152 aggicol.column = ""; 1153 1154 NodeDef[] temp = aggTable.ignoreColumns; 1155 aggTable.ignoreColumns = new MondrianGuiDef.AggIgnoreColumn[temp.length + 1]; 1156 for (int i = 0; i < temp.length; i++) { 1157 aggTable.ignoreColumns[i] = (MondrianGuiDef.AggIgnoreColumn) temp[i];} 1158 1159 aggTable.ignoreColumns[aggTable.ignoreColumns.length - 1] = aggicol; 1160 1161 Object [] parentPathObjs = new Object [parentIndex+1]; 1162 for(int i=0; i <= parentIndex; i++) { 1163 parentPathObjs[i] = tpath.getPathComponent(i) ; 1164 } 1165 TreePath parentPath = new TreePath (parentPathObjs); 1166 tree.setSelectionPath(parentPath.pathByAddingChild(aggicol)); 1167 1168 refreshTree(tree.getSelectionPath()); 1169 setTableCellFocus(0); 1170 } 1171 1172 protected void addAggForeignKey(ActionEvent evt) { 1173 TreePath tpath = tree.getSelectionPath(); 1174 int parentIndex = -1; 1175 Object path = null; 1176 if (tpath != null) { 1177 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1178 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.AggTable) { 1179 path = tpath.getPathComponent(parentIndex); 1180 break; 1181 } 1182 } 1183 1184 } 1185 if (!(path instanceof MondrianGuiDef.AggTable)) { 1187 JOptionPane.showMessageDialog(this, "Aggregate Table not selected.", alert, JOptionPane.WARNING_MESSAGE); 1188 return; 1189 } 1190 1191 1192 MondrianGuiDef.AggTable aggTable = (MondrianGuiDef.AggTable) path; 1193 1194 MondrianGuiDef.AggForeignKey aggfkey = new MondrianGuiDef.AggForeignKey(); 1195 1196 NodeDef[] temp = aggTable.foreignKeys; 1197 aggTable.foreignKeys = new MondrianGuiDef.AggForeignKey[temp.length + 1]; 1198 for (int i = 0; i < temp.length; i++) { 1199 aggTable.foreignKeys[i] = (MondrianGuiDef.AggForeignKey) temp[i];} 1200 1201 aggTable.foreignKeys[aggTable.foreignKeys.length - 1] = aggfkey; 1202 1203 Object [] parentPathObjs = new Object [parentIndex+1]; 1204 for(int i=0; i <= parentIndex; i++) { 1205 parentPathObjs[i] = tpath.getPathComponent(i) ; 1206 } 1207 TreePath parentPath = new TreePath (parentPathObjs); 1208 tree.setSelectionPath(parentPath.pathByAddingChild(aggfkey)); 1209 1210 refreshTree(tree.getSelectionPath()); 1211 setTableCellFocus(0); 1212 } 1213 1214 protected void addAggMeasure(ActionEvent evt) { 1215 TreePath tpath = tree.getSelectionPath(); 1216 int parentIndex = -1; 1217 Object path = null; 1218 if (tpath != null) { 1219 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1220 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.AggTable) { 1221 path = tpath.getPathComponent(parentIndex); 1222 break; 1223 } 1224 } 1225 1226 } 1227 if (!(path instanceof MondrianGuiDef.AggTable)) { 1229 JOptionPane.showMessageDialog(this, "Aggregate Table not selected.", alert, JOptionPane.WARNING_MESSAGE); 1230 return; 1231 } 1232 1233 1234 MondrianGuiDef.AggTable aggTable = (MondrianGuiDef.AggTable) path; 1235 1236 MondrianGuiDef.AggMeasure aggmeasure = new MondrianGuiDef.AggMeasure(); 1237 1238 NodeDef[] temp = aggTable.measures; 1239 aggTable.measures = new MondrianGuiDef.AggMeasure[temp.length + 1]; 1240 for (int i = 0; i < temp.length; i++) { 1241 aggTable.measures[i] = (MondrianGuiDef.AggMeasure) temp[i];} 1242 1243 aggTable.measures[aggTable.measures.length - 1] = aggmeasure; 1244 1245 Object [] parentPathObjs = new Object [parentIndex+1]; 1246 for(int i=0; i <= parentIndex; i++) { 1247 parentPathObjs[i] = tpath.getPathComponent(i) ; 1248 } 1249 TreePath parentPath = new TreePath (parentPathObjs); 1250 tree.setSelectionPath(parentPath.pathByAddingChild(aggmeasure)); 1251 1252 refreshTree(tree.getSelectionPath()); 1253 setTableCellFocus(0); 1254 } 1255 1256 protected void addAggLevel(ActionEvent evt) { 1257 TreePath tpath = tree.getSelectionPath(); 1258 int parentIndex = -1; 1259 Object path = null; 1260 if (tpath != null) { 1261 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1262 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.AggTable) { 1263 path = tpath.getPathComponent(parentIndex); 1264 break; 1265 } 1266 } 1267 1268 } 1269 if (!(path instanceof MondrianGuiDef.AggTable)) { 1270 JOptionPane.showMessageDialog(this, "Aggregate Table not selected.", alert, JOptionPane.WARNING_MESSAGE); 1271 return; 1272 } 1273 1274 1275 MondrianGuiDef.AggTable aggTable = (MondrianGuiDef.AggTable) path; 1276 1277 MondrianGuiDef.AggLevel agglevel = new MondrianGuiDef.AggLevel(); 1278 1279 NodeDef[] temp = aggTable.levels; 1280 aggTable.levels = new MondrianGuiDef.AggLevel[temp.length + 1]; 1281 for (int i = 0; i < temp.length; i++) { 1282 aggTable.levels[i] = (MondrianGuiDef.AggLevel) temp[i];} 1283 1284 aggTable.levels[aggTable.levels.length - 1] = agglevel; 1285 1286 Object [] parentPathObjs = new Object [parentIndex+1]; 1287 for(int i=0; i <= parentIndex; i++) { 1288 parentPathObjs[i] = tpath.getPathComponent(i) ; 1289 } 1290 TreePath parentPath = new TreePath (parentPathObjs); 1291 tree.setSelectionPath(parentPath.pathByAddingChild(agglevel)); 1292 1293 refreshTree(tree.getSelectionPath()); 1294 setTableCellFocus(0); 1295 } 1296 1297 protected void addAggFactCount(ActionEvent evt) { 1298 TreePath tpath = tree.getSelectionPath(); 1299 int parentIndex = -1; 1300 Object path = null; 1301 if (tpath != null) { 1302 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1303 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.AggTable) { 1304 path = tpath.getPathComponent(parentIndex); 1305 break; 1306 } 1307 } 1308 1309 } 1310 if ( ! ((path instanceof MondrianGuiDef.AggName) || 1311 (path instanceof MondrianGuiDef.AggPattern) )) { 1312 JOptionPane.showMessageDialog(this, "Aggregate Table or Aggregate Pattern not selected.", 1313 alert, JOptionPane.WARNING_MESSAGE); 1314 return; 1315 } 1316 1317 MondrianGuiDef.AggFactCount aggFactCount = new MondrianGuiDef.AggFactCount(); 1318 MondrianGuiDef.AggTable aggName = null; 1319 MondrianGuiDef.AggPattern aggPattern = null; 1320 if (path instanceof MondrianGuiDef.AggName) { 1321 aggName = (MondrianGuiDef.AggName) path; 1322 aggName.factcount = new MondrianGuiDef.AggFactCount(); 1323 } else { 1324 aggPattern = (MondrianGuiDef.AggPattern) path; 1325 aggPattern.factcount = new MondrianGuiDef.AggFactCount(); 1326 } 1327 1328 Object [] parentPathObjs = new Object [parentIndex+1]; 1329 for(int i=0; i <= parentIndex; i++) { 1330 parentPathObjs[i] = tpath.getPathComponent(i) ; 1331 } 1332 TreePath parentPath = new TreePath (parentPathObjs); 1333 tree.setSelectionPath(parentPath.pathByAddingChild(aggFactCount)); 1334 1335 refreshTree(tree.getSelectionPath()); 1336 setTableCellFocus(0); 1337 } 1338 1339 protected void addVirtualCubeMeasure(ActionEvent evt) { 1340 TreePath tpath = tree.getSelectionPath(); 1341 int parentIndex = -1; 1342 Object path = null; 1343 if (tpath != null) { 1344 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1345 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.VirtualCube) { 1346 path = tpath.getPathComponent(parentIndex); 1348 break; 1350 } 1351 } 1352 1353 } 1354 if (!(path instanceof MondrianGuiDef.VirtualCube)) { 1356 JOptionPane.showMessageDialog(this, "Virtual Cube not selected.", alert, JOptionPane.WARNING_MESSAGE); 1357 return; 1358 } 1359 1360 1361 MondrianGuiDef.VirtualCube cube = (MondrianGuiDef.VirtualCube) path; 1362 1363 MondrianGuiDef.VirtualCubeMeasure measure = new MondrianGuiDef.VirtualCubeMeasure(); 1364 measure.name = ""; 1366 measure.name = getNewName("New Virtual Measure ", cube.measures); 1368 measure.visible = Boolean.TRUE; 1370 NodeDef[] temp = cube.measures; 1371 cube.measures = new MondrianGuiDef.VirtualCubeMeasure[temp.length + 1]; 1372 for (int i = 0; i < temp.length; i++) { 1373 cube.measures[i] = (MondrianGuiDef.VirtualCubeMeasure) temp[i];} 1374 1375 cube.measures[cube.measures.length - 1] = measure; 1376 1377 Object [] parentPathObjs = new Object [parentIndex+1]; 1378 for(int i=0; i <= parentIndex; i++) { 1379 parentPathObjs[i] = tpath.getPathComponent(i) ; 1380 } 1381 TreePath parentPath = new TreePath (parentPathObjs); 1382 tree.setSelectionPath(parentPath.pathByAddingChild(measure)); 1383 1384 refreshTree(tree.getSelectionPath()); 1385 setTableCellFocus(0); 1386 } 1387 1388 protected void addCalculatedMember(ActionEvent evt) { 1389 TreePath tpath = tree.getSelectionPath(); 1390 Object path = null; 1391 int parentIndex = -1; 1392 if (tpath != null) { 1393 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1394 if ( (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Cube) || 1395 (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.VirtualCube) ) { 1396 path = tpath.getPathComponent(parentIndex); 1398 break; 1400 } 1401 } 1402 1403 } 1404 if ( ! ((path instanceof MondrianGuiDef.Cube) || (path instanceof MondrianGuiDef.VirtualCube) )) { 1405 JOptionPane.showMessageDialog(this, "Cube or Virtual Cube not selected.", alert, JOptionPane.WARNING_MESSAGE); 1406 return; 1407 } 1408 1409 MondrianGuiDef.Cube cube = null; 1410 MondrianGuiDef.VirtualCube vcube = null; 1411 1412 if (path instanceof MondrianGuiDef.Cube) { 1413 cube = (MondrianGuiDef.Cube) path; 1414 } else { 1415 vcube = (MondrianGuiDef.VirtualCube) path; 1416 } 1417 1418 MondrianGuiDef.CalculatedMember calcmember = new MondrianGuiDef.CalculatedMember(); 1419 calcmember.name = ""; calcmember.dimension = "Measures"; 1421 calcmember.visible = Boolean.TRUE; calcmember.formatString = ""; 1423 calcmember.formula=""; 1424 calcmember.formulaElement = new MondrianGuiDef.Formula(); 1425 calcmember.memberProperties = new MondrianGuiDef.CalculatedMemberProperty[0]; 1426 1427 if (cube != null) { 1429 calcmember.name = getNewName("New Calculated Measure ", cube.calculatedMembers); 1430 NodeDef[] temp = cube.calculatedMembers; 1431 cube.calculatedMembers = new MondrianGuiDef.CalculatedMember[temp.length + 1]; 1432 for (int i = 0; i < temp.length; i++) { 1433 cube.calculatedMembers[i] = (MondrianGuiDef.CalculatedMember) temp[i];} 1434 1435 cube.calculatedMembers[cube.calculatedMembers.length - 1] = calcmember; 1436 } else { 1437 calcmember.name = getNewName("New Calculated Measure ", vcube.calculatedMembers); 1438 NodeDef[] temp = vcube.calculatedMembers; 1439 vcube.calculatedMembers = new MondrianGuiDef.CalculatedMember[temp.length + 1]; 1440 for (int i = 0; i < temp.length; i++) { 1441 vcube.calculatedMembers[i] = (MondrianGuiDef.CalculatedMember) temp[i];} 1442 1443 vcube.calculatedMembers[vcube.calculatedMembers.length - 1] = calcmember; 1444 1445 } 1446 1447 Object [] parentPathObjs = new Object [parentIndex+1]; 1448 for(int i=0; i <= parentIndex; i++) { 1449 parentPathObjs[i] = tpath.getPathComponent(i) ; 1450 } 1451 TreePath parentPath = new TreePath (parentPathObjs); 1452 tree.setSelectionPath(parentPath.pathByAddingChild(calcmember)); 1453 1454 refreshTree(tree.getSelectionPath()); 1455 setTableCellFocus(0); 1456} 1457 1458 protected boolean editMode(EventObject evt) { 1459 editModeXML = ! isEditModeXML(); editModeButton.setSelected(isEditModeXML()); 1461 if (isEditModeXML()) { 1462 jSplitPane1.setRightComponent(jPanelXML); 1463 } else { 1464 jSplitPane1.setRightComponent(jPanel1); 1465 } 1466 Component o = parentIFrame.getDesktopPane().getParent(); 1468 while (o != null) { 1469 if (o.getClass() == Workbench.class) { 1470 ((Workbench) o).getViewXMLMenuItem().setSelected(editModeXML); 1471 break; 1472 } 1474 o= o.getParent(); 1475 } 1476 return isEditModeXML(); 1477 } 1478 1479 protected void delete(EventObject evt) { 1480 TreePath tpath = tree.getSelectionPath(); 1482 if (tpath == null) { 1483 JOptionPane.showMessageDialog(this, "Select an object in Schema to delete.", alert, JOptionPane.WARNING_MESSAGE); 1484 return ; 1485 } 1486 Object child = tpath.getLastPathComponent(); Object nextSibling = null, prevSibling = null; 1488 1489 Object parent = null; 1490 Object grandparent = null; 1491 boolean grandparentAsSibling = false; 1492 1493 for(int i=tpath.getPathCount()-1-1; i>=0;i--) { 1494 parent = tpath.getPathComponent(i); if (tpath.getPathCount()-3 > 0) { 1496 grandparent = tpath.getPathComponent(i-1); } 1498 break; 1502 } 1503 if (parent == null) { 1504 JOptionPane.showMessageDialog(this, "Schema object cannot be deleted.", alert, JOptionPane.WARNING_MESSAGE); 1505 return ; 1506 } 1507 1508 boolean tofind = true; 1509 1536 Field [] fs = parent.getClass().getFields(); 1538 for (int i = 0; i < fs.length; i++) { 1539 if (fs[i].getType().isArray() && (fs[i].getType().getComponentType().isInstance(child) )) { 1540 try { 1541 Object parentArr = fs[i].get(parent); int parentArrLen = Array.getLength(parentArr); 1543 Object newArr = Array.newInstance(fs[i].getType().getComponentType(), parentArrLen-1); 1544 tofind = true; 1545 for (int k=0, m=0; k < parentArrLen; k++) { 1546 Object match = Array.get(parentArr, k); 1547 1548 if (tofind && match.equals(child)) { 1549 if (child instanceof MondrianGuiDef.CubeDimension) { 1550 MondrianGuiDef.CubeDimension matchDim = (MondrianGuiDef.CubeDimension) match; 1552 MondrianGuiDef.CubeDimension childDim = (MondrianGuiDef.CubeDimension) child; 1553 1564 if ( ((matchDim.name== null && childDim.name==null) || ( matchDim.name != null && matchDim.name.equals(childDim.name) )) && 1565 ((matchDim.caption== null && childDim.caption==null) || ( matchDim.caption != null && matchDim.caption.equals(childDim.caption) )) && 1566 ((matchDim.foreignKey== null && childDim.foreignKey==null) || ( matchDim.foreignKey != null && matchDim.foreignKey.equals(childDim.foreignKey) )) ) { 1567 tofind = false; 1568 if (k+1 < parentArrLen) { 1569 nextSibling = Array.get(parentArr, k+1); 1570 } 1571 if(k-1 >= 0) { 1572 prevSibling = Array.get(parentArr, k-1); 1573 } 1574 continue; 1575 } 1576 } else { 1577 tofind = false; 1579 if (k+1 < parentArrLen) { 1580 nextSibling = Array.get(parentArr, k+1); 1581 } 1582 if(k-1 >= 0) { 1583 prevSibling = Array.get(parentArr, k-1); 1584 } 1585 continue; 1586 1587 } 1588 } 1589 Array.set(newArr, m++, match); 1590 } 1591 if ( (child instanceof MondrianGuiDef.SQL) && 1595 (parent instanceof MondrianGuiDef.ExpressionView) && 1596 (Array.getLength(newArr) < 1) ) { 1597 if (parent instanceof MondrianGuiDef.KeyExpression) { 1598 ((MondrianGuiDef.Level)grandparent).keyExp = null; 1599 } else if (parent instanceof MondrianGuiDef.NameExpression) { 1600 ((MondrianGuiDef.Level)grandparent).nameExp = null; 1601 } else if (parent instanceof MondrianGuiDef.OrdinalExpression) { 1602 ((MondrianGuiDef.Level)grandparent).ordinalExp = null; 1603 } else if (parent instanceof MondrianGuiDef.ParentExpression) { 1604 ((MondrianGuiDef.Level)grandparent).parentExp = null; 1605 } else if (parent instanceof MondrianGuiDef.MeasureExpression) { 1606 ((MondrianGuiDef.Measure)grandparent).measureExp = null; 1607 } 1608 grandparentAsSibling = true; 1609 } else { 1610 fs[i].set(parent, newArr); 1611 } 1612 1613 } catch(Exception ex) { 1614 } 1616 break; 1617 } else if ( fs[i].getType().isInstance(child) ) { try { 1619 if (parent instanceof MondrianGuiDef.Join || 1620 (parent instanceof MondrianGuiDef.Cube && child instanceof MondrianGuiDef.Relation) || 1621 (parent instanceof MondrianGuiDef.Closure && child instanceof MondrianGuiDef.Relation) 1622 ) { 1623 } else { 1626 if (fs[i].get(parent)==child) { 1627 fs[i].set(parent, null); 1628 break; 1629 } 1630 } 1631 } catch (Exception ex) { 1632 } 1634 } 1635 } 1636 1637 1638 TreeExpansionEvent e = null; 1640 e = new TreeExpansionEvent (tree, tpath); 1641 updater.treeCollapsed(e); 1642 1643 if (nextSibling != null) { 1644 tree.setSelectionPath(tpath.getParentPath().pathByAddingChild(nextSibling)); 1645 } else if(prevSibling != null) { 1646 tree.setSelectionPath(tpath.getParentPath().pathByAddingChild(prevSibling)); 1647 } else if (grandparentAsSibling){ 1648 tree.setSelectionPath(tpath.getParentPath().getParentPath()); 1649 } else { 1650 tree.setSelectionPath(tpath.getParentPath()); 1651 } 1652 refreshTree(tree.getSelectionPath()); 1653 } 1654 1655 1658 protected void addDimension(ActionEvent evt) { 1659 TreePath tpath = tree.getSelectionPath(); 1660 Object path = null; 1661 int parentIndex = -1; 1662 if (tpath != null) { 1663 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0; parentIndex--) { 1664 if ( (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Cube) || 1666 (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Schema) ) { 1667 path = tpath.getPathComponent(parentIndex); 1668 break; 1669 } 1671 } 1672 } 1673 1674 if ( ! ((path instanceof MondrianGuiDef.Cube) || (path instanceof MondrianGuiDef.Schema) )) { 1676 JOptionPane.showMessageDialog(this, "Cube or Schema not selected.", alert, JOptionPane.WARNING_MESSAGE); 1677 return; 1678 } 1679 1680 MondrianGuiDef.Cube cube = null; 1681 MondrianGuiDef.Schema schema = null; 1682 1683 if (path instanceof MondrianGuiDef.Cube) { 1684 cube = (MondrianGuiDef.Cube) path; 1685 } else { 1686 schema = (MondrianGuiDef.Schema) path; 1687 } 1688 1689 MondrianGuiDef.Dimension dimension = new MondrianGuiDef.Dimension(); 1690 dimension.name = ""; 1691 dimension.type = "StandardDimension"; dimension.hierarchies = new MondrianGuiDef.Hierarchy[1]; 1693 dimension.hierarchies[0] = new MondrianGuiDef.Hierarchy(); 1694 dimension.hierarchies[0].name = "New Hierarchy 0"; 1695 dimension.hierarchies[0].hasAll = true; 1696 dimension.hierarchies[0].levels = new MondrianGuiDef.Level[0]; 1697 dimension.hierarchies[0].memberReaderParameters = new MondrianGuiDef.MemberReaderParameter[0]; 1698 dimension.hierarchies[0].relation = new MondrianGuiDef.Table("", "Table", ""); 1699 1700 if (cube != null) { 1702 dimension.name = getNewName("New Dimension ", cube.dimensions); 1703 NodeDef[] temp = cube.dimensions; 1704 cube.dimensions = new MondrianGuiDef.CubeDimension[temp.length + 1]; 1705 for (int i = 0; i < temp.length; i++) { 1706 cube.dimensions[i] = (MondrianGuiDef.CubeDimension) temp[i]; 1707 } 1708 cube.dimensions[cube.dimensions.length - 1] = dimension; 1709 } else { 1710 dimension.name = getNewName("New Dimension ", schema.dimensions); 1711 NodeDef[] temp = schema.dimensions; 1712 schema.dimensions = new MondrianGuiDef.Dimension[temp.length + 1]; 1713 for (int i = 0; i < temp.length; i++) { 1714 schema.dimensions[i] = (MondrianGuiDef.Dimension) temp[i];} 1715 1716 schema.dimensions[schema.dimensions.length - 1] = dimension; 1717 } 1718 1719 Object [] parentPathObjs = new Object [parentIndex+1]; 1720 for(int i=0; i <= parentIndex; i++) { 1721 parentPathObjs[i] = tpath.getPathComponent(i) ; 1722 } 1723 TreePath parentPath = new TreePath (parentPathObjs); 1724 tree.setSelectionPath(parentPath.pathByAddingChild(dimension)); 1725 1726 refreshTree(tree.getSelectionPath()); 1727 setTableCellFocus(0); 1728 } 1729 1730 1731 protected void addVirtualCubeDimension(ActionEvent evt) { 1732 TreePath tpath = tree.getSelectionPath(); 1733 Object path = null; 1734 int parentIndex = -1; 1735 if (tpath != null) { 1736 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0; parentIndex--) { 1737 if ( tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.VirtualCube ) { 1739 path = tpath.getPathComponent(parentIndex); 1740 break; 1741 } 1743 } 1744 } 1745 1746 if ( ! (path instanceof MondrianGuiDef.VirtualCube )) { 1748 JOptionPane.showMessageDialog(this, "Virtual Cube not selected.", alert, JOptionPane.WARNING_MESSAGE); 1749 return; 1750 } 1751 1752 MondrianGuiDef.VirtualCube cube = (MondrianGuiDef.VirtualCube) path;; 1753 1754 MondrianGuiDef.VirtualCubeDimension dimension = new MondrianGuiDef.VirtualCubeDimension(); 1755 dimension.name = ""; 1756 1757 dimension.name = getNewName("New Virtual Dimension ", cube.dimensions); 1759 NodeDef[] temp = cube.dimensions; 1760 cube.dimensions = new MondrianGuiDef.VirtualCubeDimension[temp.length + 1]; 1761 for (int i = 0; i < temp.length; i++) { 1762 cube.dimensions[i] = (MondrianGuiDef.VirtualCubeDimension) temp[i]; 1763 } 1764 cube.dimensions[cube.dimensions.length - 1] = dimension; 1765 1766 Object [] parentPathObjs = new Object [parentIndex+1]; 1767 for(int i=0; i <= parentIndex; i++) { 1768 parentPathObjs[i] = tpath.getPathComponent(i) ; 1769 } 1770 TreePath parentPath = new TreePath (parentPathObjs); 1771 tree.setSelectionPath(parentPath.pathByAddingChild(dimension)); 1772 refreshTree(tree.getSelectionPath()); 1773 setTableCellFocus(0); 1774 } 1775 1776 private String getNewName(String preName, Object [] objs) { 1777 boolean exists = true; 1778 String newName="", objName = ""; 1780 1781 if (objs != null) { 1782 int objNo = objs.length; 1783 try { 1784 Field f = objs.getClass().getComponentType().getField("name"); 1785 while(exists) { 1786 newName = preName + objNo++; 1787 exists = false; 1788 for(int i = 0; i < objs.length; i++) { 1789 objName = (String ) f.get(objs[i]); 1790 if (newName.equals(objName)) { 1791 exists=true; 1792 break; 1793 } 1794 } 1795 } 1796 } catch (Exception ex) { 1797 ex.printStackTrace(); 1798 } 1799 } else { 1800 newName = preName + 0; 1801 } 1802 return newName; 1803 } 1804 protected void addNamedSet(ActionEvent evt) { 1805 TreePath tpath = tree.getSelectionPath(); 1806 int parentIndex = -1; 1807 Object path = null; 1808 if (tpath != null) { 1809 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0; parentIndex--) { 1810 if ( (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Cube) || 1812 (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Schema) ) { 1813 path = tpath.getPathComponent(parentIndex); 1814 break; 1815 } 1817 } 1818 } 1819 1820 if ( ! ((path instanceof MondrianGuiDef.Cube) || (path instanceof MondrianGuiDef.Schema) )) { 1822 JOptionPane.showMessageDialog(this, "Cube or Schema not selected.", alert, JOptionPane.WARNING_MESSAGE); 1823 return; 1824 } 1825 1826 1827 MondrianGuiDef.Cube cube = null; 1828 MondrianGuiDef.Schema schema = null; 1829 1830 if (path instanceof MondrianGuiDef.Cube) { 1831 cube = (MondrianGuiDef.Cube) path; 1832 } else { 1833 schema = (MondrianGuiDef.Schema) path; 1834 } 1835 1836 MondrianGuiDef.NamedSet namedset = new MondrianGuiDef.NamedSet(); 1837 namedset.name = ""; namedset.formula=""; 1839 namedset.formulaElement = new MondrianGuiDef.Formula(); 1840 1841 if (cube != null) { 1843 namedset.name = getNewName("New Named Set ", cube.namedSets); 1844 1845 NodeDef[] temp = cube.namedSets; 1846 cube.namedSets = new MondrianGuiDef.NamedSet[temp.length + 1]; 1847 for (int i = 0; i < temp.length; i++) { 1848 cube.namedSets[i] = (MondrianGuiDef.NamedSet) temp[i];} 1849 1850 cube.namedSets[cube.namedSets.length - 1] = namedset; 1851 } else { 1852 namedset.name = getNewName("New Named Set ", schema.namedSets); 1853 NodeDef[] temp = schema.namedSets; 1854 schema.namedSets = new MondrianGuiDef.NamedSet[temp.length + 1]; 1855 for (int i = 0; i < temp.length; i++) { 1856 schema.namedSets[i] = (MondrianGuiDef.NamedSet) temp[i];} 1857 1858 schema.namedSets[schema.namedSets.length - 1] = namedset; 1859 } 1860 1861 Object [] parentPathObjs = new Object [parentIndex+1]; 1862 for(int i=0; i <= parentIndex; i++) { 1863 parentPathObjs[i] = tpath.getPathComponent(i) ; 1864 } 1865 TreePath parentPath = new TreePath (parentPathObjs); 1866 tree.setSelectionPath(parentPath.pathByAddingChild(namedset)); 1867 1868 refreshTree(tree.getSelectionPath()); 1869 setTableCellFocus(0); 1870 } 1871 1872 protected void addDimensionUsage(ActionEvent evt) { 1873 TreePath tpath = tree.getSelectionPath(); 1874 int parentIndex = -1; 1875 Object path = null; 1876 if (tpath != null) { 1877 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1878 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Cube) { 1879 path = tpath.getPathComponent(parentIndex); 1881 break; 1883 } 1884 } 1885 1886 } 1887 if (!(path instanceof MondrianGuiDef.Cube)) { 1889 JOptionPane.showMessageDialog(this, "Cube not selected.", alert, JOptionPane.WARNING_MESSAGE); 1890 return; 1891 } 1892 1893 MondrianGuiDef.Cube cube = (MondrianGuiDef.Cube) path; 1894 1895 MondrianGuiDef.DimensionUsage dimension = new MondrianGuiDef.DimensionUsage(); 1896 dimension.name = ""; 1898 dimension.name = getNewName("New Dimension Usage ", cube.dimensions); 1900 NodeDef[] temp = cube.dimensions; 1901 cube.dimensions = new MondrianGuiDef.CubeDimension[temp.length + 1]; 1902 for (int i = 0; i < temp.length; i++) { 1903 cube.dimensions[i] = (MondrianGuiDef.CubeDimension) temp[i];} 1904 1905 cube.dimensions[cube.dimensions.length - 1] = dimension; 1906 1907 Object [] parentPathObjs = new Object [parentIndex+1]; 1908 for(int i=0; i <= parentIndex; i++) { 1909 parentPathObjs[i] = tpath.getPathComponent(i) ; 1910 } 1911 TreePath parentPath = new TreePath (parentPathObjs); 1912 tree.setSelectionPath(parentPath.pathByAddingChild(dimension)); 1913 1914 refreshTree(tree.getSelectionPath()); 1915 setTableCellFocus(0); 1916 } 1917 1918 protected void addSchemaGrant(ActionEvent evt) { 1919 TreePath tpath = tree.getSelectionPath(); 1920 int parentIndex = -1; 1921 Object path = null; 1922 if (tpath != null) { 1923 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1924 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Role) { 1925 path = tpath.getPathComponent(parentIndex); 1927 break; 1929 } 1930 } 1931 1932 } 1933 if (!(path instanceof MondrianGuiDef.Role)) { 1935 JOptionPane.showMessageDialog(this, "Role not selected.", alert, JOptionPane.WARNING_MESSAGE); 1936 return; 1937 } 1938 1939 MondrianGuiDef.Role role = (MondrianGuiDef.Role) path; 1940 1941 MondrianGuiDef.SchemaGrant schemaGrant = new MondrianGuiDef.SchemaGrant(); 1942 schemaGrant.access = ""; schemaGrant.cubeGrants = new MondrianGuiDef.CubeGrant[0]; 1944 1945 NodeDef[] temp = role.schemaGrants; 1947 role.schemaGrants = new MondrianGuiDef.SchemaGrant[temp.length + 1]; 1948 for (int i = 0; i < temp.length; i++) { 1949 role.schemaGrants[i] = (MondrianGuiDef.SchemaGrant) temp[i];} 1950 1951 role.schemaGrants[role.schemaGrants.length - 1] = schemaGrant; 1952 1953 Object [] parentPathObjs = new Object [parentIndex+1]; 1954 for(int i=0; i <= parentIndex; i++) { 1955 parentPathObjs[i] = tpath.getPathComponent(i) ; 1956 } 1957 TreePath parentPath = new TreePath (parentPathObjs); 1958 tree.setSelectionPath(parentPath.pathByAddingChild(schemaGrant)); 1959 1960 refreshTree(tree.getSelectionPath()); 1961 setTableCellFocus(0); 1962 } 1963 1964 protected void addCubeGrant(ActionEvent evt) { 1965 TreePath tpath = tree.getSelectionPath(); 1966 int parentIndex = -1; 1967 Object path = null; 1968 if (tpath != null) { 1969 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 1970 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.SchemaGrant) { 1971 path = tpath.getPathComponent(parentIndex); 1973 break; 1975 } 1976 } 1977 1978 } 1979 if (!(path instanceof MondrianGuiDef.SchemaGrant)) { 1981 JOptionPane.showMessageDialog(this, "Schema Grant not selected.", alert, JOptionPane.WARNING_MESSAGE); 1982 return; 1983 } 1984 1985 MondrianGuiDef.SchemaGrant schemaGrant = (MondrianGuiDef.SchemaGrant) path; 1986 1987 MondrianGuiDef.CubeGrant cubeGrant = new MondrianGuiDef.CubeGrant(); 1988 cubeGrant.access = ""; cubeGrant.dimensionGrants = new MondrianGuiDef.DimensionGrant[0]; 1990 cubeGrant.hierarchyGrants= new MondrianGuiDef.HierarchyGrant[0]; 1991 1992 NodeDef[] temp = schemaGrant.cubeGrants; 1994 schemaGrant.cubeGrants = new MondrianGuiDef.CubeGrant[temp.length + 1]; 1995 for (int i = 0; i < temp.length; i++) { 1996 schemaGrant.cubeGrants[i] = (MondrianGuiDef.CubeGrant) temp[i];} 1997 1998 schemaGrant.cubeGrants[schemaGrant.cubeGrants.length - 1] = cubeGrant; 1999 2000 Object [] parentPathObjs = new Object [parentIndex+1]; 2001 for(int i=0; i <= parentIndex; i++) { 2002 parentPathObjs[i] = tpath.getPathComponent(i) ; 2003 } 2004 TreePath parentPath = new TreePath (parentPathObjs); 2005 tree.setSelectionPath(parentPath.pathByAddingChild(cubeGrant)); 2006 2007 refreshTree(tree.getSelectionPath()); 2008 setTableCellFocus(0); 2009 } 2010 2011 protected void addDimensionGrant(ActionEvent evt) { 2012 TreePath tpath = tree.getSelectionPath(); 2013 int parentIndex = -1; 2014 Object path = null; 2015 if (tpath != null) { 2016 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2017 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.CubeGrant) { 2018 path = tpath.getPathComponent(parentIndex); 2020 break; 2022 } 2023 } 2024 2025 } 2026 if (!(path instanceof MondrianGuiDef.CubeGrant)) { 2028 JOptionPane.showMessageDialog(this, "Cube Grant not selected.", alert, JOptionPane.WARNING_MESSAGE); 2029 return; 2030 } 2031 2032 MondrianGuiDef.CubeGrant cubeGrant = (MondrianGuiDef.CubeGrant) path; 2033 2034 MondrianGuiDef.DimensionGrant dimeGrant = new MondrianGuiDef.DimensionGrant(); 2035 dimeGrant.access = ""; 2037 NodeDef[] temp = cubeGrant.dimensionGrants; 2039 cubeGrant.dimensionGrants = new MondrianGuiDef.DimensionGrant[temp.length + 1]; 2040 for (int i = 0; i < temp.length; i++) { 2041 cubeGrant.dimensionGrants[i] = (MondrianGuiDef.DimensionGrant) temp[i];} 2042 2043 cubeGrant.dimensionGrants[cubeGrant.dimensionGrants.length - 1] = dimeGrant; 2044 2045 Object [] parentPathObjs = new Object [parentIndex+1]; 2046 for(int i=0; i <= parentIndex; i++) { 2047 parentPathObjs[i] = tpath.getPathComponent(i) ; 2048 } 2049 TreePath parentPath = new TreePath (parentPathObjs); 2050 tree.setSelectionPath(parentPath.pathByAddingChild(dimeGrant)); 2051 2052 refreshTree(tree.getSelectionPath()); 2053 setTableCellFocus(0); 2054 } 2055 2056 protected void addHierarchyGrant(ActionEvent evt) { 2057 TreePath tpath = tree.getSelectionPath(); 2058 int parentIndex = -1; 2059 Object path = null; 2060 if (tpath != null) { 2061 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2062 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.CubeGrant) { 2063 path = tpath.getPathComponent(parentIndex); 2065 break; 2067 } 2068 } 2069 2070 } 2071 if (!(path instanceof MondrianGuiDef.CubeGrant)) { 2073 JOptionPane.showMessageDialog(this, "Cube Grant not selected.", alert, JOptionPane.WARNING_MESSAGE); 2074 return; 2075 } 2076 2077 MondrianGuiDef.CubeGrant cubeGrant = (MondrianGuiDef.CubeGrant) path; 2078 2079 MondrianGuiDef.HierarchyGrant hieGrant = new MondrianGuiDef.HierarchyGrant(); 2080 hieGrant.access = ""; hieGrant.memberGrants = new MondrianGuiDef.MemberGrant[0]; 2082 2083 NodeDef[] temp = cubeGrant.hierarchyGrants; 2085 cubeGrant.hierarchyGrants = new MondrianGuiDef.HierarchyGrant[temp.length + 1]; 2086 for (int i = 0; i < temp.length; i++) { 2087 cubeGrant.hierarchyGrants[i] = (MondrianGuiDef.HierarchyGrant) temp[i];} 2088 2089 cubeGrant.hierarchyGrants[cubeGrant.hierarchyGrants.length - 1] = hieGrant; 2090 2091 Object [] parentPathObjs = new Object [parentIndex+1]; 2092 for(int i=0; i <= parentIndex; i++) { 2093 parentPathObjs[i] = tpath.getPathComponent(i) ; 2094 } 2095 TreePath parentPath = new TreePath (parentPathObjs); 2096 tree.setSelectionPath(parentPath.pathByAddingChild(hieGrant)); 2097 2098 refreshTree(tree.getSelectionPath()); 2099 setTableCellFocus(0); 2100 } 2101 2102 protected void addMemberGrant(ActionEvent evt) { 2103 TreePath tpath = tree.getSelectionPath(); 2104 int parentIndex = -1; 2105 Object path = null; 2106 if (tpath != null) { 2107 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2108 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.HierarchyGrant) { 2109 path = tpath.getPathComponent(parentIndex); 2111 break; 2113 } 2114 } 2115 2116 } 2117 if (!(path instanceof MondrianGuiDef.HierarchyGrant)) { 2119 JOptionPane.showMessageDialog(this, "Hierarchy Grant not selected.", alert, JOptionPane.WARNING_MESSAGE); 2120 return; 2121 } 2122 2123 MondrianGuiDef.HierarchyGrant hieGrant = (MondrianGuiDef.HierarchyGrant) path; 2124 2125 MondrianGuiDef.MemberGrant memberGrant = new MondrianGuiDef.MemberGrant(); 2126 memberGrant.access = ""; 2128 NodeDef[] temp = hieGrant.memberGrants; 2130 hieGrant.memberGrants = new MondrianGuiDef.MemberGrant[temp.length + 1]; 2131 for (int i = 0; i < temp.length; i++) { 2132 hieGrant.memberGrants[i] = (MondrianGuiDef.MemberGrant) temp[i];} 2133 2134 hieGrant.memberGrants[hieGrant.memberGrants.length - 1] = memberGrant; 2135 2136 Object [] parentPathObjs = new Object [parentIndex+1]; 2137 for(int i=0; i <= parentIndex; i++) { 2138 parentPathObjs[i] = tpath.getPathComponent(i) ; 2139 } 2140 TreePath parentPath = new TreePath (parentPathObjs); 2141 tree.setSelectionPath(parentPath.pathByAddingChild(memberGrant)); 2142 2143 refreshTree(tree.getSelectionPath()); 2144 setTableCellFocus(0); 2145 } 2146 2147 2148 2151 protected void addLevel(ActionEvent evt) { 2152 TreePath tpath = tree.getSelectionPath(); 2153 int parentIndex = -1; 2154 Object path = null; 2155 if (tpath != null) { 2156 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2157 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Hierarchy) { 2158 path = tpath.getPathComponent(parentIndex); 2160 break; 2162 } 2163 } 2164 2165 } 2166 if (!(path instanceof MondrianGuiDef.Hierarchy)) { 2168 JOptionPane.showMessageDialog(this, "Hierarchy not selected.", alert, JOptionPane.WARNING_MESSAGE); 2169 return; 2170 } 2171 2172 MondrianGuiDef.Hierarchy hierarchy = (MondrianGuiDef.Hierarchy) path; 2173 2174 MondrianGuiDef.Level level = new MondrianGuiDef.Level(); 2175 level.uniqueMembers = false; 2176 level.name = ""; 2177 level.properties = new MondrianGuiDef.Property[0]; 2178 2188 2190 level.name = getNewName("New Level ", hierarchy.levels); 2192 NodeDef[] temp = hierarchy.levels; 2193 hierarchy.levels = new MondrianGuiDef.Level[temp.length + 1]; 2194 for (int i = 0; i < temp.length; i++) { 2195 hierarchy.levels[i] = (MondrianGuiDef.Level) temp[i];} 2196 2197 hierarchy.levels[hierarchy.levels.length - 1] = level; 2198 2199 Object [] parentPathObjs = new Object [parentIndex+1]; 2200 for(int i=0; i <= parentIndex; i++) { 2201 parentPathObjs[i] = tpath.getPathComponent(i) ; 2202 } 2203 TreePath parentPath = new TreePath (parentPathObjs); 2204 tree.setSelectionPath(parentPath.pathByAddingChild(level)); 2205 2206 refreshTree(tree.getSelectionPath()); 2207 setTableCellFocus(0); 2208 } 2209 2210 protected void addSQL(ActionEvent evt) { 2211 TreePath tpath = tree.getSelectionPath(); 2212 int parentIndex = -1; 2213 Object path = null; 2214 if (tpath != null) { 2215 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2216 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.ExpressionView) { path = tpath.getPathComponent(parentIndex); 2219 break; 2221 } 2222 } 2223 2224 } 2225 if (!(path instanceof MondrianGuiDef.ExpressionView)) { 2227 JOptionPane.showMessageDialog(this, "Expression not selected.", alert, JOptionPane.WARNING_MESSAGE); 2228 return; 2229 } 2230 2231 MondrianGuiDef.ExpressionView expview = (MondrianGuiDef.ExpressionView) path; 2232 2233 MondrianGuiDef.SQL sql = new MondrianGuiDef.SQL(); 2234 sql.dialect="generic"; 2235 NodeDef[] temp = expview.expressions; 2237 expview.expressions = new MondrianGuiDef.SQL[temp.length + 1]; 2238 for (int i = 0; i < temp.length; i++) { 2239 expview.expressions[i] = (MondrianGuiDef.SQL) temp[i];} 2240 2241 expview.expressions[expview.expressions.length - 1] = sql; 2242 2243 Object [] parentPathObjs = new Object [parentIndex+1]; 2244 for(int i=0; i <= parentIndex; i++) { 2245 parentPathObjs[i] = tpath.getPathComponent(i) ; 2246 } 2247 TreePath parentPath = new TreePath (parentPathObjs); 2248 tree.setSelectionPath(parentPath.pathByAddingChild(sql)); 2249 2250 refreshTree(tree.getSelectionPath()); 2251 setTableCellFocus(0); 2252 } 2253 2254 2255 protected void addKeyExp(ActionEvent evt) { 2256 TreePath tpath = tree.getSelectionPath(); 2257 int parentIndex = -1; 2258 Object path = null; 2259 if (tpath != null) { 2260 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2261 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Level) { 2262 path = tpath.getPathComponent(parentIndex); 2264 break; 2266 } 2267 } 2268 2269 } 2270 if (!(path instanceof MondrianGuiDef.Level)) { 2272 JOptionPane.showMessageDialog(this, "Level not selected.", alert, JOptionPane.WARNING_MESSAGE); 2273 return; 2274 } 2275 2276 MondrianGuiDef.Level level = (MondrianGuiDef.Level) path; 2277 2278 MondrianGuiDef.KeyExpression keyExp = new MondrianGuiDef.KeyExpression(); 2279 keyExp.expressions = new MondrianGuiDef.SQL[1]; keyExp.expressions[0] = new MondrianGuiDef.SQL(); 2281 keyExp.expressions[0].dialect = "generic"; 2282 keyExp.expressions[0].cdata = ""; 2283 level.keyExp = keyExp; 2284 2285 Object [] parentPathObjs = new Object [parentIndex+1]; 2286 for(int i=0; i <= parentIndex; i++) { 2287 parentPathObjs[i] = tpath.getPathComponent(i) ; 2288 } 2289 TreePath parentPath = new TreePath (parentPathObjs); 2290 tree.setSelectionPath(parentPath.pathByAddingChild(keyExp)); 2291 2292 refreshTree(tree.getSelectionPath()); 2293 } 2294 2295 protected void addNameExp(ActionEvent evt) { 2296 TreePath tpath = tree.getSelectionPath(); 2297 int parentIndex = -1; 2298 Object path = null; 2299 if (tpath != null) { 2300 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2301 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Level) { 2302 path = tpath.getPathComponent(parentIndex); 2303 break; 2304 } 2305 } 2306 2307 } 2308 if (!(path instanceof MondrianGuiDef.Level)) { 2309 JOptionPane.showMessageDialog(this, "Level not selected.", alert, JOptionPane.WARNING_MESSAGE); 2310 return; 2311 } 2312 2313 MondrianGuiDef.Level level = (MondrianGuiDef.Level) path; 2314 2315 MondrianGuiDef.NameExpression nameExp = new MondrianGuiDef.NameExpression(); 2316 nameExp.expressions = new MondrianGuiDef.SQL[1]; nameExp.expressions[0] = new MondrianGuiDef.SQL(); 2318 nameExp.expressions[0].dialect = "generic"; 2319 nameExp.expressions[0].cdata = ""; 2320 level.nameExp = nameExp; 2321 2322 Object [] parentPathObjs = new Object [parentIndex+1]; 2323 for(int i=0; i <= parentIndex; i++) { 2324 parentPathObjs[i] = tpath.getPathComponent(i) ; 2325 } 2326 TreePath parentPath = new TreePath (parentPathObjs); 2327 tree.setSelectionPath(parentPath.pathByAddingChild(nameExp)); 2328 2329 refreshTree(tree.getSelectionPath()); 2330 } 2331 2332 protected void addOrdinalExp(ActionEvent evt) { 2333 TreePath tpath = tree.getSelectionPath(); 2334 int parentIndex = -1; 2335 Object path = null; 2336 if (tpath != null) { 2337 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2338 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Level) { 2339 path = tpath.getPathComponent(parentIndex); 2340 break; 2341 } 2342 } 2343 2344 } 2345 if (!(path instanceof MondrianGuiDef.Level)) { 2346 JOptionPane.showMessageDialog(this, "Level not selected.", alert, JOptionPane.WARNING_MESSAGE); 2347 return; 2348 } 2349 2350 MondrianGuiDef.Level level = (MondrianGuiDef.Level) path; 2351 2352 MondrianGuiDef.OrdinalExpression ordinalExp = new MondrianGuiDef.OrdinalExpression(); 2353 ordinalExp.expressions = new MondrianGuiDef.SQL[1]; ordinalExp.expressions[0] = new MondrianGuiDef.SQL(); 2355 ordinalExp.expressions[0].dialect = "generic"; 2356 ordinalExp.expressions[0].cdata = ""; 2357 level.ordinalExp = ordinalExp; 2358 2359 Object [] parentPathObjs = new Object [parentIndex+1]; 2360 for(int i=0; i <= parentIndex; i++) { 2361 parentPathObjs[i] = tpath.getPathComponent(i) ; 2362 } 2363 TreePath parentPath = new TreePath (parentPathObjs); 2364 tree.setSelectionPath(parentPath.pathByAddingChild(ordinalExp)); 2365 2366 refreshTree(tree.getSelectionPath()); 2367 } 2368 2369 protected void addParentExp(ActionEvent evt) { 2370 TreePath tpath = tree.getSelectionPath(); 2371 int parentIndex = -1; 2372 Object path = null; 2373 if (tpath != null) { 2374 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2375 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Level) { 2376 path = tpath.getPathComponent(parentIndex); 2377 break; 2378 } 2379 } 2380 2381 } 2382 if (!(path instanceof MondrianGuiDef.Level)) { 2383 JOptionPane.showMessageDialog(this, "Level not selected.", alert, JOptionPane.WARNING_MESSAGE); 2384 return; 2385 } 2386 2387 MondrianGuiDef.Level level = (MondrianGuiDef.Level) path; 2388 2389 MondrianGuiDef.ParentExpression parentExp = new MondrianGuiDef.ParentExpression(); 2390 parentExp.expressions = new MondrianGuiDef.SQL[1]; parentExp.expressions[0] = new MondrianGuiDef.SQL(); 2392 parentExp.expressions[0].dialect = "generic"; 2393 parentExp.expressions[0].cdata = ""; 2394 level.parentExp = parentExp; 2395 2396 Object [] parentPathObjs = new Object [parentIndex+1]; 2397 for(int i=0; i <= parentIndex; i++) { 2398 parentPathObjs[i] = tpath.getPathComponent(i) ; 2399 } 2400 TreePath parentPath = new TreePath (parentPathObjs); 2401 tree.setSelectionPath(parentPath.pathByAddingChild(parentExp)); 2402 2403 refreshTree(tree.getSelectionPath()); 2404 } 2405 2406 protected void addMeasureExp(ActionEvent evt) { 2407 TreePath tpath = tree.getSelectionPath(); 2408 int parentIndex = -1; 2409 Object path = null; 2410 if (tpath != null) { 2411 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2412 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Measure) { 2413 path = tpath.getPathComponent(parentIndex); 2414 break; 2415 } 2416 } 2417 2418 } 2419 if (!(path instanceof MondrianGuiDef.Measure)) { 2420 JOptionPane.showMessageDialog(this, "Measure not selected.", alert, JOptionPane.WARNING_MESSAGE); 2421 return; 2422 } 2423 2424 MondrianGuiDef.Measure measure = (MondrianGuiDef.Measure) path; 2425 2426 MondrianGuiDef.MeasureExpression measureExp = new MondrianGuiDef.MeasureExpression(); 2427 measureExp.expressions = new MondrianGuiDef.SQL[1]; measureExp.expressions[0] = new MondrianGuiDef.SQL(); 2429 measureExp.expressions[0].dialect = "generic"; 2430 measureExp.expressions[0].cdata = ""; 2431 measure.measureExp = measureExp; 2432 2433 Object [] parentPathObjs = new Object [parentIndex+1]; 2434 for(int i=0; i <= parentIndex; i++) { 2435 parentPathObjs[i] = tpath.getPathComponent(i) ; 2436 } 2437 TreePath parentPath = new TreePath (parentPathObjs); 2438 tree.setSelectionPath(parentPath.pathByAddingChild(measureExp)); 2439 2440 refreshTree(tree.getSelectionPath()); 2441 } 2442 2443 protected void addRelation(ActionEvent evt) { 2444 TreePath tpath = tree.getSelectionPath(); 2445 int parentIndex = -1; 2446 Object path = null; 2447 if (tpath != null) { 2448 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2449 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Hierarchy) { 2450 path = tpath.getPathComponent(parentIndex); 2452 break; 2454 } 2455 } 2456 2457 } 2458 if (!(path instanceof MondrianGuiDef.Hierarchy)) { 2460 JOptionPane.showMessageDialog(this, "Hierarchy not selected.", alert, JOptionPane.WARNING_MESSAGE); 2461 return; 2462 } 2463 2464 MondrianGuiDef.Hierarchy hierarchy = (MondrianGuiDef.Hierarchy) path; 2465 2466 MondrianGuiDef.Relation relation = new MondrianGuiDef.Table("", "Table", ""); 2467 2468 hierarchy.relation = relation; 2470 2471 Object [] parentPathObjs = new Object [parentIndex+1]; 2472 for(int i=0; i <= parentIndex; i++) { 2473 parentPathObjs[i] = tpath.getPathComponent(i) ; 2474 } 2475 TreePath parentPath = new TreePath (parentPathObjs); 2476 tree.setSelectionPath(parentPath.pathByAddingChild(relation)); 2477 2478 refreshTree(tree.getSelectionPath()); 2479 setTableCellFocus(0); 2480 } 2481 2482 protected void addHierarchy(ActionEvent evt) { 2483 TreePath tpath = tree.getSelectionPath(); 2484 int parentIndex = -1; 2485 Object path = null; 2486 if (tpath != null) { 2487 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2488 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Dimension) { 2489 path = tpath.getPathComponent(parentIndex); 2491 break; 2493 } 2494 } 2495 2496 } 2497 if (!(path instanceof MondrianGuiDef.Dimension)) { 2499 JOptionPane.showMessageDialog(this, "Dimension not selected.", alert, JOptionPane.WARNING_MESSAGE); 2500 return; 2501 } 2502 2503 MondrianGuiDef.Dimension dimension = (MondrianGuiDef.Dimension) path; 2504 2505 MondrianGuiDef.Hierarchy hierarchy = new MondrianGuiDef.Hierarchy(); 2506 2507 hierarchy.name = ""; hierarchy.hasAll = Boolean.TRUE; hierarchy.levels = new MondrianGuiDef.Level[0]; 2510 hierarchy.memberReaderParameters = new MondrianGuiDef.MemberReaderParameter[0]; 2511 hierarchy.relation = new MondrianGuiDef.Table("", "Table", ""); 2512 2513 hierarchy.name = getNewName("New Hierarchy ", dimension.hierarchies); 2514 NodeDef[] temp = dimension.hierarchies; 2515 dimension.hierarchies = new MondrianGuiDef.Hierarchy[temp.length + 1]; 2516 for (int i = 0; i < temp.length; i++) { 2517 dimension.hierarchies[i] = (MondrianGuiDef.Hierarchy) temp[i];} 2518 2519 dimension.hierarchies[dimension.hierarchies.length - 1] = hierarchy; 2520 2521 Object [] parentPathObjs = new Object [parentIndex+1]; 2522 for(int i=0; i <= parentIndex; i++) { 2523 parentPathObjs[i] = tpath.getPathComponent(i) ; 2524 } 2525 TreePath parentPath = new TreePath (parentPathObjs); 2526 tree.setSelectionPath(parentPath.pathByAddingChild(hierarchy)); 2527 refreshTree(tree.getSelectionPath()); 2528 setTableCellFocus(0); 2529 } 2530 2531 2532 2535 protected void addProperty(ActionEvent evt) { 2536 TreePath tpath = tree.getSelectionPath(); 2537 int parentIndex = -1; 2538 Object path = null; 2539 if (tpath != null) { 2540 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2541 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Level) { 2542 path = tpath.getPathComponent(parentIndex); 2544 break; 2546 } 2547 } 2548 2549 } 2550 if (!(path instanceof MondrianGuiDef.Level)) { 2552 JOptionPane.showMessageDialog(this, "Level not selected.", alert, JOptionPane.WARNING_MESSAGE); 2553 return; 2554 } 2555 2556 2557 MondrianGuiDef.Level level = (MondrianGuiDef.Level) path; 2558 2559 MondrianGuiDef.Property property = new MondrianGuiDef.Property(); 2560 property.name = ""; 2562 if (level.properties == null) { 2564 level.properties = new MondrianGuiDef.Property[0]; 2565 } 2566 property.name = getNewName("New Property ", level.properties); 2567 NodeDef[] temp = level.properties; 2568 level.properties = new MondrianGuiDef.Property[temp.length + 1]; 2569 for (int i = 0; i < temp.length; i++) { 2570 level.properties[i] = (MondrianGuiDef.Property) temp[i]; 2571 } 2572 2573 level.properties[level.properties.length - 1] = property; 2574 2575 Object [] parentPathObjs = new Object [parentIndex+1]; 2576 for(int i=0; i <= parentIndex; i++) { 2577 parentPathObjs[i] = tpath.getPathComponent(i) ; 2578 } 2579 TreePath parentPath = new TreePath (parentPathObjs); 2580 tree.setSelectionPath(parentPath.pathByAddingChild(property)); 2581 2582 refreshTree(tree.getSelectionPath()); 2583 setTableCellFocus(0); 2584 } 2585 2586 2589 protected void addClosure(ActionEvent evt) { 2590 TreePath tpath = tree.getSelectionPath(); 2591 int parentIndex = -1; 2592 Object path = null; 2593 if (tpath != null) { 2594 for(parentIndex=tpath.getPathCount()-1; parentIndex>=0;parentIndex--) { 2595 if (tpath.getPathComponent(parentIndex) instanceof MondrianGuiDef.Level) { 2596 path = tpath.getPathComponent(parentIndex); 2598 break; 2600 } 2601 } 2602 2603 } 2604 if (!(path instanceof MondrianGuiDef.Level)) { 2606 JOptionPane.showMessageDialog(this, "Level not selected.", alert, JOptionPane.WARNING_MESSAGE); 2607 return; 2608 } 2609 2610 MondrianGuiDef.Level level = (MondrianGuiDef.Level) path; 2611 MondrianGuiDef.Closure closure = new MondrianGuiDef.Closure(); 2612 closure.parentColumn = ""; 2613 closure.childColumn = ""; 2614 closure.table = new MondrianGuiDef.Table("", "Table", ""); 2615 if (level.closure == null) { 2616 level.closure = closure; 2617 } 2618 2619 Object [] parentPathObjs = new Object [parentIndex+1]; 2620 for(int i=0; i <= parentIndex; i++) { 2621 parentPathObjs[i] = tpath.getPathComponent(i) ; 2622 } 2623 TreePath parentPath = new TreePath (parentPathObjs); 2624 tree.setSelectionPath(parentPath.pathByAddingChild(closure)); 2625 2626 refreshTree(tree.getSelectionPath()); 2627 setTableCellFocus(0); 2628 } 2629 2630 public MondrianGuiDef.Schema getSchema() { 2631 return this.schema; 2632 } 2633 2634 2638 public File getSchemaFile() { 2639 return this.schemaFile; 2640 } 2641 2642 2646 public void setSchemaFile(File f) { 2647 this.schemaFile = f; 2648 } 2649 2650 public Object lastSelected; 2651 2652 2657 public void valueChanged(TreeSelectionEvent e) { 2658 if (propertyTable.isEditing() && (lastSelected != e.getPath().getLastPathComponent())) { 2659 SchemaPropertyCellEditor sce = (SchemaPropertyCellEditor) propertyTable.getCellEditor(); 2660 if (sce != null) { 2661 TreeSelectionEvent e2 = e; 2662 sce.stopCellEditing(); 2663 e = e2; 2664 } 2665 2666 } 2667 lastSelected = e.getPath().getLastPathComponent(); 2668 2669 String selectedFactTable = null; 2670 String selectedFactTableSchema = null; 2671 2672 for(int i=e.getPath().getPathCount()-1; i>=0;i--) { Object comp = e.getPath().getPathComponent(i); 2675 if ( comp instanceof MondrianGuiDef.Cube && ((MondrianGuiDef.Cube) comp).fact != null ) { 2676 selectedFactTable = ((MondrianGuiDef.Table) ((MondrianGuiDef.Cube) comp).fact).name; 2677 selectedFactTableSchema = ((MondrianGuiDef.Table) ((MondrianGuiDef.Cube) comp).fact).schema; 2678 } 2680 } 2681 TreePath tpath = e.getPath(); 2682 Object o = tpath.getLastPathComponent(); 2683 Object po = null; 2684 TreePath parentTpath = tpath.getParentPath(); 2686 String parentName = ""; 2687 String elementName = ""; 2688 if (parentTpath != null) { 2689 po = parentTpath.getLastPathComponent(); 2690 Class parentClassName = po.getClass(); 2691 try { 2692 Field nameField = po.getClass().getField("name"); 2693 elementName = (String ) nameField.get(po); 2694 if (elementName == null) { 2695 elementName = ""; 2696 } else { 2697 elementName = "'" + elementName + "'"; 2698 } 2699 } catch (Exception ex) { 2700 elementName = ""; 2701 } 2702 int pos = parentClassName.toString().lastIndexOf("$"); 2703 if (pos > 0) { 2704 parentName = parentClassName.toString().substring(pos + 1); 2705 } 2706 } 2707 2708 StringWriter sxml = new StringWriter (); 2710 org.eigenbase.xom.XMLOutput pxml = new org.eigenbase.xom.XMLOutput(sxml); 2711 pxml.setIndentString(" "); 2712 2714 String [] pNames = DEF_DEFAULT; 2715 2716 validStatusLabel.setText( renderer.invalid(tree, e.getPath(), o) ); 2717 validStatusLabel2.setText( validStatusLabel.getText() ); 2718 2719 if (o instanceof MondrianGuiDef.Column) { 2720 pNames = DEF_COLUMN; 2721 targetLabel.setText(LBL_COLUMN); 2722 } else if (o instanceof MondrianGuiDef.Cube) { 2723 pNames = DEF_CUBE; 2724 targetLabel.setText(LBL_CUBE); 2725 ((MondrianGuiDef.Cube) o).displayXML(pxml, 0); 2726 } else if (o instanceof MondrianGuiDef.Dimension) { 2727 pNames = DEF_DIMENSION; 2728 if (po instanceof MondrianGuiDef.Schema) { 2729 targetLabel.setText("Shared " + LBL_DIMENSION); 2730 } else { 2731 targetLabel.setText(LBL_DIMENSION + " for " + elementName + " " + 2732 parentName); 2733 } 2734 ((MondrianGuiDef.Dimension) o).displayXML(pxml, 0); 2735 } else if (o instanceof MondrianGuiDef.DimensionUsage) { 2736 pNames = DEF_DIMENSION_USAGE; 2737 targetLabel.setText(LBL_DIMENSION_USAGE + " for " + elementName + " " + 2738 parentName); 2739 ((MondrianGuiDef.DimensionUsage) o).displayXML(pxml, 0); 2740 } else if (o instanceof MondrianGuiDef.KeyExpression) { 2741 pNames = DEF_DEFAULT; 2742 targetLabel.setText(LBL_KEY_EXPRESSION); 2743 ((MondrianGuiDef.ExpressionView) o).displayXML(pxml, 0); 2744 } else if (o instanceof MondrianGuiDef.NameExpression) { 2745 pNames = DEF_DEFAULT; 2746 targetLabel.setText(LBL_NAME_EXPRESSION); 2747 ((MondrianGuiDef.ExpressionView) o).displayXML(pxml, 0); 2748 } else if (o instanceof MondrianGuiDef.OrdinalExpression) { 2749 pNames = DEF_DEFAULT; 2750 targetLabel.setText(LBL_ORDINAL_EXPRESSION); 2751 ((MondrianGuiDef.ExpressionView) o).displayXML(pxml, 0); 2752 } else if (o instanceof MondrianGuiDef.ParentExpression) { 2753 pNames = DEF_DEFAULT; 2754 targetLabel.setText(LBL_PARENT_EXPRESSION); 2755 ((MondrianGuiDef.ExpressionView) o).displayXML(pxml, 0); 2756 } else if (o instanceof MondrianGuiDef.ExpressionView) { 2757 pNames = DEF_EXPRESSION_VIEW; 2758 targetLabel.setText(LBL_EXPRESSION_VIEW); 2759 ((MondrianGuiDef.ExpressionView) o).displayXML(pxml, 0); 2760 } else if (o instanceof MondrianGuiDef.MeasureExpression) { 2761 pNames = DEF_DEFAULT; 2762 targetLabel.setText(LBL_MEASURE_EXPRESSION); 2763 ((MondrianGuiDef.ExpressionView) o).displayXML(pxml, 0); 2764 } else if (o instanceof MondrianGuiDef.Hierarchy) { 2765 pNames = DEF_HIERARCHY; 2766 targetLabel.setText(LBL_HIERARCHY + " for " + elementName + " " + 2767 parentName); 2768 ((MondrianGuiDef.Hierarchy) o).displayXML(pxml, 0); 2769 } else if (o instanceof MondrianGuiDef.Join) { 2770 pNames = DEF_JOIN; 2771 if (parentName.equalsIgnoreCase("Join")) { 2772 Object parentJoin = parentTpath.getLastPathComponent(); 2773 int indexOfChild = tree.getModel().getIndexOfChild(parentJoin, o); 2774 switch (indexOfChild) { 2775 case 0: 2776 targetLabel.setText("Left : " + LBL_JOIN); 2777 break; 2778 case 1: 2779 targetLabel.setText("Right : " + LBL_JOIN); 2780 } 2781 } else { 2782 targetLabel.setText(LBL_JOIN + " for " + elementName + " " + 2783 parentName); 2784 } 2785 ((MondrianGuiDef.Join) o).displayXML(pxml, 0); 2786 } else if (o instanceof MondrianGuiDef.Level) { 2787 pNames = DEF_LEVEL; 2788 targetLabel.setText(LBL_LEVEL + " for " + elementName + " " + 2789 parentName); 2790 ((MondrianGuiDef.Level) o).displayXML(pxml, 0); 2791 } else if (o instanceof MondrianGuiDef.Measure) { 2792 pNames = DEF_MEASURE; 2793 targetLabel.setText(LBL_MEASURE + " for " + elementName + " " + 2794 parentName); 2795 ((MondrianGuiDef.Measure) o).displayXML(pxml, 0); 2796 } else if (o instanceof MondrianGuiDef.CalculatedMember) { 2797 pNames = DEF_CALCULATED_MEMBER; 2798 targetLabel.setText(LBL_CALCULATED_MEMBER + " for " + elementName + " " + 2799 parentName); 2800 ((MondrianGuiDef.CalculatedMember) o).displayXML(pxml, 0); 2801 } else if (o instanceof MondrianGuiDef.CalculatedMemberProperty) { 2802 pNames = DEF_CALCULATED_MEMBER_PROPERTY; 2803 targetLabel.setText(LBL_CALCULATED_MEMBER_PROPERTY); 2804 } else if (o instanceof MondrianGuiDef.NamedSet) { 2805 pNames = DEF_NAMED_SET; 2806 targetLabel.setText(LBL_NAMED_SET + " for " + elementName + " " + 2807 parentName); 2808 ((MondrianGuiDef.NamedSet) o).displayXML(pxml, 0); 2809 } else if (o instanceof MondrianGuiDef.UserDefinedFunction) { 2810 pNames = DEF_USER_DEFINED_FUNCTION; 2811 targetLabel.setText(LBL_USER_DEFINED_FUNCTION + " for " + elementName + 2812 " " + parentName); 2813 ((MondrianGuiDef.UserDefinedFunction) o).displayXML(pxml, 0); 2814 } else if (o instanceof MondrianGuiDef.MemberReaderParameter) { 2815 pNames = DEF_PARAMETER; 2816 targetLabel.setText(LBL_PARAMETER); 2817 } else if (o instanceof MondrianGuiDef.Property) { 2818 pNames = DEF_PROPERTY; 2819 targetLabel.setText(LBL_PROPERTY); 2820 ((MondrianGuiDef.Property) o).displayXML(pxml, 0); 2821 } else if (o instanceof MondrianGuiDef.Closure) { 2822 pNames = DEF_CLOSURE; 2823 targetLabel.setText(LBL_CLOSURE); 2824 ((MondrianGuiDef.Closure) o).displayXML(pxml, 0); 2825 } else if (o instanceof MondrianGuiDef.Schema) { 2826 pNames = DEF_SCHEMA; 2827 targetLabel.setText(LBL_SCHEMA); 2828 ((MondrianGuiDef.Schema) o).displayXML(pxml, 0); 2829 } else if (o instanceof MondrianGuiDef.SQL) { 2830 pNames = DEF_SQL; 2831 targetLabel.setText(LBL_SQL); 2832 ((MondrianGuiDef.SQL) o).displayXML(pxml, 0); 2833 } else if (o instanceof MondrianGuiDef.Table) { 2834 pNames = DEF_TABLE; 2835 targetLabel.setText(LBL_TABLE + " for " + elementName + " " + 2836 parentName); 2837 ((MondrianGuiDef.Table) o).displayXML(pxml, 0); 2838 } else if (o instanceof MondrianGuiDef.AggName) { 2839 pNames = DEF_AGG_NAME; 2840 targetLabel.setText(LBL_AGG_NAME); 2841 ((MondrianGuiDef.AggName) o).displayXML(pxml, 0); 2842 } else if (o instanceof MondrianGuiDef.AggIgnoreColumn) { 2843 pNames = DEF_AGG_IGNORE_COLUMN; 2844 targetLabel.setText(LBL_AGG_IGNORE_COLUMN); 2845 ((MondrianGuiDef.AggIgnoreColumn) o).displayXML(pxml, 0); 2846 } else if (o instanceof MondrianGuiDef.AggForeignKey) { 2847 pNames = DEF_AGG_FOREIGN_KEY; 2848 targetLabel.setText(LBL_AGG_FOREIGN_KEY); 2849 ((MondrianGuiDef.AggForeignKey) o).displayXML(pxml, 0); 2850 } else if (o instanceof MondrianGuiDef.AggMeasure) { 2851 pNames = DEF_AGG_MEASURE; 2852 targetLabel.setText(LBL_AGG_MEASURE); 2853 ((MondrianGuiDef.AggMeasure) o).displayXML(pxml, 0); 2854 } else if (o instanceof MondrianGuiDef.AggLevel) { 2855 pNames = DEF_AGG_LEVEL; 2856 targetLabel.setText(LBL_AGG_LEVEL); 2857 ((MondrianGuiDef.AggLevel) o).displayXML(pxml, 0); 2858 } else if (o instanceof MondrianGuiDef.AggExclude) { 2859 pNames = DEF_AGG_EXCLUDE; 2860 targetLabel.setText(LBL_AGG_EXCLUDE); 2861 ((MondrianGuiDef.AggExclude) o).displayXML(pxml, 0); 2862 } else if (o instanceof MondrianGuiDef.AggPattern) { 2863 pNames = DEF_AGG_PATTERN; 2864 targetLabel.setText(LBL_AGG_PATTERN); 2865 ((MondrianGuiDef.AggPattern) o).displayXML(pxml, 0); 2866 } else if (o instanceof MondrianGuiDef.AggFactCount) { 2867 pNames = DEF_AGG_FACT_COUNT; 2868 targetLabel.setText(LBL_AGG_FACT_COUNT); 2869 ((MondrianGuiDef.AggFactCount) o).displayXML(pxml, 0); 2870 2871 } else if (o instanceof MondrianGuiDef.View) { 2872 pNames = DEF_VIEW; 2873 targetLabel.setText(LBL_VIEW); 2874 2875 } else if (o instanceof MondrianGuiDef.Role) { 2876 pNames = DEF_ROLE; 2877 targetLabel.setText(LBL_ROLE + " for " + elementName + " " + 2878 parentName); 2879 ((MondrianGuiDef.Role) o).displayXML(pxml, 0); 2880 } else if (o instanceof MondrianGuiDef.SchemaGrant) { 2881 pNames = DEF_SCHEMA_GRANT; 2882 targetLabel.setText(LBL_SCHEMA_GRANT); 2883 ((MondrianGuiDef.SchemaGrant) o).displayXML(pxml, 0); 2884 } else if (o instanceof MondrianGuiDef.CubeGrant) { 2885 pNames = DEF_CUBE_GRANT; 2886 targetLabel.setText(LBL_CUBE_GRANT); 2887 ((MondrianGuiDef.CubeGrant) o).displayXML(pxml, 0); 2888 } else if (o instanceof MondrianGuiDef.DimensionGrant) { 2889 pNames = DEF_DIMENSION_GRANT; 2890 targetLabel.setText(LBL_DIMENSION_GRANT); 2891 ((MondrianGuiDef.DimensionGrant) o).displayXML(pxml, 0); 2892 } else if (o instanceof MondrianGuiDef.HierarchyGrant) { 2893 pNames = DEF_HIERARCHY_GRANT; 2894 targetLabel.setText(LBL_HIERARCHY_GRANT); 2895 ((MondrianGuiDef.HierarchyGrant) o).displayXML(pxml, 0); 2896 } else if (o instanceof MondrianGuiDef.MemberGrant) { 2897 pNames = DEF_MEMBER_GRANT; 2898 targetLabel.setText(LBL_MEMBER_GRANT); 2899 ((MondrianGuiDef.MemberGrant) o).displayXML(pxml, 0); 2900 2901 } else if (o instanceof MondrianGuiDef.VirtualCube) { 2902 pNames = DEF_VIRTUAL_CUBE; 2903 targetLabel.setText(LBL_VIRTUAL_CUBE + " for " + elementName + " " + 2904 parentName); 2905 ((MondrianGuiDef.VirtualCube) o).displayXML(pxml, 0); 2906 } else if (o instanceof MondrianGuiDef.VirtualCubeDimension) { 2907 pNames = DEF_VIRTUAL_CUBE_DIMENSION; 2908 targetLabel.setText(LBL_VIRTUAL_CUBE_DIMENSION + " for " + elementName + " " + 2909 parentName); 2910 ((MondrianGuiDef.VirtualCubeDimension) o).displayXML(pxml, 0); 2911 } else if (o instanceof MondrianGuiDef.VirtualCubeMeasure) { 2912 pNames = DEF_VIRTUAL_CUBE_MEASURE; 2913 targetLabel.setText(LBL_VIRTUAL_CUBE_MEASURE); 2914 ((MondrianGuiDef.VirtualCubeMeasure) o).displayXML(pxml, 0); 2915 } else { 2916 targetLabel.setText(LBL_UNKNOWN_TYPE); 2917 } 2918 2919 try { 2921 jEditorPaneXML.read(new StringReader (sxml.toString()),null); 2922 } catch(Exception ex) { 2923 } 2925 targetLabel2.setText(targetLabel.getText()); 2926 2927 PropertyTableModel ptm = new PropertyTableModel(o, pNames); 2928 2929 ptm.setFactTable(selectedFactTable); 2930 ptm.setFactTableSchema(selectedFactTableSchema); 2931 2932 Object parent = null; 2934 for(int i=e.getPath().getPathCount()-1-1; i>=0;i--) { 2935 parent = e.getPath().getPathComponent(i); break; 2937 } 2938 if (parent != null) { 2939 Field [] fs = parent.getClass().getFields(); 2941 ArrayList <Object > names = new ArrayList <Object >(); 2942 for (int i = 0; i < fs.length; i++) { 2943 if (fs[i].getType().isArray() && (fs[i].getType().getComponentType().isInstance(o) )) { 2944 try { 2948 Field fname = fs[i].getType().getComponentType().getField("name"); Object objs = fs[i].get(parent); for (int j = 0; j < Array.getLength(objs); j++) { 2951 Object child = Array.get(objs, j); 2952 Object vname = fname.get(child); 2953 names.add(vname); 2954 } 2955 ptm.setNames(names); 2956 } catch(Exception ex) { 2957 } 2959 break; 2960 } 2961 } 2962 } 2963 2964 propertyTable.setModel(ptm); 2965 propertyTable.getColumnModel().getColumn(0).setMaxWidth(150); 2966 propertyTable.getColumnModel().getColumn(0).setMinWidth(150); 2967 2969 for (int i = 0; i < propertyTable.getRowCount(); i++) { 2970 TableCellRenderer renderer = propertyTable.getCellRenderer(i, 1); 2971 Component comp = renderer.getTableCellRendererComponent(propertyTable, propertyTable.getValueAt(i, 1), false, false, i, 1); 2972 try { 2973 int height = comp.getMaximumSize().height; 2974 propertyTable.setRowHeight(i, height); 2975 } catch (Exception ea) { 2976 } 2977 } 2978 } 2979 2980 2983 public void editingCanceled(ChangeEvent e) { 2984 updater.update(); 2985 } 2986 2987 2990 public void editingStopped(ChangeEvent e) { 2991 2992 setDirty(true); 2993 if (! dirtyFlag || ((PropertyTableModel) propertyTable.getModel()).target instanceof MondrianGuiDef.Schema) { 2994 setDirtyFlag(true); setTitle(); 2996 } 2997 2998 String emsg = ((PropertyTableModel) propertyTable.getModel()).getErrorMsg(); 2999 if (emsg != null) { 3000 JOptionPane.showMessageDialog(this,emsg , "Error", JOptionPane.ERROR_MESSAGE); 3001 ((PropertyTableModel) propertyTable.getModel()).setErrorMsg(null); 3002 } 3003 3004 updater.update(); 3005 } 3006 3007 class PopupTrigger extends MouseAdapter { 3008 3009 public void mouseReleased(MouseEvent e) { 3010 if (e.isPopupTrigger()) { 3011 int x = e.getX(); 3012 int y = e.getY(); 3013 TreePath path = tree.getPathForLocation(x, y); 3014 if (path != null) { 3015 jPopupMenu.removeAll(); 3016 Object pathSelected = path.getLastPathComponent(); 3017 if (pathSelected instanceof MondrianGuiDef.Schema) { 3018 jPopupMenu.add(addCube); 3019 jPopupMenu.add(addDimension); 3020 jPopupMenu.add(addNamedSet); 3021 jPopupMenu.add(addUserDefinedFunction); 3022 jPopupMenu.add(jSeparator1); 3023 jPopupMenu.add(addVirtualCube); 3024 jPopupMenu.add(addRole); 3025 } else if (pathSelected instanceof MondrianGuiDef.Cube) { 3026 jPopupMenu.add(addDimension); 3027 jPopupMenu.add(addDimensionUsage); 3028 jPopupMenu.add(addMeasure); 3029 jPopupMenu.add(addCalculatedMember); 3030 jPopupMenu.add(addNamedSet); 3031 jPopupMenu.add(jSeparator1); 3032 jPopupMenu.add(delete); 3033 } else if (pathSelected instanceof MondrianGuiDef.Dimension) { 3034 jPopupMenu.add(addHierarchy); 3035 jPopupMenu.add(jSeparator1); 3036 jPopupMenu.add(delete); 3037 } else if (pathSelected instanceof MondrianGuiDef.Hierarchy) { 3038 jPopupMenu.add(addLevel); 3039 jPopupMenu.add(addRelation); 3040 jPopupMenu.add(jSeparator1); 3041 jPopupMenu.add(delete); 3042 if (((MondrianGuiDef.Hierarchy) pathSelected).relation == null) { 3043 addRelation.setEnabled(true); 3044 } else { 3045 addRelation.setEnabled(false); 3046 } 3047 } else if (pathSelected instanceof MondrianGuiDef.Level) { 3048 jPopupMenu.add(addProperty); 3049 jPopupMenu.add(addKeyExp); 3050 if (((MondrianGuiDef.Level) pathSelected).keyExp == null) { 3051 addKeyExp.setEnabled(true); 3052 } else { 3053 addKeyExp.setEnabled(false); 3054 } 3055 jPopupMenu.add(addNameExp); 3056 if (((MondrianGuiDef.Level) pathSelected).nameExp == null) { 3057 addNameExp.setEnabled(true); 3058 } else { 3059 addNameExp.setEnabled(false); 3060 } 3061 jPopupMenu.add(addOrdinalExp); 3062 if (((MondrianGuiDef.Level) pathSelected).ordinalExp == null) { 3063 addOrdinalExp.setEnabled(true); 3064 } else { 3065 addOrdinalExp.setEnabled(false); 3066 } 3067 jPopupMenu.add(addParentExp); 3068 if (((MondrianGuiDef.Level) pathSelected).parentExp == null) { 3069 addParentExp.setEnabled(true); 3070 } else { 3071 addParentExp.setEnabled(false); 3072 } 3073 jPopupMenu.add(addClosure); 3074 if (((MondrianGuiDef.Level) pathSelected).closure == null) { 3075 addClosure.setEnabled(true); 3076 } else { 3077 addClosure.setEnabled(false); 3078 } 3079 jPopupMenu.add(jSeparator1); 3080 jPopupMenu.add(delete); 3081 } else if (pathSelected instanceof MondrianGuiDef.KeyExpression || 3082 pathSelected instanceof MondrianGuiDef.NameExpression || 3083 pathSelected instanceof MondrianGuiDef.OrdinalExpression || 3084 pathSelected instanceof MondrianGuiDef.ParentExpression 3085 ) { 3086 jPopupMenu.add(addSQL); 3087 jPopupMenu.add(jSeparator1); 3088 jPopupMenu.add(delete); 3089 } else if (pathSelected instanceof MondrianGuiDef.Relation) { 3090 Object po = path.getParentPath().getLastPathComponent(); 3091 if (! (po instanceof MondrianGuiDef.Relation) && 3092 ! (po instanceof MondrianGuiDef.Closure)) { 3093 if (po instanceof MondrianGuiDef.Cube) { 3094 jPopupMenu.add(addAggName); 3095 jPopupMenu.add(addAggPattern); 3096 jPopupMenu.add(addAggExclude); 3097 } else { 3098 jPopupMenu.add(delete); 3099 } 3100 } else { 3101 return; 3102 } 3103 } else if (pathSelected instanceof MondrianGuiDef.Measure) { 3104 jPopupMenu.add(addMeasureExp); 3105 if (((MondrianGuiDef.Measure) pathSelected).measureExp == null) { 3106 addMeasureExp.setEnabled(true); 3107 } else { 3108 addMeasureExp.setEnabled(false); 3109 } 3110 jPopupMenu.add(jSeparator1); 3111 jPopupMenu.add(delete); 3112 } else if (pathSelected instanceof MondrianGuiDef.Closure) { 3113 jPopupMenu.add(delete); 3114 } else if (pathSelected instanceof MondrianGuiDef.AggName || 3115 pathSelected instanceof MondrianGuiDef.AggPattern) { 3116 jPopupMenu.add(addAggFactCount); 3117 jPopupMenu.add(addAggIgnoreColumn); 3118 jPopupMenu.add(addAggForeignKey); 3119 jPopupMenu.add(addAggMeasure); 3120 jPopupMenu.add(addAggLevel); 3121 if (pathSelected instanceof MondrianGuiDef.AggPattern) { 3122 jPopupMenu.add(addAggExclude); 3123 if (((MondrianGuiDef.AggPattern) pathSelected).factcount == null) { 3124 addAggFactCount.setEnabled(true); 3125 } else { 3126 addAggFactCount.setEnabled(false); 3127 } 3128 } else { 3129 if (((MondrianGuiDef.AggName) pathSelected).factcount == null) { 3130 addAggFactCount.setEnabled(true); 3131 } else { 3132 addAggFactCount.setEnabled(false); 3133 } 3134 } 3135 jPopupMenu.add(jSeparator1); 3136 jPopupMenu.add(delete); 3137 } else if (pathSelected instanceof MondrianGuiDef.VirtualCube) { 3138 jPopupMenu.add(addVirtualCubeDimension); 3139 jPopupMenu.add(addVirtualCubeMeasure); 3140 jPopupMenu.add(addCalculatedMember); 3141 jPopupMenu.add(jSeparator1); 3142 jPopupMenu.add(delete); 3143 } else if (pathSelected instanceof MondrianGuiDef.Role) { 3144 jPopupMenu.add(addSchemaGrant); 3145 jPopupMenu.add(jSeparator1); 3146 jPopupMenu.add(delete); 3147 } else if (pathSelected instanceof MondrianGuiDef.SchemaGrant) { 3148 jPopupMenu.add(addCubeGrant); 3149 jPopupMenu.add(jSeparator1); 3150 jPopupMenu.add(delete); 3151 } else if (pathSelected instanceof MondrianGuiDef.CubeGrant) { 3152 jPopupMenu.add(addDimensionGrant); 3153 jPopupMenu.add(addHierarchyGrant); 3154 jPopupMenu.add(jSeparator1); 3155 jPopupMenu.add(delete); 3156 } else if (pathSelected instanceof MondrianGuiDef.HierarchyGrant) { 3157 jPopupMenu.add(addMemberGrant); 3158 jPopupMenu.add(jSeparator1); 3159 jPopupMenu.add(delete); 3160 } else { 3161 jPopupMenu.add(delete); 3162 } 3165 jPopupMenu.show(tree, x, y); 3166 } 3167 } 3168 } 3169 } 3170 3171 public static final String [] DEF_DEFAULT = {}; 3172 public static final String [] DEF_VIRTUAL_CUBE = { "name", "caption", "enabled"}; 3173 public static final String [] DEF_VIRTUAL_CUBE_MEASURE = { "name", "cubeName", "visible" }; 3174 public static final String [] DEF_VIRTUAL_CUBE_DIMENSION = { "name", "cubeName", "caption", "foreignKey" }; 3175 public static final String [] DEF_VIEW = { "alias" }; 3176 public static final String [] DEF_TABLE = { "schema" , "name", "alias"}; 3177 public static final String [] DEF_AGG_FACT_COUNT = { "column"}; 3178 public static final String [] DEF_AGG_NAME = { "name", "ignorecase"}; 3179 public static final String [] DEF_AGG_PATTERN = { "pattern", "ignorecase"}; 3180 public static final String [] DEF_AGG_EXCLUDE = { "pattern", "name" , "ignorecase"}; 3181 public static final String [] DEF_AGG_IGNORE_COLUMN = { "column"}; 3182 public static final String [] DEF_AGG_FOREIGN_KEY = { "factColumn" , "aggColumn"}; 3183 public static final String [] DEF_AGG_MEASURE = { "column" , "name"}; 3184 public static final String [] DEF_AGG_LEVEL = { "column" , "name"}; 3185 3186 public static final String [] DEF_CLOSURE = { "parentColumn" , "childColumn"}; 3187 public static final String [] DEF_RELATION = { "name" }; 3188 public static final String [] DEF_SQL = { "cdata", "dialect" }; public static final String [] DEF_SCHEMA = {"name", "measuresCaption", "defaultRole"}; 3190 public static final String [] DEF_PROPERTY = { "name", "column", "type", "formatter", "caption" }; 3191 public static final String [] DEF_PARAMETER = { "name", "value" }; public static final String [] DEF_MEASURE = { "name", "aggregator", "column", "formatString", "visible", "datatype", "formatter", "caption"}; 3193 3194 public static final String [] DEF_CALCULATED_MEMBER = { "name", "caption", "dimension", "visible", "formula | formulaElement.cdata", "formatString"}; 3195 public static final String [] DEF_FORMULA = { "cdata" }; 3196 public static final String [] DEF_CALCULATED_MEMBER_PROPERTY = { "name", "caption", "expression", "value"}; 3197 public static final String [] DEF_NAMED_SET = { "name", "formula" }; 3198 public static final String [] DEF_USER_DEFINED_FUNCTION = { "name", "className" }; 3199 3200 public static final String [] DEF_LEVEL = { "name", "table", "column", "nameColumn", "parentColumn", "nullParentValue", "ordinalColumn", "type", "uniqueMembers", "levelType","hideMemberIf", "approxRowCount", "caption", "captionColumn", "formatter"}; 3201 public static final String [] DEF_JOIN = { "leftAlias", "leftKey", "rightAlias", "rightKey"}; 3202 public static final String [] DEF_HIERARCHY = { "name", "hasAll", "allMemberName", "allMemberCaption", "allLevelName", "defaultMember", "memberReaderClass", "primaryKeyTable", "primaryKey", "caption" }; 3203 public static final String [] DEF_EXPRESSION_VIEW = {}; 3204 public static final String [] DEF_DIMENSION_USAGE = { "name", "foreignKey", "source", "level", "usagePrefix", "caption" }; 3205 public static final String [] DEF_DIMENSION = { "name", "foreignKey", "type", "usagePrefix", "caption"}; 3206 public static final String [] DEF_CUBE = { "name", "caption", "cache", "enabled" }; 3207 public static final String [] DEF_ROLE = { "name" }; 3208 public static final String [] DEF_SCHEMA_GRANT = { "access" }; 3209 public static final String [] DEF_CUBE_GRANT = { "access", "cube" }; 3210 public static final String [] DEF_DIMENSION_GRANT = { "access", "dimension" }; 3211 public static final String [] DEF_HIERARCHY_GRANT = { "access", "hierarchy", "topLevel", "bottomLevel" }; 3212 public static final String [] DEF_MEMBER_GRANT = { "access", "member" }; 3213 public static final String [] DEF_COLUMN = { "name", "table" }; 3215 private static final String LBL_COLUMN = "Column"; 3216 private static final String LBL_CUBE = "Cube"; 3217 private static final String LBL_ROLE = "Role"; 3218 private static final String LBL_SCHEMA_GRANT = "Schema Grant"; 3219 private static final String LBL_CUBE_GRANT = "Cube Grant"; 3220 private static final String LBL_DIMENSION_GRANT = "Dimension Grant"; 3221 private static final String LBL_HIERARCHY_GRANT = "Hierarchy Grant"; 3222 private static final String LBL_MEMBER_GRANT = "Member Grant"; 3223 private static final String LBL_DIMENSION = "Dimension"; 3224 private static final String LBL_DIMENSION_USAGE = "Dimension Usage"; 3225 private static final String LBL_EXPRESSION_VIEW = "Expression View"; 3226 private static final String LBL_KEY_EXPRESSION = "Key Expression"; 3227 private static final String LBL_NAME_EXPRESSION = "Name Expression"; 3228 private static final String LBL_ORDINAL_EXPRESSION = "Ordinal Expression"; 3229 private static final String LBL_PARENT_EXPRESSION = "Parent Expression"; 3230 private static final String LBL_MEASURE_EXPRESSION = "Measure Expression"; 3231 private static final String LBL_HIERARCHY = "Hierarchy"; 3232 private static final String LBL_JOIN = "Join"; 3233 private static final String LBL_LEVEL = "Level"; 3234 private static final String LBL_MEASURE = "Measure"; 3235 private static final String LBL_CALCULATED_MEMBER = "Calculated Member"; 3236 private static final String LBL_CALCULATED_MEMBER_PROPERTY = "Calculated Member Property"; 3237 private static final String LBL_NAMED_SET = "Named Set"; 3238 private static final String LBL_USER_DEFINED_FUNCTION = "User Defined Function"; 3239 private static final String LBL_PARAMETER = "Parameter"; 3240 private static final String LBL_PROPERTY = "Property"; 3241 private static final String LBL_SCHEMA = "Schema"; 3242 private static final String LBL_SQL = "SQL"; 3243 private static final String LBL_TABLE = "Table"; 3244 private static final String LBL_CLOSURE = "Closure"; 3245 3246 private static final String LBL_AGG_NAME = "Aggregate Name"; 3247 private static final String LBL_AGG_IGNORE_COLUMN = "Aggregate Ignore Column"; 3248 private static final String LBL_AGG_FOREIGN_KEY = "Aggregate Foreign Key"; 3249 private static final String LBL_AGG_MEASURE = "Aggregate Measure"; 3250 private static final String LBL_AGG_LEVEL = "Aggregate Level"; 3251 private static final String LBL_AGG_PATTERN = "Aggregate Pattern"; 3252 private static final String LBL_AGG_EXCLUDE = "Aggregate Exclude"; 3253 private static final String LBL_AGG_FACT_COUNT = "Aggregate Fact Count"; 3254 3255 private static final String LBL_VIEW = "View"; 3256 private static final String LBL_VIRTUAL_CUBE = "Virtual Cube"; 3257 private static final String LBL_VIRTUAL_CUBE_DIMENSION = "Virtual Cube Dimension"; 3258 private static final String LBL_VIRTUAL_CUBE_MEASURE = "Virtual Cube Measure"; 3259 private static final String LBL_UNKNOWN_TYPE = "Unknown Type"; 3260 3261 private static final String alert = "Alert"; 3262 3263 private AbstractAction arrowButtonUpAction; 3264 private AbstractAction arrowButtonDownAction; 3265 3266 private AbstractAction addCube; 3267 private AbstractAction addRole; 3268 private AbstractAction addSchemaGrant; 3269 private AbstractAction addCubeGrant; 3270 private AbstractAction addDimensionGrant; 3271 private AbstractAction addHierarchyGrant; 3272 private AbstractAction addMemberGrant; 3273 3274 private AbstractAction addDimension; 3275 private AbstractAction addDimensionUsage; 3276 private AbstractAction addHierarchy; 3277 private AbstractAction addNamedSet; 3278 private AbstractAction addUserDefinedFunction; 3279 private AbstractAction addCalculatedMember; 3280 3281 private AbstractAction addMeasure; 3282 private AbstractAction addMeasureExp; 3283 private AbstractAction addLevel; 3284 private AbstractAction addSQL; 3285 private AbstractAction addKeyExp; 3286 private AbstractAction addNameExp; 3287 private AbstractAction addOrdinalExp; 3288 private AbstractAction addParentExp; 3289 private AbstractAction addRelation; 3290 private AbstractAction addProperty; 3291 private AbstractAction addClosure; 3292 3293 private AbstractAction addAggName; 3294 private AbstractAction addAggIgnoreColumn; 3295 private AbstractAction addAggForeignKey; 3296 private AbstractAction addAggMeasure; 3297 private AbstractAction addAggLevel; 3298 private AbstractAction addAggPattern; 3299 private AbstractAction addAggExclude; 3300 private AbstractAction addAggFactCount; 3301 3302 private AbstractAction addVirtualCube; 3303 private AbstractAction addVirtualCubeDimension; 3304 private AbstractAction addVirtualCubeMeasure; 3305 3306 private AbstractAction delete; 3307 3308 private AbstractAction editMode; 3309 3310 private JTable propertyTable; 3311 private JPanel jPanel1; 3312 private JPanel jPanel2; 3313 private JPanel jPanel3; 3314 private JButton addLevelButton; 3315 private JScrollPane jScrollPane2; 3316 private JScrollPane jScrollPane1; 3317 private JButton addPropertyButton; 3318 private JButton pasteButton; 3319 private JLabel targetLabel; 3320 private JLabel validStatusLabel; 3321 private JLabel targetLabel2; 3322 private JLabel validStatusLabel2; 3323 private JTree tree; 3324 private JSplitPane jSplitPane1; 3325 3326 private JButton addDimensionButton; 3327 private JButton addDimensionUsageButton; 3328 private JButton addHierarchyButton; 3329 private JButton addNamedSetButton; 3330 private JButton addUserDefinedFunctionButton; 3331 private JButton addCalculatedMemberButton; 3332 private JButton cutButton; 3333 private JButton addMeasureButton; 3334 private JButton addCubeButton; 3335 private JButton addRoleButton; 3336 private JButton addVirtualCubeButton; 3337 private JButton addVirtualCubeDimensionButton; 3338 private JButton addVirtualCubeMeasureButton; 3339 3340 private JButton deleteButton; 3341 private JToggleButton editModeButton; 3342 private JButton copyButton; 3343 private JToolBar jToolBar1; 3344 private JPopupMenu jPopupMenu; 3345 3346 private JSeparator jSeparator1; 3347 3348 private JPanel footer; 3349 private JLabel databaseLabel; 3350 3351 private JPanel jPanelXML; 3352 private JScrollPane jScrollPaneXML; 3353 private JEditorPane jEditorPaneXML; 3354 3355 public boolean isNewFile() { 3356 return newFile; 3357 } 3358 3359 public void setNewFile(boolean newFile) { 3360 this.newFile = newFile; 3361 } 3362 3363 public boolean isDirty() { 3364 return dirty; 3365 } 3366 3367 public void setDirty(boolean dirty) { 3368 this.dirty = dirty; 3369 } 3370 3371 public void setTitle() { 3372 parentIFrame.setTitle("Schema - "+schema.name+" "+"("+schemaFile.getName()+")"+(isDirty()?"*":"")); 3375 parentIFrame.setToolTipText(schemaFile.toString()); 3376 } 3377 3378 public void setDirtyFlag(boolean dirtyFlag) { 3379 this.dirtyFlag = dirtyFlag; 3380 } 3381 3382 public Object getParentObject() { 3383 TreePath tPath = tree.getSelectionPath(); 3384 if ( (tPath != null) && (tPath.getParentPath() != null) ) { 3385 return tPath.getParentPath().getLastPathComponent(); 3386 } 3387 return null; 3388 } 3389 3390 public String getJdbcConnectionUrl() { 3391 return this.jdbcMetaData.jdbcConnectionUrl; 3392 } 3393 3394 public String getErrMsg() { 3395 return errMsg; 3396 } 3397 3398 public boolean isEditModeXML() { 3399 return editModeXML; } 3401 3402} 3403 3404 | Popular Tags |