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.lib.client.i18n.TranslationManager;
021:
022: import javax.swing.*;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025:
026: /**
027: * User: Martin
028: * Date: 03.03.2006
029: * Time: 14:14:22
030: */
031: public class ProxySettingsPanel extends SettingsPanel {
032: @NotNull
033: private JRadioButton radioButtonNoProxy;
034: @NotNull
035: private JRadioButton radioButtonAutoDetectProxy;
036: @NotNull
037: private JRadioButton radioButtonUserProxy;
038:
039: @NotNull
040: private JTextField proxyHostTextField;
041: @NotNull
042: private JTextField proxyPortTextField;
043: @NotNull
044: private JLabel proxyHostLabel;
045: @NotNull
046: private JLabel proxyPortLabel;
047:
048: @NotNull
049: private JLabel userLabel;
050: @NotNull
051: private JLabel passwordLabel;
052: @NotNull
053: private JTextField userTextField;
054: @NotNull
055: private JPasswordField passwordField;
056:
057: @NotNull
058: private JCheckBox socksCheckBox;
059:
060: @NotNull
061: private ButtonGroup buttonGroup;
062:
063: public ProxySettingsPanel() {
064: @NonNls
065: FormLayout formLayout = new FormLayout(
066: "4dlu, pref, 4dlu, default:grow, 4dlu", "4dlu, "
067: + "pref, " + "4dlu, " + "pref, " + "4dlu, "
068: + "pref, " + "4dlu, " + "pref, " + "4dlu, "
069: + "pref, " + "4dlu, " + "pref, " + "10dlu, "
070: + "pref, " + "4dlu, " + "pref, " + "4dlu");
071:
072: CellConstraints cc = new CellConstraints();
073:
074: setLayout(formLayout);
075:
076: radioButtonNoProxy = new JRadioButton(TranslationManager
077: .getInstance().getTranslation("R",
078: "ProxySettingsPanel.noProxy"));
079: radioButtonAutoDetectProxy = new JRadioButton(
080: TranslationManager.getInstance().getTranslation("R",
081: "ProxySettingsPanel.autoDetectProxy"));
082: radioButtonUserProxy = new JRadioButton(TranslationManager
083: .getInstance().getTranslation("R",
084: "ProxySettingsPanel.userProxy"));
085:
086: buttonGroup = new ButtonGroup();
087: buttonGroup.add(radioButtonNoProxy);
088: buttonGroup.add(radioButtonAutoDetectProxy);
089: buttonGroup.add(radioButtonUserProxy);
090:
091: proxyHostTextField = new JTextField();
092: proxyPortTextField = new JTextField();
093:
094: socksCheckBox = new JCheckBox(TranslationManager.getInstance()
095: .getTranslation("R", "ProxySettingsPanel.socks"));
096:
097: add(radioButtonNoProxy, cc.xyw(2, 2, 3));
098: add(radioButtonAutoDetectProxy, cc.xyw(2, 4, 3));
099: add(radioButtonUserProxy, cc.xyw(2, 6, 3));
100:
101: proxyHostLabel = new JLabel(TranslationManager.getInstance()
102: .getTranslation("R", "ProxySettingsPanel.proxyHost"));
103: add(proxyHostLabel, cc.xy(2, 8));
104: add(proxyHostTextField, cc.xy(4, 8));
105:
106: proxyPortLabel = new JLabel(TranslationManager.getInstance()
107: .getTranslation("R", "ProxySettingsPanel.proxyPort"));
108: add(proxyPortLabel, cc.xy(2, 10));
109: add(proxyPortTextField, cc.xy(4, 10));
110: add(socksCheckBox, cc.xy(4, 12));
111:
112: userLabel = new JLabel(TranslationManager.getInstance()
113: .getTranslation("R", "ProxySettingsPanel.user"));
114: passwordLabel = new JLabel(TranslationManager.getInstance()
115: .getTranslation("R", "ProxySettingsPanel.password"));
116:
117: userTextField = new JTextField();
118: passwordField = new JPasswordField();
119: passwordField
120: .setPreferredSize(userTextField.getPreferredSize());
121:
122: add(userLabel, cc.xy(2, 14));
123: add(userTextField, cc.xy(4, 14));
124:
125: add(passwordLabel, cc.xy(2, 16));
126: add(passwordField, cc.xy(4, 16));
127:
128: reset();
129:
130: radioButtonNoProxy.addActionListener(new ActionListener() {
131: public void actionPerformed(@NotNull
132: ActionEvent e) {
133: proxyHostTextField.setText("");
134: proxyPortTextField.setText("");
135:
136: socksCheckBox.setSelected(false);
137:
138: enableProxyFields(false);
139: enableAuthenticationFields(false);
140: }
141: });
142:
143: radioButtonAutoDetectProxy
144: .addActionListener(new ActionListener() {
145: public void actionPerformed(@NotNull
146: ActionEvent e) {
147: String webstartHTTPProxyHost = ProxySettings
148: .getWebstartHTTPProxyHost();
149: String webstartSOCKSProxyHost = ProxySettings
150: .getWebstartSOCKSProxyHost();
151: if (webstartHTTPProxyHost != null
152: && webstartHTTPProxyHost.trim()
153: .length() > 0) {
154: proxyHostTextField
155: .setText(webstartHTTPProxyHost);
156: proxyPortTextField.setText(ProxySettings
157: .getWebstartHTTPProxyPort());
158: socksCheckBox.setSelected(false);
159: } else if (webstartSOCKSProxyHost != null
160: && webstartSOCKSProxyHost.trim()
161: .length() > 0) {
162: proxyHostTextField
163: .setText(webstartSOCKSProxyHost);
164: proxyPortTextField.setText(ProxySettings
165: .getWebstartSOCKSProxyPort());
166: socksCheckBox.setSelected(true);
167: } else {
168: proxyHostTextField.setText("");
169: proxyPortTextField.setText("");
170: socksCheckBox.setSelected(false);
171: }
172:
173: enableProxyFields(false);
174: enableAuthenticationFields(true);
175: }
176: });
177:
178: radioButtonUserProxy.addActionListener(new ActionListener() {
179: public void actionPerformed(@NotNull
180: ActionEvent e) {
181: if (ApplicationSettings.getInstance()
182: .getProxySettings().isUseSocksProxy()) {
183: proxyHostTextField.setText(ApplicationSettings
184: .getInstance().getProxySettings()
185: .getSocksProxyHost());
186: proxyPortTextField.setText(ApplicationSettings
187: .getInstance().getProxySettings()
188: .getSocksProxyPort());
189: } else {
190: proxyHostTextField.setText(ApplicationSettings
191: .getInstance().getProxySettings()
192: .getHTTPProxyHost());
193: proxyPortTextField.setText(ApplicationSettings
194: .getInstance().getProxySettings()
195: .getHTTPProxyPort());
196: }
197:
198: socksCheckBox.setSelected(ApplicationSettings
199: .getInstance().getProxySettings()
200: .isUseSocksProxy());
201:
202: enableProxyFields(true);
203: enableAuthenticationFields(true);
204: }
205: });
206: }
207:
208: private void enableProxyFields(boolean enable) {
209: proxyHostTextField.setEnabled(enable);
210: proxyPortTextField.setEnabled(enable);
211: proxyHostLabel.setEnabled(enable);
212: proxyPortLabel.setEnabled(enable);
213: socksCheckBox.setEnabled(enable);
214: }
215:
216: private void enableAuthenticationFields(boolean enable) {
217: userLabel.setEnabled(enable);
218: userTextField.setEnabled(enable);
219: passwordLabel.setEnabled(enable);
220: passwordField.setEnabled(enable);
221: }
222:
223: @NotNull
224: public ValidationResult getValidationResult() {
225: ValidationResult validationResult = new ValidationResult();
226:
227: if (radioButtonUserProxy.isSelected()) {
228: if (!ValidationUtils.isNumber(proxyPortTextField.getText()
229: .trim())) {
230: ValidationMessage validationMessage = new ValidationMessage(
231: ValidationMessage.Severity.ERROR,
232: "ProxySettingsPanel.invalidPortFormat");
233: validationResult
234: .addValidationMessage(validationMessage);
235: }
236: }
237: return validationResult;
238: }
239:
240: public void apply() {
241: final ProxySettings proxySettings = ApplicationSettings
242: .getInstance().getProxySettings();
243:
244: if (radioButtonNoProxy.isSelected()) {
245: proxySettings.setProxyType(ProxyType.NO_PROXY);
246: } else if (radioButtonAutoDetectProxy.isSelected()) {
247: proxySettings.setProxyType(ProxyType.AUTO_DETECT_PROXY);
248: } else if (radioButtonUserProxy.isSelected()) {
249: proxySettings.setProxyType(ProxyType.USER_PROXY);
250: proxySettings.setUseSocksProxy(socksCheckBox.isSelected());
251: if (socksCheckBox.isSelected()) {
252: proxySettings.setSocksProxyHost(proxyHostTextField
253: .getText().trim());
254: proxySettings.setSocksProxyPort(proxyPortTextField
255: .getText().trim());
256: } else {
257: proxySettings.setHTTPProxyHost(proxyHostTextField
258: .getText().trim());
259: proxySettings.setHTTPProxyPort(proxyPortTextField
260: .getText().trim());
261: }
262: }
263:
264: proxySettings.setProxyUser(userTextField.getText());
265: proxySettings.setProxyPassword(new String(passwordField
266: .getPassword()));
267:
268: proxySettings.applySettings();
269: }
270:
271: public void reset() {
272: final ProxySettings proxySettings = ApplicationSettings
273: .getInstance().getProxySettings();
274:
275: switch (proxySettings.getProxyType()) {
276: case NO_PROXY: {
277: buttonGroup
278: .setSelected(radioButtonNoProxy.getModel(), true);
279:
280: proxyHostTextField.setText("");
281: proxyPortTextField.setText("");
282:
283: userTextField.setText("");
284: passwordField.setText("");
285:
286: enableProxyFields(false);
287: enableAuthenticationFields(false);
288: break;
289: }
290: case AUTO_DETECT_PROXY: {
291: buttonGroup.setSelected(radioButtonAutoDetectProxy
292: .getModel(), true);
293:
294: String webstartHTTPProxyHost = ProxySettings
295: .getWebstartHTTPProxyHost();
296: String webstartSOCKSProxyHost = ProxySettings
297: .getWebstartSOCKSProxyHost();
298: if (webstartHTTPProxyHost != null
299: && webstartHTTPProxyHost.trim().length() > 0) {
300: proxyHostTextField.setText(webstartHTTPProxyHost);
301: proxyPortTextField.setText(ProxySettings
302: .getWebstartHTTPProxyPort());
303: socksCheckBox.setSelected(false);
304: } else if (webstartSOCKSProxyHost != null
305: && webstartSOCKSProxyHost.trim().length() > 0) {
306: proxyHostTextField.setText(webstartSOCKSProxyHost);
307: proxyPortTextField.setText(ProxySettings
308: .getWebstartSOCKSProxyPort());
309: socksCheckBox.setSelected(true);
310: } else {
311: proxyHostTextField.setText("");
312: proxyPortTextField.setText("");
313: socksCheckBox.setSelected(false);
314: }
315:
316: enableProxyFields(false);
317:
318: userTextField.setText("");
319: passwordField.setText("");
320:
321: enableAuthenticationFields(true);
322: break;
323: }
324: case USER_PROXY: {
325: buttonGroup.setSelected(radioButtonUserProxy.getModel(),
326: true);
327:
328: if (proxySettings.isUseSocksProxy()) {
329: proxyHostTextField.setText(proxySettings
330: .getSocksProxyHost());
331: proxyPortTextField.setText(proxySettings
332: .getSocksProxyPort());
333: } else {
334: proxyHostTextField.setText(proxySettings
335: .getHTTPProxyHost());
336: proxyPortTextField.setText(proxySettings
337: .getHTTPProxyPort());
338: }
339:
340: socksCheckBox.setSelected(proxySettings.isUseSocksProxy());
341:
342: enableProxyFields(true);
343:
344: enableAuthenticationFields(true);
345: userTextField.setText(proxySettings.getProxyUser());
346: passwordField.setText(proxySettings.getProxyPassword());
347:
348: break;
349: }
350: }
351:
352: userTextField.setText(proxySettings.getProxyUser());
353: passwordField.setText(proxySettings.getProxyPassword());
354: }
355:
356: public boolean hasChanged() {
357: return true;
358: }
359: }
|