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.WizardPageConnectionSettings;
027: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageFieldExpressions;
028: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageGroups;
029: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageSQLQuery;
030: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPageVisibleFields;
031: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
032:
033: import javax.swing.*;
034: import java.util.ArrayList;
035: import java.util.HashMap;
036:
037: /**
038: * User: Martin
039: * Date: 27.02.2006
040: * Time: 10:00:41
041: */
042: public class JDBCDataSetPlugin implements DataSetPlugin {
043: @NotNull
044: private WizardPageConnectionSettings wizardPageConnectionSettings;
045: @NotNull
046: private WizardPageFieldExpressions wizardPageFieldExpressions;
047:
048: public JDBCDataSetPlugin() {
049: }
050:
051: @NotNull
052: public String getID() {
053: return "JDBCDataSetPlugin";
054: }
055:
056: @NotNull
057: public String getLocalizedName() {
058: return TranslationManager.getInstance().getTranslation("R",
059: "JDBCDataSetPlugin.Name");
060: }
061:
062: @NotNull
063: public String getLocalizedDescription() {
064: return TranslationManager.getInstance().getTranslation("R",
065: "JDBCDataSetPlugin.Description");
066: }
067:
068: @NotNull
069: public ImageIcon getSmallIcon() {
070: return IconLoader.getInstance().getDataSetsIcon();
071: }
072:
073: public boolean isWizardable() {
074: return true;
075: }
076:
077: public void initWizardPages() {
078: wizardPageConnectionSettings = new WizardPageConnectionSettings();
079: WizardPageSQLQuery wizardPageSQLQuery = new WizardPageSQLQuery();
080: WizardPageVisibleFields wizardPageVisibleFields = new WizardPageVisibleFields();
081: WizardPageGroups wizardPageGroups = new WizardPageGroups();
082: wizardPageFieldExpressions = new WizardPageFieldExpressions();
083:
084: wizardPageConnectionSettings.setNext(wizardPageSQLQuery);
085:
086: wizardPageSQLQuery.setPrevious(wizardPageConnectionSettings);
087: wizardPageSQLQuery.setNext(wizardPageVisibleFields);
088:
089: wizardPageVisibleFields.setPrevious(wizardPageSQLQuery);
090: wizardPageVisibleFields.setNext(wizardPageGroups);
091:
092: wizardPageGroups.setPrevious(wizardPageVisibleFields);
093: wizardPageGroups.setNext(wizardPageFieldExpressions);
094:
095: wizardPageFieldExpressions.setPrevious(wizardPageGroups);
096: }
097:
098: @NotNull
099: public AbstractWizardPage getFirstWizardPage() {
100: return wizardPageConnectionSettings;
101: }
102:
103: @NotNull
104: public AbstractWizardPage getLastWizardPage() {
105: return wizardPageFieldExpressions;
106: }
107:
108: @NotNull
109: public WizardData[] getInitialWizardDatas() {
110: return WizardData.EMPTY_ARRAY;
111: }
112:
113: @NotNull
114: public TableModelDataSetReportElement createDataSet(@NotNull
115: HashMap<String, WizardData> wizardDatas) {
116: JDBCDataSetReportElement jdbcDataSetReportElement = ReportElementInfoFactory
117: .getInstance().getJDBCDataSetReportElementInfo()
118: .createReportElement();
119:
120: @Nullable
121: WizardData columnInfoWizardData = wizardDatas
122: .get(WizardData.COLUMN_INFOS);
123: if (columnInfoWizardData != null
124: && columnInfoWizardData.getValue() != null) {
125: //noinspection unchecked
126: jdbcDataSetReportElement
127: .setColumnInfos(new ArrayList<ColumnInfo>(
128: (ArrayList<ColumnInfo>) columnInfoWizardData
129: .getValue()));
130: }
131:
132: @Nullable
133: WizardData driverClassWizardData = wizardDatas
134: .get(WizardData.DRIVER_CLASS);
135: if (driverClassWizardData != null) {
136: Object driverClass = driverClassWizardData.getValue();
137: if (driverClass != null) {
138: jdbcDataSetReportElement.setDriverClass(driverClass
139: .toString());
140: }
141: }
142:
143: @Nullable
144: WizardData maxPreviewRowsWizardData = wizardDatas
145: .get(WizardData.MAX_PREVIEW_ROWS);
146: if (maxPreviewRowsWizardData != null) {
147: Object maxPreviewRows = maxPreviewRowsWizardData.getValue();
148: if (maxPreviewRows != null) {
149: jdbcDataSetReportElement
150: .setMaxPreviewRows(((Integer) maxPreviewRows)
151: .intValue());
152: }
153: }
154:
155: @Nullable
156: WizardData jarWizardData = wizardDatas.get(WizardData.JARS);
157: if (jarWizardData != null) {
158: Object jars = jarWizardData.getValue();
159: if (jars != null) {
160: jdbcDataSetReportElement.setJars((String[]) jars);
161: }
162: }
163:
164: @Nullable
165: WizardData usernameWizardData = wizardDatas
166: .get(WizardData.USERNAME);
167: if (usernameWizardData != null) {
168: Object username = usernameWizardData.getValue();
169: if (username != null) {
170: jdbcDataSetReportElement.setUserName(username
171: .toString());
172: }
173: }
174:
175: @Nullable
176: WizardData passwordWizardData = wizardDatas
177: .get(WizardData.PASSWORD);
178: if (passwordWizardData != null) {
179: Object password = passwordWizardData.getValue();
180: if (password != null) {
181: jdbcDataSetReportElement.setPassword(password
182: .toString());
183: }
184: }
185:
186: @Nullable
187: WizardData sqlQueryWizardData = wizardDatas
188: .get(WizardData.SQL_QUERY);
189: if (sqlQueryWizardData != null) {
190: Object sqlQuery = sqlQueryWizardData.getValue();
191: if (sqlQuery != null) {
192: jdbcDataSetReportElement.setSqlQuery(sqlQuery
193: .toString());
194: }
195: }
196:
197: @Nullable
198: WizardData connectionStringWizardData = wizardDatas
199: .get(WizardData.CONNECTION_STRING);
200: if (connectionStringWizardData != null) {
201: Object connectionString = connectionStringWizardData
202: .getValue();
203: if (connectionString != null) {
204: jdbcDataSetReportElement
205: .setConnectionString(connectionString
206: .toString());
207: }
208: }
209:
210: return jdbcDataSetReportElement;
211: }
212:
213: public boolean canRead(@Nullable
214: String classname) {
215: return "org.pentaho.reportdesigner.crm.report.datasetplugin.jdbc.JDBCDataSetReportElement"
216: .equals(classname);
217: }
218:
219: //TODO check if this implementation is OK
220: @NotNull
221: public ReportElement createEmptyInstance(@NotNull
222: String className) {
223: return ReportElementInfoFactory.getInstance()
224: .getJDBCDataSetReportElementInfo()
225: .createReportElement();
226: }
227: }
|