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.settings;
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.util.JFileChooserHelper;
021: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
022: import org.pentaho.reportdesigner.lib.client.util.UncaughtExcpetionsModel;
023: import org.pentaho.reportdesigner.lib.client.components.CenterPanelDialog;
024:
025: import javax.swing.*;
026: import java.awt.*;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.ActionListener;
029: import java.io.File;
030: import java.io.IOException;
031:
032: /**
033: * User: Martin
034: * Date: 02.03.2006
035: * Time: 07:37:12
036: */
037: public class BrowserSettingsPanel extends SettingsPanel {
038: @NotNull
039: private JRadioButton defaultBrowserRadioButton;
040: @NotNull
041: private JRadioButton customExecutableRadioButton;
042: @NotNull
043: private JButton showFileChooserButton;
044: @NotNull
045: private JTextField customExecutableTextField;
046: @NotNull
047: private JTextField customParametersTextField;
048: @NotNull
049: private JLabel sampleCustomExecutableLabel;
050:
051: @NotNull
052: private ButtonGroup buttonGroup;
053: @NotNull
054: private JLabel customExecutableLabel;
055: @NotNull
056: private JLabel customParametersLabel;
057:
058: public BrowserSettingsPanel() {
059: @NonNls
060: FormLayout formLayout = new FormLayout(
061: "4dlu, pref, 4dlu, 10dlu:grow, 0dlu, default, 4dlu",
062: "4dlu, pref, " + "4dlu, pref, " + "4dlu, pref, "
063: + "4dlu, pref, " + "4dlu, pref, " + "4dlu, ");
064:
065: @NonNls
066: CellConstraints cc = new CellConstraints();
067:
068: setLayout(formLayout);
069:
070: defaultBrowserRadioButton = new JRadioButton(
071: TranslationManager
072: .getInstance()
073: .getTranslation("R",
074: "BrowserSettingsPanel.defaultBrowserRadioButton"));
075: customExecutableRadioButton = new JRadioButton(
076: TranslationManager
077: .getInstance()
078: .getTranslation("R",
079: "BrowserSettingsPanel.customExecutableRadioButton"));
080:
081: showFileChooserButton = new JButton(TranslationManager
082: .getInstance().getTranslation("R",
083: "BrowserSettingsPanel.showFileChooserButton"));
084: showFileChooserButton.setMargin(new Insets(0, 0, 0, 0));
085:
086: customExecutableTextField = new JTextField();
087: customParametersTextField = new JTextField("{0}");
088: sampleCustomExecutableLabel = new JLabel(
089: TranslationManager
090: .getInstance()
091: .getTranslation("R",
092: "BrowserSettingsPanel.sampleCustomExecutableTextArea"));
093:
094: customExecutableLabel = new JLabel(
095: TranslationManager
096: .getInstance()
097: .getTranslation("R",
098: "BrowserSettingsPanel.customExecutableTextField"));
099: customParametersLabel = new JLabel(
100: TranslationManager
101: .getInstance()
102: .getTranslation("R",
103: "BrowserSettingsPanel.customParametersTextField"));
104:
105: add(defaultBrowserRadioButton, cc.xyw(2, 2, 3));
106: add(customExecutableRadioButton, cc.xyw(2, 4, 3));
107: add(customExecutableLabel, cc.xy(2, 6));
108: add(customExecutableTextField, cc.xy(4, 6));
109: add(customParametersLabel, cc.xy(2, 8));
110: add(customParametersTextField, cc.xy(4, 8));
111: add(showFileChooserButton, cc.xy(6, 6, "fill, fill"));
112: add(sampleCustomExecutableLabel, cc.xy(4, 10));
113:
114: buttonGroup = new ButtonGroup();
115: buttonGroup.add(defaultBrowserRadioButton);
116: buttonGroup.add(customExecutableRadioButton);
117:
118: showFileChooserButton.addActionListener(new ActionListener() {
119: public void actionPerformed(@NotNull
120: ActionEvent e) {
121: JFileChooser fileChooser = new JFileChooserHelper(
122: CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
123: int value = fileChooser
124: .showOpenDialog(BrowserSettingsPanel.this );
125: if (value == JFileChooser.APPROVE_OPTION) {
126: File selectedFile = fileChooser.getSelectedFile();
127: try {
128: customExecutableTextField.setText(selectedFile
129: .getCanonicalPath());
130: } catch (IOException e1) {
131: UncaughtExcpetionsModel.getInstance()
132: .addException(e1);
133: }
134: }
135: }
136: });
137:
138: customExecutableRadioButton
139: .addActionListener(new ActionListener() {
140: public void actionPerformed(@NotNull
141: ActionEvent e) {
142: changeTextFieldState(customExecutableRadioButton
143: .isSelected());
144: }
145: });
146:
147: defaultBrowserRadioButton
148: .addActionListener(new ActionListener() {
149: public void actionPerformed(@NotNull
150: ActionEvent e) {
151: changeTextFieldState(customExecutableRadioButton
152: .isSelected());
153: }
154: });
155:
156: reset();
157: }
158:
159: @NotNull
160: public ValidationResult getValidationResult() {
161: return new ValidationResult();
162: }
163:
164: public void apply() {
165: ApplicationSettings.getInstance().setUseDefaultBrowser(
166: defaultBrowserRadioButton.isSelected());
167: ApplicationSettings.getInstance().setCustomBrowserExecutable(
168: customExecutableTextField.getText());
169: ApplicationSettings.getInstance().setCustomBrowserParameters(
170: customParametersTextField.getText());
171: }
172:
173: public void reset() {
174: buttonGroup
175: .setSelected(defaultBrowserRadioButton.getModel(),
176: ApplicationSettings.getInstance()
177: .isUseDefaultBrowser());
178: buttonGroup.setSelected(customExecutableRadioButton.getModel(),
179: !ApplicationSettings.getInstance()
180: .isUseDefaultBrowser());
181: customExecutableTextField.setText(ApplicationSettings
182: .getInstance().getCustomBrowserExecutable());
183: customParametersTextField.setText(ApplicationSettings
184: .getInstance().getCustomBrowserParameters());
185:
186: changeTextFieldState(customExecutableRadioButton.isSelected());
187: }
188:
189: private void changeTextFieldState(boolean enable) {
190: customExecutableLabel.setEnabled(enable);
191: customParametersLabel.setEnabled(enable);
192: customExecutableTextField.setEnabled(enable);
193: customParametersTextField.setEnabled(enable);
194: sampleCustomExecutableLabel.setEnabled(enable);
195: showFileChooserButton.setEnabled(enable);
196: }
197:
198: public boolean hasChanged() {
199: return true;
200: }
201: }
|