KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > PivotTableFrame


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 JavaDoc;
15 import java.awt.*;
16 import java.awt.event.WindowAdapter JavaDoc;
17 import java.awt.event.ActionListener JavaDoc;
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.util.*;
20 import java.util.zip.ZipOutputStream JavaDoc;
21 import java.io.File JavaDoc;
22
23 import com.calipso.reportgenerator.common.InfoException;
24
25 /**
26  * Esta clase muestra el cubo en un frame propio
27  */

28 public class PivotTableFrame extends ReportFrame implements ActionListener JavaDoc, 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 JavaDoc 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   /**
63    * Inicializa
64    * @param reportDefId
65    * @param reportManager
66    */

67   public PivotTableFrame(IReportFrame parent, String JavaDoc reportDefId, IReportManager reportManager, Map params, String JavaDoc 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 JavaDoc reportDefId, IReportManager reportManager, Map params, String JavaDoc userId, String JavaDoc 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 JavaDoc 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     //TODO: el MicroReport puede tener n vistas, con lo cual esto no seria lo mas correcto.
118
super.reportResult = reportManager.ExecReportQuery(reportHandle,microReport.getReportView());
119     initComponents();
120   }
121
122   public PivotTableFrame(IReportFrame parent, MicroReport microReport, IReportManager reportManager, String JavaDoc 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   /**
140    * Inicializa los componentes del cubo
141    */

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 JavaDoc() {
149       public void windowClosing() {
150         System.exit(0);
151       }
152     });
153
154     /*getGraphicButton().addActionListener(new java.awt.event.ActionListener() {
155       public void actionPerformed(java.awt.event.ActionEvent evt) {
156         doGraphics();
157       }
158     });*/

159
160     /*getSinTotales().addActionListener(new java.awt.event.ActionListener() {
161       public void actionPerformed(java.awt.event.ActionEvent evt) {
162         try {
163           pivotTable.setPivoteTableSinTotales();
164         }
165         catch (Exception e) {
166           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("103"), e);
167         }
168       }
169     });*/

170
171     /*getPrintButton().addActionListener(new java.awt.event.ActionListener() {
172       public void actionPerformed(java.awt.event.ActionEvent evt) {
173         printPivotTable();
174
175       }
176     });*/

177
178     /*getExportMicroReportButton().addActionListener(new java.awt.event.ActionListener() {
179       public void actionPerformed(java.awt.event.ActionEvent evt) {
180         exportMicroReport();
181       }
182     });*/

183
184     /*maximizar.addActionListener(new java.awt.event.ActionListener() {
185       public void actionPerformed(java.awt.event.ActionEvent evt) {
186         maximizarActionPerformed();
187       }
188     });*/

189
190     frame.pack();
191     java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
192     frame.setSize(new java.awt.Dimension JavaDoc(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 JavaDoc 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 JavaDoc zipOutputStream = microReport.getZip(file.getPath(), reportGeneratorConfiguration.isCsvSerialized());
216         zipOutputStream.close();
217       }
218       catch (Exception JavaDoc e) {
219         ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("267"),e);
220       }
221     }
222   }
223
224   /**
225    * Devuleve un map con los view para el reporte para el usuario
226    * @return
227    */

228   public Map getViews(String JavaDoc reportDefinitionId) throws InfoException {
229     Map map = reportManager.getReportViews(reportDefinitionId,userID);
230     Map returnMap = new HashMap();
231     String JavaDoc 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(createEastBoxPanel(), BorderLayout.WEST);
246
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     //bottomPanel.setPreferredSize(new Dimension(100, 10));
254
return bottomPanel;
255   }
256
257   private Component createPivoteTablePanel() {
258     pivotPanel = new JPanel();
259     pivotPanel.setLayout(new BorderLayout());
260     //pivotPanel.setPreferredSize(new Dimension(700,450));
261
return pivotPanel;
262   }
263
264   private Component createEastBoxPanel() {
265     boxPanel = new javax.swing.JPanel JavaDoc();
266     boxPanel.setLayout(new javax.swing.BoxLayout JavaDoc(boxPanel, javax.swing.BoxLayout.Y_AXIS));
267     //boxPanel.add(createJButtonResize());
268
//boxPanel.add(createJButtonSinTotals());
269
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 JavaDoc(WIDTH, HEIGTH));
296     printButton.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
297     printButton.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc(WIDTH, HEIGTH));
306     exportMicroReportButton.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
307     exportMicroReportButton.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc(WIDTH, HEIGTH));
317     graphicButton.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
318     graphicButton.setPreferredSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
319     return graphicButton;
320   }
321
322   /*private JButton createJButtonSinTotals() {
323     sinTotales = new JButton(LanguageTraslator.traslate("135"));
324     sinTotales.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
325     sinTotales.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
326     sinTotales.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
327     return sinTotales;
328   }*/

329
330   /*private JButton createJButtonResize() {
331     maximizar = new JButton(LanguageTraslator.traslate("136"));
332     maximizar.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
333     maximizar.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
334     maximizar.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
335     return maximizar;
336   }*/

337
338   private JButton createJButtonSearcher() {
339     searcher = makeNavigationButton("search", "BUSCAR",
340                                     "Busca valores para las dimensiones",
341                                     "");
342     searcher.setMaximumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
343     searcher.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
344     searcher.setPreferredSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
345     return searcher;
346   }
347
348   private JButton makeNavigationButton(String JavaDoc imageName,
349                                          String JavaDoc actionCommand,
350                                          String JavaDoc toolTipText,
351                                          String JavaDoc altText) {
352
353
354     String JavaDoc imgLocation = reportGeneratorConfiguration.getImagesPath()
355                          + "\\" + imageName
356                          + ".gif";
357
358     //Create and initialize the button.
359

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 JavaDoc(WIDTH, HEIGTH));
378     excel.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
379     excel.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc(WIDTH, HEIGTH));
388     semaforo.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
389     semaforo.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc(WIDTH, HEIGTH));
398     viewBtn.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
399     viewBtn.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc(WIDTH, HEIGTH));
408     editDimensionValueBtn.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
409     editDimensionValueBtn.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc(WIDTH, HEIGTH));
418     ordenBtn.setMinimumSize(new java.awt.Dimension JavaDoc(WIDTH, HEIGTH));
419     ordenBtn.setPreferredSize(new java.awt.Dimension JavaDoc(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 reportQuery = getReportResult().getReportQuery();
426
reportQuery.getQueryMetricFromName(state.getName()).setVisible(state.getVisible());
427
428     try {
429       //reportQuery = updateDimensionLocation(tableProperties, reportQuery);
430
reportQuery = buildNewQueryExcludeValue(tableProperties, reportQuery, false, false);
431       //reportQuery = updateVisibleMetrics(tableProperties, reportQuery);
432
//reportQuery.setVisibleTotals(tableProperties.isWithTotal());
433
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 JavaDoc 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   /**
463    * Devuelve el Frame
464    * @return
465    */

466   public JFrame getFrame() {
467     if (frame == null) {
468       frame = new JFrame();
469       //frame.getContentPane().setLayout(new BorderLayout());
470
frame.setTitle(reportResult.getReportSpec().getTitle());
471       frame.setName("Cube");
472     }
473     return frame;
474   }
475
476   /**
477    * Muestra el cubo
478    */

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   /**
508    * Luego de un drag and drop regenera la query
509    */

510   public void revalidateReportResult(PivotTableProperties tableProperties) {
511     if (reportManager != null) {
512       try {
513         buildNewQuery(tableProperties);
514       }
515       catch (Exception JavaDoc e) {
516         ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e);
517       }
518     }
519   }
520
521   /**
522    * Construye la nueva query a partir de las nuevas posiciones de las dimensiones y la ejecuta.
523    */

524   public void buildNewQuery(PivotTableProperties tableProperties) throws InfoException {
525     System.gc();
526     ReportQuery reportQuery = getReportManager().getDefaultReportQuery(reportHandle);
527     //ReportQuery reportQuery = getReportResult().getReportQuery();
528
//reportQuery = updateDimensionLocation(tableProperties, reportQuery);
529
reportQuery = buildNewQueryExcludeValue(tableProperties, reportQuery, false, true);
530     //reportQuery = updateVisibleMetrics(tableProperties, reportQuery);
531
//reportQuery.setVisibleTotals(tableProperties.isWithTotal());
532
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   /**
574    * Actualiza los valores de metricas visibles de la reportquery de acuerdo a la pivot table properties
575    * @param tableProperties
576    * @param reportQuery
577    */

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 JavaDoc 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   /**
633    * Devuelve el administrador de reportes
634    * @return
635    */

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 JavaDoc getUserID() {
677     return userID;
678   }
679
680   public void setUserID(String JavaDoc userID) {
681     this.userID = userID;
682   }
683
684   public int getReportHandle() {
685     return reportHandle;
686   }
687
688
689   /**
690    * ejecuta un drilldown segun la definición
691    * @param drillDownDefinition
692    */

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 JavaDoc 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 JavaDoc 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 JavaDoc e) {
737             throw new InfoException("151", e);
738         }
739       }
740     }else{
741       String JavaDoc dimSourceNames="";
742       for (int i =0;(i<drillDownDefinition.getDimensionBindSpecs().size());i++){
743         String JavaDoc 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 JavaDoc urlBase, String JavaDoc reportId, String JavaDoc user) throws InfoException {
752     String JavaDoc url = getUrl(urlBase, params, reportId, user);
753     try {
754       BrowserLauncher.openURL(url);
755     } catch (Exception JavaDoc e) {
756       throw new InfoException(LanguageTraslator.traslate("464"), e);
757     }
758   }
759
760   private String JavaDoc getUrl(String JavaDoc baseUrl, Map params, String JavaDoc definitionId, String JavaDoc user) {
761     String JavaDoc 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 JavaDoc dimSourceName = ((DimensionBindSpec)drillDownDefinition.getDimensionBindSpecs().get(i)).getSourceDimensionName();
777       if (!(cubeValues.containsKey(dimSourceName))){
778         returnValue = false;
779       }
780
781     }
782     return returnValue;
783   }
784
785   /**
786    * Devuelve los parámetros cargados según el mapeo
787    * @param drillDownSpec
788    * @return
789    */

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   /**
799    * Carga los parámetros a partir de los valores de las dimensiones
800    * @param params
801    * @param drillDownSpec
802    * @param cubeValues
803    */

804   private void addFromDimension(Map params, DrillDownSpec drillDownSpec, Map cubeValues) {
805     String JavaDoc sourceDimensionName;
806     DimensionBindSpec dimensionBind;
807     String JavaDoc 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   /**
819    * Carga los parámetros de acuerdo a los mapeos de parámetro a parámetro
820    * @param params
821    * @param drillDownSpec
822    */

823   private void addFromParameter(Map params, DrillDownSpec drillDownSpec) {
824     String JavaDoc 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 JavaDoc 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 JavaDoc());
880       pivotTable.getRowHeaderjTable().setModel(new DefaultTableModel JavaDoc());
881       pivotTable.getColumnHeaderjTable().setModel(new DefaultTableModel JavaDoc());
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   /**
894    * Ecuta un reporte que está exportado a micro report. Lo busca según los parámetros que se pasan en el repositorio de microreport
895    * @param params
896    * @param reportDefinitionID
897    * @param userID
898    */

899   private void executeExportedReport(Map params, String JavaDoc reportDefinitionID, String JavaDoc 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 JavaDoc {
920     String JavaDoc 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