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.properties.editors;
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.pentaho.reportdesigner.crm.report.configuration.ReportConfiguration;
021: import org.pentaho.reportdesigner.crm.report.configuration.ReportConfigurationEditor;
022: import org.pentaho.reportdesigner.crm.report.util.JFreeReportBootingHelper;
023: import org.pentaho.reportdesigner.lib.client.components.CenterPanelDialog;
024: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
025: import org.pentaho.reportdesigner.lib.client.util.UncaughtExcpetionsModel;
026: import org.pentaho.reportdesigner.lib.client.util.WindowUtils;
027:
028: import javax.swing.*;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031:
032: /**
033: * User: Martin
034: * Date: 17.03.2007
035: * Time: 11:46:14
036: */
037: public class ReportConfigurationChooser {
038: private ReportConfigurationChooser() {
039: }
040:
041: @NotNull
042: public static ReportConfiguration showReportConfigurationChooser(
043: @NotNull
044: JComponent parent, @NotNull
045: String title, @NotNull
046: ReportConfiguration origReportConfiguration) {
047: //noinspection ConstantConditions
048: if (parent == null) {
049: throw new IllegalArgumentException(
050: "parent must not be null");
051: }
052: //noinspection ConstantConditions
053: if (title == null) {
054: throw new IllegalArgumentException("title must not be null");
055: }
056: //noinspection ConstantConditions
057: if (origReportConfiguration == null) {
058: throw new IllegalArgumentException(
059: "origReportConfiguration must not be null");
060: }
061:
062: JFreeReportBootingHelper.boot(parent);
063:
064: final CenterPanelDialog centerPanelDialog = CenterPanelDialog
065: .createDialog(parent, title,
066: CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
067:
068: @NonNls
069: final FormLayout formLayout = new FormLayout(
070: "4dlu, fill:default:grow, 4dlu",
071: "4dlu, fill:default:grow, 4dlu");
072: final JPanel centerPanel = new JPanel(formLayout);
073:
074: final CellConstraints cc = new CellConstraints();
075:
076: ReportConfigurationEditor configurationEditor;
077: try {
078: configurationEditor = new ReportConfigurationEditor(
079: origReportConfiguration);
080: centerPanelDialog.dispose();
081: centerPanel.add(configurationEditor, cc.xy(2, 2));
082: } catch (Throwable e) {
083: UncaughtExcpetionsModel.getInstance().addException(e);
084: return origReportConfiguration;
085: }
086:
087: final boolean[] action = new boolean[] { false };
088:
089: JButton okButton = new JButton(TranslationManager.getInstance()
090: .getTranslation("R", "Button.ok"));
091: okButton.addActionListener(new ActionListener() {
092: public void actionPerformed(@NotNull
093: ActionEvent e) {
094: action[0] = true;
095: centerPanelDialog.dispose();
096: }
097: });
098:
099: JButton cancelButton = new JButton(TranslationManager
100: .getInstance().getTranslation("R", "Button.cancel"));
101: cancelButton.addActionListener(new ActionListener() {
102: public void actionPerformed(@NotNull
103: ActionEvent e) {
104: action[0] = false;
105: centerPanelDialog.dispose();
106: }
107: });
108:
109: centerPanelDialog.setButtons(okButton, cancelButton, okButton,
110: cancelButton);
111:
112: centerPanelDialog.setCenterPanel(centerPanel);
113: centerPanelDialog.pack();
114: centerPanelDialog.setSize(800, 600);
115: WindowUtils.setLocationRelativeTo(centerPanelDialog, parent);
116: centerPanelDialog.setVisible(true);
117:
118: if (action[0]) {
119: return configurationEditor.getReportConfiguration();
120: }
121: return origReportConfiguration;
122: }
123: }
|