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.wizard;
015:
016: import com.jgoodies.forms.layout.CellConstraints;
017: import com.jgoodies.forms.layout.FormLayout;
018: import org.jetbrains.annotations.NonNls;
019: import org.jetbrains.annotations.NotNull;
020: import org.jetbrains.annotations.Nullable;
021: import org.pentaho.reportdesigner.crm.report.IconLoader;
022: import org.pentaho.reportdesigner.crm.report.datasetplugin.DataSetPlugin;
023: import org.pentaho.reportdesigner.crm.report.datasetplugin.DataSetPluginRegistry;
024: import org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard.WizardPagePageSetup;
025: import org.pentaho.reportdesigner.lib.client.components.ComponentFactory;
026: import org.pentaho.reportdesigner.lib.client.components.TextComponentHelper;
027: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
028: import org.pentaho.reportdesigner.lib.client.util.UncaughtExcpetionsModel;
029:
030: import javax.swing.*;
031: import javax.swing.text.html.HTMLDocument;
032: import javax.swing.text.html.HTMLEditorKit;
033: import java.awt.*;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036: import java.util.ArrayList;
037: import java.util.Arrays;
038: import java.util.Iterator;
039: import java.util.LinkedHashSet;
040:
041: /**
042: * User: Martin
043: * Date: 20.01.2006
044: * Time: 09:48:17
045: */
046: public class WizardPageDataSet extends AbstractWizardPage {
047: @NotNull
048: private JPanel centerPanel;
049: @NotNull
050: private JComboBox dataSetComboBox;
051: @NotNull
052: private WizardPagePageSetup wizardPagePageSetup;
053:
054: public WizardPageDataSet() {
055: @NonNls
056: FormLayout formLayout = new FormLayout(
057: "0dlu, max(50dlu;pref), 4dlu, max(100dlu;pref), 4dlu, 10dlu:grow, 0dlu",
058: "0dlu, pref, 4dlu, fill:pref:grow, 0dlu");
059: @NonNls
060: CellConstraints cc = new CellConstraints();
061:
062: centerPanel = new JPanel(formLayout);
063:
064: LinkedHashSet<DataSetPlugin> dataSetPlugins = DataSetPluginRegistry
065: .getInstance().getDataSetPlugins();
066:
067: for (Iterator<DataSetPlugin> iterator = dataSetPlugins
068: .iterator(); iterator.hasNext();) {
069: DataSetPlugin dataSetPlugin = iterator.next();
070: if (!dataSetPlugin.isWizardable()) {
071: iterator.remove();
072: }
073: }
074:
075: dataSetComboBox = new JComboBox(dataSetPlugins
076: .toArray(new DataSetPlugin[dataSetPlugins.size()]));
077: dataSetComboBox.setRenderer(new DefaultListCellRenderer() {
078: @NotNull
079: public Component getListCellRendererComponent(@NotNull
080: JList list, @Nullable
081: Object value, int index, boolean isSelected,
082: boolean cellHasFocus) {
083: JLabel label = (JLabel) super
084: .getListCellRendererComponent(list, value,
085: index, isSelected, cellHasFocus);
086: try {
087: if (value instanceof DataSetPlugin) {
088: DataSetPlugin dataSetPlugin = (DataSetPlugin) value;
089: label.setText(dataSetPlugin.getLocalizedName());
090: }
091: } catch (Throwable e) {
092: UncaughtExcpetionsModel.getInstance().addException(
093: e);
094: }
095: return label;
096: }
097: });
098:
099: JLabel dataSetLabel = ComponentFactory.createLabel("R",
100: "WizardPageDataSet.DataSetLabel", dataSetComboBox);
101:
102: centerPanel.add(dataSetLabel, cc.xy(2, 2));
103: centerPanel.add(dataSetComboBox, cc.xy(4, 2));
104:
105: final JEditorPane descriptionTextArea = new JEditorPane();
106: HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
107:
108: htmlEditorKit.getStyleSheet().addRule(
109: "body { font-family: "
110: + dataSetLabel.getFont().getFamily()
111: + ", sans-serif; font-size: "
112: + dataSetLabel.getFont().getSize() + "pt;}");//NON-NLS
113: HTMLDocument htmlDocument = (HTMLDocument) htmlEditorKit
114: .createDefaultDocument();
115: descriptionTextArea.setEditorKit(htmlEditorKit);
116: descriptionTextArea.setDocument(htmlDocument);
117: descriptionTextArea.setContentType("text/html");//NON-NLS
118: descriptionTextArea.setEditable(false);
119: TextComponentHelper
120: .installDefaultPopupMenu(descriptionTextArea);
121: JScrollPane scrollPane = new JScrollPane(descriptionTextArea);
122: scrollPane.setPreferredSize(new Dimension(100, 100));
123: centerPanel.add(scrollPane, cc.xyw(4, 4, 3));
124:
125: DataSetPlugin selectedItem = (DataSetPlugin) dataSetComboBox
126: .getSelectedItem();
127: descriptionTextArea.setText(selectedItem
128: .getLocalizedDescription());
129:
130: dataSetComboBox.addActionListener(new ActionListener() {
131: public void actionPerformed(@NotNull
132: ActionEvent e) {
133: DataSetPlugin selectedItem = (DataSetPlugin) dataSetComboBox
134: .getSelectedItem();
135: descriptionTextArea.setText(selectedItem
136: .getLocalizedDescription());
137: }
138: });
139:
140: wizardPagePageSetup = new WizardPagePageSetup();
141: }
142:
143: @NotNull
144: public JComponent getCenterPanel() {
145: return centerPanel;
146: }
147:
148: public boolean canNext() {
149: return true;
150: }
151:
152: public boolean hasNext() {
153: return true;
154: }
155:
156: @Nullable
157: public WizardPage getNext() {
158: DataSetPlugin dataSetPlugin = (DataSetPlugin) dataSetComboBox
159: .getSelectedItem();
160: dataSetPlugin.initWizardPages();
161: setNext(dataSetPlugin.getFirstWizardPage());
162: AbstractWizardPage wizardPage = dataSetPlugin
163: .getLastWizardPage();
164: if (wizardPage != null) {
165: wizardPage.setNext(wizardPagePageSetup);
166: }
167: wizardPagePageSetup.setPrevious(wizardPage);
168:
169: return super .getNext();
170: }
171:
172: public boolean canPrevious() {
173: return false;
174: }
175:
176: public boolean canCancel() {
177: return true;
178: }
179:
180: public boolean canFinish() {
181: return true;
182: }
183:
184: @NotNull
185: public WizardData[] getWizardDatas() {
186: DataSetPlugin dataSetPlugin = (DataSetPlugin) dataSetComboBox
187: .getSelectedItem();
188: ArrayList<WizardData> wizardDatas = new ArrayList<WizardData>();
189: wizardDatas.addAll(Arrays.asList(dataSetPlugin
190: .getInitialWizardDatas()));
191: wizardDatas.add(new WizardData(WizardData.DATA_SET_PLUGIN,
192: dataSetComboBox.getSelectedItem()));
193: return wizardDatas.toArray(new WizardData[wizardDatas.size()]);
194: }
195:
196: @NotNull
197: public String getTitle() {
198: return TranslationManager.getInstance().getTranslation("R",
199: "WizardPageDataSet.Title");
200: }
201:
202: @NotNull
203: public ImageIcon getIcon() {
204: return IconLoader.getInstance().getWizardPageWelcomeIcon();
205: }
206:
207: @NotNull
208: public String getDescription() {
209: return TranslationManager.getInstance().getTranslation("R",
210: "WizardPageDataSet.Description");
211: }
212:
213: public void dispose() {
214: }
215: }
|