001: package com.calipso.reportgenerator.userinterface.dinamicchart;
002:
003: import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
004: import com.calipso.reportgenerator.common.ReportResult;
005: import com.calipso.reportgenerator.common.IReportManager;
006: import com.calipso.reportgenerator.userinterface.PivotTableProperties;
007: import com.calipso.reportgenerator.userinterface.ColumnProperties;
008: import com.calipso.reportgenerator.userinterface.MetricState;
009:
010: import java.util.*;
011: import java.awt.*;
012:
013: import com.calipso.reportgenerator.common.InfoException;
014:
015: /**
016: *
017: * User: soliveri
018: * Date: Jul 29, 2003
019: * Time: 12:58:23 PM
020: *
021: */
022:
023: public class ChartPivotTableManager {
024:
025: private static ChartPivotTableManager manager = new ChartPivotTableManager();
026: private HashMap targetPanels;
027: private com.calipso.reportgenerator.userinterface.dinamicchart.ChartQueryBuilder chartQueryBuilder;
028: private PivotTableProperties tableProperties;
029: private com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable gui;
030:
031: public static ChartPivotTableManager getManager() {
032: return manager;
033: }
034:
035: public void setManagerComponents(
036: com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable gui,
037: ReportResult reportResult, HashMap targetPanels,
038: IReportManager reportManager, Map params, String userId,
039: int reportHandle) throws InfoException {
040: this .gui = gui;
041: this .targetPanels = targetPanels;
042: tableProperties = new PivotTableProperties(reportResult);
043: chartQueryBuilder = new com.calipso.reportgenerator.userinterface.dinamicchart.ChartQueryBuilder(
044: reportManager, params, userId, reportHandle);
045: }
046:
047: public void dropJustHappened(DropPanel panel, String incoming,
048: Point point) {
049: regenerateModel(panel, getSourcePanel(
050: DimensionDefinitionLocationType.PAGE.toString(),
051: DimensionDefinitionLocationType.COLUMN.toString(),
052: DimensionDefinitionLocationType.ROW.toString(),
053: incoming), incoming, point);
054: }
055:
056: private void regenerateModel(DropPanel target, DropPanel source,
057: String dimension, Point point) {
058: target.addIncomingDimension(source, dimension, point);
059: updateProperties();
060: try {
061: gui.setReportResult(chartQueryBuilder
062: .buildNewQuery(tableProperties));
063: gui.repaintComponents();
064: } catch (InfoException e) {
065: e.printStackTrace();
066: }
067: }
068:
069: private void updateProperties() {
070: DropPanel rowPanel = (DropPanel) targetPanels
071: .get(DimensionDefinitionLocationType.ROW.toString());
072: fillTableProperties(rowPanel.getDimensions(),
073: DimensionDefinitionLocationType.ROW.toString());
074: DropPanel pagePanel = (DropPanel) targetPanels
075: .get(DimensionDefinitionLocationType.PAGE.toString());
076: fillTableProperties(pagePanel.getDimensions(),
077: DimensionDefinitionLocationType.PAGE.toString());
078: DropPanel colPanel = (DropPanel) targetPanels
079: .get(DimensionDefinitionLocationType.COLUMN.toString());
080: fillTableProperties(colPanel.getDimensions(),
081: DimensionDefinitionLocationType.COLUMN.toString());
082: }
083:
084: private void fillTableProperties(Vector dimensions, String location) {
085: for (int i = 0; i < dimensions.size(); i++) {
086: SourceDimension dimension = (SourceDimension) dimensions
087: .elementAt(i);
088: ColumnProperties properties = new ColumnProperties();
089: properties.setColumnName(dimension.getName());
090: properties.setLocation(location);
091: properties.setUbication(i);
092: properties.setExcludeValue(dimension.getExcludedValues());
093: tableProperties.setColumnProperties(properties);
094: }
095: }
096:
097: private DropPanel getSourcePanel(String panel1, String panel2,
098: String panel3, String incoming) {
099: if (((DropPanel) targetPanels.get(panel1)).contains(incoming)) {
100: return (DropPanel) targetPanels.get(panel1);
101: } else if (((DropPanel) targetPanels.get(panel2))
102: .contains(incoming)) {
103: return (DropPanel) targetPanels.get(panel2);
104: } else if (((DropPanel) targetPanels.get(panel3))
105: .contains(incoming)) {
106: return (DropPanel) targetPanels.get(panel3);
107: }
108: return null;
109: }
110:
111: public void dimensionValuesChanged(SourceDimension dimension,
112: HashSet dimensionValues) {
113: /*Iterator propertiesIterator = tableProperties.getColumnProperties().iterator();
114: while(propertiesIterator.hasNext()) {
115: ColumnProperties columnProperties = (ColumnProperties) propertiesIterator.next();
116: if(columnProperties.getColumnName().equals(dimension.getName())) {
117: columnProperties.setExcludeValue(dimensionValues);
118: break;
119: }
120: }*/
121: try {
122: updateProperties();
123: gui.setReportResult(chartQueryBuilder
124: .buildNewQuery(tableProperties));
125: gui.repaintComponents();
126: } catch (InfoException e) {
127: e.printStackTrace();
128: }
129: }
130:
131: public void chartTypeChanged(int chartType, boolean byRow) {
132: gui.generateChart(chartType, byRow);
133: }
134:
135: public void chartChanged(int chartType, boolean order) {
136: gui.generateChart(chartType, order);
137: }
138:
139: public void metricStateChanged(String metricName, boolean isVisible) {
140: MetricState metricState = (MetricState) tableProperties
141: .getMetricStates().get(metricName);
142: metricState.setVisible(isVisible);
143: metricState.getMetricSpec().setVisible(isVisible);
144: try {
145: gui.setReportResult(chartQueryBuilder
146: .buildNewQuery(tableProperties));
147: gui.repaintComponents();
148: } catch (InfoException e) {
149: e.printStackTrace();
150: }
151: }
152:
153: public void chartCustomizerChanged(int chartType, boolean byRow) {
154: gui.generateChart(chartType, byRow);
155: }
156: }
|