001: /*
002: * Copyright 2006-2007 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.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.model;
015:
016: import org.jetbrains.annotations.NonNls;
017: import org.jetbrains.annotations.NotNull;
018: import org.jetbrains.annotations.Nullable;
019: import org.pentaho.reportdesigner.crm.report.datasetplugin.DataSetPlugin;
020: import org.pentaho.reportdesigner.crm.report.model.dataset.DataSetReportElement;
021: import org.pentaho.reportdesigner.crm.report.reportelementinfo.ReportElementInfoFactory;
022: import org.pentaho.reportdesigner.crm.report.templateplugin.IndentedLayoutPlugin;
023: import org.pentaho.reportdesigner.crm.report.templateplugin.LayoutException;
024: import org.pentaho.reportdesigner.crm.report.templateplugin.LayoutPlugin;
025: import org.pentaho.reportdesigner.crm.report.templateplugin.LayoutStyle;
026: import org.pentaho.reportdesigner.crm.report.wizard.WizardData;
027: import org.pentaho.reportdesigner.lib.client.util.UncaughtExcpetionsModel;
028:
029: import java.util.HashMap;
030:
031: /**
032: * User: Martin
033: * Date: 20.10.2005
034: * Time: 15:57:25
035: */
036: @NonNls
037: public class ReportFactory {
038: private ReportFactory() {
039: }
040:
041: @NotNull
042: public static Report createEmptyReport() {
043: return new Report(ReportElementInfoFactory.getInstance()
044: .getBandToplevelReportElementInfo(
045: BandToplevelType.REPORT_HEADER)
046: .createReportElement(), ReportElementInfoFactory
047: .getInstance().getBandToplevelReportElementInfo(
048: BandToplevelType.REPORT_FOOTER)
049: .createReportElement(), ReportElementInfoFactory
050: .getInstance().getBandToplevelReportElementInfo(
051: BandToplevelType.PAGE_HEADER)
052: .createReportElement(), ReportElementInfoFactory
053: .getInstance().getBandToplevelReportElementInfo(
054: BandToplevelType.PAGE_FOOTER)
055: .createReportElement(), ReportElementInfoFactory
056: .getInstance().getReportGroupsElementInfo()
057: .createReportElement(), ReportElementInfoFactory
058: .getInstance().getBandToplevelReportElementInfo(
059: BandToplevelType.ITEM_BAND)
060: .createReportElement(), ReportElementInfoFactory
061: .getInstance().getBandToplevelReportElementInfo(
062: BandToplevelType.WATERMARK)
063: .createReportElement(), ReportElementInfoFactory
064: .getInstance().getBandToplevelReportElementInfo(
065: BandToplevelType.NO_DATA_BAND)
066: .createReportElement(), new PageDefinition(
067: PageFormatPreset.A4, PageOrientation.PORTRAIT, 20, 20,
068: 20, 20), ReportElementInfoFactory.getInstance()
069: .getReportFunctionsElementInfo().createReportElement());
070: }
071:
072: @NotNull
073: public static SubReport createEmptySubReport() {
074: return new SubReport(ReportElementInfoFactory.getInstance()
075: .getBandToplevelReportElementInfo(
076: BandToplevelType.REPORT_HEADER)
077: .createReportElement(), ReportElementInfoFactory
078: .getInstance().getBandToplevelReportElementInfo(
079: BandToplevelType.REPORT_FOOTER)
080: .createReportElement(), ReportElementInfoFactory
081: .getInstance().getBandToplevelReportElementInfo(
082: BandToplevelType.PAGE_HEADER)
083: .createReportElement(), ReportElementInfoFactory
084: .getInstance().getBandToplevelReportElementInfo(
085: BandToplevelType.PAGE_FOOTER)
086: .createReportElement(), ReportElementInfoFactory
087: .getInstance().getReportGroupsElementInfo()
088: .createReportElement(), ReportElementInfoFactory
089: .getInstance().getBandToplevelReportElementInfo(
090: BandToplevelType.ITEM_BAND)
091: .createReportElement(), ReportElementInfoFactory
092: .getInstance().getBandToplevelReportElementInfo(
093: BandToplevelType.WATERMARK)
094: .createReportElement(), ReportElementInfoFactory
095: .getInstance().getBandToplevelReportElementInfo(
096: BandToplevelType.NO_DATA_BAND)
097: .createReportElement(), new PageDefinition(
098: PageFormatPreset.A4, PageOrientation.PORTRAIT, 20, 20,
099: 20, 20), ReportElementInfoFactory.getInstance()
100: .getReportFunctionsElementInfo().createReportElement());
101: }
102:
103: @NotNull
104: public static Report createReport(@NotNull
105: HashMap<String, WizardData> wizardDatas) {
106: Report report = ReportElementInfoFactory.getInstance()
107: .getReportReportElementInfo().createReportElement();
108: @Nullable
109: WizardData wizardData = wizardDatas
110: .get(WizardData.LAYOUT_PLUGIN);
111: LayoutPlugin layoutPlugin = null;
112: if (wizardData != null && wizardData.getValue() != null
113: && wizardData.getValue() instanceof LayoutPlugin) {
114: layoutPlugin = (LayoutPlugin) wizardData.getValue();
115: }
116:
117: if (layoutPlugin == null) {
118: layoutPlugin = new IndentedLayoutPlugin();
119: }
120:
121: LayoutStyle layoutStyle = LayoutStyle.BLUE;
122: @Nullable
123: WizardData wizardDataLayoutStyle = wizardDatas
124: .get(WizardData.LAYOUT_PLUGIN);
125: if (wizardDataLayoutStyle != null) {
126: Object layoutStyleObject = wizardDataLayoutStyle.getValue();
127: if (layoutStyleObject instanceof LayoutStyle) {
128: layoutStyle = (LayoutStyle) layoutStyleObject;
129: }
130: }
131:
132: try {
133: layoutPlugin.addVisualReportElements(report, wizardDatas,
134: layoutStyle);
135: } catch (LayoutException e) {
136: UncaughtExcpetionsModel.getInstance().addException(e);
137: }
138:
139: @Nullable
140: WizardData wizardDataDataSetPlugin = wizardDatas
141: .get(WizardData.DATA_SET_PLUGIN);
142: if (wizardDataDataSetPlugin == null
143: || wizardDataDataSetPlugin.getValue() == null
144: || !(wizardDataDataSetPlugin.getValue() instanceof DataSetPlugin)) {
145: throw new RuntimeException(
146: "Could not create report. DataSetPlugin was expected but not available.");
147: }
148:
149: DataSetPlugin dataSetPlugin = (DataSetPlugin) wizardDataDataSetPlugin
150: .getValue();
151: if (dataSetPlugin != null) {
152: DataSetReportElement dataSet = dataSetPlugin
153: .createDataSet(wizardDatas);
154: report.getDataSetsReportElement().addChild(dataSet);
155: }
156:
157: return report;
158: }
159:
160: }
|