1 4 5 package com.calipso.reportgenerator.userinterface; 6 7 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType; 8 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionOrderType; 9 import com.calipso.reportgenerator.reportdefinitions.ReportView; 10 import com.calipso.reportgenerator.userinterface.DimensionValuesSearcherUI; 11 import com.calipso.reportgenerator.common.*; 12 import javax.swing.*; 13 import javax.swing.table.DefaultTableModel ; 14 import java.awt.*; 15 import java.awt.event.*; 16 import java.util.*; 17 import java.util.List ; 18 import java.io.IOException ; 19 import javax.swing.table.*; 20 import com.calipso.reportgenerator.common.InfoException; 21 22 26 public class PivotTable extends JComponent implements FieldPositionListener { 27 28 private Container contentPane; 29 private JPanel pageFields; 30 private JPanel pageFillerRigth; 31 private JScrollPane pageFieldsScrollPane; 32 private JScrollPane centerJScrollPane; 33 private JScrollPane leftCenterScrollPane; 34 private JScrollPane colTableJScroll; 35 private JScrollBar pageFieldScrollBar; 36 private JSplitPane mainSplit; 37 private JPanel mainSplitPanel; 38 private JPanel leftCenterPanel; 39 private JPanel rigthCenterPanel; 40 private JPanel leftSplitNorthPanel; 41 private JPanel centerSplitNorthPanel; 42 private JPanel southRowFieldDropTarget; 43 private JPanel columnPanel; 44 private JPanel southFiller; 45 private JPanel eastFiller; 46 private JPanel columnHeaderPanel; 47 private JPanel northPanel; 48 private JTable datajTable; 49 private JTable rowHeaderjTable; 50 private JTable columnHeaderjTable; 51 private JPanel pageConteinerComponent; 52 private JFrame frame; 53 private JButton maximizar; 54 private JScrollBar horizontal; 55 private JScrollBar vertical; 56 private ReportResult reportResult; 57 private PivotTableFrame pivotTableFrame; 58 private Map changeDimensionLocation; 59 private boolean withTotals; 60 private int page; 61 private int row; 62 private int col; 63 private Map dragPanels; 64 private Map targetPanels; 65 private ColorConditionManager colorConditionManager; 66 private int width; 67 private Map metricStates; 68 private Map rowHeaderDimension; 69 private PivotTableProperties tableProperties; 70 private AplicationView view; 71 private JPanel metrics; 72 private JPopupMenu popupMenu; 73 private final int DEFAULT_COLUMN_WIDTH = 75; 74 private ReportView reportView; 75 76 77 81 public PivotTable(PivotTableFrame pivotTableFrame, ReportView reportView) throws InfoException { 82 col = 0; 83 row = 0; 84 page = 0; 85 width = 0; 86 this.reportView = reportView; 87 this.pivotTableFrame = pivotTableFrame; 88 this.maximizar = pivotTableFrame.getMaximizar(); 89 this.colorConditionManager = new ColorConditionManager(); 90 if (this.reportView== null){ 91 tableProperties = new PivotTableProperties(); 92 tableProperties.setConditionManager(this.colorConditionManager); 93 tableProperties.setWithTotal(true); 94 setReportResult(pivotTableFrame.getReportResult()); 95 initTableProperties(); 96 withTotals = true; 97 }else { 98 tableProperties = new PivotTableProperties(); 99 tableProperties.setConditionManager(this.colorConditionManager); 100 tableProperties.setWithTotal(reportView.getVisibleTotals()); 101 withTotals = reportView.getVisibleTotals(); 102 setReportResult(pivotTableFrame.getReportResult()); 103 initTableProperties(); 104 tableProperties.assignFromView(reportView); 105 } 106 this.changeDimensionLocation = new Hashtable(); 107 setContentPane(pivotTableFrame.getPivotPanel()); 108 setFrame(pivotTableFrame.getFrame()); 109 initComponents(); 110 setColorConditionManager(this.colorConditionManager); 111 setComponentSize(); 112 setRowSize(); 113 setDefaultSize(); 114 if (getRowHeaderDimension().isEmpty()) { 115 mainSplit.setDividerLocation(100); 116 } 117 else{ 118 mainSplit.setDividerLocation(adjustmentSizeSplit()); 119 } 120 } 121 122 126 127 private void initTableProperties() throws InfoException { 128 try { 129 ArrayList rowList = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.ROW); 130 fillColumnsProperties(rowList, DimensionDefinitionLocationType.ROW.toString()); 131 132 ArrayList pageList = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.PAGE); 133 fillColumnsProperties(pageList, DimensionDefinitionLocationType.PAGE.toString()); 134 135 ArrayList columnList = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.COLUMN); 136 fillColumnsProperties(columnList, DimensionDefinitionLocationType.COLUMN.toString()); 137 } 138 catch (Exception e) { 139 throw new InfoException(LanguageTraslator.traslate("227")); 140 141 } 142 getMetricStates(); 143 144 } 145 146 147 150 private void setDefaultSize() { 151 152 for (int index = 0; index < tableProperties.getColumnProperties().size(); index++) { 153 ColumnProperties properties = (ColumnProperties) tableProperties.getColumnProperties().get(index); 154 if (properties.getLocation().compareToIgnoreCase("PAGE") == 0) { 155 properties.setWidth(DEFAULT_COLUMN_WIDTH); 156 } 157 else { 158 if (properties.getLocation().compareToIgnoreCase("COLUMN") == 0) { 159 properties.setWidth(DEFAULT_COLUMN_WIDTH); 160 } 161 } 162 } 163 } 164 165 168 private void setRowSize() { 169 Map map = getRowHeaderDimension(); 170 Iterator iterator = map.values().iterator(); 171 int index = 0; 172 while (iterator.hasNext()) { 173 ColumnProperties properties = (ColumnProperties) iterator.next(); 174 JPanel panel = (JPanel) dragPanels.get(properties.getColumnName()); 175 panel.getPreferredSize().width = DEFAULT_COLUMN_WIDTH; 176 panel.setMinimumSize(panel.getPreferredSize()); 177 panel.setMaximumSize(panel.getPreferredSize()); 178 tableProperties.getColumnProperties().remove(properties); 179 properties.setWidth(DEFAULT_COLUMN_WIDTH); 180 rowHeaderjTable.getColumnModel().getColumn(index).setPreferredWidth(DEFAULT_COLUMN_WIDTH); 181 tableProperties.getColumnProperties().add(properties); 182 index++; 183 } 184 rowHeaderDimension = map; 185 mainSplit.setDividerLocation(DEFAULT_COLUMN_WIDTH * index); 186 mainSplit.setMinimumSize(new Dimension(100, 0)); 187 mainSplit.invalidate(); 188 invaildatePanels(); 189 } 190 191 195 private Map getAllRowColumnProperties() { 196 Map map = new HashMap(); 197 for (int index = 0; index < tableProperties.getColumnProperties().size(); index++) { 198 ColumnProperties properties = (ColumnProperties) tableProperties.getColumnProperties().get(index); 199 if (properties.getLocation().compareToIgnoreCase("ROW") == 0) { 200 Object [] objects = (Object []) changeDimensionLocation.get(properties.getColumnName()); 201 if (objects != null) { 202 properties.setUbication(((Integer ) objects[1]).intValue()); 203 } 204 map.put(properties.getColumnName(), properties); 205 } 206 } 207 return map; 208 } 209 210 214 private void setColorConditionManager(ColorConditionManager colorConditionManager) { 215 this.colorConditionManager = colorConditionManager; 216 tableProperties.setConditionManager(colorConditionManager); 217 ((DataTableCellRenderer) getDatajTable().getDefaultRenderer(Object .class)).setColorConditionManager(colorConditionManager); 218 } 219 220 223 private void initComponents() throws InfoException { 224 dragPanels = new Hashtable(); 225 targetPanels = new Hashtable(); 226 popupMenu = new JPopupMenu(); 227 fillParamValuePopupMenu(); 228 getContentPane().add(createPageFieldComponents(), BorderLayout.NORTH); 229 getContentPane().add(createMainSplitPanel(), BorderLayout.CENTER); 230 getContentPane().add(createMetricsPanel(), BorderLayout.SOUTH); 231 fillContents(getReportResult()); 232 createEvent(); 233 } 234 235 239 private Component createMetricsPanel() { 240 metrics = new JPanel(); 241 metrics.setLayout(new javax.swing.BoxLayout (metrics, javax.swing.BoxLayout.X_AXIS)); 242 List list = getReportResult().getReportQuery().getMetrics(); 243 for (int index = 0; index < list.size(); index++) { 244 QueryMetric metric = (QueryMetric) list.get(index); 245 if(metric.getVisible()) { 246 final JCheckBox checkBox = new JCheckBox(getReportResult().getMetricFromName(metric.getName()).getCaption(), true); 247 checkBox.setName(metric.getName()); 248 metrics.add(checkBox); 249 checkBox.addActionListener(new ActionListener() { 250 public void actionPerformed(ActionEvent e) { 251 try { 252 setMetricsProperties(checkBox); 253 } 254 catch (InfoException e1) { 255 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("137"), e1); 256 } 257 } 258 }); 259 } else { 260 final JCheckBox checkBox = new JCheckBox(getReportResult().getMetricFromName(metric.getName()).getCaption(), false); 261 checkBox.setName(metric.getName()); 262 metrics.add(checkBox); 263 checkBox.addActionListener(new ActionListener() { 264 public void actionPerformed(ActionEvent e) { 265 try { 266 setMetricsProperties(checkBox); 267 } 268 catch (InfoException e1) { 269 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("137"), e1); 270 } 271 } 272 }); 273 } 274 } 275 JScrollPane pane = new JScrollPane(metrics); 276 pane.setSize(new Dimension(getPreferredSize().width, 50)); 277 pane.setPreferredSize(new Dimension(getPreferredSize().width, 50)); 278 pane.setMaximumSize(new Dimension(getPreferredSize().width, 50)); 279 pane.setMinimumSize(new Dimension(getPreferredSize().width, 50)); 280 return pane; 281 } 282 283 288 private void setMetricsProperties(JCheckBox checkBox) throws InfoException { 289 String name = checkBox.getName(); 290 ((MetricState) getMetricStates().get(name)).setVisible(checkBox.isSelected()); 291 { 292 pivotTableFrame.updateQuerry((MetricState) metricStates.get(checkBox.getName()), checkBox, tableProperties); 293 if (!tableProperties.getMetricProperies().contains(getMetricStates().get(name))) { 294 tableProperties.getMetricProperies().add(getMetricStates().get(name)); 295 } 296 else { 297 tableProperties.getMetricProperies().remove(getMetricStates().get(name)); 298 tableProperties.getMetricProperies().add(getMetricStates().get(name)); 299 } 300 fillContents(reportResult); 301 resizeComponent(); 302 303 304 } 305 } 306 307 311 public void updateMetricCheckBoxes() throws InfoException { 312 String name; 313 for (int i = 0; i < metrics.getComponentCount(); i++) { 314 JCheckBox jCheckBox = (JCheckBox) metrics.getComponents()[i]; 315 name = jCheckBox.getName(); 316 jCheckBox.setSelected(reportResult.getReportQuery().getQueryMetricFromName(name).getVisible()); 317 } 318 } 319 320 324 public Map getMetricStates() throws InfoException{ 325 if (metricStates == null) { 326 metricStates = new HashMap(); 327 loadAllMetrics(metricStates); 328 } 329 return metricStates; 330 } 331 332 336 private void createEvent() { 337 338 pageFieldScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener () { 339 public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) { 340 pageFieldScrollBarAdjustmentValueChanged(evt); 341 } 342 }); 343 rowHeaderjTable.addComponentListener(new java.awt.event.ComponentAdapter () { 344 public void componentResized(java.awt.event.ComponentEvent evt) { 345 try { 346 rowHeaderjTableComponentResized(); 347 } 348 catch (InfoException e) { 349 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e); 350 } 351 } 352 }); 353 358 horizontal.addAdjustmentListener(new java.awt.event.AdjustmentListener () { 359 public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) { 360 horizontalScrollBarAdjustmentValue(evt); 361 } 362 }); 363 vertical.addAdjustmentListener(new java.awt.event.AdjustmentListener () { 364 public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) { 365 verticalScrollBarAdjustmentValue(evt); 366 } 367 }); 368 rowHeaderjTable.getTableHeader().addMouseListener(new java.awt.event.MouseAdapter () { 369 public void mouseReleased(java.awt.event.MouseEvent evt) { 370 rowTableHeaderMouseReleased(evt); 371 } 372 }); 373 datajTable.getTableHeader().addMouseListener(new java.awt.event.MouseAdapter () { 374 public void mouseReleased(java.awt.event.MouseEvent evt) { 375 dataTableHeaderMouseReleased(); 376 } 377 }); 378 379 384 385 402 datajTable.addMouseListener(new MouseAdapter() { 403 public void mouseClicked(MouseEvent e) { 404 fillParamValuePopupMenu(e); 405 } 406 }); 407 417 427 } 428 429 public void executeViewBtn() { 430 try { 431 fillComponents(); 432 executeAplicationView(); 433 } 434 catch (InfoException e1) { 435 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e1); 436 437 } 438 } 439 440 444 public void executeEditOrdenValues() throws InfoException { 445 Map dimensionOrders = new HashMap(); 446 Map dimensionCaptions = new HashMap(); 447 Iterator iterator; 448 iterator = tableProperties.getColumnProperties().iterator(); 449 while (iterator.hasNext()) { 450 ColumnProperties properties = (ColumnProperties) iterator.next(); 451 String columnName = properties.getColumnName(); 452 dimensionOrders.put(columnName, new Boolean (properties.getOrder().getType() == DimensionDefinitionOrderType.A_TYPE)); 453 dimensionCaptions.put(columnName, reportResult.getDimensionFromName(columnName).getCaption()); 454 } 455 if (DimensionOrderEditor.editDimensionOrder(getFrame(), dimensionOrders, dimensionCaptions, pivotTableFrame.getReportGeneratorConfiguration())) { 456 iterator = tableProperties.getColumnProperties().iterator(); 457 while (iterator.hasNext()) { 458 ColumnProperties properties = (ColumnProperties) iterator.next(); 459 String columnName = properties.getColumnName(); 460 if (((Boolean ) dimensionOrders.get(columnName)).booleanValue()) { 461 properties.setOrder(DimensionDefinitionOrderType.A); 462 } 463 else { 464 properties.setOrder(DimensionDefinitionOrderType.D); 465 } 466 } 467 getPivotTableFrame().buildNewQuery(tableProperties); 468 fillContents(getReportResult()); 469 } 470 } 471 472 476 public void executeEditDimensionValues() throws InfoException { 477 Map dimensionRankMetrics = new HashMap(); 478 Map fieldCaptions = new HashMap(); 479 List metricNames = new ArrayList(); 480 Iterator iterator; 481 iterator = tableProperties.getColumnProperties().iterator(); 482 while (iterator.hasNext()) { 483 ColumnProperties properties = (ColumnProperties) iterator.next(); 484 String columnName = properties.getColumnName(); 485 String rankMetricName = properties.getRankMetricName(); 486 dimensionRankMetrics.put(columnName, rankMetricName); 487 fieldCaptions.put(columnName, reportResult.getDimensionFromName(columnName).getCaption()); 488 } 489 490 iterator = tableProperties.getMetricProperies().iterator(); 491 while (iterator.hasNext()) { 492 MetricState metricState = (MetricState) iterator.next(); 493 String name = metricState.getName(); 494 metricNames.add(name); 495 fieldCaptions.put(name, metricState.getCaption()); 496 } 497 498 if (RankMetricEditor.editRankMetrics(getFrame(), dimensionRankMetrics, metricNames, fieldCaptions, pivotTableFrame.getReportGeneratorConfiguration())) { 499 iterator = tableProperties.getColumnProperties().iterator(); 500 while (iterator.hasNext()) { 501 ColumnProperties properties = (ColumnProperties) iterator.next(); 502 String columnName = properties.getColumnName(); 503 properties.setRankMetricName((String ) dimensionRankMetrics.get(columnName)); 504 } 505 pivotTableFrame.buildNewQuery(tableProperties); 506 fillContents(getReportResult()); 507 } 508 } 509 510 511 514 private void fillParamValuePopupMenu() { 515 DrillDownSpec drillDownSpec = null; 516 Iterator iterator = reportResult.getReportSpec().getDrillDownSpecs().iterator(); 517 while (iterator.hasNext()) { 518 drillDownSpec = (DrillDownSpec) iterator.next(); 519 JMenuItem item = new JMenuItem(drillDownSpec.getDescription()); 520 popupMenu.add(item); 521 final DrillDownSpec drillDownSpec1 = drillDownSpec; 522 item.addActionListener(new ActionListener() { 523 public void actionPerformed(ActionEvent e) { 524 try { 525 pivotTableFrame.drillDown(drillDownSpec1, getMapDrillDown()); 526 } 527 catch (InfoException e1) { 528 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("151"), e1); 529 } 530 } 531 }); 532 } 533 } 534 535 539 private void fillParamValuePopupMenu(MouseEvent e) { 540 if (e.getButton() == 3) { 541 popupMenu.show(datajTable, e.getPoint().x, e.getPoint().y); 542 } 543 } 544 545 549 private Map getMapDrillDown() { 550 Map values = new Hashtable(); 551 String dimensionName, value; 552 Object [] rowsDesc = getRowModel().getValueFrom(getDatajTable().getSelectedRow()); 553 for (int j = 0; j < getReportResult().getReportQuery().getRowDimensions().size(); j++) { 554 dimensionName = ((QueryDimension) getReportResult().getReportQuery().getRowDimensions().get(j)).getName(); 555 if (rowsDesc[j] != null) { 556 value = rowsDesc[j].toString(); 557 values.put(dimensionName, value); 558 } 559 } 560 561 Object [] columnDesc = getColModel().getValueFrom(getDatajTable().getSelectedColumn()); 562 for (int j = 0; j < getReportResult().getReportQuery().getColumnDimensions().size(); j++) { 563 dimensionName = ((QueryDimension) getReportResult().getReportQuery().getColumnDimensions().get(j)).getName(); 564 if (columnDesc[j] != null) { 565 value = columnDesc[j].toString(); 566 values.put(dimensionName, value); 567 } 568 } 569 return values; 570 } 571 572 576 public void executeAplicationView() throws InfoException { 577 view = new AplicationView(new JFrame(), true, this, getPivotTableFrame().getMicroReport()); 578 view.setVisible(true); 579 view.addWindowListener(new WindowAdapter() { 580 public void windowClosed(WindowEvent e) { 581 try { 582 updateFromView(); 583 } 584 catch (InfoException ex) { 585 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), ex); 586 } 587 588 } 589 }); 590 } 591 592 595 private void updateFromView() throws InfoException { 596 fillContents(reportResult); 597 setColorConditionManager(tableProperties.getConditionManager()); 598 DefaultTableModel tableDataModel = (DefaultTableModel ) getDatajTable().getModel(); 599 tableDataModel.fireTableChanged(null); 600 dataTableHeaderMouseReleased(); 601 maximizarActionPerformed(); 602 rowHeaderjTable.revalidate(); 603 invaildatePanels(); 604 updateMetricCheckBoxes(); 605 } 606 607 public void applyView(String reportViewId) { 608 PivotTableProperties pivoteTableProperties = getTableProperties(); 609 pivoteTableProperties.setConditionManager(getColorConditionManager()); 610 try { 611 reportView = getPivotTableFrame().getReportManager().getReportViewFromID(reportViewId,reportResult.getReportSpec().getDefinitionId(),getPivotTableFrame().getUserID()); 612 pivoteTableProperties.assignFromView(reportView); 613 getPivotTableFrame().buildNewQuery(pivoteTableProperties); 614 updateFromView(); 615 } catch (InfoException e) { 616 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("368"), e); 617 } 618 } 619 622 private void updateTableProperties(String positionName, String fieldName) { 623 Iterator iterator = tableProperties.getColumnProperties().iterator(); 624 while (iterator.hasNext()) { 625 ColumnProperties properties = (ColumnProperties) iterator.next(); 626 if (properties.getColumnName().compareToIgnoreCase(fieldName) == 0) { 627 properties.setLocation(positionName); 628 } 629 } 630 rowHeaderDimension = getAllRowColumnProperties(); 631 updateTablePropertiesUbications(); 632 633 } 634 635 638 private void updateTablePropertiesUbications() { 639 for (int i = 0; i < tableProperties.getColumnProperties().size(); i++) { 640 ColumnProperties properties = (ColumnProperties) tableProperties.getColumnProperties().get(i); 641 Object [] object = (Object []) changeDimensionLocation.get(properties.getColumnName()); 642 properties.setUbication(((Integer ) object[1]).intValue()); 643 } 644 rowHeaderDimension = getAllRowColumnProperties(); 645 } 646 647 public void executeSearcher() { 648 if(getDatajTable().getSelectedColumns().length == 1 && getDatajTable().getSelectedRows().length == 1) { 649 JFrame subFrame = new JFrame(); 650 DimensionValuesSearcherUI searcherUI = new DimensionValuesSearcherUI(subFrame, true, reportResult, this, pivotTableFrame.getReportGeneratorConfiguration()); 651 searcherUI.setVisible(true); 652 validate(); 653 } else { 654 JOptionPane.showMessageDialog(this, LanguageTraslator.traslate("283")); 655 } 656 } 657 658 public void executeExcelFormatSerializer() throws IOException { 659 ExcelFormatSerializer serializer = new ExcelFormatSerializer(this); 660 JFileChooser fileChooser = new JFileChooser(); 661 int returnVal = fileChooser.showSaveDialog(this); 662 if(returnVal == JFileChooser.APPROVE_OPTION) { 663 String path = fileChooser.getSelectedFile().getPath(); 664 serializer.serializeTo(path); 665 } 666 } 667 668 671 public void executeSemafore() { 672 ColorConditionUI sem = null; 673 ColorConditionManager clon = null; 674 try { 675 676 clon = (ColorConditionManager) colorConditionManager.clone(); 677 JFrame frame = new JFrame(); 678 sem = new ColorConditionUI(frame, true, clon, getMetricStates(), pivotTableFrame.getReportGeneratorConfiguration()); 679 } 680 catch (Exception e) { 681 InfoException infoException = new InfoException(LanguageTraslator.traslate("219")); 682 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("219"), infoException); 683 } 684 sem.setVisible(true); 685 setColorConditionManager(clon); 686 DefaultTableModel tableDataModel = (DefaultTableModel ) getDatajTable().getModel(); 687 tableDataModel.fireTableChanged(null); 688 } 689 690 691 695 private void loadAllMetrics(Map states) throws InfoException{ 696 java.util.List list = reportResult.getReportQuery().getMetrics(); 697 for (int index = 0; index < list.size(); index++) { 698 QueryMetric queryMetric = (QueryMetric) list.get(index); 699 ReportMetricSpec metricSpec = reportResult.getMetricFromName(queryMetric.getName()); 700 if(metricSpec!=null){ 701 MetricState metricState = new MetricState(metricSpec); 702 metricState.setVisible(queryMetric.getVisible()); 703 states.put(metricSpec.getName(), metricState); 704 tableProperties.setVisibleMetrics(metricState); 705 }else{ 706 throw new InfoException(LanguageTraslator.traslate("377") + " " + queryMetric.getName()); 707 } 708 } 709 } 710 711 715 private void dataTableHeaderMouseReleased() { 716 String width = null; 717 if (pivotTableFrame.isSelected()) { 718 if (rowHeaderjTable.getTableHeader().isVisible()) { 719 for (int index = 0; index < datajTable.getTableHeader().getColumnModel().getColumnCount(); index++) { 720 width = Integer.toString(datajTable.getColumnModel().getColumn(index).getPreferredWidth()); 721 datajTable.getTableHeader().getColumnModel().getColumn(index). 722 setHeaderValue(new Integer (index)); 723 columnHeaderjTable.getTableHeader().getColumnModel().getColumn(index).setPreferredWidth(Integer.parseInt(width)); 724 columnHeaderjTable.getTableHeader().getColumnModel().getColumn(index).setMinWidth(30); 725 datajTable.getTableHeader().getColumnModel().getColumn(index).setMinWidth(30); 726 } 727 datajTable.getTableHeader().setPreferredSize(new Dimension(0, 16)); 728 datajTable.getTableHeader().revalidate(); 729 } 730 else { 731 pivotTableFrame.setState(false); 732 datajTable.getTableHeader().setPreferredSize(new Dimension(0, 16)); 733 } 734 } 735 } 736 737 742 private void rowTableHeaderMouseReleased(MouseEvent evt) { 743 int width = 0; 744 int heigth = 0; 745 int col = 0; 746 if (rowHeaderjTable.getTableHeader().isVisible()) { 747 col = rowHeaderjTable.columnAtPoint(evt.getPoint()); 748 if (col < 0) 749 col = 0; 750 width = rowHeaderjTable.getTableHeader().getColumnModel().getColumn(col).getWidth(); 751 for (Iterator iterator = targetPanels.values().iterator(); iterator.hasNext();) { 752 JPanel panel1 = (JPanel) iterator.next(); 753 panel1.setMinimumSize(new Dimension(30, (int) panel1.getPreferredSize().getHeight())); 754 if (panel1.getName() == DimensionDefinitionLocationType.ROW.toString() && panel1.getComponentCount() > 0) { 755 DragSourcePanel drag = (DragSourcePanel) panel1.getComponent(col); 756 drag.setMinimumSize(new Dimension(30, (int) drag.getPreferredSize().getHeight())); 757 drag.setPreferredSize(new Dimension(width, (int) drag.getPreferredSize().getHeight())); 758 panel1.setPreferredSize(new Dimension(width, (int) panel1.getPreferredSize().getHeight())); 759 heigth = (int) panel1.getPreferredSize().getHeight(); 760 panel1.setPreferredSize(new Dimension(width, heigth)); 761 rowHeaderjTable.getTableHeader().getColumnModel().getColumn(col).setMinWidth(30); 762 rowHeaderjTable.revalidate(); 763 } 764 } 765 Rectangle rec = rowHeaderjTable.getCellRect(0, rowHeaderjTable.getColumnCount(), true); 766 mainSplit.setDividerLocation(rec.x); 767 } 768 } 769 770 775 private void horizontalScrollBarAdjustmentValue(AdjustmentEvent evt) { 776 int widrh = datajTable.getPreferredScrollableViewportSize().width; 777 float porc = (widrh * 10) / 100; 778 horizontal.setUnitIncrement((int) porc); 779 colTableJScroll.getHorizontalScrollBar().setValue(evt.getAdjustable().getValue()); 780 centerJScrollPane.getHorizontalScrollBar().setValue(evt.getAdjustable().getValue()); 781 } 782 783 787 private void verticalScrollBarAdjustmentValue(AdjustmentEvent evt) { 788 leftCenterScrollPane.getVerticalScrollBar().setValue(evt.getAdjustable().getValue()); 789 centerJScrollPane.getVerticalScrollBar().setValue(evt.getAdjustable().getValue()); 790 } 791 792 793 797 public void maximizarActionPerformed() { 798 if (pivotTableFrame.isSelected()) { 799 for (int index = 0; index < rowHeaderjTable.getTableHeader().getColumnModel().getColumnCount(); index++) { 800 rowHeaderjTable.getTableHeader().getColumnModel().getColumn(index). 801 setHeaderValue(Integer.toString(index)); 802 rowHeaderjTable.getTableHeader().getColumnModel().getColumn(index).setMinWidth(20); 803 } 804 for (int index = 0; index < datajTable.getTableHeader().getColumnModel().getColumnCount(); index++) { 805 datajTable.getTableHeader().getColumnModel().getColumn(index). 806 setHeaderValue(Integer.toString(index)); 807 } 808 rowHeaderjTable.getTableHeader().setPreferredSize(new Dimension(0, 18)); 809 datajTable.getTableHeader().setPreferredSize(new Dimension(0, 16)); 810 rowHeaderjTable.getTableHeader().setReorderingAllowed(false); 811 datajTable.getTableHeader().setReorderingAllowed(false); 812 813 } 814 else { 815 rowHeaderjTable.getTableHeader().setPreferredSize(new Dimension(0, 0)); 816 datajTable.getTableHeader().setPreferredSize(new Dimension(0, 0)); 817 } 818 rowHeaderjTable.getTableHeader().getColumnModel().setColumnMargin(0); 819 rowHeaderjTable.getTableHeader().updateUI(); 820 datajTable.getTableHeader().getColumnModel().setColumnMargin(0); 821 datajTable.getTableHeader().updateUI(); 822 } 823 824 828 private void rowHeaderjTableComponentResized() throws InfoException { 829 setRowDimensionMap(); 830 setSize(); 831 invaildatePanels(); 832 } 833 834 838 private void pageFieldScrollBarAdjustmentValueChanged(AdjustmentEvent evt) { 839 int value = evt.getValue(); 840 pageFieldsScrollPane.getHorizontalScrollBar().setValue(value); 841 } 842 843 846 private void setComponentSize() { 847 Dimension dim = leftSplitNorthPanel.getPreferredSize(); 848 dim.width = columnPanel.getPreferredSize().width; 849 dim.height += columnPanel.getPreferredSize().height - 5; 850 leftSplitNorthPanel.setPreferredSize(dim); 851 } 852 853 856 private void resizeComponent() { 857 Dimension dimension = northPanel.getPreferredSize(); 858 leftSplitNorthPanel.setPreferredSize(dimension); 859 leftSplitNorthPanel.revalidate(); 860 } 861 862 865 866 private void setSize() { 867 int width = 0; 868 int index = 0; 869 rowHeaderjTable.validate(); 870 Iterator iterator = getAllRowColumnProperties().values().iterator(); 871 while (iterator.hasNext()) { 872 ColumnProperties properties = (ColumnProperties) iterator.next(); 873 JPanel panel = (JPanel) dragPanels.get(properties.getColumnName()); 874 width = properties.getWidth(); 875 if (index == 0) { 876 width++; 877 } 878 panel.setPreferredSize(new Dimension(width, (int) panel.getPreferredSize().getHeight())); 879 ((JPanel) panel.getParent()).revalidate(); 880 panel.revalidate(); 881 rowHeaderjTable.invalidate(); 882 ((HeaderTableUI)rowHeaderjTable.getUI()).resetFinals(); 883 index++; 884 } 885 } 886 887 891 private Component createMainSplitPanel() { 892 mainSplitPanel = new JPanel(); 893 mainSplit = new JSplitPane(); 894 mainSplit.setLeftComponent(createLeftCenterPanel()); 895 mainSplit.setRightComponent(createRigthCenterPanel()); 896 mainSplitPanel.setLayout(new BorderLayout()); 897 mainSplitPanel.add(mainSplit, BorderLayout.CENTER); 898 mainSplit.setDividerSize(3); 899 return mainSplitPanel; 900 } 901 902 906 private Component createRigthCenterPanel() { 907 rigthCenterPanel = new JPanel(); 908 rigthCenterPanel.setLayout(new BorderLayout()); 909 rigthCenterPanel.add(createNorthPanel(), BorderLayout.NORTH); 910 rigthCenterPanel.add(createCenterJScrollPane(), BorderLayout.CENTER); 911 rigthCenterPanel.add(createHorizontalScrollBar(), BorderLayout.SOUTH); 912 centerJScrollPane.setHorizontalScrollBar(horizontal); 913 centerJScrollPane.setVerticalScrollBar(createVeritcalScrollBar()); 914 return rigthCenterPanel; 915 } 916 917 921 private JScrollBar createVeritcalScrollBar() { 922 vertical = new JScrollBar(JScrollBar.VERTICAL); 923 return vertical; 924 } 925 926 930 private Component createHorizontalScrollBar() { 931 horizontal = new JScrollBar(JScrollBar.HORIZONTAL); 932 JPanel horizontalPanel = new JPanel(new BorderLayout()); 933 horizontalPanel.add(horizontal, BorderLayout.CENTER); 934 return horizontalPanel; 935 } 936 937 941 private Component createNorthPanel() { 942 northPanel = new JPanel(); 943 northPanel.setLayout(new BorderLayout()); 944 northPanel.add(createNorthJPanel(), BorderLayout.CENTER); 945 return northPanel; 946 } 947 948 952 private Component createNorthJPanel() { 953 JPanel component = new JPanel(); 954 component.setLayout(new BorderLayout()); 955 component.add(createEastFiller(), BorderLayout.EAST); 956 component.add(createColumnHeaderPanel(), BorderLayout.CENTER); 957 return component; 958 } 959 960 964 private Component createColumnHeaderPanel() { 965 columnHeaderPanel = new JPanel(); 966 columnHeaderPanel.setLayout(new BorderLayout()); 967 columnHeaderPanel.add(createColumnPanel(), BorderLayout.SOUTH); 968 columnHeaderPanel.add(createColumnDropTarget(), BorderLayout.NORTH); 969 return columnHeaderPanel; 970 } 971 972 976 private Component createColumnPanel() { 977 columnPanel = new JPanel(); 978 columnPanel.setLayout(new BorderLayout()); 979 columnPanel.add(createColTableJScroll(), BorderLayout.CENTER); 980 return columnPanel; 981 } 982 983 988 private Component createColumnDropTarget() { 989 JComponent panel = createTargetPanel(DimensionDefinitionLocationType.COLUMN.toString(), Color.WHITE); 990 panel.setPreferredSize(new Dimension(0, 15)); 991 return panel; 992 } 993 994 998 private Component createEastFiller() { 999 eastFiller = new JPanel(); 1000 eastFiller.setLayout(new BorderLayout()); 1001 eastFiller.setPreferredSize(new Dimension(15, 0)); 1002 return eastFiller; 1003 } 1004 1005 1009 private Component createCenterJScrollPane() { 1010 centerJScrollPane = new JScrollPane(); 1011 centerJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 1012 centerJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 1013 JPanel aux = new JPanel(new BorderLayout()); 1014 aux.add(createTableData(), BorderLayout.CENTER); 1015 aux.add(datajTable.getTableHeader(), BorderLayout.NORTH); 1016 centerJScrollPane.getViewport().add(aux); 1017 return centerJScrollPane; 1018 } 1019 1020 1024 private Component createColTableJScroll() { 1025 colTableJScroll = new JScrollPane(); 1026 colTableJScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 1027 colTableJScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 1028 colTableJScroll.setAutoscrolls(true); 1029 JPanel aux = new JPanel(); 1030 JViewport view = new JViewport(); 1031 aux.setLayout(new BorderLayout()); 1032 aux.add(createColumnHeaderTable(), BorderLayout.CENTER); 1033 view.add(aux, BorderLayout.NORTH); 1034 colTableJScroll.setViewport(view); 1035 return colTableJScroll; 1036 } 1037 1038 1042 private JTable createColumnHeaderTable() { 1043 columnHeaderjTable = new JTable(); 1044 columnHeaderjTable.setDefaultRenderer(Object .class, new HeaderTableRenderer()); 1045 columnHeaderjTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN); 1046 columnHeaderjTable.setUI(new ColumnHeaderTableUI()); 1047 columnHeaderjTable.addMouseListener(new MouseAdapter() { 1048 public void mouseReleased(MouseEvent e) { 1049 try { 1050 changeNodeState(e); 1051 } catch (Exception el) { 1052 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("328"),el); 1053 } 1054 } 1055 }); 1056 return columnHeaderjTable; 1057 } 1058 1059 1060 protected DimensionValueNode getRowsRoot(){ 1061 return ((HeaderTableModel)getRowHeaderjTable().getModel()).getDimensionValueNode(); 1062 } 1063 1064 protected DimensionValueNode getColumnsRoot(){ 1065 return ((HeaderTableModel)getColumnHeaderjTable().getModel()).getDimensionValueNode(); 1066 } 1067 1068 1072 public void fillContents(ReportResult reportResult) throws InfoException { 1073 removeAllPanels(); 1074 JTable rowTable = getRowHeaderjTable(); 1075 JTable colTable = getColumnHeaderjTable(); 1076 JTable dataTable = getDatajTable(); 1077 fillComponents(); 1078 Vector dataVector = ((CubeReportResult)reportResult).getDataVector(); 1079 TableModel dataModel; 1080 if (dataVector!= null){ 1081 dataModel = new DefaultTableModel (dataVector,getColumnsNames(((Vector)dataVector.get(0)).size())); 1082 }else{ 1083 dataVector = new Vector(); 1084 dataModel = new DefaultTableModel (dataVector,null); 1085 } 1086 1087 dataTable.setModel(dataModel); 1088 if (dataVector.size() > 0) { 1089 rowTable.setModel(((CubeReportResult)reportResult).getRowsModel()); 1090 colTable.setModel(((CubeReportResult)reportResult).getColumnsModel()); 1091 } 1092 1098 DefaultTableModel tableDataModel = (DefaultTableModel ) dataTable.getModel(); 1099 tableDataModel.fireTableChanged(null); 1100 if (!getRowHeaderDimension().isEmpty()) { 1101 applyDimensionColumnProperties(); 1102 invaildatePanels(); 1103 } 1104 1105 pivotTableFrame.setState(false); 1107 maximizarActionPerformed(); 1108 if (getRowHeaderDimension().isEmpty()) { 1109 mainSplit.setDividerLocation(100); 1110 } 1111 else { 1112 int heigth = pivotTableFrame.getFrame().getContentPane().getPreferredSize().height; 1113 leftCenterPanel.setPreferredSize(new Dimension(adjustmentSizeSplit(),heigth)); 1114 setSize(); 1115 invaildatePanels(); 1116 } 1117 mainSplit.invalidate(); 1118 } 1119 1120 private void applyDimensionColumnProperties() { 1121 Iterator iterator = tableProperties.getColumnProperties().iterator(); 1122 int ubication = 0; 1123 while (iterator.hasNext()) { 1124 ColumnProperties properties = (ColumnProperties) iterator.next(); 1125 if (DimensionDefinitionLocationType.ROW.toString().compareToIgnoreCase(properties.getLocation()) == 0) { 1126 ubication = properties.getUbication(); 1127 if (rowHeaderjTable.getColumnModel().getColumnCount() >0 ){ 1128 rowHeaderjTable.getColumnModel().getColumn(ubication).setPreferredWidth(properties.getWidth()); 1129 } 1130 } 1131 } 1132 } 1133 1134 1137 private void setRowDimensionMap() throws InfoException { 1138 Map rowDimension = getAllRowColumnProperties(); 1139 for (int index = 0; index < rowHeaderjTable.getModel().getColumnCount(); index++) { 1140 if (!rowDimension.isEmpty()) { 1141 1142 JPanel panel = (JPanel) targetPanels.get(DimensionDefinitionLocationType.ROW.toString()); 1143 DragSourcePanel sourcePanel = (DragSourcePanel) panel.getComponent(index); 1144 ColumnProperties properties = tableProperties.getRowColumn(sourcePanel.getName()); 1145 properties.setWidth(rowHeaderjTable.getColumnModel().getColumn(index).getWidth()); 1146 properties.setColumnName(sourcePanel.getName()); 1147 ArrayList list = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.valueOf(panel.getName())); 1148 QueryDimension queryDimension = (QueryDimension) list.get(index); 1149 properties.setOrder(queryDimension.getOrder()); 1150 properties.setLocation(DimensionDefinitionLocationType.ROW.toString()); 1151 rowDimension.put(sourcePanel.getName(), properties); 1152 rowDimension.put(properties.getColumnName(), properties); 1153 } 1154 } 1155 tableProperties.updateColumnsProperties(); 1156 rowHeaderDimension = rowDimension; 1157 } 1158 1159 1162 private int adjustmentSizeSplit() { 1163 Map rowDimension = getAllRowColumnProperties(); 1164 int widthSplit = 0; 1165 if (!rowDimension.isEmpty()) { 1166 Iterator iterator = rowDimension.values().iterator(); 1167 while (iterator.hasNext()) { 1168 ColumnProperties properties = (ColumnProperties) iterator.next(); 1169 if (properties != null) { 1170 widthSplit += properties.getWidth() + 2; 1171 } 1172 } 1173 } 1174 return widthSplit; 1175 } 1176 1177 1178 1181 private void removeAllPanels() { 1182 Iterator iterator = targetPanels.values().iterator(); 1183 while (iterator.hasNext()) { 1184 DropTargetPanel panel = (DropTargetPanel) iterator.next(); 1185 if (panel.getComponentCount() > 0) { 1186 panel.removeAllComponents(); 1187 } 1188 } 1189 changeDimensionLocation = new HashMap(); 1190 dragPanels = new Hashtable(); 1191 page = 0; 1192 col = 0; 1193 row = 0; 1194 } 1195 1196 1200 private void changeNodeState(MouseEvent e) throws InfoException { 1201 JTable comp = (JTable) e.getComponent(); 1202 int row = comp.rowAtPoint(e.getPoint()); 1203 int col = comp.columnAtPoint(e.getPoint()); 1204 Rectangle rect = comp.getCellRect(row, col, true); 1205 double cellx = e.getPoint().getX() - rect.getX(); 1206 double celly = e.getPoint().getY() - rect.getY(); 1207 HeaderTableRenderer renderer = (HeaderTableRenderer) comp.getDefaultRenderer(Object .class); 1208 int iconWidth = renderer.getIconWidth(); 1209 int iconHeight = renderer.getIconHeight(); 1210 if (cellx <= iconWidth && celly <= iconHeight) { 1211 HeaderTableModel model = (HeaderTableModel) comp.getModel(); 1212 boolean stateChanged = model.changeNodeState(row, col); 1213 if (stateChanged) { 1214 boolean isDistributed = pivotTableFrame.getReportGeneratorConfiguration().getIsDistributed(); 1215 Vector dataVector = pivotTableFrame.getReportManager().getUpdatedDataModel(pivotTableFrame.getReportHandle(), model.getMode(), row, col, isDistributed); 1216 1217 TableModel dataModel = new DefaultTableModel (dataVector,getColumnsNames(((Vector)dataVector.get(0)).size())); 1218 getDatajTable().setModel(dataModel); 1219 getDatajTable().revalidate(); 1220 1221 int count; 1222 if (model.getMode() == HeaderTableModel.MODE_ROW) { 1223 ((HeaderTableUI)rowHeaderjTable.getUI()).resetFinals(); 1224 count = dataVector.size(); 1225 ((HeaderTableModel) comp.getModel()).setRowCount(count); 1226 HeaderTableModel tm = ((HeaderTableModel) comp.getModel()); 1227 tm.fireTableChanged(null); 1228 setSize(); 1229 } 1230 else { 1231 ((HeaderTableUI)columnHeaderjTable.getUI()).resetFinals(); 1232 count = ((Vector)dataVector.get(0)).size(); 1233 ((HeaderTableModel) comp.getModel()).setRowCount(count); 1234 HeaderTableModel tm = ((HeaderTableModel) comp.getModel()); 1235 DefaultTableModel tableDataModel = (DefaultTableModel ) datajTable.getModel(); 1236 tableDataModel.fireTableChanged(null); 1237 tm.fireTableChanged(null); 1238 revalidateTable(); 1239 } 1240 } 1241 } 1242 } 1243 1244 1245 1248 private void revalidateTable() { 1249 for (int index = 0; index < datajTable.getModel().getColumnCount(); index++) { 1250 columnHeaderjTable.getColumnModel().getColumn(index).setWidth(datajTable.getTableHeader().getColumnModel().getColumn(index).getWidth()); 1251 } 1252 } 1253 1254 1258 private Component createTableData() { 1259 datajTable = new JTable(); 1260 DataTableCellRenderer cellRenderer = new DataTableCellRenderer(colorConditionManager, getReportResult(), Color.WHITE); 1261 cellRenderer.setHorizontalAlignment(JLabel.RIGHT); 1262 datajTable.setDefaultRenderer(Object .class, cellRenderer); 1263 datajTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN); 1264 datajTable.setColumnSelectionAllowed(true); 1265 datajTable.setAutoscrolls(false); 1266 datajTable.getTableHeader().setPreferredSize(new Dimension(0, 0)); 1267 datajTable.setDefaultEditor(Object .class, null); 1268 return datajTable; 1269 } 1270 1271 1275 private Component createLeftCenterPanel() { 1276 leftCenterPanel = new JPanel(); 1277 leftCenterPanel.setLayout(new BorderLayout()); 1278 leftCenterPanel.add(createLeftSplitNorthPanel(), BorderLayout.NORTH); 1279 leftCenterPanel.add(createCenterSplitPanel(), BorderLayout.CENTER); 1280 leftCenterPanel.add(createSouthFiller(), BorderLayout.SOUTH); 1281 return leftCenterPanel; 1282 } 1283 1284 1288 private Component createSouthFiller() { 1289 southFiller = new JPanel(); 1290 southFiller.setLayout(new BorderLayout()); 1291 southFiller.setPreferredSize(new Dimension(0, 15)); 1292 return southFiller; 1293 } 1294 1295 1299 private Component createCenterSplitPanel() { 1300 centerSplitNorthPanel = new JPanel(); 1301 centerSplitNorthPanel.setLayout(new BorderLayout()); 1302 centerSplitNorthPanel.add(createLeftCenterScrollPane(), BorderLayout.CENTER); 1303 return centerSplitNorthPanel; 1304 } 1305 1306 1310 private Component createLeftCenterScrollPane() { 1311 leftCenterScrollPane = new JScrollPane(); 1312 leftCenterScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 1313 leftCenterScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 1314 leftCenterScrollPane.getViewport().add(createRowHeaderjTable(), BorderLayout.CENTER); 1315 return leftCenterScrollPane; 1316 } 1317 1318 1322 private Component createRowHeaderjTable() { 1323 rowHeaderjTable = new JTable(); 1324 rowHeaderjTable.setDefaultRenderer(Object .class, new HeaderTableRenderer()); 1325 rowHeaderjTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); 1326 rowHeaderjTable.getTableHeader().setPreferredSize(new Dimension(0, 0)); 1327 rowHeaderjTable.setUI(new RowHeaderTableUI()); 1328 rowHeaderjTable.addMouseListener(new MouseAdapter() { 1329 public void mouseReleased(MouseEvent e) { 1330 try { 1331 changeNodeState(e); 1332 } catch (InfoException e1) { 1333 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("328"), e1); 1334 } 1335 } 1336 }); 1337 return rowHeaderjTable; 1338 } 1339 1340 1344 private Component createLeftSplitNorthPanel() { 1345 leftSplitNorthPanel = new JPanel(); 1346 leftSplitNorthPanel.setLayout(new BorderLayout()); 1347 leftSplitNorthPanel.add(crateSouthRowFieldDropTarget(), BorderLayout.SOUTH); 1348 return leftSplitNorthPanel; 1349 } 1350 1351 1356 1357 private Component crateSouthRowFieldDropTarget() { 1358 southRowFieldDropTarget = new JPanel(); 1359 southRowFieldDropTarget.setLayout(new BorderLayout()); 1360 JComponent comp = (JComponent) crateRowFieldDropTarget(); 1361 southRowFieldDropTarget.setPreferredSize(new Dimension(0, 18)); 1362 southRowFieldDropTarget.add(comp); 1363 return southRowFieldDropTarget; 1364 } 1365 1366 1370 private Component crateRowFieldDropTarget() { 1371 return createTargetPanel(DimensionDefinitionLocationType.ROW.toString(), Color.WHITE); 1372 } 1373 1374 1375 1379 private Component createPageFieldComponents() { 1380 pageFields = new JPanel(); 1381 pageFields.setLayout(new BorderLayout()); 1382 pageFields.add(createPageFillerEast(), BorderLayout.EAST); 1383 pageFields.add(createPageFieldsScrollPane(), BorderLayout.CENTER); 1384 return pageFields; 1385 } 1386 1387 1391 private JComponent createPageFieldsScrollPane() { 1392 pageFieldsScrollPane = new javax.swing.JScrollPane (); 1393 pageFieldsScrollPane.setPreferredSize(new Dimension(0, 20)); 1394 pageFieldsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 1395 pageFieldsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 1396 pageFieldsScrollPane.getViewport().add(createPageConteinerComponent(), FlowLayout.LEFT); 1397 return pageFieldsScrollPane; 1398 } 1399 1400 1404 private Component createPageConteinerComponent() { 1405 pageConteinerComponent = new JPanel(); 1406 pageConteinerComponent.setLayout(new BorderLayout()); 1407 JComponent comp = createPageFieldDropTarget(); 1408 pageConteinerComponent.add(comp, BorderLayout.CENTER); 1409 return pageConteinerComponent; 1410 } 1411 1412 1415 1416 private JComponent createPageFieldDropTarget() { 1417 return createTargetPanel(DimensionDefinitionLocationType.PAGE.toString(), Color.WHITE); 1418 } 1419 1420 1424 private JComponent createPageFillerEast() { 1425 pageFillerRigth = new JPanel(new BorderLayout()); 1426 pageFillerRigth.setPreferredSize(new Dimension(32, 18)); 1427 pageFillerRigth.add(createPageFieldScrollBar(), BorderLayout.CENTER); 1428 return pageFillerRigth; 1429 } 1430 1431 1432 1436 private JComponent createPageFieldScrollBar() { 1437 pageFieldScrollBar = new JScrollBar(); 1438 pageFieldScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL); 1439 pageFieldScrollBar.setUnitIncrement(10); 1440 return pageFieldScrollBar; 1441 } 1442 1443 1451 public void fieldPositionChanged(String positionName, String fieldName, Point location) throws InfoException { 1452 pivotTableFrame.setState(false); 1453 DropTargetPanel panel = (DropTargetPanel) targetPanels.get(positionName); 1454 DragSourcePanel dpanel = (DragSourcePanel) dragPanels.get(fieldName); 1455 panel.addFieldPanel(dpanel); 1456 changePositionPanel(fieldName, positionName, location); 1457 changeDimensionLocation.remove(fieldName); 1458 changePosition(panel, positionName); 1459 this.width = 0; 1460 1461 updateTableProperties(positionName, fieldName); 1462 pivotTableFrame.revalidateReportResult(tableProperties); 1463 fillContents(reportResult); 1464 invaildatePanels(); 1465 } 1466 1467 1472 public int getColumnPropertiesIndex(String s) { 1473 ArrayList properties = tableProperties.getColumnProperties(); 1474 for (int index = 0; index < properties.size(); index++) { 1475 ColumnProperties columnProperties = (ColumnProperties) properties.get(index); 1476 if (columnProperties.getColumnName().compareToIgnoreCase(s) == 0) { 1477 return index; 1478 } 1479 } 1480 return -1; 1481 } 1482 1483 1488 private void changePosition(DropTargetPanel panel, String positionName) { 1489 Integer pos = null; 1490 for (int i = 0; i < panel.getComponentCount(); i++) { 1491 DragSourcePanel aux = (DragSourcePanel) panel.getComponent(i); 1492 Object [] values = (Object []) changeDimensionLocation.get(aux.getName()); 1493 if (values != null) { 1494 values[1] = new Integer (i); 1495 putObject(aux.getName(), values); 1496 } 1497 else { 1498 Object [] val = new Object [3]; 1499 if (positionName == DimensionDefinitionLocationType.ROW.toString()) { 1500 pos = new Integer (DimensionDefinitionLocationType.ROW_TYPE); 1501 val[0] = pos; 1502 val[1] = new Integer (i); 1503 putObject(aux.getName(), val); 1504 1505 } 1506 if (positionName == DimensionDefinitionLocationType.COLUMN.toString()) { 1507 pos = new Integer (DimensionDefinitionLocationType.COLUMN_TYPE); 1508 val[0] = pos; 1509 val[1] = new Integer (i); 1510 putObject(aux.getName(), val); 1511 1512 } 1513 if (positionName == DimensionDefinitionLocationType.PAGE.toString()) { 1514 pos = new Integer (DimensionDefinitionLocationType.PAGE_TYPE); 1515 val[0] = pos; 1516 val[1] = new Integer (i); 1517 putObject(aux.getName(), val); 1518 } 1519 } 1520 } 1521 } 1522 1523 1529 private void changePositionPanel(String name, String position, Point location) { 1530 this.width = 0; 1531 Component[] aux = new Component[2]; 1532 JPanel panel1 = (JPanel) targetPanels.get(position); 1533 JPanel source = (JPanel) dragPanels.get(name); 1534 if (panel1.getComponents().length > 1) { 1535 DragSourcePanel drag = null; 1536 for (int index = 0; index < panel1.getComponentCount(); index++) { 1537 drag = (DragSourcePanel) panel1.getComponent(index); 1538 if (index == 0 && drag.getWidth() > location.getX()) { 1539 aux[0] = source; 1540 aux[1] = drag; 1541 Component[] comp = changePositionPanels(panel1.getComponents(), aux[0], aux[1], index); 1542 panel1.removeAll(); 1543 insertComponents(comp, panel1); 1544 return; 1545 } 1546 else { 1547 width += drag.getWidth(); 1548 if (width < location.getX()) { 1549 aux[0] = source; 1550 aux[1] = drag; 1551 } 1552 else { 1553 aux[0] = source; 1554 aux[1] = drag; 1555 Component[] comp = changePositionPanels(panel1.getComponents(), aux[0], aux[1], index); 1556 panel1.removeAll(); 1557 insertComponents(comp, panel1); 1558 return; 1559 } 1560 } 1561 } 1562 } 1563 } 1564 1565 1571 private void insertComponents(Component[] comp, JPanel panel1) { 1572 for (int index = 0; index < comp.length; index++) { 1573 panel1.add(comp[index]); 1574 } 1575 } 1576 1577 1580 private Component[] changePositionPanels(Component[] components, Component source, Component drag, int locationIndex) { 1581 Component[] aux = new Component[components.length]; 1582 int auxIndex = 0; 1583 for (int index = 0; index < components.length; index++) { 1584 if (components[index] == drag) { 1585 aux[index] = source; 1586 auxIndex = index; 1587 1588 } 1589 } 1590 if (locationIndex == 0) { 1591 System.arraycopy(components, 0, aux, auxIndex + 1, components.length - 1); 1592 } 1593 else { 1594 System.arraycopy(components, 0, aux, 0, locationIndex); 1595 if ((aux.length - 1) - locationIndex == 1) { 1596 aux[aux.length - 1] = drag; 1597 } 1598 else { 1599 if ((aux.length - 1) - locationIndex > 0) { 1600 for (int i = locationIndex; i < components.length - 1; i++) { 1601 aux[i + 1] = components[i]; 1602 } 1603 } 1604 } 1605 } 1606 return aux; 1607 } 1608 1609 1610 1616 private void changePositionHasTable(String fieldName, DimensionDefinitionLocationType location) { 1617 Object [] values = new Object [2]; 1618 if (location.getType() == DimensionDefinitionLocationType.PAGE_TYPE) { 1619 values[0] = new Integer (location.getType()); 1620 values[1] = new Integer (page++); 1621 putObject(fieldName, values); 1622 } 1623 if (location.getType() == DimensionDefinitionLocationType.ROW_TYPE) { 1624 values[0] = new Integer (location.getType()); 1625 values[1] = new Integer (row++); 1626 putObject(fieldName, values); 1627 } 1628 if (location.getType() == DimensionDefinitionLocationType.COLUMN_TYPE) { 1629 values[0] = new Integer (location.getType()); 1630 values[1] = new Integer (col++); 1631 putObject(fieldName, values); 1632 } 1633 } 1634 1635 1641 private void putObject(String key, Object [] values) { 1642 if (changeDimensionLocation.get(key) == null) { 1643 changeDimensionLocation.put(key, values); 1644 } 1645 else { 1646 changeDimensionLocation.remove(key); 1647 changeDimensionLocation.put(key, values); 1648 } 1649 } 1650 1651 1654 public void invaildatePanels() { 1655 for (Iterator iterator = targetPanels.values().iterator(); iterator.hasNext();) { 1656 JPanel panel1 = (JPanel) iterator.next(); 1657 panel1.invalidate(); 1658 panel1.revalidate(); 1659 } 1660 ((HeaderTableUI)columnHeaderjTable.getUI()).resetFinals(); 1661 ((HeaderTableUI)rowHeaderjTable.getUI()).resetFinals(); 1662 resizeComponent(); 1663 1664 getContentPane().repaint(); 1665 } 1666 1667 1673 private void addDragPanel(String s, DropTargetPanel panel, DimensionDefinitionLocationType location) { 1674 DragSourcePanel dragPanel = panel.addField(s, this, getColumnDescriptionFromName(s)); 1675 dragPanel.setBackground(Color.GRAY); 1676 s.trim(); 1677 dragPanels.put(s, dragPanel); 1678 changePositionHasTable(s, location); 1679 if (location == DimensionDefinitionLocationType.PAGE) { 1680 int width = dragPanel.getMinimumSize().width; 1681 pageFieldScrollBar.setMaximum(pageFieldScrollBar.getMaximum() + width); 1682 1683 } 1684 } 1685 1686 1689 private void fillComponents() throws InfoException { 1690 DimensionDefinitionLocationType location; 1691 location = DimensionDefinitionLocationType.PAGE; 1692 addFieldsByLocation((DropTargetPanel) targetPanels.get(location.toString()), location); 1693 location = DimensionDefinitionLocationType.ROW; 1694 addFieldsByLocation((DropTargetPanel) targetPanels.get(location.toString()), location); 1695 location = DimensionDefinitionLocationType.COLUMN; 1696 addFieldsByLocation((DropTargetPanel) targetPanels.get(location.toString()), location); 1697 } 1698 1699 1702 private void addFieldsByLocation(DropTargetPanel targetPanel, DimensionDefinitionLocationType location) throws InfoException { 1703 ArrayList list = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(location); 1704 loadTargetPanel(list, targetPanel); 1705 1706 } 1707 1708 1714 private void fillColumnsProperties(ArrayList list, String location) throws InfoException { 1715 Iterator iterator = list.iterator(); 1716 while (iterator.hasNext()) { 1717 QueryDimension dimension = (QueryDimension) iterator.next(); 1718 ColumnProperties properties = new ColumnProperties(); 1719 properties.setColumnName(dimension.getName()); 1720 properties.setWidth(DEFAULT_COLUMN_WIDTH); 1721 int indexDimension = reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getIndex(); 1722 properties.setExcludeValue(reportResult.getReportQuery().getExcludedValues(indexDimension)); 1723 properties.setOrder(reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getOrder()); 1724 properties.setLocation(location); 1725 properties.setRankMetricName(reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getRankMetricName()); 1726 properties.setOrder(reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getOrder()); 1727 tableProperties.getColumnProperties().add(properties); 1728 1729 } 1730 } 1731 1732 1737 private void loadTargetPanel(ArrayList list, DropTargetPanel targetPanel) throws InfoException { 1738 for (int i = 0; i < list.size(); i++) { 1739 QueryDimension queryDimension = (QueryDimension) list.get(i); 1740 addDragPanel(queryDimension.getName(), targetPanel, queryDimension.getLocation()); 1741 loadRowTableProperties(queryDimension, targetPanel); 1742 } 1743 rowHeaderDimension = getAllRowColumnProperties(); 1744 1745 } 1746 1747 1753 private void loadRowTableProperties(QueryDimension queryDimension, DropTargetPanel targetPanel) throws InfoException { 1754 int index = getColumnPropertiesIndex(queryDimension.getName()); 1755 if (index < 0) { 1756 ColumnProperties properties = tableProperties.getRowColumn(queryDimension.getName()); 1757 properties.setColumnName(queryDimension.getName()); 1758 properties.setLocation(targetPanel.getName()); 1759 properties.setOrder(queryDimension.getOrder()); 1760 properties.setUbication(getComponentIndex(targetPanel, queryDimension.getName())); 1761 tableProperties.updateColumnsProperties(); 1762 } 1763 else { 1764 Object [] value = (Object []) changeDimensionLocation.get(queryDimension.getName()); 1765 ColumnProperties properties = tableProperties.getRowColumn(queryDimension.getName()); 1766 properties.setColumnName(queryDimension.getName()); 1767 properties.setLocation(targetPanel.getName()); 1768 properties.setOrder(queryDimension.getOrder()); 1769 int position = ((Integer ) value[1]).intValue(); 1770 properties.setUbication(position); 1771 tableProperties.updateColumnsProperties(); 1772 } 1773 } 1774 1775 1776 1782 private int getComponentIndex(DropTargetPanel targetPanel, String name) { 1783 for (int index = 0; index < targetPanel.getComponentCount(); index++) { 1784 JPanel panel = (JPanel) targetPanel.getComponent(index); 1785 if (panel.getName().compareToIgnoreCase(name) == 0) { 1786 return index; 1787 } 1788 } 1789 return -1; 1790 } 1791 1792 1797 private String getColumnDescriptionFromName(String name) { 1798 if (reportResult != null) { 1799 return reportResult.getDimensionFromName(name).getCaption(); 1800 } 1801 return name; 1802 1803 } 1804 1805 1811 private DropTargetPanel createTargetPanel(String s, Color color) { 1812 DropTargetPanel panel; 1813 panel = new DropTargetPanel(s, mainSplit); 1814 panel.setBackground(color); 1815 panel.setFieldPositionListener(this); 1816 targetPanels.put(s, panel); 1817 return panel; 1818 } 1819 1820 1824 public void setFrame(JFrame frame) { 1825 this.frame = frame; 1826 this.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 1827 } 1828 1829 1833 public JFrame getFrame() { 1834 return frame; 1835 } 1836 1837 1841 public JSplitPane getMainSplit() { 1842 return mainSplit; 1843 } 1844 1845 1849 public Container getContentPane() { 1850 return contentPane; 1851 } 1852 1853 1857 public void setContentPane(Container contentPane) { 1858 this.contentPane = contentPane; 1859 } 1860 1861 1864 public void printPivoteTable(IReportManager reportManager, ReportView reportView,Dimension dim) { 1865 try { 1866 ReportUI reportUI = new ReportUI(reportResult, reportResult.getReportSpec(), reportManager, getPivotTableFrame().getReportGeneratorConfiguration(), reportView, dim); 1867 if(reportUI.getFrame()!=null){ 1868 reportUI.show(); 1869 } 1870 } 1871 catch (Exception e) { 1872 InfoException infoException = new InfoException(LanguageTraslator.traslate("220")); 1873 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("220"), infoException); 1874 } 1875 } 1876 1877 private void setQueryDimensionLocationFrom(String [] rowDimensionNames, ReportQuery query, int type) { 1878 for(int i = 0 ; i < rowDimensionNames.length ; i++) { 1879 try { 1880 query.setDimensionLocationOrder(rowDimensionNames[i], type); 1881 } catch (InfoException e) { 1882 e.printStackTrace(); 1883 } 1884 } 1885 } 1886 1887 private String [] getDimensionNames(Collection rowDimensions) { 1888 String [] names = new String [rowDimensions.size()]; 1889 Iterator iterator = rowDimensions.iterator(); 1890 for(int i = 0 ; iterator.hasNext() ; i++) { 1891 ReportDimensionSpec spec = (ReportDimensionSpec) iterator.next(); 1892 names[i] = spec.getName(); 1893 } 1894 return names; 1895 } 1896 1897 1901 public JTable getDatajTable() { 1902 return datajTable; 1903 } 1904 1905 1909 public JTable getRowHeaderjTable() { 1910 return rowHeaderjTable; 1911 } 1912 1913 1917 public JTable getColumnHeaderjTable() { 1918 return columnHeaderjTable; 1919 } 1920 1921 1925 public ReportResult getReportResult() { 1926 return reportResult; 1927 } 1928 1929 1933 public void setReportResult(ReportResult reportResult) throws InfoException { 1934 this.reportResult = reportResult; 1935 JTable table = getDatajTable(); 1936 if (table != null) { 1937 TableCellRenderer renderer = table.getDefaultRenderer(Object .class); 1938 if (renderer instanceof DataTableCellRenderer) { 1939 ((DataTableCellRenderer) renderer).setReportResult(reportResult); 1940 } 1941 } 1942 if (tableProperties != null) { 1943 tableProperties.setReportResult(reportResult); 1944 } 1945 } 1946 1947 1951 public Map getChangeDimensionLocation() { 1952 return changeDimensionLocation; 1953 } 1954 1955 1959 public Component getLeftCenterPanel() { 1960 return leftCenterPanel; 1961 } 1962 1963 1967 public void setPivoteTableSinTotales() throws InfoException { 1968 if (getColModel().getWithTotals() && getRowModel().getWithTotals()) { 1969 withTotals = false; 1970 pivotTableFrame.setState(false); 1971 tableProperties.setWithTotal(withTotals); 1972 pivotTableFrame.buildNewQuery(tableProperties); 1973 fillContents(getReportResult()); 1974 } 1975 else { 1976 withTotals = true; 1977 pivotTableFrame.setState(false); 1978 tableProperties.setWithTotal(withTotals); 1979 pivotTableFrame.buildNewQuery(tableProperties); 1981 fillContents(getReportResult()); 1982 } 1983 invaildatePanels(); 1984 if (getRowHeaderDimension().isEmpty()) { 1985 mainSplit.setDividerLocation(100); 1986 } 1987 else { 1988 int heigth = pivotTableFrame.getFrame().getContentPane().getPreferredSize().height; 1989 leftCenterPanel.setPreferredSize(new Dimension(adjustmentSizeSplit(),heigth)); 1990 } 1991 1992 } 1993 1994 1995 1999 public HeaderTableModel getColModel() { 2000 return (HeaderTableModel) getColumnHeaderjTable().getModel(); 2001 } 2002 2003 2007 public HeaderTableModel getRowModel() { 2008 return (HeaderTableModel) getRowHeaderjTable().getModel(); 2009 } 2010 2011 2015 public ColorConditionManager getColorConditionManager() { 2016 return colorConditionManager; 2017 } 2018 2019 2023 public Map getRowHeaderDimension() { 2024 if (rowHeaderDimension == null) { 2025 return rowHeaderDimension = new HashMap(); 2026 } 2027 return rowHeaderDimension; 2028 } 2029 2030 2034 public PivotTableProperties getTableProperties() { 2035 return tableProperties; 2036 } 2037 2038 2042 public void setTableProperties(PivotTableProperties tableProperties) { 2043 this.tableProperties = tableProperties; 2044 } 2045 2046 2050 public AplicationView getView() { 2051 return view; 2052 } 2053 2054 2055 2059 2060 public PivotTableFrame getPivotTableFrame() { 2061 return pivotTableFrame; 2062 } 2063 2064 2068 public void setWithTotals(boolean withTotals) { 2069 this.withTotals = withTotals; 2070 } 2071 2072 2077 protected Vector getColumnsNames(int columnCount){ 2078 Vector names = new Vector(columnCount); 2079 for (int i = 0; i < columnCount; i++) { 2080 names.add(String.valueOf(i)); 2081 } 2082 return names; 2083 } 2084 2085 private boolean getIsReadOnly(){ 2086 return (getPivotTableFrame().getMicroReport()!=null); 2087 } 2088 2089 2090} | Popular Tags |