001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.actions;
014:
015: import java.awt.Font;
016: import java.awt.event.ActionEvent;
017: import java.awt.event.ActionListener;
018:
019: import javax.swing.AbstractAction;
020: import javax.swing.JButton;
021: import javax.swing.JCheckBox;
022: import javax.swing.JTextField;
023:
024: import com.eviware.soapui.SoapUI;
025: import com.eviware.soapui.model.settings.Settings;
026: import com.eviware.soapui.settings.UISettings;
027: import com.eviware.soapui.support.components.SimpleForm;
028: import com.eviware.soapui.support.types.StringToStringMap;
029: import com.eviware.soapui.ui.desktop.DesktopRegistry;
030: import com.jgoodies.forms.builder.ButtonBarBuilder;
031: import com.l2fprod.common.swing.JFontChooser;
032:
033: /**
034: * Preferences class for UISettings
035: *
036: * @author ole.matzura
037: */
038:
039: public class UIPrefs implements Prefs {
040: public static final String ORDER_PROJECTS = "Order Projects";
041: public static final String ORDER_TESTSUITES = "Order TestSuites";
042: public static final String ORDER_REQUESTS = "Order Requests";
043: public static final String NO_RESIZE_REQUEST_EDITOR = "Disable auto-resize";
044: public static final String START_WITH_REQUEST_TABS = "Tabbed request view";
045: public static final String AUTO_VALIDATE_REQUEST = "Validate Requests";
046: public static final String ABORT_ON_INVALID_REQUEST = "Abort on invalid";
047: public static final String AUTO_VALIDATE_RESPONSE = "Validate Responses";
048: public static final String CREATE_BACKUP = "Create Backup";
049: public static final String BACKUP_FOLDER = "Backup Folder";
050: public static final String DESKTOP_TYPE = "Desktop Type";
051: public static final String NATIVE_LAF = "Native L&F";
052: public static final String ENABLE_GROOVY_LOG_DURING_LOADTEST = "Do not disable Groovy Log";
053:
054: private JTextField editorFontTextField;
055: private SimpleForm editorForm;
056: private final String title;
057: private JCheckBox abortCheckBox;
058: private JCheckBox autoValidateCheckBox;
059: private JCheckBox backupCheckBox;
060: private JTextField backupFolder;
061:
062: public UIPrefs(String title) {
063: this .title = title;
064: }
065:
066: public String getTitle() {
067: return title;
068: }
069:
070: public SimpleForm getForm() {
071: if (editorForm == null) {
072: ButtonBarBuilder builder = new ButtonBarBuilder();
073: editorFontTextField = new JTextField(20);
074: editorFontTextField.setEnabled(false);
075: builder.addFixed(editorFontTextField);
076: builder.addRelatedGap();
077: builder.addFixed(new JButton(new AbstractAction(
078: "Select Font..") {
079: public void actionPerformed(ActionEvent e) {
080: Font font = JFontChooser.showDialog(null,
081: "Select XML Editor Font", Font
082: .decode(editorFontTextField
083: .getText()));
084:
085: if (font != null)
086: editorFontTextField.setText(font.getFontName()
087: + "-plain-" + font.getSize());
088: }
089: }));
090:
091: editorForm = new SimpleForm();
092: editorForm.addSpace(5);
093: editorForm.append("Editor Font", builder.getPanel());
094: editorForm.appendSeparator();
095:
096: editorForm.appendCheckBox(ORDER_PROJECTS,
097: "(orders Projects alphabetically in tree)", false);
098: editorForm.appendCheckBox(ORDER_REQUESTS,
099: "(orders Requests alphabetically in tree)", false);
100: editorForm
101: .appendCheckBox(
102: ORDER_TESTSUITES,
103: "(orders TestSuites alphabetically in tree)",
104: false);
105: editorForm.appendSeparator();
106:
107: editorForm.appendCheckBox(NO_RESIZE_REQUEST_EDITOR,
108: "(disables automatic resizing of request editors)",
109: true);
110: editorForm
111: .appendCheckBox(
112: START_WITH_REQUEST_TABS,
113: "(defaults the request editor to the tabbed layout)",
114: true);
115: editorForm.appendSeparator();
116:
117: autoValidateCheckBox = editorForm
118: .appendCheckBox(
119: AUTO_VALIDATE_REQUEST,
120: "(always validate request messages before they are sent)",
121: true);
122: abortCheckBox = editorForm.appendCheckBox(
123: ABORT_ON_INVALID_REQUEST,
124: "(aborts invalid requests)", true);
125: editorForm.appendCheckBox(AUTO_VALIDATE_RESPONSE,
126: "(always validate response messages)", true);
127:
128: autoValidateCheckBox
129: .addActionListener(new ActionListener() {
130:
131: public void actionPerformed(ActionEvent e) {
132: abortCheckBox
133: .setEnabled(autoValidateCheckBox
134: .isSelected());
135: }
136: });
137:
138: editorForm.appendSeparator();
139: backupCheckBox = editorForm.appendCheckBox(CREATE_BACKUP,
140: "(backup project files before they are saved)",
141: true);
142: backupFolder = editorForm
143: .appendTextField(BACKUP_FOLDER,
144: "(folder to backup to, can be both relative or absolut)");
145: backupCheckBox.addActionListener(new ActionListener() {
146:
147: public void actionPerformed(ActionEvent e) {
148: backupFolder
149: .setEnabled(backupCheckBox.isSelected());
150: }
151: });
152:
153: if (SoapUI.isStandalone()) {
154: editorForm.appendSeparator();
155: editorForm.appendComboBox(DESKTOP_TYPE, DesktopRegistry
156: .getInstance().getNames(),
157: "Select the type of desktop to use");
158: editorForm.appendCheckBox(NATIVE_LAF,
159: "(use native Look & Feel - requires restart)",
160: true);
161: }
162:
163: editorForm.appendSeparator();
164: editorForm
165: .appendCheckBox(
166: ENABLE_GROOVY_LOG_DURING_LOADTEST,
167: "(do not disable the groovy log when running LoadTests)",
168: true);
169: }
170:
171: return editorForm;
172: }
173:
174: public void getFormValues(Settings settings) {
175: StringToStringMap values = new StringToStringMap();
176: editorForm.getValues(values);
177: storeValues(values, settings);
178: }
179:
180: public void storeValues(StringToStringMap values, Settings settings) {
181: if (editorFontTextField != null)
182: settings.setString(UISettings.EDITOR_FONT,
183: editorFontTextField.getText());
184:
185: settings.setBoolean(UISettings.ORDER_PROJECTS, values
186: .getBoolean(ORDER_PROJECTS));
187: settings.setBoolean(UISettings.ORDER_REQUESTS, values
188: .getBoolean(ORDER_REQUESTS));
189: settings.setBoolean(UISettings.ORDER_TESTSUITES, values
190: .getBoolean(ORDER_TESTSUITES));
191: settings.setBoolean(UISettings.NO_RESIZE_REQUEST_EDITOR, values
192: .getBoolean(NO_RESIZE_REQUEST_EDITOR));
193: settings.setBoolean(UISettings.START_WITH_REQUEST_TABS, values
194: .getBoolean(START_WITH_REQUEST_TABS));
195: settings.setBoolean(UISettings.AUTO_VALIDATE_REQUEST, values
196: .getBoolean(AUTO_VALIDATE_REQUEST));
197: settings.setBoolean(UISettings.ABORT_ON_INVALID_REQUEST, values
198: .getBoolean(ABORT_ON_INVALID_REQUEST));
199: settings.setBoolean(UISettings.AUTO_VALIDATE_RESPONSE, values
200: .getBoolean(AUTO_VALIDATE_RESPONSE));
201: settings.setBoolean(UISettings.CREATE_BACKUP, values
202: .getBoolean(CREATE_BACKUP));
203: settings.setString(UISettings.BACKUP_FOLDER, values
204: .get(BACKUP_FOLDER));
205:
206: if (SoapUI.isStandalone()) {
207: settings.setString(UISettings.DESKTOP_TYPE, values
208: .get(DESKTOP_TYPE));
209: settings.setBoolean(UISettings.NATIVE_LAF, values
210: .getBoolean(NATIVE_LAF));
211: }
212:
213: settings.setBoolean(UISettings.DONT_DISABLE_GROOVY_LOG, values
214: .getBoolean(ENABLE_GROOVY_LOG_DURING_LOADTEST));
215: }
216:
217: public void setFormValues(Settings settings) {
218: String editorFont = settings.getString(UISettings.EDITOR_FONT,
219: UISettings.DEFAULT_EDITOR_FONT);
220: if (editorFont == null || editorFont.length() == 0)
221: editorFont = UISettings.DEFAULT_EDITOR_FONT;
222:
223: editorFontTextField.setText(editorFont);
224: editorForm.setValues(getValues(settings));
225:
226: abortCheckBox.setEnabled(settings
227: .getBoolean(UISettings.AUTO_VALIDATE_REQUEST));
228: backupFolder.setEnabled(settings
229: .getBoolean(UISettings.CREATE_BACKUP));
230: }
231:
232: public StringToStringMap getValues(Settings settings) {
233: StringToStringMap values = new StringToStringMap();
234: values.put(ORDER_PROJECTS, settings
235: .getBoolean(UISettings.ORDER_PROJECTS));
236: values.put(ORDER_REQUESTS, settings
237: .getBoolean(UISettings.ORDER_REQUESTS));
238: values.put(ORDER_TESTSUITES, settings
239: .getBoolean(UISettings.ORDER_TESTSUITES));
240: values.put(NO_RESIZE_REQUEST_EDITOR, settings
241: .getBoolean(UISettings.NO_RESIZE_REQUEST_EDITOR));
242: values.put(START_WITH_REQUEST_TABS, settings
243: .getBoolean(UISettings.START_WITH_REQUEST_TABS));
244: values.put(AUTO_VALIDATE_REQUEST, settings
245: .getBoolean(UISettings.AUTO_VALIDATE_REQUEST));
246: values.put(ABORT_ON_INVALID_REQUEST, settings
247: .getBoolean(UISettings.ABORT_ON_INVALID_REQUEST));
248: values.put(AUTO_VALIDATE_RESPONSE, settings
249: .getBoolean(UISettings.AUTO_VALIDATE_RESPONSE));
250: values.put(CREATE_BACKUP, settings
251: .getBoolean(UISettings.CREATE_BACKUP));
252: values.put(BACKUP_FOLDER, settings.getString(
253: UISettings.BACKUP_FOLDER, ""));
254:
255: if (SoapUI.isStandalone()) {
256: values.put(DESKTOP_TYPE, settings.getString(
257: UISettings.DESKTOP_TYPE, "Windows"));
258: values.put(NATIVE_LAF, settings
259: .getBoolean(UISettings.NATIVE_LAF));
260: }
261:
262: values.put(ENABLE_GROOVY_LOG_DURING_LOADTEST, settings
263: .getBoolean(UISettings.DONT_DISABLE_GROOVY_LOG));
264:
265: return values;
266: }
267: }
|