1 11 package mondrian.gui; 12 13 import java.awt.event.FocusAdapter ; 14 import java.awt.event.ItemListener ; 15 import java.awt.event.MouseAdapter ; 16 17 import javax.swing.*; 18 import javax.swing.event.CellEditorListener ; 19 import javax.swing.event.ChangeEvent ; 20 import java.awt.*; 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.awt.event.KeyAdapter ; 24 import java.awt.event.KeyEvent ; 25 import java.awt.event.MouseEvent ; 26 import java.awt.event.MouseListener ; 27 import java.util.ArrayList ; 28 import java.util.EventObject ; 29 import java.util.Vector ; 30 import javax.swing.border.*; 31 import javax.swing.text.JTextComponent ; 32 33 38 public class SchemaPropertyCellEditor implements javax.swing.table.TableCellEditor { 39 ArrayList listeners; 40 JTextField stringEditor; 41 JCheckBox booleanEditor; 42 JTextField integerEditor; 43 JTable tableEditor; 44 Component activeEditor; 45 JComboBox listEditor; 46 JComboBox relationList; JTable relationTable; 48 JPanel relationRenderer; 49 50 JDBCMetaData jdbcMetaData; 51 ComboBoxModel allOptions, selOptions; 52 String listEditorValue ; 53 MouseListener ml; 54 ItemListener il; 55 ActionListener al; 56 57 String noSelect = "-- No Selection --"; 58 FocusAdapter editorFocus; 59 60 public SchemaPropertyCellEditor(JDBCMetaData jdbcMetaData) { 61 this(); 62 this.jdbcMetaData = jdbcMetaData; 63 } 64 65 66 public SchemaPropertyCellEditor() { 67 68 69 70 listeners = new ArrayList (); 71 stringEditor = new JTextField(); 72 stringEditor.setFont(Font.decode("Dialog")); 73 stringEditor.setBorder(null); 74 75 booleanEditor = new JCheckBox(); 76 booleanEditor.setBackground(Color.white); 77 78 integerEditor = new JTextField(); 79 integerEditor.setBorder(null); 80 integerEditor.setHorizontalAlignment(JTextField.RIGHT); 81 integerEditor.setFont(Font.decode("Courier")); 82 83 tableEditor = new JTable(); 84 85 listEditor = new JComboBox(); 86 listEditor.setEditable(true); 87 listEditor.setMaximumSize(stringEditor.getMaximumSize()); 88 listEditor.setFont(Font.decode("Dialog")); 89 listEditor.setBackground(Color.white); 90 listEditor.setBorder(new EmptyBorder(0, 0, 0, 0)); 92 136 137 al = new ActionListener () { 138 boolean all = true; 139 public void actionPerformed(ActionEvent e) { 140 if (e.getActionCommand().equals("comboBoxChanged") && listEditor.getSelectedIndex() == 0) { if (all) { 143 listEditor.setModel(allOptions); 144 } else { 145 listEditor.setModel(selOptions); 146 } 147 listEditor.setSelectedIndex(-1); 148 all = !all; 149 150 } 151 if (listEditor.isDisplayable()) { 152 listEditor.setPopupVisible(true); 153 } 154 } 155 156 }; 157 158 159 JTextComponent editor = (JTextComponent ) listEditor.getEditor().getEditorComponent(); 160 161 editor.addMouseListener(new MouseAdapter () { 162 public void mousePressed(MouseEvent e) { 163 if (listEditor.isDisplayable()) { 164 listEditor.setPopupVisible(true); 165 } 166 } 167 }); 168 169 editor.addKeyListener(new KeyAdapter () { 170 171 public void keyPressed(KeyEvent e) { 172 if (listEditor.isDisplayable()) { 173 listEditor.setPopupVisible(true); 174 } 175 } 176 public void keyReleased(KeyEvent e) { 177 if (e.getKeyCode()==KeyEvent.VK_ESCAPE) { 179 listEditor.setSelectedItem(listEditorValue); 180 listEditor.getEditor().setItem(listEditorValue); 181 } 182 } 183 }); 184 185 192 relationRenderer = new JPanel(); 193 relationList = new JComboBox( new String [] {"Join", "Table"} ); 195 relationList.setMaximumSize(stringEditor.getMaximumSize()); 196 relationTable = new JTable(); 197 relationRenderer.add(relationList); 198 relationRenderer.add(relationTable); 199 200 } 201 202 public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, final int column) { 203 204 PropertyTableModel tableModel = (PropertyTableModel) table.getModel(); 205 Class parentClassz = null; 206 if (tableModel.getParentTarget() != null) { 207 parentClassz = tableModel.getParentTarget().getClass();} 208 Class targetClassz = tableModel.target.getClass(); 209 String propertyName = tableModel.getRowName(row); 210 String selectedFactTable = tableModel.getFactTable(); 211 String selectedFactTableSchema = tableModel.getFactTableSchema(); 212 listEditorValue=null; 214 if (targetClassz == MondrianGuiDef.UserDefinedFunction.class && propertyName.equals("className")) { 215 Vector udfs = getUdfs(); 216 ComboBoxModel cAlludfs = new DefaultComboBoxModel(udfs); 217 218 listEditor.setEditable(true); 219 listEditor.setToolTipText(null); 220 listEditor.removeActionListener(al); 222 223 listEditor.setModel(cAlludfs); 224 listEditor.setSelectedItem((String )value); 225 listEditorValue = (String )value; 226 activeEditor= listEditor; 227 } else if (targetClassz == MondrianGuiDef.Measure.class && propertyName.equals("formatString")) { 228 Vector formatStrs = getFormatStrings(); 229 ComboBoxModel cAllformatStrs = new DefaultComboBoxModel(formatStrs); 230 231 listEditor.setEditable(true); 232 listEditor.setToolTipText(null); 233 listEditor.removeActionListener(al); 234 235 listEditor.setModel(cAllformatStrs); 236 listEditor.setSelectedItem((String )value); 237 listEditorValue = (String )value; 238 activeEditor= listEditor; 239 } else if (targetClassz == MondrianGuiDef.Measure.class && propertyName.equals("aggregator")) { 240 listEditor.setEditable(false); 241 listEditor.setToolTipText(null); 242 listEditor.removeActionListener(al); 243 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Measure._aggregator_values)); 244 listEditor.setSelectedItem((String )value); 245 activeEditor= listEditor; 246 247 } else if (targetClassz == MondrianGuiDef.Measure.class && propertyName.equals("datatype")) { 248 listEditor.setEditable(false); 249 listEditor.setToolTipText(null); 250 listEditor.removeActionListener(al); 251 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Measure._datatype_values)); 252 listEditor.setSelectedItem((String )value); 253 activeEditor= listEditor; 254 255 } else if (targetClassz == MondrianGuiDef.SQL.class && propertyName.equals("dialect")) { 256 listEditor.setEditable(false); 257 listEditor.setToolTipText(null); 258 listEditor.removeActionListener(al); 259 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.SQL._dialect_values)); 260 listEditor.setSelectedItem((String )value); 261 activeEditor= listEditor; 262 263 } else if (targetClassz == MondrianGuiDef.Level.class && propertyName.equals("hideMemberIf")) { 264 listEditor.setEditable(false); 265 listEditor.setToolTipText(null); 266 listEditor.removeActionListener(al); 267 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Level._hideMemberIf_values)); 268 listEditor.setSelectedItem((String )value); 269 activeEditor= listEditor; 270 271 } else if (targetClassz == MondrianGuiDef.Level.class && propertyName.equals("levelType")) { 272 listEditor.setEditable(false); 273 listEditor.setToolTipText(null); 274 listEditor.removeActionListener(al); 275 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Level._levelType_values)); 276 listEditor.setSelectedItem((String )value); 277 activeEditor= listEditor; 278 279 } else if (targetClassz == MondrianGuiDef.Level.class && propertyName.equals("type")) { 280 listEditor.setEditable(false); 281 listEditor.setToolTipText(null); 282 listEditor.removeActionListener(al); 283 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Level._type_values)); 284 listEditor.setSelectedItem((String )value); 285 activeEditor= listEditor; 286 287 } else if (targetClassz == MondrianGuiDef.Dimension.class && propertyName.equals("type")) { 288 listEditor.setEditable(false); 289 listEditor.setToolTipText(null); 290 listEditor.removeActionListener(al); 291 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Dimension._type_values)); 292 listEditor.setSelectedItem((String )value); 293 activeEditor= listEditor; 294 295 } else if ( targetClassz == MondrianGuiDef.DimensionUsage.class && propertyName.equals("source")) { 296 Vector source = getSource(); 297 ComboBoxModel cAllsource = new DefaultComboBoxModel(source); 298 299 listEditor.setEditable(true); 300 listEditor.setToolTipText(null); 301 listEditor.removeActionListener(al); 302 303 listEditor.setModel(cAllsource); 304 listEditor.setSelectedItem((String )value); 305 listEditorValue = (String )value; 306 activeEditor= listEditor; 307 308 } else if ((tableModel.target instanceof MondrianGuiDef.Grant || tableModel.target instanceof MondrianGuiDef.MemberGrant) && propertyName.equals("access")){ 309 310 listEditor.setEditable(false); 311 listEditor.setToolTipText(null); 312 listEditor.removeActionListener(al); 313 314 ComboBoxModel cAccess = new DefaultComboBoxModel(MondrianGuiDef.Grant._access_values); 315 316 if ( targetClassz == MondrianGuiDef.SchemaGrant.class ) { 317 cAccess = new DefaultComboBoxModel(new String [] {"all", "none", "all_dimensions"} ); 318 } else if ( targetClassz == MondrianGuiDef.CubeGrant.class || 319 targetClassz == MondrianGuiDef.DimensionGrant.class || 320 targetClassz == MondrianGuiDef.MemberGrant.class) { 321 cAccess = new DefaultComboBoxModel(new String [] {"all", "none"} ); 322 } else if (targetClassz == MondrianGuiDef.HierarchyGrant.class ) { 323 cAccess = new DefaultComboBoxModel(new String [] {"all", "none", "custom"} ); 324 } 325 listEditor.setModel(cAccess); 326 327 listEditor.setSelectedItem((String )value); 328 activeEditor= listEditor; 329 330 } else if ((targetClassz == MondrianGuiDef.DimensionGrant.class && propertyName.equals("dimension")) || 331 (targetClassz == MondrianGuiDef.HierarchyGrant.class && propertyName.equals("hierarchy")) 332 ){ 333 Vector source = getDimensions(); 334 ComboBoxModel cAllsource = new DefaultComboBoxModel(source); 335 336 listEditor.setEditable(false); 337 listEditor.setToolTipText(null); 338 listEditor.removeActionListener(al); 339 340 listEditor.setModel(cAllsource); 341 listEditor.setSelectedItem((String )value); 342 listEditorValue = (String )value; 343 activeEditor= listEditor; 344 345 } else if ((targetClassz == MondrianGuiDef.HierarchyGrant.class && (propertyName.equals("topLevel") || propertyName.equals("bottomLevel"))) 346 ){ 347 Vector source = getLevels(( (MondrianGuiDef.HierarchyGrant) tableModel.target).hierarchy); 348 ComboBoxModel cAllsource = new DefaultComboBoxModel(source); 349 350 listEditor.setEditable(false); 351 listEditor.setToolTipText(null); 352 listEditor.removeActionListener(al); 353 354 listEditor.setModel(cAllsource); 355 listEditor.setSelectedItem((String )value); 356 listEditorValue = (String )value; 357 activeEditor= listEditor; 358 359 } else if (( (targetClassz == MondrianGuiDef.VirtualCubeDimension.class || targetClassz == MondrianGuiDef.VirtualCubeMeasure.class) && 360 propertyName.equals("cubeName")) || 361 (targetClassz == MondrianGuiDef.CubeGrant.class && propertyName.equals("cube")) 362 ){ 363 Vector source = getCubes(); 364 ComboBoxModel cAllsource = new DefaultComboBoxModel(source); 365 366 listEditor.setEditable(false); 367 listEditor.setToolTipText(null); 368 listEditor.removeActionListener(al); 369 370 listEditor.setModel(cAllsource); 371 listEditor.setSelectedItem((String )value); 372 listEditorValue = (String )value; 373 activeEditor= listEditor; 374 } else if ( (targetClassz == MondrianGuiDef.Dimension.class && propertyName.equals("foreignKey")) || 376 (targetClassz == MondrianGuiDef.DimensionUsage.class && propertyName.equals("foreignKey")) || 377 (targetClassz == MondrianGuiDef.Measure.class && propertyName.equals("column")) ) { 378 Vector fks = new Vector (jdbcMetaData.getFactTableFKs(selectedFactTableSchema, selectedFactTable)); fks.add(0, "<< All Columns >>"); 380 Vector allcols = new Vector (jdbcMetaData.getAllColumns(selectedFactTableSchema, selectedFactTable)); 381 ComboBoxModel cFks = new DefaultComboBoxModel(fks); 382 383 listEditor.setEditable(true); 384 listEditor.setToolTipText(null); 385 listEditor.removeActionListener(al); 386 if ((fks.size() > 1) && propertyName.equals("foreignKey")){ 387 allcols.add(0, "<< Foreign keys >>"); 388 ComboBoxModel cAllcols = new DefaultComboBoxModel(allcols); 389 listEditor.setModel(cFks); 390 selOptions = cFks; 392 allOptions = cAllcols; 393 listEditor.addActionListener(al); 396 } else { 397 ComboBoxModel cAllcols = new DefaultComboBoxModel(allcols); 398 listEditor.setModel(cAllcols); 399 } 400 401 listEditor.setSelectedItem((String )value); 402 listEditorValue = (String )value; 403 activeEditor= listEditor; 404 } else if (targetClassz == MondrianGuiDef.Hierarchy.class && propertyName.equals("primaryKey")) { 405 MondrianGuiDef.Hierarchy hProps = (MondrianGuiDef.Hierarchy) tableModel.getValue(); 406 String pkTable = hProps.primaryKeyTable; 407 408 String schemaName = null; 409 Vector allcols = jdbcMetaData.getAllColumns(schemaName, pkTable); 410 String pk = jdbcMetaData.getTablePK(schemaName, pkTable); 411 412 ComboBoxModel cAllcols = new DefaultComboBoxModel(allcols); 413 414 listEditor.setEditable(true); 415 listEditor.setToolTipText(null); 416 listEditor.removeActionListener(al); 417 418 listEditor.setModel(cAllcols); 419 if (value == null || ((String ) value).equals("")) { 420 listEditor.setSelectedItem(pk); 421 } else { 422 listEditor.setSelectedItem((String )value); 423 listEditorValue = (String )value; 424 } 425 activeEditor= listEditor; 426 } else if ( (targetClassz == MondrianGuiDef.Level.class && propertyName.equals("column")) || 427 (targetClassz == MondrianGuiDef.Property.class && propertyName.equals("column")) 428 ) { 429 430 MondrianGuiDef.Level lProps; 431 if (targetClassz == MondrianGuiDef.Level.class) { 432 lProps = (MondrianGuiDef.Level) tableModel.getValue(); 433 } else { 434 lProps = (MondrianGuiDef.Level) this.getParentObject(); 435 } 436 437 String lTable = lProps.table; 438 Vector allcols = jdbcMetaData.getAllColumns(null, lTable); ComboBoxModel cAllcols = new DefaultComboBoxModel(allcols); 440 441 listEditor.setEditable(true); 442 listEditor.setToolTipText(null); 443 listEditor.removeActionListener(al); 444 445 listEditor.setModel(cAllcols); 446 listEditor.setSelectedItem((String )value); 447 listEditorValue = (String )value; 448 activeEditor= listEditor; 449 451 } else if (targetClassz == MondrianGuiDef.Property.class && propertyName.equals("type")) { 452 listEditor.setEditable(false); 453 listEditor.setToolTipText(null); 454 listEditor.removeActionListener(al); 455 listEditor.setModel(new DefaultComboBoxModel(MondrianGuiDef.Property._type_values)); 456 listEditor.setSelectedItem((String )value); 457 activeEditor= listEditor; 458 459 } else if (targetClassz == MondrianGuiDef.Table.class && propertyName.equals("schema")) { 460 Vector allschemas = jdbcMetaData.getAllSchemas(); 461 ComboBoxModel cAllschemas = new DefaultComboBoxModel(allschemas); 462 463 listEditor.setEditable(true); 464 listEditor.setToolTipText(null); 465 listEditor.removeActionListener(al); 466 467 listEditor.setModel(cAllschemas); 468 listEditor.setSelectedItem((String )value); 469 listEditorValue = (String )value; 470 activeEditor= listEditor; 471 } else if(( targetClassz == MondrianGuiDef.Table.class && propertyName.equals("name")) || 472 (targetClassz == MondrianGuiDef.Hierarchy.class && propertyName.equals("primaryKeyTable")) || 473 (targetClassz == MondrianGuiDef.Level.class && propertyName.equals("table")) 474 ) { 475 String schema = ""; 476 if (targetClassz == MondrianGuiDef.Table.class) { 477 MondrianGuiDef.Table tProps = (MondrianGuiDef.Table) tableModel.getValue(); 478 schema = tProps.schema; 479 } 480 Vector factTables = new Vector (jdbcMetaData.getFactTables(schema)); 481 Vector allTablesMinusFact = new Vector (jdbcMetaData.getAllTables(schema, selectedFactTable)); 482 Vector allTables = new Vector (jdbcMetaData.getAllTables(schema)); 483 Vector dimeTables = new Vector (jdbcMetaData.getDimensionTables(schema, selectedFactTable)); 484 485 ComboBoxModel cFactTables = new DefaultComboBoxModel(factTables); ComboBoxModel cAllTables = new DefaultComboBoxModel((allTablesMinusFact.size() >0)?allTablesMinusFact:allTables); ComboBoxModel cDimeTables = new DefaultComboBoxModel(dimeTables); 489 listEditor.setEditable(true); 490 listEditor.setToolTipText(null); 491 listEditor.removeActionListener(al); 492 listEditor.setModel(cAllTables); 493 allOptions = cAllTables; 494 boolean toggleModel = false; 495 if (parentClassz == MondrianGuiDef.Cube.class) { 496 cAllTables = new DefaultComboBoxModel(allTables); 497 allOptions = cAllTables; 498 if (factTables.size() > 0) { 499 ((DefaultComboBoxModel) cFactTables).insertElementAt("<< All Tables >>",0); 500 ((DefaultComboBoxModel) cAllTables).insertElementAt("<< Fact Tables >>",0); 501 listEditor.setModel(cFactTables); 502 selOptions = cFactTables; 504 toggleModel=true; 505 } 506 } else { 507 if (dimeTables.size() > 0) { 508 ((DefaultComboBoxModel) cDimeTables).insertElementAt("<< All Tables >>",0); 509 ((DefaultComboBoxModel) cAllTables).insertElementAt("<< Dimension Tables >>",0); 510 listEditor.setModel(cDimeTables); 511 selOptions = cDimeTables; 513 toggleModel=true; 514 } 515 } 516 517 if (toggleModel) { 518 listEditor.addActionListener(al);} 519 listEditor.setSelectedItem((String )value); 520 listEditorValue = (String )value; 521 activeEditor= listEditor; 522 } else if (value instanceof String ) { 523 activeEditor = stringEditor; 524 stringEditor.setText((String )value); 525 } else if (value instanceof Boolean ) { 526 activeEditor = booleanEditor; 527 booleanEditor.setSelected((Boolean ) value); 528 } else if (value instanceof Integer ) { 529 activeEditor = integerEditor; 530 integerEditor.setText((String )value); 531 } else if (value == null ) { 532 value = ""; 533 activeEditor = stringEditor; 534 stringEditor.setText((String )value); 535 } else if (value.getClass() == MondrianGuiDef.Join.class) { 536 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(); 537 tableEditor.setDefaultEditor(Object .class, spce); 538 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 539 tableEditor.setDefaultRenderer(Object .class, spcr); 540 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_JOIN); 541 tableEditor.setModel(ptm); 542 activeEditor = tableEditor; 543 } else if (value.getClass() == MondrianGuiDef.NameExpression.class) { 544 return null; 545 } else if (value.getClass() == MondrianGuiDef.Relation.class) { 546 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(); 547 tableEditor.setDefaultEditor(Object .class, spce); 548 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 549 tableEditor.setDefaultRenderer(Object .class, spcr); 550 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_RELATION); 551 tableEditor.setModel(ptm); 552 activeEditor = tableEditor; 553 return null; 554 } else if (value.getClass() == MondrianGuiDef.OrdinalExpression.class) { 555 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(); 556 tableEditor.setDefaultEditor(Object .class, spce); 557 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 558 tableEditor.setDefaultRenderer(Object .class, spcr); 559 PropertyTableModel ptm = new PropertyTableModel(((MondrianGuiDef.OrdinalExpression)value).expressions[0],SchemaExplorer.DEF_SQL); 561 ptm.setParentTarget(((PropertyTableModel) table.getModel()).target); 562 tableEditor.setModel(ptm); 563 activeEditor = tableEditor; 564 } else if (value.getClass() == MondrianGuiDef.Formula.class) { 565 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(jdbcMetaData); 566 tableEditor.setDefaultEditor(Object .class, spce); 567 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 568 tableEditor.setDefaultRenderer(Object .class, spcr); 569 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_FORMULA); 570 tableEditor.setModel(ptm); 571 tableEditor.getColumnModel().getColumn(0).setMaxWidth(100); 572 tableEditor.getColumnModel().getColumn(0).setMinWidth(100); 573 activeEditor = tableEditor; 574 } else if (value.getClass() == MondrianGuiDef.CalculatedMemberProperty.class) { 575 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(jdbcMetaData); 576 tableEditor.setDefaultEditor(Object .class, spce); 577 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 578 tableEditor.setDefaultRenderer(Object .class, spcr); 579 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_CALCULATED_MEMBER_PROPERTY); 580 tableEditor.setModel(ptm); 581 tableEditor.getColumnModel().getColumn(0).setMaxWidth(100); 582 tableEditor.getColumnModel().getColumn(0).setMinWidth(100); 583 activeEditor = tableEditor; 584 } else if (value.getClass() == MondrianGuiDef.Table.class) { 585 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(jdbcMetaData); 586 for (int i = listeners.size() - 1; i >= 0; i--) { 589 spce.addCellEditorListener(((CellEditorListener )listeners.get(i))); 590 } 591 tableEditor.setDefaultEditor(Object .class, spce); 592 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 593 tableEditor.setDefaultRenderer(Object .class, spcr); 594 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_TABLE); 595 ptm.setFactTable(selectedFactTable); 596 if (targetClassz == MondrianGuiDef.Cube.class) { 597 ptm.setParentTarget(((PropertyTableModel) table.getModel()).target);} 598 tableEditor.setModel(ptm); 599 tableEditor.getColumnModel().getColumn(0).setMaxWidth(100); 600 tableEditor.getColumnModel().getColumn(0).setMinWidth(100); 601 activeEditor = tableEditor; 602 } else if (value.getClass() == MondrianGuiDef.AggFactCount.class) { 603 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(jdbcMetaData); 604 for (int i = listeners.size() - 1; i >= 0; i--) { 607 spce.addCellEditorListener(((CellEditorListener )listeners.get(i))); 608 } 609 tableEditor.setDefaultEditor(Object .class, spce); 610 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 611 tableEditor.setDefaultRenderer(Object .class, spcr); 612 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_AGG_FACT_COUNT); 613 ptm.setFactTable(selectedFactTable); 614 618 tableEditor.setModel(ptm); 619 tableEditor.getColumnModel().getColumn(0).setMaxWidth(100); 620 tableEditor.getColumnModel().getColumn(0).setMinWidth(100); 621 activeEditor = tableEditor; 622 } else if (value.getClass() == MondrianGuiDef.Closure.class) { 623 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(jdbcMetaData); 624 for (int i = listeners.size() - 1; i >= 0; i--) { 627 spce.addCellEditorListener(((CellEditorListener )listeners.get(i))); 628 } 629 tableEditor.setDefaultEditor(Object .class, spce); 630 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 631 tableEditor.setDefaultRenderer(Object .class, spcr); 632 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_CLOSURE); 633 ptm.setFactTable(selectedFactTable); 634 if (targetClassz == MondrianGuiDef.Level.class) { 635 ptm.setParentTarget(((PropertyTableModel) table.getModel()).target);} 636 tableEditor.setModel(ptm); 637 tableEditor.getColumnModel().getColumn(0).setMaxWidth(100); 638 tableEditor.getColumnModel().getColumn(0).setMinWidth(100); 639 spcr.setTableRendererHeight(tableEditor, null); 640 activeEditor = tableEditor; 641 } else if (value.getClass() == MondrianGuiDef.Property.class) { 642 SchemaPropertyCellEditor spce = new SchemaPropertyCellEditor(); 643 tableEditor.setDefaultEditor(Object .class, spce); 644 SchemaPropertyCellRenderer spcr = new SchemaPropertyCellRenderer(); 645 tableEditor.setDefaultRenderer(Object .class, spcr); 646 PropertyTableModel ptm = new PropertyTableModel(value,SchemaExplorer.DEF_PROPERTY); 647 tableEditor.setModel(ptm); 648 activeEditor = tableEditor; 649 } else { 650 value = ""; 651 activeEditor = stringEditor; 652 stringEditor.setText((String )value); 653 } 654 activeEditor.setVisible(true); 655 656 669 670 table.changeSelection(row, column, false, false); 671 activeEditor.setBackground(new java.awt.Color (224, 249, 255)); 672 activeEditor.requestFocusInWindow(); 673 return activeEditor; 674 } 675 676 682 public void addCellEditorListener(CellEditorListener l) { 683 listeners.add(l); 684 } 685 686 690 public void cancelCellEditing() { 691 if (activeEditor != null) { 692 activeEditor.setVisible(false); 693 fireEditingCancelled(); 694 } 695 } 696 697 701 public Object getCellEditorValue() { 702 if (activeEditor == stringEditor) { 703 return stringEditor.getText(); 704 } else if (activeEditor == booleanEditor) { 705 return booleanEditor.isSelected(); 706 } else if (activeEditor == listEditor) { 707 if (listEditor.isEditable()) { 708 return listEditor.getEditor().getItem(); } else { 710 if(listEditor.getSelectedItem() == noSelect) { 711 return null; } 713 return listEditor.getSelectedItem(); } 715 } else if (activeEditor == tableEditor) { 716 return ((PropertyTableModel) tableEditor.getModel()).getValue(); 717 } 718 719 return null; 720 } 721 722 736 public boolean isCellEditable(EventObject anEvent) { 737 return true; 738 } 739 740 745 public void removeCellEditorListener(CellEditorListener l) { 746 listeners.remove(l); 747 } 748 749 766 public boolean shouldSelectCell(EventObject anEvent) { 767 return true; 768 } 769 770 778 public boolean stopCellEditing() { 779 if (activeEditor != null) { 780 781 if (activeEditor == tableEditor) { 782 if (tableEditor.isEditing()) { 783 788 ArrayList nestedTableEditors = new ArrayList (); 789 JTable nestedTableEditor = tableEditor; 790 while (nestedTableEditor != null) { 793 nestedTableEditors.add(nestedTableEditor); 794 SchemaPropertyCellEditor sce = (SchemaPropertyCellEditor) nestedTableEditor.getCellEditor(); 795 if (sce != null && sce.activeEditor == sce.tableEditor && sce.tableEditor.isEditing()) { 796 nestedTableEditor = sce.tableEditor; } else { 799 nestedTableEditor = null; 800 } 801 } 802 for (int i=nestedTableEditors.size()-1; i>=0; i--) { 803 ((JTable) nestedTableEditors.get(i)).editingStopped(null); 804 } 805 814 815 } 816 817 } 818 activeEditor.setVisible(false); 819 fireEditingStopped(); 820 } 821 return true; 822 } 823 824 protected void fireEditingStopped() { 825 ChangeEvent ce = new ChangeEvent (this); 826 for (int i = listeners.size() - 1; i >= 0; i--) { 827 ((CellEditorListener )listeners.get(i)).editingStopped(ce); 828 } 829 } 830 831 protected void fireEditingCancelled() { 832 ChangeEvent ce = new ChangeEvent (this); 833 for (int i = listeners.size() - 1; i >= 0; i--) { 834 ((CellEditorListener )listeners.get(i)).editingCanceled(ce); 835 } 836 } 837 private Vector getUdfs() { 838 Vector udfs = new Vector (); 839 MondrianGuiDef.Schema s = this.getSchema(); 840 if (s != null) { 841 MondrianGuiDef.UserDefinedFunction [] u = s.userDefinedFunctions; 842 for (int i=0; i<u.length; i++){ 843 if (!(u[i].className== null || udfs.contains(u[i].className))) { 844 udfs.add(u[i].className); 845 } 846 } 847 } 848 849 return udfs; 850 } 851 852 private Vector getFormatStrings() { 853 Vector fs = new Vector (); 854 MondrianGuiDef.Schema s = this.getSchema(); 855 if (s != null) { 856 MondrianGuiDef.Cube [] c = s.cubes; 857 for (int i=0; i<c.length; i++){ 858 MondrianGuiDef.Measure [] m = c[i].measures; 859 for (int j=0; j<m.length; j++){ 860 if (!(m[j].formatString == null || fs.contains(m[j].formatString))) { 861 fs.add(m[j].formatString); 862 } 863 } 864 } 865 } 866 return fs; 867 } 868 869 private MondrianGuiDef.Schema getSchema() { 870 SchemaExplorer se = this.getSchemaExplorer(); 871 return (se ==null)?null:se.getSchema(); 872 } 873 874 private Object getParentObject() { 875 SchemaExplorer se = this.getSchemaExplorer(); 876 if (se != null) { 877 Object po = se.getParentObject(); 878 return po; 879 } 880 return null; 881 } 882 883 private SchemaExplorer getSchemaExplorer() { 884 SchemaExplorer se =null; 885 for (int i = listeners.size() - 1; i >= 0; i--) { 886 CellEditorListener cel = ((CellEditorListener )listeners.get(i)); 887 if (cel instanceof SchemaExplorer) { 888 se = (SchemaExplorer) cel; 889 break; 890 } 891 } 892 return se; 893 } 894 895 private Vector getSource() { Vector source = new Vector (); 897 MondrianGuiDef.Schema s = this.getSchema(); 898 if (s != null) { 899 MondrianGuiDef.Dimension [] u = s.dimensions; 900 for (int i=0; i<u.length; i++){ 901 source.add(u[i].name); 902 } 903 } 904 return source; 905 } 906 907 private Vector getCubes() { 908 Vector source = new Vector (); 909 MondrianGuiDef.Schema s = this.getSchema(); 911 if (s != null) { 912 MondrianGuiDef.Cube [] u = s.cubes; 913 for (int i=0; i<u.length; i++){ 914 source.add(u[i].name); 915 } 916 } 917 return source; 918 } 919 920 private void generatePrimaryKeyTables(Object relation, Vector v) { 921 if (relation == null) { 922 return; 923 } 924 if (relation instanceof MondrianGuiDef.Table) { 925 String sname = ((MondrianGuiDef.Table) relation).schema; 926 v.add( ((sname==null || sname.equals(""))?"":sname+ "->") + ((MondrianGuiDef.Table) relation).name); 927 return; 928 } 929 MondrianGuiDef.Join currentJoin = (MondrianGuiDef.Join)relation; 930 generatePrimaryKeyTables(currentJoin.left, v); 931 generatePrimaryKeyTables(currentJoin.right, v); 932 return ; 933 } 934 935 private Vector getDimensions() { 936 Vector dims = new Vector (); 937 Object po = getParentObject() ; if (po != null) { 939 MondrianGuiDef.CubeGrant parent = (MondrianGuiDef.CubeGrant) po; 940 if (! (parent.cube == null || parent.cube.equals(""))) { 941 MondrianGuiDef.Schema s = getSchema(); 942 if (s != null) { 943 for (int i=0; i<s.cubes.length ; i++) { 944 if (s.cubes[i].name.equals(parent.cube)) { 945 for (int j=0; j<s.cubes[i].dimensions.length; j++) { 946 dims.add(s.cubes[i].dimensions[j].name); 947 } 948 break; 949 } 950 } 951 } 952 } 953 } 954 return dims; 955 } 956 957 private String cacheCube = ""; 958 private String cacheHierarchy = ""; 959 private Vector hlevels = new Vector (); 960 961 private Vector getLevels(String hierarchy) { 962 if (! (hierarchy == null || hierarchy.equals(""))) { 963 if (hierarchy.startsWith("[") && hierarchy.endsWith("]")) { 964 hierarchy = hierarchy.substring(1, hierarchy.length()-1); 965 } 966 Object po = getParentObject() ; if (po != null) { 968 MondrianGuiDef.CubeGrant parent = (MondrianGuiDef.CubeGrant) po; 969 if (! (parent.cube == null || parent.cube.equals(""))) { 970 if (cacheCube.equals(parent.cube) && cacheHierarchy.equals(hierarchy)) { 971 return hlevels; 972 } else { 973 hlevels = new Vector (); 974 cacheCube = parent.cube; 975 cacheHierarchy = hierarchy; 976 MondrianGuiDef.Schema s = getSchema(); 977 if (s != null) { 978 for (int i=0; i<s.cubes.length ; i++) { 980 if (s.cubes[i].name.equals(parent.cube)) { 981 for (int j=0; j<s.cubes[i].dimensions.length; j++) { 983 if (s.cubes[i].dimensions[j].name.equals(hierarchy)) { 984 MondrianGuiDef.Dimension d = null; 985 if (s.cubes[i].dimensions[j] instanceof MondrianGuiDef.Dimension) { 986 d = (MondrianGuiDef.Dimension)s.cubes[i].dimensions[j]; 987 } else { 988 MondrianGuiDef.DimensionUsage d2 = (MondrianGuiDef.DimensionUsage)s.cubes[i].dimensions[j]; 989 for (int m=0; m< s.dimensions.length; m++) { 990 if (s.dimensions[m].name.equals(d2.source)) { 991 d = s.dimensions[m]; 992 break; 993 } 994 } 995 } 996 if (d.hierarchies[0] !=null) { 997 for (int k=0; k<d.hierarchies[0].levels.length; k++ ) { 998 hlevels.add(d.hierarchies[0].levels[k].name); 999 } 1000 } 1001 break; 1002 } 1003 } 1004 break; 1005 } 1006 } 1007 } 1008 } 1009 } 1010 } 1011 } 1012 return hlevels; 1013 } 1014 1015 1029} 1030 1031 1032 | Popular Tags |