001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * Created Jul 06, 2007
014: * @author gmoran
015: */
016: package org.pentaho.plugin.jfreereport.reportcharts;
017:
018: import java.util.ArrayList;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.jfree.data.general.AbstractDataset;
023: import org.jfree.report.event.ReportEvent;
024: import org.jfree.report.function.AbstractFunction;
025: import org.jfree.report.function.Expression;
026: import org.jfree.report.function.FunctionUtilities;
027: import org.pentaho.messages.Messages;
028:
029: /**
030: * Creation-Date: 07.06.2007, 18:30:22
031: *
032: * @author Gretchen Moran
033: */
034: public abstract class BaseCollectorFunction extends AbstractFunction
035: implements ICollectorFunction {
036:
037: private AbstractDataset dataset;
038:
039: private String group;
040:
041: private String resetGroup;
042:
043: private ArrayList results;
044:
045: private int currentIndex;
046:
047: private boolean summaryOnly = true;
048:
049: private boolean seriesColumn = false;
050:
051: protected static final Log logger = LogFactory
052: .getLog(BaseCollectorFunction.class);
053:
054: public BaseCollectorFunction() {
055: this .results = new ArrayList();
056: }
057:
058: /*
059: * ---------------------------------------------------------------- Standard accessors - we use indexed properties for the series config.
060: */
061:
062: public abstract AbstractDataset getNewDataset();
063:
064: public boolean isSummaryOnly() {
065: return summaryOnly;
066: }
067:
068: public void setSummaryOnly(boolean value) {
069: summaryOnly = value;
070: }
071:
072: public boolean isSeriesColumn() {
073: return seriesColumn;
074: }
075:
076: public void setSeriesColumn(boolean value) {
077: seriesColumn = value;
078: }
079:
080: public String getGroup() {
081: return group;
082: }
083:
084: public void setGroup(final String group) {
085: this .group = group;
086: }
087:
088: public String getResetGroup() {
089: return resetGroup;
090: }
091:
092: public void setResetGroup(final String resetGroup) {
093: this .resetGroup = resetGroup;
094: }
095:
096: /*
097: * ---------------------------------------------------------------- Now the function implementation ...
098: */
099:
100: /**
101: * @return the dataset
102: */
103: public Object getValue() {
104: return this ;
105: }
106:
107: public Object getDatasourceValue() {
108: return dataset;
109: }
110:
111: public void reportInitialized(ReportEvent event) {
112: currentIndex = -1;
113: logger
114: .debug(Messages
115: .getString("CATEGORYSETCOLL.USER_DEBUG_REPORT_INITIALIZED")); //$NON-NLS-1$
116: if (FunctionUtilities.isDefinedPrepareRunLevel(this , event)) {
117: dataset = null;
118: results.clear();
119: if (getResetGroup() == null) {
120:
121: dataset = getNewDataset();
122: results.add(dataset);
123:
124: }
125: } else {
126: // Activate the current group, which was filled in the prepare run.
127: if (getResetGroup() == null) {
128: dataset = (AbstractDataset) results.get(0);
129: }
130: }
131: }
132:
133: public void groupStarted(ReportEvent event) {
134: final String localGroup = getGroup();
135: if (localGroup != null) {
136:
137: logger
138: .debug(Messages
139: .getString("CATEGORYSETCOLL.USER_DEBUG_GROUP_STARTED")); //$NON-NLS-1$
140: if (FunctionUtilities
141: .isDefinedGroup(getResetGroup(), event)) {
142: // reset ...
143: if (FunctionUtilities.isDefinedPrepareRunLevel(this ,
144: event)) {
145: dataset = getNewDataset();
146: results.add(dataset);
147: } else {
148: if (FunctionUtilities.isLayoutLevel(event)) {
149: // Activate the current group, which was filled in the prepare run.
150: currentIndex += 1;
151: dataset = (AbstractDataset) results
152: .get(currentIndex);
153: }
154: }
155: }
156: }
157: }
158:
159: /**
160: * Return a completly separated copy of this function. The copy no longer shares any changeable objects with the original function.
161: * Also from Thomas:
162: * Should retain data from the report definition, but clear calculated data.
163: *
164: * @return a copy of this function.
165: */
166: public Expression getInstance() {
167: final BaseCollectorFunction fn = (BaseCollectorFunction) super
168: .getInstance();
169: fn.dataset = null;
170: fn.results = new ArrayList();
171: return fn;
172: }
173:
174: public Object getCacheKey() {
175: return this .dataset;
176: }
177:
178: // public void setCacheKey(Object cacheKey) {
179: // this.cacheKey = cacheKey;
180: // }
181:
182: }
|