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.ReportBandChangedEvent; 37 import it.businesslogic.ireport.gui.event.ReportListener; 38 import it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener; 39 import it.businesslogic.ireport.util.LanguageChangedListener; 40 import javax.swing.tree.DefaultMutableTreeNode ; 41 import javax.swing.tree.DefaultTreeSelectionModel ; 42 import it.businesslogic.ireport.gui.*; 43 import it.businesslogic.ireport.*; 44 import it.businesslogic.ireport.gui.event.*; 45 import java.util.Enumeration ; 46 import java.util.Vector ; 47 import javax.swing.tree.TreePath ; 48 import it.businesslogic.ireport.chart.gui.*; 49 import it.businesslogic.ireport.gui.docking.GenericDragTargetListener; 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 import it.businesslogic.ireport.util.LanguageChangedEvent; 56 60 public class DocumentStructurePanel extends javax.swing.JPanel implements ReportListener, SubDatasetObjectChangedListener, it.businesslogic.ireport.util.LanguageChangedListener { 61 62 private boolean dontHandleEvent = false; 63 64 private JReportFrame oldJReportFrame = null; 65 66 67 public DocumentStructurePanel() { 68 initComponents(); 69 70 DefaultTreeSelectionModel dtsm = (DefaultTreeSelectionModel )jTreeDocument.getSelectionModel(); 71 dtsm.setSelectionMode( DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION ); 72 73 jTreeDocument.setDropTarget(new DropTarget (this, new GenericDragTargetListener())); 74 75 DocumentStructureTreeNode rootDoc = new DocumentStructureTreeNode(it.businesslogic.ireport.util.I18n.getString("document","Document")); 77 79 javax.swing.tree.DefaultTreeModel modelDoc = new javax.swing.tree.DefaultTreeModel (rootDoc); 80 81 jTreeDocument.setModel( modelDoc ); 82 jTreeDocument.setCellRenderer( new DocumentStructureTreeCellRenderer()); 83 84 } 86 87 92 private void initComponents() { 94 jPopupMenuDocumentStructure = new javax.swing.JPopupMenu (); 95 jMenuItemDS_properties = new javax.swing.JMenuItem (); 96 jMenuItemDS_chartProperties = new javax.swing.JMenuItem (); 97 jSeparator22 = new javax.swing.JSeparator (); 98 jMenuItemMoveUp = new javax.swing.JMenuItem (); 99 jMenuItemMoveDown = new javax.swing.JMenuItem (); 100 jSeparator23 = new javax.swing.JSeparator (); 101 jMenuItemDS_cut = new javax.swing.JMenuItem (); 102 jMenuItemDS_copy = new javax.swing.JMenuItem (); 103 jMenuItemDS_paste = new javax.swing.JMenuItem (); 104 jMenuItemDS_delete = new javax.swing.JMenuItem (); 105 jPopupMenuDocumentStructureBand = new javax.swing.JPopupMenu (); 106 jMenuItemDSB_properties = new javax.swing.JMenuItem (); 107 jPopupMenuDocumentStructureGroup = new javax.swing.JPopupMenu (); 108 jMenuItemUngroup = new javax.swing.JMenuItem (); 109 jScrollPane2 = new javax.swing.JScrollPane (); 110 jTreeDocument = new javax.swing.JTree (); 111 112 jMenuItemDS_properties.setText("Properties"); 113 jMenuItemDS_properties.addActionListener(new java.awt.event.ActionListener () { 114 public void actionPerformed(java.awt.event.ActionEvent evt) { 115 jMenuItemDS_propertiesActionPerformed(evt); 116 } 117 }); 118 119 jPopupMenuDocumentStructure.add(jMenuItemDS_properties); 120 121 jMenuItemDS_chartProperties.setIcon(new javax.swing.ImageIcon ("")); 122 jMenuItemDS_chartProperties.setText("Chart properties"); 123 jMenuItemDS_chartProperties.addActionListener(new java.awt.event.ActionListener () { 124 public void actionPerformed(java.awt.event.ActionEvent evt) { 125 jMenuItemDS_chartPropertiesActionPerformed(evt); 126 } 127 }); 128 129 jPopupMenuDocumentStructure.add(jMenuItemDS_chartProperties); 130 131 jPopupMenuDocumentStructure.add(jSeparator22); 132 133 jMenuItemMoveUp.setText("Move up"); 134 jMenuItemMoveUp.addActionListener(new java.awt.event.ActionListener () { 135 public void actionPerformed(java.awt.event.ActionEvent evt) { 136 jMenuItemMoveUpActionPerformed(evt); 137 } 138 }); 139 140 jPopupMenuDocumentStructure.add(jMenuItemMoveUp); 141 142 jMenuItemMoveDown.setText("Move down"); 143 jMenuItemMoveDown.addActionListener(new java.awt.event.ActionListener () { 144 public void actionPerformed(java.awt.event.ActionEvent evt) { 145 jMenuItemMoveDownActionPerformed(evt); 146 } 147 }); 148 149 jPopupMenuDocumentStructure.add(jMenuItemMoveDown); 150 151 jPopupMenuDocumentStructure.add(jSeparator23); 152 153 jMenuItemDS_cut.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/cut.png"))); 154 jMenuItemDS_cut.setText("Cut"); 155 jMenuItemDS_cut.setEnabled(false); 156 jMenuItemDS_cut.addActionListener(new java.awt.event.ActionListener () { 157 public void actionPerformed(java.awt.event.ActionEvent evt) { 158 jMenuItemDS_cutActionPerformed(evt); 159 } 160 }); 161 162 jPopupMenuDocumentStructure.add(jMenuItemDS_cut); 163 164 jMenuItemDS_copy.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/copy.png"))); 165 jMenuItemDS_copy.setText("Copy"); 166 jMenuItemDS_copy.setEnabled(false); 167 jMenuItemDS_copy.addActionListener(new java.awt.event.ActionListener () { 168 public void actionPerformed(java.awt.event.ActionEvent evt) { 169 jMenuItemDS_copyActionPerformed(evt); 170 } 171 }); 172 173 jPopupMenuDocumentStructure.add(jMenuItemDS_copy); 174 175 jMenuItemDS_paste.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/paste.png"))); 176 jMenuItemDS_paste.setText("Paste"); 177 jMenuItemDS_paste.setEnabled(false); 178 jMenuItemDS_paste.addActionListener(new java.awt.event.ActionListener () { 179 public void actionPerformed(java.awt.event.ActionEvent evt) { 180 jMenuItemDS_pasteActionPerformed(evt); 181 } 182 }); 183 184 jPopupMenuDocumentStructure.add(jMenuItemDS_paste); 185 186 jMenuItemDS_delete.setIcon(new javax.swing.ImageIcon (getClass().getResource("/it/businesslogic/ireport/icons/menu/delete.png"))); 187 jMenuItemDS_delete.setText("Delete"); 188 jMenuItemDS_delete.setEnabled(false); 189 jMenuItemDS_delete.addActionListener(new java.awt.event.ActionListener () { 190 public void actionPerformed(java.awt.event.ActionEvent evt) { 191 jMenuItemDS_deleteActionPerformed(evt); 192 } 193 }); 194 195 jPopupMenuDocumentStructure.add(jMenuItemDS_delete); 196 197 jMenuItemDSB_properties.setText("Band properties"); 198 jMenuItemDSB_properties.addActionListener(new java.awt.event.ActionListener () { 199 public void actionPerformed(java.awt.event.ActionEvent evt) { 200 jMenuItemDSB_propertiesActionPerformed(evt); 201 } 202 }); 203 204 jPopupMenuDocumentStructureBand.add(jMenuItemDSB_properties); 205 206 jMenuItemUngroup.setText("Ungroup"); 207 jMenuItemUngroup.addActionListener(new java.awt.event.ActionListener () { 208 public void actionPerformed(java.awt.event.ActionEvent evt) { 209 jMenuItemUngroupActionPerformed(evt); 210 } 211 }); 212 213 jPopupMenuDocumentStructureGroup.add(jMenuItemUngroup); 214 215 setLayout(new java.awt.BorderLayout ()); 216 217 jTreeDocument.addTreeExpansionListener(new javax.swing.event.TreeExpansionListener () { 218 public void treeCollapsed(javax.swing.event.TreeExpansionEvent evt) { 219 jTreeDocumentTreeCollapsed(evt); 220 } 221 public void treeExpanded(javax.swing.event.TreeExpansionEvent evt) { 222 jTreeDocumentTreeExpanded(evt); 223 } 224 }); 225 jTreeDocument.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener () { 226 public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { 227 jTreeDocumentValueChanged(evt); 228 } 229 }); 230 jTreeDocument.addMouseListener(new java.awt.event.MouseAdapter () { 231 public void mousePressed(java.awt.event.MouseEvent evt) { 232 jTreeDocumentMousePressed(evt); 233 } 234 }); 235 236 jScrollPane2.setViewportView(jTreeDocument); 237 238 add(jScrollPane2, java.awt.BorderLayout.CENTER); 239 I18n.addOnLanguageChangedListener( this ); 242 } 244 private void jMenuItemUngroupActionPerformed(java.awt.event.ActionEvent evt) { 246 if (jTreeDocument.getSelectionCount() > 0) { 247 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 248 if (elementNode.getUserObject() instanceof ElementGroup) { 249 String elementGroupName = ((ElementGroup)elementNode.getUserObject()).getName(); 250 while ( ((DocumentStructureTreeNode)elementNode.getParent()).getUserObject() instanceof ElementGroup) 251 { 252 elementNode = (DocumentStructureTreeNode)elementNode.getParent(); 253 elementGroupName = ((ElementGroup)elementNode.getUserObject()).getName() + "." + elementGroupName; 254 } 255 256 String newElementGroupName = elementGroupName; 257 if (newElementGroupName.lastIndexOf(".")>=0) 258 { 259 newElementGroupName = newElementGroupName.substring(0,newElementGroupName.lastIndexOf(".")); 260 } 261 else 262 { 263 newElementGroupName = ""; 264 } 265 266 267 UnGroupEmentsOperation undoOp = new UnGroupEmentsOperation(MainFrame.getMainInstance().getActiveReportFrame()); 268 Vector elements = MainFrame.getMainInstance().getActiveReportFrame().getReport().getElements(); 269 for (int i=0; i<elements.size(); ++i) 270 { 271 ReportElement element = (ReportElement)elements.elementAt(i); 272 String oldElementGroupName = element.getElementGroup(); 273 if (element.getElementGroup().startsWith(elementGroupName+".") || element.getElementGroup().equals(elementGroupName)) 274 { 275 String tmpElementGroupName = element.getElementGroup().substring(elementGroupName.length()); 276 if (tmpElementGroupName.length() == 0) tmpElementGroupName = newElementGroupName; 277 tmpElementGroupName = newElementGroupName + tmpElementGroupName; 278 if (tmpElementGroupName.startsWith(".")) tmpElementGroupName = tmpElementGroupName.substring(1); 279 280 element.setElementGroup(tmpElementGroupName); 281 undoOp.addElement(element, i,i, oldElementGroupName, tmpElementGroupName); 282 } 283 } 284 285 MainFrame.getMainInstance().getActiveReportFrame().addUndoOperation(undoOp); 286 287 MainFrame.getMainInstance().getActiveReportFrame().fireReportListenerReportElementsChanged(new ReportElementChangedEvent(MainFrame.getMainInstance().getActiveReportFrame(), new Vector () , ReportElementChangedEvent.REMOVED )); 288 } 289 } 290 292 293 } 295 private void jTreeDocumentTreeCollapsed(javax.swing.event.TreeExpansionEvent evt) { } 299 private void jTreeDocumentTreeExpanded(javax.swing.event.TreeExpansionEvent evt) { 302 303 } 305 private void jMenuItemDSB_propertiesActionPerformed(java.awt.event.ActionEvent evt) {if (jTreeDocument.getSelectionCount() > 0) { 307 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 308 if (elementNode.getUserObject() instanceof Band) { 309 String thisBand = ((Band)elementNode.getUserObject()).getName(); 310 MainFrame.getMainInstance().jMenuItemBandsActionPerformed(evt); 311 MainFrame.getMainInstance().getBandsDialog().setSelectedBand( thisBand ); 312 } 313 } 314 } 316 private void jMenuItemDS_deleteActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().deleteSelectedElements(); 318 } 320 private void jMenuItemDS_pasteActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().paste(); 322 } 324 private void jMenuItemDS_copyActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().copy(); 326 } 328 private void jMenuItemDS_cutActionPerformed(java.awt.event.ActionEvent evt) {MainFrame.getMainInstance().getActiveReportFrame().cut(); 330 } 332 private void jMenuItemMoveDownActionPerformed(java.awt.event.ActionEvent evt) {if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 334 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 335 jrf.moveDown(); 336 337 if (jrf.getSelectedElements().size()>0) 338 updateDocumentStructureTree(jrf); 339 340 } 341 } 343 private void jMenuItemMoveUpActionPerformed(java.awt.event.ActionEvent evt) { if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 345 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 346 jrf.moveUp(); 347 this.jTreeDocument.updateUI(); 348 printSelectedPaths("Prima"); 349 if (jrf.getSelectedElements().size()>0) 350 updateDocumentStructureTree(jrf); 351 352 printSelectedPaths("Dopo"); 353 354 } 355 356 } 358 private void jMenuItemDS_chartPropertiesActionPerformed(java.awt.event.ActionEvent evt) { if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 360 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 361 if (jTreeDocument.getSelectionCount() > 0) { 362 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 363 if (elementNode.getUserObject() instanceof ChartReportElement2 ) 364 { 365 ChartPropertiesDialog cpd = new ChartPropertiesDialog(MainFrame.getMainInstance(),true); 366 cpd.setChartElement( (ChartReportElement2)elementNode.getUserObject()); 367 cpd.setVisible(true); 368 } 369 370 } 371 } 372 } 374 public void languageChanged(LanguageChangedEvent evt) { 375 376 this.applyI18n(); 377 } 378 379 380 private void jMenuItemDS_propertiesActionPerformed(java.awt.event.ActionEvent evt) { MainFrame.getMainInstance().getElementPropertiesDialog().setVisible(true); 382 MainFrame.getMainInstance().getElementPropertiesDialog().updateSelection(); 383 } 385 private void jTreeDocumentValueChanged(javax.swing.event.TreeSelectionEvent evt) { if (isDontHandleEvent()) return; 387 388 if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 390 try { 392 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 393 Vector elementsToSelect = new Vector (); 394 395 TreePath [] path = jTreeDocument.getSelectionPaths(); 396 397 398 for (int i=0; i<path.length; ++i) { 399 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)path[i].getLastPathComponent(); 400 if (elementNode.getUserObject() instanceof ReportElement) { 401 elementsToSelect.addElement( (ReportElement)elementNode.getUserObject()); 402 } 403 else if (path.length == 1) { 404 jrf.setSelectedElement(null); 405 return; 406 } 407 else if (elementNode.getUserObject() instanceof ElementGroup) 408 { 409 410 jrf.setSelectedElement(null); 411 return; 412 } 413 } 414 415 jrf.setSelectedElement(null); 416 Enumeration e = elementsToSelect.elements(); 417 while (e.hasMoreElements()) { 418 jrf.addSelectedElement((ReportElement)e.nextElement(), false); 419 } 420 jrf.fireSelectionChangedEvent(); 421 } catch (Exception ex) 422 {} 423 } 425 } 427 private void jTreeDocumentMousePressed(java.awt.event.MouseEvent evt) { if (evt.getButton() == evt.BUTTON3) { 429 if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 430 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 431 jTreeDocument.setSelectionPath( jTreeDocument.getPathForLocation(evt.getX(), evt.getY() ) ); 432 if (jTreeDocument.getSelectionCount() > 0) { 433 DocumentStructureTreeNode elementNode = (DocumentStructureTreeNode)jTreeDocument.getSelectionPath().getLastPathComponent(); 434 if (elementNode.getUserObject() instanceof ReportElement) { 435 jMenuItemDS_chartProperties.setVisible( elementNode.getUserObject() instanceof ChartReportElement2 ); 437 this.jPopupMenuDocumentStructure.show(jTreeDocument, evt.getPoint().x, evt.getPoint().y); 438 439 } else if (elementNode.getUserObject() instanceof Band) { 440 this.jPopupMenuDocumentStructureBand.show(jTreeDocument, evt.getPoint().x, evt.getPoint().y); 442 443 } else if (elementNode.getUserObject() instanceof ElementGroup) { 444 this.jPopupMenuDocumentStructureGroup.show(jTreeDocument, evt.getPoint().x, evt.getPoint().y); 446 447 } 448 } 449 } 450 451 } 452 else if (evt.getButton() == evt.BUTTON1 && evt.getClickCount() == 2) { 453 454 if (MainFrame.getMainInstance().getActiveReportFrame() != null) { 455 456 JReportFrame jrf = MainFrame.getMainInstance().getActiveReportFrame(); 457 if (jrf.getSelectedElements().size() > 0) { 458 MainFrame.getMainInstance().getElementPropertiesDialog().setVisible(true); 459 } 461 } 462 } 463 } 465 public void printSelectedPaths(String prefix) 466 { 467 try { 468 Enumeration enum_extended_paths = jTreeDocument.getExpandedDescendants(new TreePath (new Object []{ jTreeDocument.getModel().getRoot() })); 469 if (enum_extended_paths != null) 470 { 471 while (enum_extended_paths.hasMoreElements()) 472 { 473 TreePath path = (TreePath )enum_extended_paths.nextElement(); 474 } 476 } 477 } catch (Exception ex) 478 { 479 ex.printStackTrace(); 480 } 481 } 482 483 private javax.swing.JMenuItem jMenuItemDSB_properties; 485 private javax.swing.JMenuItem jMenuItemDS_chartProperties; 486 private javax.swing.JMenuItem jMenuItemDS_copy; 487 private javax.swing.JMenuItem jMenuItemDS_cut; 488 private javax.swing.JMenuItem jMenuItemDS_delete; 489 private javax.swing.JMenuItem jMenuItemDS_paste; 490 private javax.swing.JMenuItem jMenuItemDS_properties; 491 private javax.swing.JMenuItem jMenuItemMoveDown; 492 private javax.swing.JMenuItem jMenuItemMoveUp; 493 private javax.swing.JMenuItem jMenuItemUngroup; 494 private javax.swing.JPopupMenu jPopupMenuDocumentStructure; 495 private javax.swing.JPopupMenu jPopupMenuDocumentStructureBand; 496 private javax.swing.JPopupMenu jPopupMenuDocumentStructureGroup; 497 private javax.swing.JScrollPane jScrollPane2; 498 private javax.swing.JSeparator jSeparator22; 499 private javax.swing.JSeparator jSeparator23; 500 private javax.swing.JTree jTreeDocument; 501 503 504 public void updateDocumentStructureTree(JReportFrame jrf) 505 { 506 List openedPaths = null; 507 508 try { 509 510 openedPaths = new ArrayList (); 511 Enumeration enum_extended_paths = jTreeDocument.getExpandedDescendants(new TreePath (new Object []{ jTreeDocument.getModel().getRoot() })); 512 if (enum_extended_paths!=null) 513 { 514 while (enum_extended_paths.hasMoreElements()) 515 { 516 TreePath path = (TreePath )enum_extended_paths.nextElement(); 517 openedPaths.add( ((DocumentStructureTreeNode)path.getLastPathComponent()).getNodeId() ); 518 } 519 } 520 } catch (Exception ex) 521 { 522 ex.printStackTrace(); 523 } 524 525 if (jrf != oldJReportFrame) 526 { 527 if (oldJReportFrame != null) oldJReportFrame.setOpenedNodesDocumentStructure( openedPaths ); 528 if (jrf != null) openedPaths = jrf.getOpenedNodesDocumentStructure(); 529 } 530 531 setDontHandleEvent(true); 532 ((DocumentStructureTreeNode)this.jTreeDocument.getModel().getRoot()).removeAllChildren(); 534 ((javax.swing.tree.DefaultTreeModel )(this.jTreeDocument.getModel())).reload(); 535 536 if (jrf != null) 537 { 538 539 540 Enumeration bands = jrf.getReport().getBands().elements(); 541 while (bands.hasMoreElements()) 542 { 543 Band band = (Band)bands.nextElement(); 544 DocumentStructureTreeNode bandNode = new DocumentStructureTreeNode(band); 545 ((DocumentStructureTreeNode)this.jTreeDocument.getModel().getRoot()).add( bandNode); 546 547 Enumeration elements = jrf.getReport().getElements().elements(); 548 while (elements.hasMoreElements()) 549 { 550 ReportElement element = (ReportElement)elements.nextElement(); 551 if (element.getBand() == band) 552 { 553 String elementGroup = element.getElementGroup(); 554 try { 555 if (element.getParentElement() != null) 556 { 557 DocumentStructureTreeNode parentNode = findElementTreeNode(element.getParentElement(),true); 558 if (parentNode != null) 559 { 560 addElementToGroup(parentNode, elementGroup, element, openedPaths); 561 if (openedPaths != null && openedPaths.contains(parentNode.getNodeId())) 562 { 563 this.expandPath(parentNode); 564 } 565 } 566 567 } 568 else 569 { 570 addElementToGroup(bandNode, elementGroup, element, openedPaths); 571 } 572 573 } catch (Exception ex) 574 { 575 ex.printStackTrace(); 576 } 577 } 578 } 579 if (openedPaths != null && openedPaths.contains(bandNode.getNodeId())) 580 { 581 this.expandPath(bandNode); 582 } 583 } 584 setDontHandleEvent(false); 585 this.reportElementsSelectionChanged(new ReportElementsSelectionEvent(jrf, jrf.getSelectedElements())); 586 } 587 588 oldJReportFrame = jrf; 589 590 jTreeDocument.updateUI(); 591 } 592 593 public void addElementToGroup(DocumentStructureTreeNode parentNode, String subGroup, ReportElement element, List openedPaths) 594 { 595 if (subGroup.equals("")) 597 { 598 DocumentStructureTreeNode newNode = new DocumentStructureTreeNode(element); 599 parentNode.add( newNode); 600 601 if (openedPaths != null && openedPaths.contains(newNode.getNodeId())) 602 { 603 expandPath( (DocumentStructureTreeNode)newNode); 604 } 605 606 return; 607 } 608 String levelGroupName = ""; 609 if (subGroup.indexOf(".")>=0) 610 { 611 levelGroupName = subGroup.substring(0, subGroup.indexOf(".")); 612 subGroup = subGroup.substring(subGroup.indexOf(".")+1); 613 } 614 else 615 { 616 levelGroupName = subGroup; 617 subGroup = ""; 618 } 619 620 for (int i =0; i<parentNode.getChildCount(); ++i) 622 { 623 DocumentStructureTreeNode dmtn = (DocumentStructureTreeNode)parentNode.getChildAt(i); 624 if (dmtn.getUserObject() != null && dmtn.getUserObject() instanceof ElementGroup) 625 { 626 ElementGroup ge = (ElementGroup)dmtn.getUserObject(); 627 if (ge.getName().equals( levelGroupName )) 628 { 629 addElementToGroup(dmtn, subGroup, element, openedPaths); 630 return; 631 } 632 } 633 } 634 635 DocumentStructureTreeNode dmtn = new DocumentStructureTreeNode(new ElementGroup(levelGroupName)); 637 parentNode.add( dmtn ); 638 addElementToGroup(dmtn, subGroup, element, openedPaths); 639 640 if (openedPaths != null && openedPaths.contains(dmtn.getNodeId())) 641 { 642 expandPath( (DocumentStructureTreeNode)dmtn); 643 } 644 645 646 } 647 648 public void expandPath(DocumentStructureTreeNode node) 649 { 650 try { 652 if (node.getParent() != null) 653 { 654 expandPath((DocumentStructureTreeNode)node.getParent()); 655 } 656 jTreeDocument.expandPath(new TreePath (((DocumentStructureTreeNode)node).getPath() )); 657 } catch (Exception ex) 658 { 659 ex.printStackTrace(); 660 } 661 } 662 663 664 public void reportBandChanged(ReportBandChangedEvent evt) { 665 this.updateDocumentStructureTree( evt.getJReportFrame()); 666 } 667 668 public void reportElementsChanged(ReportElementChangedEvent evt) { 669 670 if (evt.getType() == ReportElementChangedEvent.CHANGED) { 671 for (int ir=0; ir<evt.getElements().size(); ++ir) 672 { 673 ReportElement re = (ReportElement)evt.getElements().elementAt(ir); 674 675 DocumentStructureTreeNode node = findElementTreeNode(re, true); 676 if (node == null) { 677 node = findElementTreeNode(re, false); 680 if (node == null) return; node.removeFromParent(); 683 DocumentStructureTreeNode root = (DocumentStructureTreeNode)jTreeDocument.getModel().getRoot(); 685 for (int i=0; i<root.getChildCount(); ++i) { 686 DocumentStructureTreeNode bandNode = (DocumentStructureTreeNode)root.getChildAt(i); 687 if (bandNode.getUserObject() == re.band) { 688 bandNode.add( node ); 689 setDontHandleEvent(true); 690 if (evt.getJReportFrame().getSelectedElements().contains( re )) { 691 jTreeDocument.getSelectionModel().addSelectionPath(new TreePath (new Object [] 692 {root, bandNode,node})); 693 } 694 setDontHandleEvent(false); 695 break; 696 } 697 } 698 } 699 } 700 jTreeDocument.updateUI(); 701 } 702 else if (evt.getType() == ReportElementChangedEvent.REMOVED) { 703 704 715 updateDocumentStructureTree( MainFrame.getMainInstance().getActiveReportFrame() ); 716 jTreeDocument.updateUI(); 717 } 718 else if (evt.getType() == ReportElementChangedEvent.ADDED) { 719 720 updateDocumentStructureTree( MainFrame.getMainInstance().getActiveReportFrame() ); 721 722 760 761 jTreeDocument.updateUI(); 762 } 763 764 765 } 767 768 769 public void reportElementsSelectionChanged(ReportElementsSelectionEvent evt) { 770 771 if (evt.getCrosstabReportElement() != null) return; 772 setDontHandleEvent(true); 773 774 TreePath [] path = jTreeDocument.getSelectionPaths(); 775 if (path != null && evt.getSelectedElements() != null && evt.getSelectedElements().size() == 0 && 776 ( ((DocumentStructureTreeNode) path[0].getLastPathComponent()).getUserObject() instanceof Band 777 || ((DocumentStructureTreeNode) path[0].getLastPathComponent()).getUserObject() instanceof ElementGroup)) { 778 setDontHandleEvent(false); 779 return; 780 } 781 782 jTreeDocument.getSelectionModel().clearSelection(); 783 784 785 java.util.Vector v = evt.getSelectedElements(); 786 Enumeration e = v.elements(); 787 while (e.hasMoreElements()) { 788 ReportElement re = (ReportElement)e.nextElement(); 789 DocumentStructureTreeNode enode = findElementTreeNode( re, true); 792 if (enode != null) 794 { 795 jTreeDocument.getSelectionModel().addSelectionPath(new TreePath (enode.getPath())); 796 } 797 798 } 799 800 setDontHandleEvent(false); 801 802 } 803 804 858 859 866 public DocumentStructureTreeNode findElementTreeNode( ReportElement re, boolean searchInYourBandOnly) { 867 DocumentStructureTreeNode root = (DocumentStructureTreeNode)jTreeDocument.getModel().getRoot(); 870 for (int i=0; i<root.getChildCount(); ++i) { 871 DocumentStructureTreeNode bandNode = (DocumentStructureTreeNode)root.getChildAt(i); 872 if (!searchInYourBandOnly || bandNode.getUserObject() == re.band) { 873 874 DocumentStructureTreeNode newchild = findElementInTreeNode(bandNode,re); 875 if (newchild != null) return newchild; 876 } 877 } 878 return null; 879 } 880 881 public DocumentStructureTreeNode findElementInTreeNode(DocumentStructureTreeNode parentNode, ReportElement re) 882 { 883 for (int k=0; k<parentNode.getChildCount(); ++k) { 884 DocumentStructureTreeNode child = (DocumentStructureTreeNode)parentNode.getChildAt(k); 885 if (child.getUserObject() == re) { 886 return child; 887 } 888 if (!re.getElementGroup().equals("") || re.getParentElement() != null) 889 { 890 if (child.getUserObject() instanceof ElementGroup || 891 child.getUserObject() instanceof FrameReportElement) 892 { 893 DocumentStructureTreeNode newchild = findElementInTreeNode(child,re); 894 if (newchild != null) return newchild; 895 } 896 } 897 } 898 return null; 899 } 900 901 public boolean isDontHandleEvent() { 902 return dontHandleEvent; 903 } 904 905 public void setDontHandleEvent(boolean dontHandleEvent) { 906 this.dontHandleEvent = dontHandleEvent; 907 } 908 909 public void applyI18n(){ 910 jMenuItemDS_chartProperties.setText(I18n.getString("documentStructurePanel.menuItemDS_chartProperties","Chart properties")); 912 jMenuItemUngroup.setText(I18n.getString("documentStructurePanel.menuItemUngroup","Ungroup")); 913 jMenuItemDS_cut.setText(it.businesslogic.ireport.util.I18n.getString("cut","Cut")); 915 jMenuItemDS_copy.setText(it.businesslogic.ireport.util.I18n.getString("copy","Copy")); 916 jMenuItemDS_paste.setText(it.businesslogic.ireport.util.I18n.getString("paste","Paste")); 917 jMenuItemDS_delete.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete")); 918 jMenuItemMoveUp.setText(it.businesslogic.ireport.util.I18n.getString("moveUp","Move up")); 919 jMenuItemMoveDown.setText(it.businesslogic.ireport.util.I18n.getString("moveDown","Move down")); 920 jMenuItemDSB_properties.setText(it.businesslogic.ireport.util.I18n.getString("bandProperties","Band properties")); 921 jMenuItemDS_properties.setText(it.businesslogic.ireport.util.I18n.getString("properties","Properties")); 922 jMenuItemDS_cut.setText(it.businesslogic.ireport.util.I18n.getString("cut","Cut")); 923 jMenuItemDS_copy.setText(it.businesslogic.ireport.util.I18n.getString("copy","Copy")); 924 jMenuItemDS_paste.setText(it.businesslogic.ireport.util.I18n.getString("paste","Paste")); 925 jMenuItemDS_delete.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete")); 926 jMenuItemMoveUp.setText(it.businesslogic.ireport.util.I18n.getString("moveUp","Move up")); 927 jMenuItemMoveDown.setText(it.businesslogic.ireport.util.I18n.getString("moveDown","Move down")); 928 jMenuItemDSB_properties.setText(it.businesslogic.ireport.util.I18n.getString("bandProperties","Band properties")); 929 jMenuItemDS_properties.setText(it.businesslogic.ireport.util.I18n.getString("properties","Properties")); 930 931 ((DefaultMutableTreeNode )this.jTreeDocument.getModel().getRoot()).setUserObject( it.businesslogic.ireport.util.I18n.getString("document","Document")); 932 933 } 934 935 public void subDatasetObjectChanged(SubDatasetObjectChangedEvent evt) { 936 937 } 938 939 public void setCutCopyEnabled(boolean enabled) { 940 this.jMenuItemDS_cut.setEnabled(enabled); 941 this.jMenuItemDS_copy.setEnabled(enabled); 942 this.jMenuItemDS_delete.setEnabled(enabled); 943 } 944 945 public void setPasteEnebled(boolean enabled) { 946 this.jMenuItemDS_paste.setEnabled(enabled); 947 } 948 } 949 | Popular Tags |