001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * SubDataset.java
028: *
029: * Created on 28 settembre 2005, 1.39
030: *
031: */
032:
033: package it.businesslogic.ireport;
034:
035: import it.businesslogic.ireport.gui.event.SubDatasetObjectChangedEvent;
036: import java.util.*;
037: import org.syntax.jedit.IReportKeywordLookup;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class SubDataset {
044:
045: private String name = "";
046:
047: private IReportKeywordLookup keywordLookup = new IReportKeywordLookup();
048:
049: private String query = "";
050:
051: private Vector fields = new Vector();
052:
053: private Vector parameters = new Vector();
054:
055: private Vector variables = new Vector();
056:
057: private Vector groups = new Vector();
058:
059: private Vector sortFields = new Vector();
060:
061: private java.util.Vector JRproperties = new Vector();
062:
063: private String whenResourceMissingType = "Null";
064:
065: private String scriptletClass = "";
066:
067: private String ResourceBundleBaseName = "";
068:
069: private String filterExpression = "";
070:
071: /**
072: * the type of the query
073: * iReport understands "sql", "hql" and "xPath";
074: */
075: private String queryLanguage = "sql";
076:
077: /** Getter for property query.
078: * @return Value of property query.
079: *
080: */
081: public java.lang.String getQuery() {
082: return query;
083: }
084:
085: /** Setter for property query.
086: * @param query New value of property query.
087: *
088: */
089: public void setQuery(java.lang.String query) {
090: if ((this .query == null) ? query == null : this .query
091: .equals(query))
092: return;
093: this .query = query;
094: this
095: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
096: this , SubDatasetObjectChangedEvent.QUERY,
097: SubDatasetObjectChangedEvent.MODIFIED, query,
098: query));
099: }
100:
101: /**********************************************************/
102: // FIELDS
103: /** Getter for property fields.
104: * @return Value of property fields.
105: *
106: */
107: public java.util.Vector getFields() {
108: return fields;
109: }
110:
111: public void addField(JRField field) {
112: this .fields.add(field);
113: getKeywordLookup().addKeyword("$F{" + field.getName() + "}");
114: this
115: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
116: this , SubDatasetObjectChangedEvent.FIELD,
117: SubDatasetObjectChangedEvent.ADDED, field,
118: field));
119: }
120:
121: public void removeField(JRField field) {
122: this .fields.remove(field);
123: getKeywordLookup().removeKeyword("$F{" + field.getName() + "}");
124: this
125: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
126: this , SubDatasetObjectChangedEvent.FIELD,
127: SubDatasetObjectChangedEvent.DELETED, field,
128: field));
129: }
130:
131: /** Setter for property fields.
132: * @param fields New value of property fields.
133: *
134: */
135: public void setFields(java.util.Vector fields) {
136: this .fields = fields;
137: }
138:
139: /** Getter for property parameters.
140: * @return Value of property parameters.
141: *
142: */
143: public java.util.Vector getParameters() {
144: return parameters;
145: }
146:
147: /** Setter for property parameters.
148: * @param parameters New value of property parameters.
149: *
150: */
151: public void setParameters(java.util.Vector parameters) {
152: this .parameters = parameters;
153: }
154:
155: public void addParameter(JRParameter parameter) {
156: this .parameters.add(parameter);
157: getKeywordLookup()
158: .addKeyword("$P{" + parameter.getName() + "}");
159: this
160: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
161: this , SubDatasetObjectChangedEvent.PARAMETER,
162: SubDatasetObjectChangedEvent.ADDED, parameter,
163: parameter));
164: }
165:
166: public void removeParameter(JRParameter parameter) {
167: if (parameter.isBuiltin())
168: return;
169: this .parameters.remove(parameter);
170: getKeywordLookup().removeKeyword(
171: "$P{" + parameter.getName() + "}");
172: this
173: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
174: this , SubDatasetObjectChangedEvent.PARAMETER,
175: SubDatasetObjectChangedEvent.DELETED,
176: parameter, parameter));
177: }
178:
179: /** Getter for property variables.
180: * @return Value of property variables.
181: *
182: */
183: public java.util.Vector getVariables() {
184: return variables;
185: }
186:
187: public void addVariable(JRVariable variable) {
188: this .variables.add(variable);
189: getKeywordLookup().addKeyword("$V{" + variable.getName() + "}");
190: this
191: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
192: this , SubDatasetObjectChangedEvent.VARIABLE,
193: SubDatasetObjectChangedEvent.ADDED, variable,
194: variable));
195: }
196:
197: public void removeVariable(JRVariable variable) {
198: if (variable.isBuiltin())
199: return;
200: this .variables.remove(variable);
201: getKeywordLookup().removeKeyword(
202: "$V{" + variable.getName() + "}");
203: this
204: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
205: this , SubDatasetObjectChangedEvent.VARIABLE,
206: SubDatasetObjectChangedEvent.DELETED, variable,
207: variable));
208: }
209:
210: /** Setter for property variables.
211: * @param variables New value of property variables.
212: *
213: */
214: public void setVariables(java.util.Vector variables) {
215: this .variables = variables;
216: }
217:
218: /** Getter for property groups.
219: * @return Value of property groups.
220: *
221: */
222: public java.util.Vector getGroups() {
223: return groups;
224: }
225:
226: /** Setter for property groups.
227: * @param groups New value of property groups.
228: *
229: */
230: public void setGroups(java.util.Vector groups) {
231: this .groups = groups;
232: }
233:
234: /**********************************************************/
235: // KEYWORDS LOOKUP
236: public IReportKeywordLookup getKeywordLookup() {
237: return keywordLookup;
238: }
239:
240: public void setKeywordLookup(IReportKeywordLookup keywordLookup) {
241: this .keywordLookup = keywordLookup;
242: }
243:
244: public String getWhenResourceMissingType() {
245: return whenResourceMissingType;
246: }
247:
248: public void setWhenResourceMissingType(
249: String whenResourceMissingType) {
250: this .whenResourceMissingType = whenResourceMissingType;
251: }
252:
253: /** Getter for property scriptletClass.
254: * @return Value of property scriptletClass.
255: *
256: */
257: public java.lang.String getScriptletClass() {
258: return scriptletClass;
259: }
260:
261: /** Setter for property scriptletClass.
262: * @param scriptletClass New value of property scriptletClass.
263: *
264: */
265: public void setScriptletClass(java.lang.String scriptletClass) {
266: this .scriptletClass = scriptletClass;
267: }
268:
269: public String getResourceBundleBaseName() {
270: return ResourceBundleBaseName;
271: }
272:
273: public void setResourceBundleBaseName(String ResourceBundleBaseName) {
274: this .ResourceBundleBaseName = ResourceBundleBaseName;
275: }
276:
277: /** Getter for property name.
278: * @return Value of property name.
279: *
280: */
281: public java.lang.String getName() {
282: return name;
283: }
284:
285: /** Setter for property name.
286: * @param name New value of property name.
287: *
288: */
289: public void setName(java.lang.String name) {
290: this .name = name;
291: }
292:
293: public String toString() {
294: return getName();
295: }
296:
297: /**
298: * Utility field used by event firing mechanism.
299: */
300: private javax.swing.event.EventListenerList listenerList = null;
301:
302: /**
303: * Registers SubDatasetObjectChangedListener to receive events.
304: * @param listener The listener to register.
305: */
306: public synchronized void addSubDatasetObjectChangedListener(
307: it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener listener) {
308: if (getListenerList() == null) {
309: setListenerList(new javax.swing.event.EventListenerList());
310: }
311: getListenerList()
312: .add(
313: it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener.class,
314: listener);
315: }
316:
317: /**
318: * Removes SubDatasetObjectChangedListener from the list of listeners.
319: * @param listener The listener to remove.
320: */
321: public synchronized void removeSubDatasetObjectChangedListener(
322: it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener listener) {
323: getListenerList()
324: .remove(
325: it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener.class,
326: listener);
327: }
328:
329: /**
330: * Notifies all registered listeners about the event.
331: *
332: * @param event The event to be fired
333: */
334: public void fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(
335: it.businesslogic.ireport.gui.event.SubDatasetObjectChangedEvent event) {
336: if (getListenerList() == null)
337: return;
338: Object[] listeners = getListenerList().getListenerList();
339: for (int i = listeners.length - 2; i >= 0; i -= 2) {
340: if (listeners[i] == it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener.class) {
341: ((it.businesslogic.ireport.gui.event.SubDatasetObjectChangedListener) listeners[i + 1])
342: .subDatasetObjectChanged(event);
343: }
344: }
345: }
346:
347: public SubDataset() {
348: addVariable(new JRVariable("PAGE_NUMBER", "java.lang.Integer",
349: true));
350: addVariable(new JRVariable("COLUMN_NUMBER",
351: "java.lang.Integer", true));
352: addVariable(new JRVariable("REPORT_COUNT", "java.lang.Integer",
353: true));
354: addVariable(new JRVariable("PAGE_COUNT", "java.lang.Integer",
355: true));
356: addVariable(new JRVariable("COLUMN_COUNT", "java.lang.Integer",
357: true));
358:
359: addParameter(new JRParameter("REPORT_PARAMETERS_MAP",
360: "java.util.Map", false, "", true));
361: addParameter(new JRParameter("REPORT_CONNECTION",
362: "java.sql.Connection", false, "", true));
363: addParameter(new JRParameter("REPORT_MAX_COUNT",
364: "java.lang.Integer", false, "", true));
365: addParameter(new JRParameter("REPORT_DATA_SOURCE",
366: "net.sf.jasperreports.engine.JRDataSource", false, "",
367: true));
368: addParameter(new JRParameter("REPORT_SCRIPTLET",
369: "net.sf.jasperreports.engine.JRAbstractScriptlet",
370: false, "", true));
371: addParameter(new JRParameter("REPORT_LOCALE",
372: "java.util.Locale", false, "", true));
373: addParameter(new JRParameter("REPORT_RESOURCE_BUNDLE",
374: "java.util.ResourceBundle", false, "", true));
375: addParameter(new JRParameter("REPORT_TIME_ZONE",
376: "java.util.TimeZone", false, "", true));
377: addParameter(new JRParameter("REPORT_VIRTUALIZER",
378: "net.sf.jasperreports.engine.JRVirtualizer", false, "",
379: true));
380: addParameter(new JRParameter("REPORT_CLASS_LOADER",
381: "java.lang.ClassLoader", false, "", true));
382: addParameter(new JRParameter("REPORT_URL_HANDLER_FACTORY",
383: "java.net.URLStreamHandlerFactory", false, "", true));
384: addParameter(new JRParameter("REPORT_FORMAT_FACTORY",
385: "net.sf.jasperreports.engine.util.FormatFactory",
386: false, "", true));
387: addParameter(new JRParameter("IS_IGNORE_PAGINATION",
388: "java.lang.Boolean", false, "", true));
389:
390: addParameter(new JRParameter("HIBERNATE_SESSION",
391: "org.hibernate.Session", false, "", true));
392: addParameter(new JRParameter("XML_DATA_DOCUMENT",
393: "org.w3c.dom.Document", false, "", true));
394: addParameter(new JRParameter("JPA_ENTITY_MANAGER",
395: "javax.persistence.EntityManager", false, "", true));
396: addParameter(new JRParameter("JPA_QUERY_HINTS_MAP",
397: "java.util.Map", false, "", true));
398: addParameter(new JRParameter("MONDRIAN_CONNECTION",
399: "mondrian.olap.Connection", false, "", true));
400:
401: //addParameter(new JRParameter("XMLA_URL","java.util.String",false,"",true));
402: //addParameter(new JRParameter("XMLA_DATASOURCE","java.util.String",false,"",true));
403: //addParameter(new JRParameter("XMLA_CATALOG","java.util.String",false,"",true));
404: }
405:
406: public void addJRProperty(JRProperty property) {
407: this .JRproperties.add(property);
408: }
409:
410: public void removeJRProperty(JRProperty property) {
411: this .JRproperties.remove(property);
412: }
413:
414: /** Getter for property JRproperties.
415: * @return Value of property JRproperties.
416: *
417: */
418: public java.util.Vector getJRproperties() {
419: return JRproperties;
420: }
421:
422: /** Setter for property JRproperties.
423: * @param JRproperties New value of property JRproperties.
424: *
425: */
426: public void setJRproperties(java.util.Vector JRproperties) {
427: this .JRproperties = JRproperties;
428: }
429:
430: public String getQueryLanguage() {
431: return queryLanguage;
432: }
433:
434: public void setQueryLanguage(String queryLanguage) {
435: if ((this .queryLanguage == null) ? queryLanguage == null
436: : this .queryLanguage.equals(queryLanguage))
437: return;
438: this .queryLanguage = queryLanguage;
439: this
440: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
441: this ,
442: SubDatasetObjectChangedEvent.QUERY_LANGUAGE,
443: SubDatasetObjectChangedEvent.MODIFIED,
444: queryLanguage, queryLanguage));
445: }
446:
447: protected String language = "java";
448:
449: public javax.swing.event.EventListenerList getListenerList() {
450: return listenerList;
451: }
452:
453: public void setListenerList(
454: javax.swing.event.EventListenerList listenerList) {
455: this .listenerList = listenerList;
456: }
457:
458: public String getFilterExpression() {
459: return filterExpression;
460: }
461:
462: public void setFilterExpression(String filterExpression) {
463: this .filterExpression = filterExpression;
464: }
465:
466: public Vector getSortFields() {
467: return sortFields;
468: }
469:
470: public void setSortFields(Vector sortFields) {
471: this .sortFields = sortFields;
472: }
473:
474: public void addSortField(SortField sortField) {
475: this .getSortFields().add(sortField);
476: this
477: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
478: this , SubDatasetObjectChangedEvent.SORTFIELD,
479: SubDatasetObjectChangedEvent.ADDED, sortField,
480: sortField));
481: }
482:
483: public void removeSortField(SortField sortField) {
484: this .getSortFields().remove(sortField);
485: this
486: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
487: this, SubDatasetObjectChangedEvent.SORTFIELD,
488: SubDatasetObjectChangedEvent.DELETED,
489: sortField, sortField));
490: }
491: }
|