KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > dinamicchart > ChartPivotTableManager


1 package com.calipso.reportgenerator.userinterface.dinamicchart;
2
3 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
4 import com.calipso.reportgenerator.common.ReportResult;
5 import com.calipso.reportgenerator.common.IReportManager;
6 import com.calipso.reportgenerator.userinterface.PivotTableProperties;
7 import com.calipso.reportgenerator.userinterface.ColumnProperties;
8 import com.calipso.reportgenerator.userinterface.MetricState;
9
10 import java.util.*;
11 import java.awt.*;
12
13 import com.calipso.reportgenerator.common.InfoException;
14
15 /**
16  *
17  * User: soliveri
18  * Date: Jul 29, 2003
19  * Time: 12:58:23 PM
20  *
21  */

22
23 public class ChartPivotTableManager {
24
25   private static ChartPivotTableManager manager = new ChartPivotTableManager();
26   private HashMap targetPanels;
27   private com.calipso.reportgenerator.userinterface.dinamicchart.ChartQueryBuilder chartQueryBuilder;
28   private PivotTableProperties tableProperties;
29   private com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable gui;
30
31   public static ChartPivotTableManager getManager() {
32     return manager;
33   }
34
35   public void setManagerComponents(com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable gui, ReportResult reportResult, HashMap targetPanels, IReportManager reportManager, Map params, String JavaDoc userId, int reportHandle) throws InfoException {
36     this.gui = gui;
37     this.targetPanels = targetPanels;
38     tableProperties = new PivotTableProperties(reportResult);
39     chartQueryBuilder = new com.calipso.reportgenerator.userinterface.dinamicchart.ChartQueryBuilder(reportManager, params, userId, reportHandle);
40   }
41
42   public void dropJustHappened(DropPanel panel, String JavaDoc incoming, Point point) {
43     regenerateModel(panel, getSourcePanel(DimensionDefinitionLocationType.PAGE.toString(),
44                     DimensionDefinitionLocationType.COLUMN.toString(),
45                     DimensionDefinitionLocationType.ROW.toString(),
46                     incoming), incoming, point);
47   }
48
49   private void regenerateModel(DropPanel target, DropPanel source, String JavaDoc dimension, Point point) {
50     target.addIncomingDimension(source, dimension, point);
51     updateProperties();
52     try {
53       gui.setReportResult(chartQueryBuilder.buildNewQuery(tableProperties));
54       gui.repaintComponents();
55     } catch (InfoException e) {
56       e.printStackTrace();
57     }
58   }
59
60   private void updateProperties() {
61     DropPanel rowPanel = (DropPanel) targetPanels.get(DimensionDefinitionLocationType.ROW.toString());
62     fillTableProperties(rowPanel.getDimensions(), DimensionDefinitionLocationType.ROW.toString());
63     DropPanel pagePanel = (DropPanel) targetPanels.get(DimensionDefinitionLocationType.PAGE.toString());
64     fillTableProperties(pagePanel.getDimensions(), DimensionDefinitionLocationType.PAGE.toString());
65     DropPanel colPanel = (DropPanel) targetPanels.get(DimensionDefinitionLocationType.COLUMN.toString());
66     fillTableProperties(colPanel.getDimensions(), DimensionDefinitionLocationType.COLUMN.toString());
67   }
68
69   private void fillTableProperties(Vector dimensions, String JavaDoc location) {
70     for(int i = 0 ; i < dimensions.size() ; i++) {
71       SourceDimension dimension = (SourceDimension) dimensions.elementAt(i);
72       ColumnProperties properties = new ColumnProperties();
73       properties.setColumnName(dimension.getName());
74       properties.setLocation(location);
75       properties.setUbication(i);
76       properties.setExcludeValue(dimension.getExcludedValues());
77       tableProperties.setColumnProperties(properties);
78     }
79   }
80
81   private DropPanel getSourcePanel(String JavaDoc panel1, String JavaDoc panel2, String JavaDoc panel3, String JavaDoc incoming) {
82     if(((DropPanel) targetPanels.get(panel1)).contains(incoming)) {
83       return (DropPanel) targetPanels.get(panel1);
84     } else if(((DropPanel) targetPanels.get(panel2)).contains(incoming)) {
85       return (DropPanel) targetPanels.get(panel2);
86     } else if(((DropPanel) targetPanels.get(panel3)).contains(incoming)) {
87       return (DropPanel) targetPanels.get(panel3);
88     }
89     return null;
90   }
91
92   public void dimensionValuesChanged(SourceDimension dimension, HashSet dimensionValues) {
93     /*Iterator propertiesIterator = tableProperties.getColumnProperties().iterator();
94     while(propertiesIterator.hasNext()) {
95       ColumnProperties columnProperties = (ColumnProperties) propertiesIterator.next();
96       if(columnProperties.getColumnName().equals(dimension.getName())) {
97         columnProperties.setExcludeValue(dimensionValues);
98         break;
99       }
100     }*/

101     try {
102       updateProperties();
103       gui.setReportResult(chartQueryBuilder.buildNewQuery(tableProperties));
104       gui.repaintComponents();
105     } catch (InfoException e) {
106       e.printStackTrace();
107     }
108   }
109
110   public void chartTypeChanged(int chartType, boolean byRow) {
111     gui.generateChart(chartType, byRow);
112   }
113
114   public void chartChanged(int chartType, boolean order) {
115     gui.generateChart(chartType, order);
116   }
117
118   public void metricStateChanged(String JavaDoc metricName, boolean isVisible) {
119     MetricState metricState = (MetricState) tableProperties.getMetricStates().get(metricName);
120     metricState.setVisible(isVisible);
121     metricState.getMetricSpec().setVisible(isVisible);
122     try {
123       gui.setReportResult(chartQueryBuilder.buildNewQuery(tableProperties));
124       gui.repaintComponents();
125     } catch (InfoException e) {
126       e.printStackTrace();
127     }
128   }
129
130   public void chartCustomizerChanged(int chartType, boolean byRow) {
131     gui.generateChart(chartType, byRow);
132   }
133 }
134
135
Popular Tags