1 32 33 package it.businesslogic.ireport.gui.documentstructure; 34 import it.businesslogic.ireport.ElementGroup; 35 import it.businesslogic.ireport.gui.MainFrame; 36 import it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener; 37 import it.businesslogic.ireport.gui.event.ReportListener; 38 import it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener; 39 import javax.swing.tree.DefaultMutableTreeNode ; 40 import javax.swing.tree.DefaultTreeSelectionModel ; 41 import it.businesslogic.ireport.gui.*; 42 import it.businesslogic.ireport.*; 43 import it.businesslogic.ireport.crosstab.CrosstabCell; 44 import it.businesslogic.ireport.crosstab.gui.CrosstabEditorPanel; 45 import it.businesslogic.ireport.gui.docking.GenericDragTargetListener; 46 import it.businesslogic.ireport.gui.event.*; 47 import java.util.Enumeration ; 48 import java.util.Vector ; 49 import javax.swing.tree.TreePath ; 50 import it.businesslogic.ireport.undo.UnGroupEmentsOperation; 51 import java.awt.dnd.DropTarget ; 52 import java.util.ArrayList ; 53 import java.util.List ; 54 import it.businesslogic.ireport.util.I18n; 55 59 public class CrosstabStructurePanel extends javax.swing.JPanel implements ReportListener, SubDatasetObjectChangedListener, CrosstabLayoutChangedListener { 60 61 private boolean dontHandleEvent = false; 62 63 private JReportFrame oldJReportFrame = null; 64 private CrosstabReportElement crosstabReportElement = null; 65 private CrosstabEditorPanel oldCrosstabEditorPanel = null; 66 67 68 public CrosstabStructurePanel() { 69 initComponents(); 70 71 DefaultTreeSelectionModel dtsm = (DefaultTreeSelectionModel )jTreeDocument.getSelectionModel(); 72 dtsm.setSelectionMode( DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION ); 73 74 DocumentStructureTreeNode rootDoc = new DocumentStructureTreeNode(it.businesslogic.ireport.util.I18n.getString("crossTab","Crosstab")); 75 javax.swing.tree.DefaultTreeModel modelDoc = new javax.swing.tree.DefaultTreeModel (rootDoc); 76 77 jTreeDocument.setDropTarget(new DropTarget (this, new GenericDragTargetListener())); 78 79 jTreeDocument.setModel( modelDoc ); 80 jTreeDocument.setCellRenderer( new DocumentStructureTreeCellRenderer()); 81 82 } 83 84 89 private void initComponents() { 91 jPopupMenuDocumentStructure = new javax.swing.JPopupMenu (); 92 jMenuItemDS_properties = new javax.swing.JMenuItem (); 93 jMenuItemDSB_crosstabProperties1 = new javax.swing.JMenuItem (); 94 jSeparator22 = new javax.swing.JSeparator (); 95 jMenuItemMoveUp = new javax.swing.JMenuItem (); 96 jMenuItemMoveDown = new javax.swing.JMenuItem (); 97 jSeparator23 = new javax.swing.JSeparator (); 98 jMenuItemDS_cut = new javax.swing.JMenuItem (); 99 jMenuItemDS_copy = new javax.swing.JMenuItem (); 100 jMenuItemDS_paste = new javax.swing.JMenuItem (); 101 jMenuItemDS_delete = new javax.swing.JMenuItem (); 102 jPopupMenuDocumentStructureCell = new javax.swing.JPopupMenu (); 103 jMenuItemDSB_crosstabProperties = new javax.swing.JMenuItem (); 104 jMenuItemDSB_properties = new javax.swing.JMenuItem (); 105 jPopupMenuDocumentStructureGroup = new javax.swing.JPopupMenu (); 106 jMenuItemUngroup = new javax.swing.JMenuItem (); 107 jScrollPane2 = new javax.swing.JScrollPane (); 108 jTreeDocument = new javax.swing.JTree (); 109 110 jMenuItemDS_properties.setText("Properties"); 111 jMenuItemDS_properties.addActionListener(new java.awt.event.ActionListener () { 112 public void actionPerformed(java.awt.event.ActionEvent evt) { 113 jMenuItemDS_propertiesActionPerformed(evt); 114 } 115 }); 116 117 jPopupMenuDocumentStructure.add(jMenuItemDS_properties); 118 119 jMenuItemDSB_crosstabProperties1.setText("Crosstab properties"); 120 jMenuItemDSB_crosstabProperties1.addActionListener(new java.awt.event.ActionListener () { 121 public void actionPerformed(java.awt.event.ActionEvent evt) { 122 jMenuItemDSB_crosstabPropertiesjMenuItemDSB_propertiesActionPerformed1(evt); 123 } 124 }); 125 126 jPopupMenuDocumentStructure.add(jMenuItemDSB_crosstabProperties1); 127 128 jPopupMenuDocumentStructure.add(jSeparator22); 129 130 jMenuItemMoveUp.setText("Move up"); 131 jMenuItemMoveUp.setEnabled(false); 132 jMenuItemMoveUp.addActionListener(new java.awt.event.ActionListener () { 133 public void actionPerformed(java.awt.event.ActionEvent evt) { 134 jMenuItemMoveUpActionPerformed(evt); 135 } 136 }); 137 138 jPopupMenuDocumentStructure.add(jMenuItemMoveUp); 139 140 jMenuItemMoveDown.setText("Move down"); 141 jMenuItemMoveDown.setEnabled(false); 142 jMenuItemMoveDown.addActionListener(new java.awt.event.ActionListener () { 143 public void actionPerformed(java.awt.event.ActionEvent evt) { 144 jMenuItemMoveDownActionPerformed(evt); 145 } 146 }); 147 148 jPopupMenuDocumentStructure.add(jMenuItemMoveDown); 149 150 jPopupMenuDocumentStructure.add(jSeparator23); 151 152 jMenuItemDS_cut.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/cut.png"))); 153 jMenuItemDS_cut.setText("Cut"); 154 jMenuItemDS_cut.setEnabled(false); 155 jMenuItemDS_cut.addActionListener(new java.awt.event.ActionListener () { 156 public void actionPerformed(java.awt.event.ActionEvent evt) { 157 jMenuItemDS_cutActionPerformed(evt); 158 } 159 }); 160 161 jPopupMenuDocumentStructure.add(jMenuItemDS_cut); 162 163 jMenuItemDS_copy.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/copy.png"))); 164 jMenuItemDS_copy.setText("Copy"); 165 jMenuItemDS_copy.setEnabled(false); 166 jMenuItemDS_copy.addActionListener(new java.awt.event.ActionListener () { 167 public void actionPerformed(java.awt.event.ActionEvent evt) { 168 jMenuItemDS_copyActionPerformed(evt); 169 } 170 }); 171 172 jPopupMenuDocumentStructure.add(jMenuItemDS_copy); 173 174 jMenuItemDS_paste.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/paste.png"))); 175 jMenuItemDS_paste.setText("Paste"); 176 jMenuItemDS_paste.setEnabled(false); 177 jMenuItemDS_paste.addActionListener(new java.awt.event.ActionListener () { 178 public void actionPerformed(java.awt.event.ActionEvent evt) { 179 jMenuItemDS_pasteActionPerformed(evt); 180 } 181 }); 182 183 jPopupMenuDocumentStructure.add(jMenuItemDS_paste); 184 185 jMenuItemDS_delete.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/delete.png"))); 186 jMenuItemDS_delete.setText("Delete"); 187 jMenuItemDS_delete.setEnabled(false); 188 jMenuItemDS_delete.addActionListener(new java.awt.event.ActionListener () { 189 public void actionPerformed(java.awt.event.ActionEvent evt) { 190 jMenuItemDS_deleteActionPerformed(evt); 191 } 192 }); 193 194 jPopupMenuDocumentStructure.add(jMenuItemDS_delete); 195 196 jMenuItemDSB_crosstabProperties.setText("Crosstab properties"); 197 jMenuItemDSB_crosstabProperties.addActionListener(new java.awt.event.ActionListener () { 198 public void actionPerformed(java.awt.event.ActionEvent evt) { 199 jMenuItemDSB_propertiesActionPerformed1(evt); 200 } 201 }); 202 203 jPopupMenuDocumentStructureCell.add(jMenuItemDSB_crosstabProperties); 204 205 jMenuItemDSB_properties.setText("Cell properties"); 206 jMenuItemDSB_properties.addActionListener(new java.awt.event.ActionListener () { 207 public void actionPerformed(java.awt.event.ActionEvent evt) { 208 jMenuItemDSB_propertiesActionPerformed(evt); 209 } 210 }); 211 212 jPopupMenuDocumentStructureCell.add(jMenuItemDSB_properties); 213 214 jMenuItemUngroup.setText("Ungroup"); 215 jMenuItemUngroup.addActionListener(new java.awt.event.ActionListener () { 216 public void actionPerformed(java.awt.event.ActionEvent evt) { 217 jMenuItemUngroupActionPerformed(evt); 218 } 219 }); 220 221 jPopupMenuDocumentStructureGroup.add(jMenuItemUngroup); 222 223 setLayout(new java.awt.BorderLayout ()); 224 225 jTreeDocument.addTreeExpansionListener(new javax.swing.event.TreeExpansionListener () { 226 public void treeCollapsed(javax.swing.event.TreeExpansionEvent evt) { 227 jTreeDocumentTreeCollapsed(evt); 228 } 229 public void treeExpanded(javax.swing.event.TreeExpansionEvent evt) { 230 jTreeDocumentTreeExpanded(evt); 231 } 232 }); 233 jTreeDocument.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener () { 234 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { 235 jTreeDocumentValueChanged(evt); 236 } 237 }); 238 jTreeDocument.addMouseListener(new java.awt.event.MouseAdapter () { 239 public void mousePressed(java.awt.event.MouseEvent evt) { 240 jTreeDocumentMousePressed(evt); 241 } 242 }); 243 244 jScrollPane2.setViewportView(jTreeDocument); 245 246 add(jScrollPane2, java.awt.BorderLayout.CENTER); 247 248 } 250 private void jMenuItemDSB_crosstabPropertiesjMenuItemDSB_propertiesActionPerformed1(java.awt.event.ActionEvent evt) { it.businesslogic.ireport.crosstab.gui.CrosstabPropertiesDialog cpd = new it.businesslogic.ireport.crosstab.gui.CrosstabPropertiesDialog(MainFrame.getMainInstance(),true); 252 cpd.setCurrentCrosstabReportElement( getCrosstabReportElement() ); 253 cpd.setVisible(true); 254 } 256 private void jMenuItemDSB_propertiesActionPerformed1(java.awt.event.ActionEvent evt) { 258 it.businesslogic.ireport.crosstab.gui.CrosstabPropertiesDialog cpd = new it.businesslogic.ireport.crosstab.gui.CrosstabPropertiesDialog(MainFrame.getMainInstance(),true); 259 cpd.setCurrentCrosstabReportElement( getCrosstabReportElement() ); 260 cpd.setVisible(true); 261 262 } 264 private void jMenuItemUngroupActionPerformed(java.awt.event.ActionEvent evt) { 266 if (jTreeDocument.getSelectionCount() > 0) { 267 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 268 if (elementNode.getUserObject() instanceof ElementGroup) { 269 String elementGroupName = ((ElementGroup)elementNode.getUserObject()).getName(); 270 while ( ((DocumentStructureTreeNode)elementNode.getParent()).getUserObject() instanceof ElementGroup) 271 { 272 elementNode = (DocumentStructureTreeNode)elementNode.getParent(); 273 elementGroupName = ((ElementGroup)elementNode.getUserObject()).getName() + "." + elementGroupName; 274 } 275 276 String newElementGroupName = elementGroupName; 277 if (newElementGroupName.lastIndexOf(".")>=0) 278 { 279 newElementGroupName = newElementGroupName.substring(0,newElementGroupName.lastIndexOf(".")); 280 } 281 else 282 { 283 newElementGroupName = ""; 284 } 285 286 287 UnGroupEmentsOperation undoOp = new UnGroupEmentsOperation(MainFrame.getMainInstance().getActiveReportFrame()); 288 Vector elements = getCrosstabReportElement().getElements(); 289 for (int i=0; i<elements.size(); ++i) 290 { 291 ReportElement element = (ReportElement)elements.elementAt(i); 292 String oldElementGroupName = element.getElementGroup(); 293 if (element.getElementGroup().startsWith(elementGroupName+".") || element.getElementGroup().equals(elementGroupName)) 294 { 295 String tmpElementGroupName = element.getElementGroup().substring(elementGroupName.length()); 296 if (tmpElementGroupName.length() == 0) tmpElementGroupName = newElementGroupName; 297 tmpElementGroupName = newElementGroupName + tmpElementGroupName; 298 if (tmpElementGroupName.startsWith(".")) tmpElementGroupName = tmpElementGroupName.substring(1); 299 300 element.setElementGroup(tmpElementGroupName); 301 undoOp.addElement(element, i,i, oldElementGroupName, tmpElementGroupName); 302 } 303 } 304 305 MainFrame.getMainInstance().getActiveReportFrame().addUndoOperation(undoOp); 306 307 MainFrame.getMainInstance().getActiveReportFrame().fireReportListenerReportElementsChanged(new ReportElementChangedEvent(MainFrame.getMainInstance().getActiveReportFrame(), new Vector () , ReportElementChangedEvent.REMOVED )); 308 } 309 } 310 312 313 } 315 private void jTreeDocumentTreeCollapsed(javax.swing.event.TreeExpansionEvent evt) { } 319 private void jTreeDocumentTreeExpanded(javax.swing.event.TreeExpansionEvent evt) { 322 323 } 325 private void jMenuItemDSB_propertiesActionPerformed(java.awt.event.ActionEvent evt) {if (jTreeDocument.getSelectionCount() > 0) { 327 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 328 if (elementNode.getUserObject() instanceof CrosstabCell) { 329 CrosstabCell thisCell = ((CrosstabCell)elementNode.getUserObject()); 330 MainFrame.getMainInstance().getActiveReportFrame().getSelectedCrosstabEditorPanel().editCell(thisCell); 331 } 332 } 333 } 335 private void jMenuItemDS_deleteActionPerformed(java.awt.event.ActionEvent evt) { MainFrame.getMainInstance().getActiveReportFrame().getSelectedCrosstabEditorPanel().deleteSelectedElements(); 337 } 339 private void jMenuItemDS_pasteActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().paste(); 341 } 343 private void jMenuItemDS_copyActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().copy(); 345 } 347 private void jMenuItemDS_cutActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().cut(); 349 } 351 private void jMenuItemMoveDownActionPerformed(java.awt.event.ActionEvent evt) {if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 353 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 354 jrf.moveDown(); 355 356 if (jrf.getSelectedCrosstabEditorPanel().getSelectedElements().size()>0) 357 updateDocumentStructureTree(jrf, getCrosstabReportElement()); 358 359 } 360 } 362 private void jMenuItemMoveUpActionPerformed(java.awt.event.ActionEvent evt) { if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 364 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 365 jrf.moveUp(); 366 this.jTreeDocument.updateUI(); 367 368 if (jrf.getSelectedCrosstabEditorPanel().getSelectedElements().size()>0) 369 updateDocumentStructureTree(jrf, getCrosstabReportElement()); 370 } 371 372 } 374 private void jMenuItemDS_propertiesActionPerformed(java.awt.event.ActionEvent evt) { MainFrame.getMainInstance().getElementPropertiesDialog().setVisible(true); 376 } 379 private void jTreeDocumentValueChanged(javax.swing.event.TreeSelectionEvent evt) { if (isDontHandleEvent()) return; 381 382 if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 384 try { 386 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 387 Vector elementsToSelect = new Vector (); 388 389 TreePath [] path = jTreeDocument.getSelectionPaths(); 390 391 392 for (int i=0; i<path.length; ++i) { 393 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)path[i].getLastPathComponent(); 394 if (elementNode.getUserObject() instanceof ReportElement) { 395 elementsToSelect.addElement( (ReportElement)elementNode.getUserObject()); 396 } 397 else if (path.length == 1) { 398 jrf.getSelectedCrosstabEditorPanel().setSelectedElement(null); 399 return; 400 } 401 else if (elementNode.getUserObject() instanceof ElementGroup) 402 { 403 404 jrf.getSelectedCrosstabEditorPanel().setSelectedElement(null); 405 return; 406 } 407 } 408 409 jrf.getSelectedCrosstabEditorPanel().setSelectedElement(null); 410 Enumeration e = elementsToSelect.elements(); 411 while (e.hasMoreElements()) { 412 jrf.getSelectedCrosstabEditorPanel().addSelectedElement((ReportElement)e.nextElement(), false); 413 } 414 jrf.getSelectedCrosstabEditorPanel().fireSelectionChangedEvent(); 415 } catch (Exception ex) 416 {} 417 } 419 } 421 private void jTreeDocumentMousePressed(java.awt.event.MouseEvent evt) { if (evt.getButton() == evt.BUTTON3) { 423 if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 424 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 425 jTreeDocument.setSelectionPath( jTreeDocument.getPathForLocation(evt.getX(), evt.getY() ) ); 426 if (jTreeDocument.getSelectionCount() > 0) { 427 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 428 if (elementNode.getUserObject() instanceof ReportElement) { 429 this.jPopupMenuDocumentStructure.show(jTreeDocument, evt.getPoint().x, evt.getPoint().y); 431 432 } else if (elementNode.getUserObject() instanceof CrosstabCell) { 433 this.jPopupMenuDocumentStructureCell.show(jTreeDocument, evt.getPoint().x, evt.getPoint().y); 435 436 } else if (elementNode.getUserObject() instanceof ElementGroup) { 437 this.jPopupMenuDocumentStructureGroup.show(jTreeDocument, evt.getPoint().x, evt.getPoint().y); 439 440 } 441 } 442 } 443 444 } 445 else if (evt.getButton() == evt.BUTTON1 && evt.getClickCount() == 2) { 446 447 if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 448 449 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 450 if (jrf.getSelectedCrosstabEditorPanel().getSelectedElements().size() > 0) { 451 MainFrame.getMainInstance().getElementPropertiesDialog().setVisible(true); 452 MainFrame.getMainInstance().getElementPropertiesDialog().updateSelection(); 453 } 454 } 455 } 456 } 458 public void printSelectedPaths(String prefix) 459 { 460 try { 461 Enumeration enum_extended_paths = jTreeDocument.getExpandedDescendants(new TreePath (new Object []{ jTreeDocument.getModel().getRoot() })); 462 if (enum_extended_paths != null) 463 { 464 while (enum_extended_paths.hasMoreElements()) 465 { 466 TreePath path = (TreePath )enum_extended_paths.nextElement(); 467 } 469 } 470 } catch (Exception ex) 471 { 472 ex.printStackTrace(); 473 } 474 } 475 476 private javax.swing.JMenuItem jMenuItemDSB_crosstabProperties; 478 private javax.swing.JMenuItem jMenuItemDSB_crosstabProperties1; 479 private javax.swing.JMenuItem jMenuItemDSB_properties; 480 private javax.swing.JMenuItem jMenuItemDS_copy; 481 private javax.swing.JMenuItem jMenuItemDS_cut; 482 private javax.swing.JMenuItem jMenuItemDS_delete; 483 private javax.swing.JMenuItem jMenuItemDS_paste; 484 private javax.swing.JMenuItem jMenuItemDS_properties; 485 private javax.swing.JMenuItem jMenuItemMoveDown; 486 private javax.swing.JMenuItem jMenuItemMoveUp; 487 private javax.swing.JMenuItem jMenuItemUngroup; 488 private javax.swing.JPopupMenu jPopupMenuDocumentStructure; 489 private javax.swing.JPopupMenu jPopupMenuDocumentStructureCell; 490 private javax.swing.JPopupMenu jPopupMenuDocumentStructureGroup; 491 private javax.swing.JScrollPane jScrollPane2; 492 private javax.swing.JSeparator jSeparator22; 493 private javax.swing.JSeparator jSeparator23; 494 private javax.swing.JTree jTreeDocument; 495 497 498 499 public void saveSelection() 500 { 501 List openedPaths = null; 502 try { 503 504 openedPaths = new ArrayList (); 505 Enumeration enum_extended_paths = jTreeDocument.getExpandedDescendants(new TreePath (new Object []{ jTreeDocument.getModel().getRoot() })); 506 if (enum_extended_paths!=null) 507 { 508 while (enum_extended_paths.hasMoreElements()) 509 { 510 TreePath path = (TreePath )enum_extended_paths.nextElement(); 511 openedPaths.add( ((DocumentStructureTreeNode)path.getLastPathComponent()).getNodeId() ); 512 } 513 } 514 } catch (Exception ex) 515 { 516 ex.printStackTrace(); 517 } 518 519 if (oldCrosstabEditorPanel != null) oldCrosstabEditorPanel.setOpenedNodesDocumentStructure( openedPaths ); 520 } 521 522 523 public void updateDocumentStructureTree(JReportFrame jrf, CrosstabReportElement crosstabReportElement) 524 { 525 526 527 List openedPaths = null; 528 529 try { 530 531 openedPaths = new ArrayList (); 532 Enumeration enum_extended_paths = jTreeDocument.getExpandedDescendants(new TreePath (new Object []{ jTreeDocument.getModel().getRoot() })); 533 if (enum_extended_paths!=null) 534 { 535 while (enum_extended_paths.hasMoreElements()) 536 { 537 TreePath path = (TreePath )enum_extended_paths.nextElement(); 538 openedPaths.add( ((DocumentStructureTreeNode)path.getLastPathComponent()).getNodeId() ); 539 } 540 } 541 } catch (Exception ex) 542 { 543 ex.printStackTrace(); 544 } 545 546 if (jrf != null && jrf.getSelectedCrosstabEditorPanel() != oldCrosstabEditorPanel) 547 { 548 if (oldCrosstabEditorPanel != null) oldCrosstabEditorPanel.setOpenedNodesDocumentStructure( openedPaths ); 549 if (jrf != null && jrf.getSelectedCrosstabEditorPanel() != null) 550 { 551 openedPaths = jrf.getSelectedCrosstabEditorPanel().getOpenedNodesDocumentStructure(); 552 oldCrosstabEditorPanel = jrf.getSelectedCrosstabEditorPanel(); 553 } 554 else 555 { 556 oldCrosstabEditorPanel = null; 557 } 558 559 } 560 561 if (getCrosstabReportElement() != null && getCrosstabReportElement() != crosstabReportElement) 562 { 563 getCrosstabReportElement().removeCrosstabLayoutChangedListener(this); 564 } 565 566 this.setCrosstabReportElement( crosstabReportElement ); 567 568 if (getCrosstabReportElement() != null) 569 { 570 this.getCrosstabReportElement().addCrosstabLayoutChangedListener( this ); 571 } 572 573 setDontHandleEvent(true); 574 ((DocumentStructureTreeNode)this.jTreeDocument.getModel().getRoot()).removeAllChildren(); 576 ((javax.swing.tree.DefaultTreeModel )(this.jTreeDocument.getModel())).reload(); 577 578 if (jrf != null && getCrosstabReportElement() != null) 579 { 580 581 582 Enumeration cells = getCrosstabReportElement().getCells().elements(); 583 while (cells.hasMoreElements()) 584 { 585 CrosstabCell cell = (CrosstabCell)cells.nextElement(); 586 DocumentStructureTreeNode bandNode = new DocumentStructureTreeNode(cell); 587 ((DocumentStructureTreeNode)this.jTreeDocument.getModel().getRoot()).add( bandNode); 588 589 Enumeration elements = getCrosstabReportElement().getElements().elements(); 590 while (elements.hasMoreElements()) 591 { 592 ReportElement element = (ReportElement)elements.nextElement(); 593 if (element.getCell() == cell) 594 { 595 String elementGroup = element.getElementGroup(); 596 try { 597 if (element.getParentElement() != null) 598 { 599 DocumentStructureTreeNode parentNode = findElementTreeNode(element.getParentElement(),true); 600 if (parentNode != null) 601 { 602 addElementToGroup(parentNode, elementGroup, element, openedPaths); 603 if (openedPaths != null && openedPaths.contains(parentNode.getNodeId())) 604 { 605 this.expandPath(parentNode); 606 } 607 } 608 } 609 else 610 { 611 addElementToGroup(bandNode, elementGroup, element, openedPaths); 612 } 613 614 } catch (Exception ex) 615 { 616 ex.printStackTrace(); 617 } 618 } 619 } 620 if (openedPaths != null && openedPaths.contains(bandNode.getNodeId())) 621 { 622 this.expandPath(bandNode); 623 } 624 } 625 setDontHandleEvent(false); 626 if (jrf.getSelectedCrosstabEditorPanel() != null) 627 { 628 this.reportElementsSelectionChanged(new ReportElementsSelectionEvent(jrf, getCrosstabReportElement(), jrf.getSelectedCrosstabEditorPanel().getSelectedElements())); 629 } 630 } 631 632 oldJReportFrame = jrf; 633 setCrosstabReportElement( crosstabReportElement); 634 635 jTreeDocument.updateUI(); 636 } 637 638 public void addElementToGroup(DocumentStructureTreeNode parentNode, String subGroup, ReportElement element, List openedPaths) 639 { 640 if (subGroup.equals("")) 642 { 643 DocumentStructureTreeNode newNode = new DocumentStructureTreeNode(element); 644 parentNode.add( newNode); 645 646 if (openedPaths != null && openedPaths.contains(newNode.getNodeId())) 647 { 648 expandPath( (DocumentStructureTreeNode)newNode); 649 } 650 651 return; 652 } 653 String levelGroupName = ""; 654 if (subGroup.indexOf(".")>=0) 655 { 656 levelGroupName = subGroup.substring(0, subGroup.indexOf(".")); 657 subGroup = subGroup.substring(subGroup.indexOf(".")+1); 658 } 659 else 660 { 661 levelGroupName = subGroup; 662 subGroup = ""; 663 } 664 665 for (int i =0; i<parentNode.getChildCount(); ++i) 667 { 668 DocumentStructureTreeNode dmtn = (DocumentStructureTreeNode)parentNode.getChildAt(i); 669 if (dmtn.getUserObject() != null && dmtn.getUserObject() instanceof ElementGroup) 670 { 671 ElementGroup ge = (ElementGroup)dmtn.getUserObject(); 672 if (ge.getName().equals( levelGroupName )) 673 { 674 addElementToGroup(dmtn, subGroup, element, openedPaths); 675 return; 676 } 677 } 678 } 679 680 DocumentStructureTreeNode dmtn = new DocumentStructureTreeNode(new ElementGroup(levelGroupName)); 682 parentNode.add( dmtn ); 683 addElementToGroup(dmtn, subGroup, element, openedPaths); 684 685 if (openedPaths != null && openedPaths.contains(dmtn.getNodeId())) 686 { 687 expandPath( (DocumentStructureTreeNode)dmtn); 688 } 689 690 691 } 692 693 public void expandPath(DocumentStructureTreeNode node) 694 { 695 try { 697 if (node.getParent() != null) 698 { 699 expandPath((DocumentStructureTreeNode)node.getParent()); 700 } 701 jTreeDocument.expandPath(new TreePath (((DocumentStructureTreeNode)node).getPath() )); 702 } catch (Exception ex) 703 { 704 ex.printStackTrace(); 705 } 706 } 707 708 709 public void crosstabLayoutChanged(CrosstabLayoutChangedEvent evt) { 710 711 if (evt.getCrosstabReportElement() == getCrosstabReportElement()) 712 { 713 714 this.updateDocumentStructureTree( MainFrame.getMainInstance().getActiveReportFrame() , getCrosstabReportElement()); 715 } 716 } 717 718 public void reportElementsChanged(ReportElementChangedEvent evt) { 719 720 if (evt.getType() == ReportElementChangedEvent.CHANGED) { 721 for (int ir=0; ir<evt.getElements().size(); ++ir) 722 { 723 ReportElement re = (ReportElement)evt.getElements().elementAt(ir); 724 725 DocumentStructureTreeNode node = findElementTreeNode(re, true); 726 if (node == null) { 727 node = findElementTreeNode(re, false); 730 if (node == null) return; node.removeFromParent(); 733 DocumentStructureTreeNode root = (DocumentStructureTreeNode)jTreeDocument.getModel().getRoot(); 735 for (int i=0; i<root.getChildCount(); ++i) { 736 DocumentStructureTreeNode bandNode = (DocumentStructureTreeNode)root.getChildAt(i); 737 if (bandNode.getUserObject() == re.band) { 738 bandNode.add( node ); 739 setDontHandleEvent(true); 740 if (evt.getJReportFrame().getSelectedCrosstabEditorPanel().getSelectedElements().contains( re )) { 741 jTreeDocument.getSelectionModel().addSelectionPath(new TreePath (new Object [] 742 {root, bandNode,node})); 743 } 744 setDontHandleEvent(false); 745 break; 746 } 747 } 748 } 749 } 750 jTreeDocument.updateUI(); 751 } 752 else if (evt.getType() == ReportElementChangedEvent.REMOVED) { 753 754 updateDocumentStructureTree( MainFrame.getMainInstance().getActiveReportFrame(), getCrosstabReportElement()); 755 jTreeDocument.updateUI(); 756 } 757 else if (evt.getType() == ReportElementChangedEvent.ADDED) { 758 759 updateDocumentStructureTree( MainFrame.getMainInstance().getActiveReportFrame(),getCrosstabReportElement() ); 760 jTreeDocument.updateUI(); 761 } 762 763 764 } 766 767 768 public void reportElementsSelectionChanged(ReportElementsSelectionEvent evt) { 769 770 if (evt.getCrosstabReportElement() == null) return; 771 setDontHandleEvent(true); 772 773 TreePath [] path = jTreeDocument.getSelectionPaths(); 774 if (path != null && evt.getSelectedElements() != null && evt.getSelectedElements().size() == 0 && 775 ( ((DocumentStructureTreeNode) path[0].getLastPathComponent()).getUserObject() instanceof CrosstabCell 776 || ((DocumentStructureTreeNode) path[0].getLastPathComponent()).getUserObject() instanceof ElementGroup)) { 777 setDontHandleEvent(false); 778 return; 779 } 780 781 jTreeDocument.getSelectionModel().clearSelection(); 782 783 784 java.util.Vector v = evt.getSelectedElements(); 785 Enumeration e = v.elements(); 786 while (e.hasMoreElements()) { 787 ReportElement re = (ReportElement)e.nextElement(); 788 DocumentStructureTreeNode enode = findElementTreeNode( re, true); 791 if (enode != null) 793 { 794 jTreeDocument.getSelectionModel().addSelectionPath(new TreePath (enode.getPath())); 795 } 796 797 } 798 799 setDontHandleEvent(false); 800 801 } 802 803 810 public DocumentStructureTreeNode findElementTreeNode( ReportElement re, boolean searchInYourCellOnly) { 811 DocumentStructureTreeNode root = (DocumentStructureTreeNode)jTreeDocument.getModel().getRoot(); 814 for (int i=0; i<root.getChildCount(); ++i) { 815 DocumentStructureTreeNode cellNode = (DocumentStructureTreeNode)root.getChildAt(i); 816 if (!searchInYourCellOnly || cellNode.getUserObject() == re.getCell()) { 817 818 DocumentStructureTreeNode newchild = findElementInTreeNode(cellNode,re); 819 if (newchild != null) return newchild; 820 } 821 } 822 return null; 823 } 824 825 public DocumentStructureTreeNode findElementInTreeNode(DocumentStructureTreeNode parentNode, ReportElement re) 826 { 827 for (int k=0; k<parentNode.getChildCount(); ++k) { 828 DocumentStructureTreeNode child = (DocumentStructureTreeNode)parentNode.getChildAt(k); 829 if (child.getUserObject() == re) { 830 return child; 831 } 832 if (!re.getElementGroup().equals("") || re.getParentElement() != null) 833 { 834 if (child.getUserObject() instanceof ElementGroup || 835 child.getUserObject() instanceof FrameReportElement) 836 { 837 DocumentStructureTreeNode newchild = findElementInTreeNode(child,re); 838 if (newchild != null) return newchild; 839 } 840 } 841 } 842 return null; 843 } 844 845 public boolean isDontHandleEvent() { 846 return dontHandleEvent; 847 } 848 849 public void setDontHandleEvent(boolean dontHandleEvent) { 850 this.dontHandleEvent = dontHandleEvent; 851 } 852 853 public void applyI18n(){ 854 jMenuItemDSB_crosstabProperties.setText(I18n.getString("crosstabStructurePanel.menuItemDSB_crosstabProperties","Crosstab properties")); 856 jMenuItemDSB_crosstabProperties1.setText(I18n.getString("crosstabStructurePanel.menuItemDSB_crosstabProperties1","Crosstab properties")); 857 jMenuItemUngroup.setText(I18n.getString("crosstabStructurePanel.menuItemUngroup","Ungroup")); 858 jMenuItemDS_cut.setText(it.businesslogic.ireport.util.I18n.getString("cut","Cut")); 860 jMenuItemDS_copy.setText(it.businesslogic.ireport.util.I18n.getString("copy","Copy")); 861 jMenuItemDS_paste.setText(it.businesslogic.ireport.util.I18n.getString("paste","Paste")); 862 jMenuItemDS_delete.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete")); 863 jMenuItemMoveUp.setText(it.businesslogic.ireport.util.I18n.getString("moveUp","Move up")); 864 jMenuItemMoveDown.setText(it.businesslogic.ireport.util.I18n.getString("moveDown","Move down")); 865 jMenuItemDSB_properties.setText(it.businesslogic.ireport.util.I18n.getString("cellProperties","Cell properties")); 866 jMenuItemDS_properties.setText(it.businesslogic.ireport.util.I18n.getString("properties","Properties")); 867 jMenuItemDS_cut.setText(it.businesslogic.ireport.util.I18n.getString("cut","Cut")); 868 jMenuItemDS_copy.setText(it.businesslogic.ireport.util.I18n.getString("copy","Copy")); 869 jMenuItemDS_paste.setText(it.businesslogic.ireport.util.I18n.getString("paste","Paste")); 870 jMenuItemDS_delete.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete")); 871 jMenuItemMoveUp.setText(it.businesslogic.ireport.util.I18n.getString("moveUp","Move up")); 872 jMenuItemMoveDown.setText(it.businesslogic.ireport.util.I18n.getString("moveDown","Move down")); 873 jMenuItemDSB_properties.setText(it.businesslogic.ireport.util.I18n.getString("cellProperties","Cell properties")); 874 jMenuItemDS_properties.setText(it.businesslogic.ireport.util.I18n.getString("properties","Properties")); 875 876 ((DefaultMutableTreeNode )this.jTreeDocument.getModel().getRoot()).setUserObject( it.businesslogic.ireport.util.I18n.getString("crossTab","Crosstab")); 877 878 879 } 880 881 public void subDatasetObjectChanged(SubDatasetObjectChangedEvent evt) { 882 883 } 884 885 public void setCutCopyEnabled(boolean enabled) { 886 this.jMenuItemDS_cut.setEnabled(enabled); 887 this.jMenuItemDS_copy.setEnabled(enabled); 888 this.jMenuItemDS_delete.setEnabled(enabled); 889 } 890 891 public void setPasteEnebled(boolean enabled) { 892 this.jMenuItemDS_paste.setEnabled(enabled); 893 } 894 895 public CrosstabReportElement getCrosstabReportElement() { 896 return crosstabReportElement; 897 } 898 899 public void setCrosstabReportElement(CrosstabReportElement crosstabReportElement) { 900 this.crosstabReportElement = crosstabReportElement; 901 } 902 903 public void reportBandChanged(ReportBandChangedEvent evt) { 904 } 905 906 public void crosstabMeasureChanged(CrosstabLayoutChangedEvent evt) { 907 } 908 909 910 } 911 | Popular Tags |