1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType; 4 import com.calipso.reportgenerator.reportdefinitions.types.ReportDefinitionReportTypeType; 5 import com.calipso.reportgenerator.reportdefinitions.types.DrillDownDefinitionTypeType; 6 import com.calipso.reportgenerator.reportdefinitions.ReportDefinition; 7 import com.calipso.reportgenerator.reportdefinitions.ReportSourceDefinition; 8 import com.calipso.reportgenerator.reportdefinitions.ReportView; 9 import com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable; 10 import com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotFrame; 11 import com.calipso.reportgenerator.common.*; 12 13 import javax.swing.*; 14 import javax.swing.table.DefaultTableModel ; 15 import java.awt.*; 16 import java.awt.event.WindowAdapter ; 17 import java.awt.event.ActionListener ; 18 import java.awt.event.ActionEvent ; 19 import java.util.*; 20 import java.util.zip.ZipOutputStream ; 21 import java.io.File ; 22 23 import com.calipso.reportgenerator.common.InfoException; 24 25 28 public class PivotTableFrame extends ReportFrame implements ActionListener , IReportFrame { 29 30 private ReportViewerToolBar toolBar; 31 private JFrame frame; 32 private PivotTable pivotTable; 33 private JPanel bottomPanel; 34 private JButton printButton; 35 private JButton exportMicroReportButton; 36 private JButton graphicButton; 37 private JPanel pivotPanel; 38 private JButton maximizar; 39 private JButton semaforo; 40 private JButton searcher; 41 private JButton excel; 42 private JButton viewBtn; 43 private JButton editDimensionValueBtn; 44 private boolean state; 45 private int reportHandle; 46 private IReportFrame parent; 47 private String userID; 48 private Map params; 49 private JButton ordenBtn; 50 private JPanel centerPanel; 51 private JPanel boxPanel; 52 private int WIDTH = 90; 53 private int HEIGTH = 26; 54 private ReportSpec reportSpec; 55 private boolean fromMicroReport=false; 56 private MicroReport microReport; 57 private ReportGeneratorConfiguration reportGeneratorConfiguration; 58 private ReportView reportView; 59 private boolean autoRefresh = true; 60 61 62 67 public PivotTableFrame(IReportFrame parent, String reportDefId, IReportManager reportManager, Map params, String userId, ReportGeneratorConfiguration reportGeneratorConfiguration) throws InfoException { 68 this.reportGeneratorConfiguration = reportGeneratorConfiguration; 69 this.parent = parent; 70 this.params = params; 71 this.setUserID(userId); 72 this.reportSpec = reportManager.getReportSpec(reportDefId); 73 if (reportSpec.getCached()) { 74 reportHandle = reportManager.PrepareReport(reportDefId); 75 } 76 else { 77 reportHandle = reportManager.PrepareReport(reportDefId, params); 78 } 79 super.reportManager = reportManager; 80 ReportQuery query = reportManager.getDefaultReportQuery(reportHandle, getUserID()); 81 query.setParamValues(params); 82 super.reportResult = reportManager.ExecReportQuery(reportHandle, query); 83 initComponents(); 84 } 85 86 public PivotTableFrame(IReportFrame parent, String reportDefId, IReportManager reportManager, Map params, String userId, String reportViewID, ReportGeneratorConfiguration reportGeneratorConfiguration) throws InfoException { 87 this.reportGeneratorConfiguration = reportGeneratorConfiguration; 88 this.params = params; 89 this.parent = parent; 90 this.setUserID(userId); 91 this.reportSpec = reportManager.getReportSpec(reportDefId); 92 if (reportSpec.getCached()) { 93 reportHandle = reportManager.PrepareReport(reportDefId); 94 } 95 else { 96 reportHandle = reportManager.PrepareReport(reportDefId, params); 97 } 98 super.reportManager = reportManager; 99 reportView = reportManager.getReportViewFromID(reportViewID,reportDefId,userId); 100 super.reportResult = reportManager.ExecReportQuery(reportHandle,reportView); 101 initComponents(); 102 } 103 104 105 public PivotTableFrame(IReportFrame parent, MicroReport microReport, IReportManager reportManager, String userId, ReportGeneratorConfiguration reportGeneratorConfiguration) throws InfoException { 106 this.reportGeneratorConfiguration = reportGeneratorConfiguration; 107 this.parent = parent; 108 this.microReport = microReport; 109 fromMicroReport = true; 110 this.reportView = microReport.getReportView(); 111 this.setUserID(userId); 112 microReport.getReportSourceDefinition().setCached(true); 113 microReport.getReportSourceDefinition().setIncrementalDimension(""); 114 this.reportSpec = reportManager.getReportSpec(microReport.getReportDefinition(),microReport.getReportSourceDefinition()); 115 reportHandle = reportManager.PrepareReport(microReport); 116 super.reportManager = reportManager; 117 super.reportResult = reportManager.ExecReportQuery(reportHandle,microReport.getReportView()); 119 initComponents(); 120 } 121 122 public PivotTableFrame(IReportFrame parent, MicroReport microReport, IReportManager reportManager, String userId, ReportGeneratorConfiguration reportGeneratorConfiguration, Map params) throws InfoException { 123 this.reportGeneratorConfiguration = reportGeneratorConfiguration; 124 this.parent = parent; 125 this.microReport = microReport; 126 fromMicroReport = true; 127 this.reportView = microReport.getReportView(); 128 this.setUserID(userId); 129 microReport.getReportSourceDefinition().setCached(true); 130 microReport.getReportSourceDefinition().setIncrementalDimension(""); 131 this.reportSpec = reportManager.getReportSpec(microReport.getReportDefinition(),microReport.getReportSourceDefinition()); 132 reportHandle = reportManager.PrepareReport(microReport); 133 super.reportManager = reportManager; 134 super.reportResult = reportManager.ExecReportQuery(reportHandle,params); 135 initComponents(); 136 } 137 138 139 142 143 private void initComponents() throws InfoException { 144 state = false; 145 getFrame().getContentPane().setLayout(new BorderLayout()); 146 getFrame().getContentPane().add(createCenterPanelAplication(), BorderLayout.CENTER); 147 pivotTable = new PivotTable(this, reportView); 148 frame.addWindowListener(new WindowAdapter () { 149 public void windowClosing() { 150 System.exit(0); 151 } 152 }); 153 154 159 160 170 171 177 178 183 184 189 190 frame.pack(); 191 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 192 frame.setSize(new java.awt.Dimension (700,450)); 193 frame.setLocation((screenSize.width - 700) / 2, (screenSize.height - 450) / 2); 194 } 195 196 public void doGraphics() { 197 ChartUI chart = new ChartUI(pivotTable, reportGeneratorConfiguration); 198 chart.setVisible(true); 199 } 200 201 public void printPivotTable(Dimension dim) { 202 pivotTable.printPivoteTable(reportManager, reportView, dim); 203 } 204 205 public void exportMicroReport() { 206 JFileChooser fileChooser = new JFileChooser(); 207 int mode = fileChooser.showSaveDialog(null); 208 if (mode == JFileChooser.APPROVE_OPTION) { 209 File file = fileChooser.getSelectedFile(); 210 try { 211 ReportDefinition reportDefinition = this.reportManager.getReportDefinitionFromID(reportSpec.getDefinitionId()); 212 ReportSourceDefinition reportSourceDefinition = this.reportManager.getReportSourceDefinitionFromID(reportDefinition.getReportSource()); 213 ReportView reportView = pivotTable.getTableProperties().getReportView(reportDefinition.getId(),getUserID(),""); 214 MicroReport microReport = new MicroReport(reportManager.getMatrix(reportHandle),reportSourceDefinition,reportDefinition,reportView,"",userID,getViews(reportDefinition.getId()),params); 215 ZipOutputStream zipOutputStream = microReport.getZip(file.getPath(), reportGeneratorConfiguration.isCsvSerialized()); 216 zipOutputStream.close(); 217 } 218 catch (Exception e) { 219 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("267"),e); 220 } 221 } 222 } 223 224 228 public Map getViews(String reportDefinitionId) throws InfoException { 229 Map map = reportManager.getReportViews(reportDefinitionId,userID); 230 Map returnMap = new HashMap(); 231 String reportName; 232 for (int i=0;i<map.size();i++){ 233 reportName = map.values().toArray()[i].toString(); 234 returnMap.put(reportName,reportManager.getReportViewFromID(reportName,reportDefinitionId, userID)); 235 } 236 return returnMap; 237 } 238 239 private JButton getExportMicroReportButton() { 240 return exportMicroReportButton; 241 } 242 243 private Component createCenterPanelAplication() { 244 centerPanel = new JPanel(new BorderLayout()); 245 centerPanel.add(createPivoteTablePanel(), BorderLayout.CENTER); 247 centerPanel.add(createBottomPanel(), BorderLayout.SOUTH); 248 return centerPanel; 249 } 250 251 private Component createBottomPanel() { 252 bottomPanel = new JPanel(); 253 return bottomPanel; 255 } 256 257 private Component createPivoteTablePanel() { 258 pivotPanel = new JPanel(); 259 pivotPanel.setLayout(new BorderLayout()); 260 return pivotPanel; 262 } 263 264 private Component createEastBoxPanel() { 265 boxPanel = new javax.swing.JPanel (); 266 boxPanel.setLayout(new javax.swing.BoxLayout (boxPanel, javax.swing.BoxLayout.Y_AXIS)); 267 boxPanel.add(createJButtonView()); 270 boxPanel.add(createJButtonSemaforo()); 271 boxPanel.add(createJButtonSearcher()); 272 boxPanel.add(createJButtonExcel()); 273 boxPanel.add(createJButtonGraphic()); 274 boxPanel.add(createJButtonEditDimensionValues()); 275 boxPanel.add(createJButtonOrden()); 276 boxPanel.add(createJButtonPrint()); 277 boxPanel.add(createJButtonExportMicroReport()); 278 return boxPanel; 279 } 280 281 public void maximizarActionPerformed() { 282 if (state) { 283 state = false; 284 } 285 else { 286 state = true; 287 } 288 289 } 290 291 private JButton createJButtonPrint() { 292 this.printButton = makeNavigationButton("print16", "IMPRIMIR", 293 "Imprime la definicion actual", 294 ""); 295 printButton.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 296 printButton.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 297 printButton.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 298 return printButton; 299 } 300 301 private JButton createJButtonExportMicroReport() { 302 this.exportMicroReportButton = makeNavigationButton("save16", "EXPORTAR", 303 "Guarda en disco la definicion actual", 304 ""); 305 exportMicroReportButton.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 306 exportMicroReportButton.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 307 exportMicroReportButton.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 308 return exportMicroReportButton; 309 } 310 311 312 private JButton createJButtonGraphic() { 313 this.graphicButton = makeNavigationButton("GRAFICO", "GRAFICO", 314 "Realiza graficos estadisticos", 315 ""); 316 graphicButton.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 317 graphicButton.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 318 graphicButton.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 319 return graphicButton; 320 } 321 322 329 330 337 338 private JButton createJButtonSearcher() { 339 searcher = makeNavigationButton("search", "BUSCAR", 340 "Busca valores para las dimensiones", 341 ""); 342 searcher.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 343 searcher.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 344 searcher.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 345 return searcher; 346 } 347 348 private JButton makeNavigationButton(String imageName, 349 String actionCommand, 350 String toolTipText, 351 String altText) { 352 353 354 String imgLocation = reportGeneratorConfiguration.getImagesPath() 355 + "\\" + imageName 356 + ".gif"; 357 358 360 JButton button = new JButton(new ImageIcon(imgLocation, altText)); 361 button.setActionCommand(actionCommand); 362 button.setToolTipText(toolTipText); 363 button.addActionListener(this); 364 if (imgLocation != null) { 365 button.setIcon(new ImageIcon(imgLocation, altText)); 366 } else { 367 button.setText(altText); 368 } 369 370 return button; 371 } 372 373 private JButton createJButtonExcel() { 374 excel = makeNavigationButton("EXCEL", "EXCEL", 375 "Importa a excel los valores de la tabla", 376 ""); 377 excel.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 378 excel.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 379 excel.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 380 return excel; 381 } 382 383 private JButton createJButtonSemaforo() { 384 semaforo = makeNavigationButton("SEMAFORO1", "SEMAFORO", 385 "Semaforizacion de valores", 386 ""); 387 semaforo.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 388 semaforo.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 389 semaforo.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 390 return semaforo; 391 } 392 393 private JButton createJButtonView() { 394 viewBtn = makeNavigationButton("PERFILES3", "PERFILES", 395 "Establece perfiles de usuario", 396 ""); 397 viewBtn.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 398 viewBtn.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 399 viewBtn.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 400 return viewBtn; 401 } 402 403 private JButton createJButtonEditDimensionValues() { 404 editDimensionValueBtn = makeNavigationButton("RANKING", "RANKING", 405 "Realiza un ranking en base a una dimension", 406 ""); 407 editDimensionValueBtn.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 408 editDimensionValueBtn.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 409 editDimensionValueBtn.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 410 return editDimensionValueBtn; 411 } 412 413 private JButton createJButtonOrden() { 414 ordenBtn = makeNavigationButton("ORDEN", "ORDEN", 415 "Ordena en forma ascendente o descendente", 416 ""); 417 ordenBtn.setMaximumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 418 ordenBtn.setMinimumSize(new java.awt.Dimension (WIDTH, HEIGTH)); 419 ordenBtn.setPreferredSize(new java.awt.Dimension (WIDTH, HEIGTH)); 420 return ordenBtn; 421 } 422 423 public void updateQuerry(MetricState state, JCheckBox checkBox, PivotTableProperties tableProperties) throws InfoException { 424 ReportQuery reportQuery = getReportManager().getDefaultReportQuery(reportHandle); 425 reportQuery.getQueryMetricFromName(state.getName()).setVisible(state.getVisible()); 427 428 try { 429 reportQuery = buildNewQueryExcludeValue(tableProperties, reportQuery, false, false); 431 pivotPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR)); 434 if (isAutoRefresh()){ 435 reportResult = getReportManager().ExecReportQuery(reportHandle, reportQuery); 436 pivotTable.setReportResult(reportResult); 437 }else{ 438 pivotTable.setReportResult(new CubeReportResult(reportResult.getReportSpec(),reportQuery,null,null,null) ); 439 } 440 441 parent.getToolBar().getBtSizes().setSelected(false); 442 parent.getToolBar().setBtTotalsState(false); 443 pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 444 } 445 catch (Exception e) { 446 reportQuery.getQueryMetricFromName(state.getName()).setVisible(true); 447 pivotTable.setVisible(false); 448 checkBox.setSelected(true); 449 if (isAutoRefresh()) { 450 reportResult = getReportManager().ExecReportQuery(reportHandle, reportQuery); 451 pivotTable.setReportResult(reportResult); 452 }else{ 453 pivotTable.setReportResult(new CubeReportResult(reportResult.getReportSpec(),reportQuery,null,null,null) ); 454 } 455 456 pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 457 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("137"), e); 458 459 } 460 } 461 462 466 public JFrame getFrame() { 467 if (frame == null) { 468 frame = new JFrame(); 469 frame.setTitle(reportResult.getReportSpec().getTitle()); 471 frame.setName("Cube"); 472 } 473 return frame; 474 } 475 476 479 public void show() { 480 getFrame().setVisible(true); 481 } 482 483 public JButton getMaximizar() { 484 return maximizar; 485 } 486 487 public void setMaximizar(JButton maximizar) { 488 this.maximizar = maximizar; 489 } 490 491 public ReportResult getReportResult() { 492 return reportResult; 493 } 494 495 public JPanel getPivotPanel() { 496 return pivotPanel; 497 } 498 499 public Map getParams() { 500 return params; 501 } 502 503 public void setParams(Map params) { 504 this.params = params; 505 } 506 507 510 public void revalidateReportResult(PivotTableProperties tableProperties) { 511 if (reportManager != null) { 512 try { 513 buildNewQuery(tableProperties); 514 } 515 catch (Exception e) { 516 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e); 517 } 518 } 519 } 520 521 524 public void buildNewQuery(PivotTableProperties tableProperties) throws InfoException { 525 System.gc(); 526 ReportQuery reportQuery = getReportManager().getDefaultReportQuery(reportHandle); 527 reportQuery = buildNewQueryExcludeValue(tableProperties, reportQuery, false, true); 530 pivotPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR)); 533 if (isAutoRefresh()){ 534 reportResult = getReportManager().ExecReportQuery(reportHandle, reportQuery); 535 pivotTable.setWithTotals(tableProperties.isWithTotal()); 536 pivotTable.setReportResult( reportResult); 537 }else{ 538 pivotTable.setWithTotals(tableProperties.isWithTotal()); 539 pivotTable.setReportResult(new CubeReportResult(reportResult.getReportSpec(),reportQuery,null,null,null) ); 540 } 541 parent.getToolBar().getBtSizes().setSelected(false); 542 parent.getToolBar().setBtSizesState(false); 543 pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 544 } 545 546 547 private ReportQuery updateDimensionLocation(PivotTableProperties tableProperties, ReportQuery reportQuery) throws InfoException { 548 ColumnProperties columnProperties; 549 DimensionDefinitionLocationType location = DimensionDefinitionLocationType.PAGE; 550 QueryDimension queryDimension; 551 for (int i = 0; i < tableProperties.getColumnProperties().size(); i++) { 552 columnProperties = (ColumnProperties) tableProperties.getColumnProperties().get(i); 553 if (columnProperties.getLocation().equalsIgnoreCase(DimensionDefinitionLocationType.PAGE.toString())) { 554 location = DimensionDefinitionLocationType.PAGE; 555 } 556 else 557 if (columnProperties.getLocation().equalsIgnoreCase(DimensionDefinitionLocationType.ROW.toString())) { 558 location = DimensionDefinitionLocationType.ROW; 559 } 560 if (columnProperties.getLocation().equalsIgnoreCase(DimensionDefinitionLocationType.COLUMN.toString())) { 561 location = DimensionDefinitionLocationType.COLUMN; 562 } 563 queryDimension = reportQuery.getQueryDimensionFromName(columnProperties.getColumnName()); 564 queryDimension.setLocation(location); 565 queryDimension.setLocationOrder(columnProperties.getUbication()); 566 queryDimension.setRankMetricName(columnProperties.getRankMetricName()); 567 queryDimension.setOrder(columnProperties.getOrder()); 568 } 569 return reportQuery; 570 } 571 572 573 578 private ReportQuery updateVisibleMetrics(PivotTableProperties tableProperties, ReportQuery reportQuery) throws InfoException { 579 MetricState metricState; 580 for (int i = 0; i < tableProperties.getMetricProperies().size(); i++) { 581 metricState = (MetricState) tableProperties.getMetricProperies().get(i); 582 reportQuery.getQueryMetricFromName(metricState.getName()).setVisible(metricState.getVisible()); 583 } 584 return reportQuery; 585 } 586 587 public ReportQuery buildNewQueryExcludeValue(PivotTableProperties tableProperties, ReportQuery reportQuery, boolean executeQuery, boolean updateMetrics) { 588 try { 589 Iterator iterator = tableProperties.getMetricProperies().iterator(); 590 while (iterator.hasNext()) { 591 MetricState state = (MetricState) iterator.next(); 592 reportQuery.getQueryMetricFromName(state.getName()).setVisible(state.getVisible()); 593 } 594 reportQuery = updateDimensionLocation(tableProperties, reportQuery); 595 if(updateMetrics) { 596 reportQuery = updateVisibleMetrics(tableProperties, reportQuery); 597 } 598 reportQuery.setVisibleTotals(tableProperties.isWithTotal()); 599 updateDimensionValues(tableProperties, reportQuery); 600 if(reportView == null) { 601 reportQuery.setParamValues(params); 602 } 603 if ( executeQuery == true) { 604 pivotPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR)); 605 if (isAutoRefresh()){ 606 reportResult = getReportManager().ExecReportQuery(reportHandle, reportQuery); 607 pivotTable.setReportResult(reportResult); 608 }else{ 609 pivotTable.setReportResult(new CubeReportResult(reportResult.getReportSpec(),reportQuery,null,null,null) ); 610 } 611 612 parent.getToolBar().getBtSizes().setSelected(false); 613 parent.getToolBar().setBtSizesState(false); 614 pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 615 } 616 } 617 catch (Exception e) { 618 ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e); 619 } 620 return reportQuery; 621 } 622 623 private void updateDimensionValues(PivotTableProperties tableProperties, ReportQuery reportQuery) throws InfoException { 624 Iterator iterator = tableProperties.getColumnProperties().iterator(); 625 while (iterator.hasNext()) { 626 ColumnProperties properties = (ColumnProperties) iterator.next(); 627 int dimensionIndex = reportQuery.getQueryDimensionFromName(properties.getColumnName()).getIndex(); 628 reportQuery.setExcludedValues(dimensionIndex, properties.getExcludeValue()); 629 } 630 } 631 632 636 public IReportManager getReportManager() { 637 return reportManager; 638 } 639 640 public PivotTable getPivotTable() { 641 return pivotTable; 642 } 643 644 public void setPivotTable(PivotTable pivotTable) { 645 this.pivotTable = pivotTable; 646 } 647 648 public JButton getPrintButton() { 649 return printButton; 650 } 651 652 public JButton getGraphicButton() { 653 return graphicButton; 654 } 655 656 public boolean isSelected() { 657 return state; 658 } 659 660 public void setState(boolean state) { 661 this.state = state; 662 } 663 664 public JButton getSemaforo() { 665 return semaforo; 666 } 667 668 public JButton getSearcher() { 669 return searcher; 670 } 671 672 public JButton getViewBtn() { 673 return viewBtn; 674 } 675 676 public String getUserID() { 677 return userID; 678 } 679 680 public void setUserID(String userID) { 681 this.userID = userID; 682 } 683 684 public int getReportHandle() { 685 return reportHandle; 686 } 687 688 689 693 public void drillDown(DrillDownSpec drillDownDefinition, Map cubeValues) throws InfoException { 694 if ( validDrillDownValues(drillDownDefinition, cubeValues)){ 695 Map params = getDrillDownParams(drillDownDefinition, cubeValues); 696 switch (drillDownDefinition.getType().getType()){ 697 case DrillDownDefinitionTypeType.MICROREPORT_TYPE: 698 executeExportedReport(params,drillDownDefinition.getTargetReportDefinitionID(), getUserID()); 699 break; 700 case DrillDownDefinitionTypeType.STATICWEB_TYPE: 701 params = ReportFilterBuilder.mergeParamValues(getParams(), params); 702 executeWebDrillDown(params, drillDownDefinition.getTargetReportDefinitionID(), reportSpec.getDefinitionId(), userID); 703 break; 704 default : 705 ReportSpec reportSpec = getReportManager().getReportSpec(drillDownDefinition.getTargetReportDefinitionID()); 706 String reportDefinitionId = drillDownDefinition.getTargetReportDefinitionID(); 707 try { 708 if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.CUBE_TYPE) { 709 if ((!reportDefinitionId.equals("")) && (!getUserID().equals(""))){ 710 PivotTableFrame pivotTableFrame=null; 711 toolBar = new ReportViewerToolBar(JToolBar.HORIZONTAL); 712 toolBar.drillDownExecuted(); 713 pivotTableFrame = new PivotTableFrame(this, reportDefinitionId,getReportManager(),params,getUserID(),getReportGeneratorConfiguration()); 714 toolBar.setPivotTableFrame(pivotTableFrame); 715 pivotTableFrame.getFrame().getContentPane().add(toolBar, BorderLayout.PAGE_START); 716 pivotTableFrame.show(); 717 } 718 }else if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.CHARTCUBE_TYPE) { 719 ChartPivotTable chartPivotTable = new ChartPivotTable(reportSpec, getReportManager() , params, userID, reportDefinitionId,this); 720 chartPivotTable.paintComponents(true); 721 ChartPivotFrame chartPivotFrame = new ChartPivotFrame(); 722 chartPivotFrame.show(chartPivotTable); 723 }else if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.ACCUM_TYPE) { 724 ReportResult reportResult = getReportManager().ExecReportQuery(reportSpec.getDefinitionId(), params); 725 ReportUI reportUI = null; 726 String reportView = ""; 727 ReportView view = null; 728 if(reportView!=null && !reportView.equalsIgnoreCase("")){ 729 view = getReportManager().getReportViewFromID(reportView, reportSpec.getDefinitionId(), getUserID()); 730 } 731 reportUI = new ReportUI(reportResult,reportResult.getReportSpec(), getReportManager(),getReportGeneratorConfiguration(), view, this.getFrame().getSize()); 732 if(reportUI!=null){ 733 reportUI.show(); 734 } 735 } 736 }catch (Exception e) { 737 throw new InfoException("151", e); 738 } 739 } 740 }else{ 741 String dimSourceNames=""; 742 for (int i =0;(i<drillDownDefinition.getDimensionBindSpecs().size());i++){ 743 String dimName = ((DimensionBindSpec)drillDownDefinition.getDimensionBindSpecs().get(i)).getSourceDimensionName(); 744 dimSourceNames = dimSourceNames + " "+ getReportResult().getReportSpec().getDimensionFromName(dimName).getCaption(); 745 } 746 throw new InfoException(LanguageTraslator.traslate("416")+" "+dimSourceNames); 747 } 748 749 } 750 751 private void executeWebDrillDown(Map params, String urlBase, String reportId, String user) throws InfoException { 752 String url = getUrl(urlBase, params, reportId, user); 753 try { 754 BrowserLauncher.openURL(url); 755 } catch (Exception e) { 756 throw new InfoException(LanguageTraslator.traslate("464"), e); 757 } 758 } 759 760 private String getUrl(String baseUrl, Map params, String definitionId, String user) { 761 String url = baseUrl; 762 url += ("ReportDefinition=" + definitionId + "&"); 763 url += ("User=" + user); 764 Iterator it = params.entrySet().iterator(); 765 while (it.hasNext()) { 766 url += "&"; 767 Map.Entry entry = (Map.Entry) it.next(); 768 url += (entry.getKey().toString().trim() + "=" + entry.getValue().toString().trim()); 769 } 770 return url; 771 } 772 773 private boolean validDrillDownValues(DrillDownSpec drillDownDefinition, Map cubeValues) { 774 boolean returnValue = true; 775 for (int i =0;((i<drillDownDefinition.getDimensionBindSpecs().size())&&(returnValue));i++){ 776 String dimSourceName = ((DimensionBindSpec)drillDownDefinition.getDimensionBindSpecs().get(i)).getSourceDimensionName(); 777 if (!(cubeValues.containsKey(dimSourceName))){ 778 returnValue = false; 779 } 780 781 } 782 return returnValue; 783 } 784 785 790 private Map getDrillDownParams(DrillDownSpec drillDownSpec, Map cubeValues) { 791 Map params = new Hashtable(); 792 793 addFromParameter(params, drillDownSpec); 794 addFromDimension(params, drillDownSpec, cubeValues); 795 return params; 796 } 797 798 804 private void addFromDimension(Map params, DrillDownSpec drillDownSpec, Map cubeValues) { 805 String sourceDimensionName; 806 DimensionBindSpec dimensionBind; 807 String filterName; 808 for (int i = 0; i < drillDownSpec.getDimensionBindSpecs().size(); i++) { 809 dimensionBind = (DimensionBindSpec) drillDownSpec.getDimensionBindSpecs().toArray()[i]; 810 sourceDimensionName = dimensionBind.getSourceDimensionName(); 811 filterName = dimensionBind.getTargetFilterName() + dimensionBind.getTargetParameterName(); 812 if (cubeValues.containsKey(sourceDimensionName)) { 813 params.put(filterName, cubeValues.get(sourceDimensionName)); 814 } 815 } 816 } 817 818 823 private void addFromParameter(Map params, DrillDownSpec drillDownSpec) { 824 String sourceName, targetName; 825 for (int i = 0; i < drillDownSpec.getParameterBindSpecs().size(); i++) { 826 ParameterBindSpec parameterBindSpec = (ParameterBindSpec) drillDownSpec.getParameterBindSpecs().toArray()[i]; 827 sourceName = parameterBindSpec.getSourceFilterName() + parameterBindSpec.getSourceParameterName(); 828 targetName = parameterBindSpec.getTargetFilterName() + parameterBindSpec.getTargetParameterName(); 829 params.put(targetName, getReportResult().getReportSpec().getParamValues(false).get(sourceName)); 830 } 831 } 832 833 834 public JButton getEditDimensionValueBtn() { 835 return editDimensionValueBtn; 836 } 837 838 public JButton getOrdenBtn() { 839 return ordenBtn; 840 } 841 842 public boolean getFromMicroReport() { 843 return fromMicroReport; 844 } 845 846 public MicroReport getMicroReport() { 847 return microReport; 848 } 849 850 public JPanel getCenterPanel() { 851 return centerPanel; 852 } 853 854 public ReportGeneratorConfiguration getReportGeneratorConfiguration() { 855 return reportGeneratorConfiguration; 856 } 857 858 public JButton getExcel() { 859 return excel; 860 } 861 862 public void actionPerformed(ActionEvent e) { 863 if(e.getActionCommand().equals("BUSCAR")) { 864 865 } 866 } 867 868 public ReportViewerToolBar getToolBar() { 869 return toolBar; 870 } 871 872 public Frame owner() { 873 return parent.owner(); 874 } 875 876 public void setAutoRefresh(boolean value) throws InfoException { 877 autoRefresh = value; 878 if ( ! autoRefresh ){ 879 pivotTable.getDatajTable().setModel(new DefaultTableModel ()); 880 pivotTable.getRowHeaderjTable().setModel(new DefaultTableModel ()); 881 pivotTable.getColumnHeaderjTable().setModel(new DefaultTableModel ()); 882 }else{ 883 buildNewQuery(pivotTable.getTableProperties()); 884 pivotTable.fillContents(reportResult); 885 pivotTable.invaildatePanels(); 886 } 887 } 888 889 public boolean isAutoRefresh() { 890 return autoRefresh; 891 } 892 893 899 private void executeExportedReport(Map params, String reportDefinitionID, String userID) throws InfoException { 900 MicroReport microReport = null; 901 try { 902 microReport = getReportManager().getMicroReport(reportDefinitionID,params); 903 } catch (InfoException e) { 904 throw new InfoException(LanguageTraslator.traslate("462"),e); 905 } 906 toolBar = new ReportViewerToolBar(JToolBar.HORIZONTAL); 907 toolBar.drillDownExecuted(); 908 PivotTableFrame pivotTableFrame2 = null; 909 try { 910 pivotTableFrame2 = new PivotTableFrame(this,microReport,getReportManager(),getUserID(),getReportGeneratorConfiguration(),params); 911 } catch (InfoException e) { 912 throw new InfoException(LanguageTraslator.traslate("463"),e); 913 } 914 toolBar.setPivotTableFrame(pivotTableFrame2); 915 pivotTableFrame2.getFrame().getContentPane().add(toolBar, BorderLayout.PAGE_START); 916 pivotTableFrame2.show(); 917 } 918 919 public void launchInfoPage() throws Exception { 920 String infoPage = reportSpec.getInfoPage(); 921 if(infoPage==null || infoPage.equals("")){ 922 JOptionPane.showMessageDialog(getPivotTable(), LanguageTraslator.traslate("531"), LanguageTraslator.traslate("532"), JOptionPane.WARNING_MESSAGE); 923 }else{ 924 BrowserLauncher.openURL(infoPage); 925 } 926 } 927 } 928 | Popular Tags |