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.datasetplugin;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018: import org.pentaho.reportdesigner.crm.report.IconLoader;
019: import org.pentaho.reportdesigner.crm.report.connection.ColumnInfo;
020: import org.pentaho.reportdesigner.crm.report.datasetplugin.jdbc.JDBCDataSetReportElement;
021: import org.pentaho.reportdesigner.crm.report.model.ReportElement;
022: import org.pentaho.reportdesigner.crm.report.model.dataset.TableModelDataSetReportElement;
023: import org.pentaho.reportdesigner.crm.report.reportelementinfo.ReportElementInfoFactory;
024: import org.pentaho.reportdesigner.crm.report.wizard.AbstractWizardPage;
025: import org.pentaho.reportdesigner.crm.report.wizard.WizardData;
026: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageFieldExpressions;
027: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageGroups;
028: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageSQLQuery;
029: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageVisibleFields;
030: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
031:
032: import javax.swing.*;
033: import java.util.ArrayList;
034: import java.util.HashMap;
035:
036: /**
037: * User: Martin
038: * Date: 27.02.2006
039: * Time: 10:00:41
040: */
041: public class SampleDBDataSetPlugin implements DataSetPlugin {
042: @NotNull
043: private static final String[] EMPTY_STRING_ARRAY = new String[0];
044:
045: @NotNull
046: private WizardPageSQLQuery wizardPageSQLQuery;
047: @NotNull
048: private WizardPageFieldExpressions wizardPageFieldExpressions;
049:
050: public SampleDBDataSetPlugin() {
051: }
052:
053: @NotNull
054: public String getID() {
055: return "SampleDBDataSetPlugin";
056: }
057:
058: @NotNull
059: public String getLocalizedName() {
060: return TranslationManager.getInstance().getTranslation("R",
061: "SampleDBDataSetPlugin.Name");
062: }
063:
064: @NotNull
065: public String getLocalizedDescription() {
066: return TranslationManager.getInstance().getTranslation("R",
067: "SampleDBDataSetPlugin.Description");
068: }
069:
070: @NotNull
071: public ImageIcon getSmallIcon() {
072: return IconLoader.getInstance().getDataSetsIcon();
073: }
074:
075: public boolean isWizardable() {
076: return true;
077: }
078:
079: public void initWizardPages() {
080: wizardPageSQLQuery = new WizardPageSQLQuery();
081: WizardPageVisibleFields wizardPageVisibleFields = new WizardPageVisibleFields();
082: WizardPageGroups wizardPageGroups = new WizardPageGroups();
083: wizardPageFieldExpressions = new WizardPageFieldExpressions();
084:
085: wizardPageSQLQuery.setNext(wizardPageVisibleFields);
086:
087: wizardPageVisibleFields.setPrevious(wizardPageSQLQuery);
088: wizardPageVisibleFields.setNext(wizardPageGroups);
089:
090: wizardPageGroups.setPrevious(wizardPageVisibleFields);
091: wizardPageGroups.setNext(wizardPageFieldExpressions);
092:
093: wizardPageFieldExpressions.setPrevious(wizardPageGroups);
094: }
095:
096: @NotNull
097: public WizardData[] getInitialWizardDatas() {
098: //noinspection HardCodedStringLiteral,HardcodedLineSeparator
099: return new WizardData[] {
100: new WizardData(WizardData.JARS, EMPTY_STRING_ARRAY),
101: new WizardData(WizardData.DRIVER_CLASS,
102: "org.hsqldb.jdbcDriver"),//NON-NLS
103: new WizardData(WizardData.CONNECTION_STRING,
104: "jdbc:hsqldb:mem:sample"),//NON-NLS
105: new WizardData(
106: WizardData.SQL_QUERY,
107: "SELECT\n"
108: + "CUSTOMERS.FIRST_NAME, CUSTOMERS.LAST_NAME,\n"
109: + "PRODUCTS.PRODUCT_NAME, PRODUCTS.PRODUCT_DESCRIPTION, PRODUCTS.PRICE\n"
110: + "FROM CUSTOMERS\n"
111: + "JOIN ORDERS ON CUSTOMERS.CUSTOMER_ID=ORDERS.CUSTOMER_ID\n"
112: + "JOIN ORDER_ITEMS ON ORDER_ITEMS.ORDER_ID=ORDERS.ORDER_ID\n"
113: + "JOIN PRODUCTS ON ORDER_ITEMS.PRODUCT_ID=PRODUCTS.PRODUCT_ID\n"
114: + "ORDER BY\n"
115: + "CUSTOMERS.FIRST_NAME, CUSTOMERS.LAST_NAME, PRODUCTS.PRODUCT_NAME"),
116: new WizardData(WizardData.USERNAME, "sa"),//NON-NLS
117: new WizardData(WizardData.PASSWORD, "") };
118: }
119:
120: @NotNull
121: public AbstractWizardPage getFirstWizardPage() {
122: return wizardPageSQLQuery;
123: }
124:
125: @NotNull
126: public AbstractWizardPage getLastWizardPage() {
127: return wizardPageFieldExpressions;
128: }
129:
130: @NotNull
131: public TableModelDataSetReportElement createDataSet(@NotNull
132: HashMap<String, WizardData> wizardDatas) {
133: JDBCDataSetReportElement jdbcDataSetReportElement = ReportElementInfoFactory
134: .getInstance().getSampleDataSetReportElementInfo()
135: .createReportElement();
136:
137: @Nullable
138: WizardData columnInfosWizardData = wizardDatas
139: .get(WizardData.COLUMN_INFOS);
140: if (columnInfosWizardData != null
141: && columnInfosWizardData.getValue() != null) {
142: //noinspection unchecked
143: jdbcDataSetReportElement
144: .setColumnInfos(new ArrayList<ColumnInfo>(
145: (ArrayList<ColumnInfo>) columnInfosWizardData
146: .getValue()));
147: }
148: jdbcDataSetReportElement.setJars(EMPTY_STRING_ARRAY);
149: jdbcDataSetReportElement
150: .setDriverClass("org.hsqldb.jdbcDriver");
151: jdbcDataSetReportElement.setMaxPreviewRows(100);
152: jdbcDataSetReportElement.setUserName("sa");//NON-NLS
153: jdbcDataSetReportElement.setPassword("");
154:
155: @Nullable
156: WizardData sqlQueryWizardData = wizardDatas
157: .get(WizardData.SQL_QUERY);
158: if (sqlQueryWizardData != null) {
159: Object sqlQuery = sqlQueryWizardData.getValue();
160: if (sqlQuery != null) {
161: jdbcDataSetReportElement.setSqlQuery(sqlQuery
162: .toString());
163: }
164: }
165: jdbcDataSetReportElement
166: .setConnectionString("jdbc:hsqldb:mem:sample");//NON-NLS
167:
168: return jdbcDataSetReportElement;
169: }
170:
171: public boolean canRead(@Nullable
172: String classname) {
173: return "org.pentaho.reportdesigner.crm.report.datasetplugin.sampledb.SampleDataSetReportElement"
174: .equals(classname);
175: }
176:
177: @NotNull
178: public ReportElement createEmptyInstance(@NotNull
179: String className) {
180: return ReportElementInfoFactory.getInstance()
181: .getSampleDataSetReportElementInfo()
182: .createReportElement();
183: }
184: }
|