View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.actions;
14  
15  import java.awt.event.ActionEvent;
16  import java.awt.event.ActionListener;
17  
18  import javax.swing.JCheckBox;
19  import javax.swing.JTextField;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.model.settings.Settings;
23  import com.eviware.soapui.settings.UISettings;
24  import com.eviware.soapui.support.components.SimpleForm;
25  import com.eviware.soapui.support.types.StringToStringMap;
26  import com.eviware.soapui.ui.desktop.DesktopRegistry;
27  
28  /***
29   * Preferences class for UISettings
30   * 
31   * @author ole.matzura
32   */
33  
34  public class UIPrefs implements Prefs
35  {
36  	public static final String CLOSE_PROJECTS = "Close Projects";
37  	public static final String ORDER_PROJECTS = "Order Projects";
38  	public static final String ORDER_REQUESTS = "Order Requests";
39  	public static final String SHOW_DESCRIPTIONS = "Show Descriptions";
40  	public static final String CREATE_BACKUP = "Create Backup";
41  	public static final String BACKUP_FOLDER = "Backup Folder";
42  	public static final String DESKTOP_TYPE = "Desktop Type";
43  	public static final String NATIVE_LAF = "Native L&F";
44  	public static final String ENABLE_GROOVY_LOG_DURING_LOADTEST = "Do not disable Groovy Log";
45  	public static final String SHOW_LOGS_AT_STARTUP = "Show Log Tabs";
46  	public static final String AUTOSAVE_INTERVAL = "AutoSave Interval";
47  	public static final String AUTOSAVE_ONEXIT = "Save projects on exit";
48  	public static final String SHOW_STARTUP_PAGE = "Show Startup Page";
49  	public static final String LINEBRAK = "Normalize line-break";
50  	public static final String GC_INTERVAL = "Garbage Collection Interval";
51  	public static final String RAW_RESPONSE_MESSAGE_SIZE = "Size of Raw Response Message to Show";
52  	public static final String RAW_REQUEST_MESSAGE_SIZE = "Size of Raw Request Message to Show";
53  
54  	private SimpleForm editorForm;
55  	private final String title;
56  	private JCheckBox backupCheckBox;
57  	private JTextField backupFolder;
58  
59  	public UIPrefs( String title )
60  	{
61  		this.title = title;
62  	}
63  
64  	public String getTitle()
65  	{
66  		return title;
67  	}
68  
69  	public SimpleForm getForm()
70  	{
71  		if( editorForm == null )
72  		{
73  			editorForm = new SimpleForm();
74  			editorForm.addSpace( 5 );
75  			editorForm.appendCheckBox( CLOSE_PROJECTS, "Close all projects on startup", false );
76  			editorForm.appendSeparator();
77  			editorForm.appendCheckBox( ORDER_PROJECTS, "Order Projects alphabetically in tree", false );
78  			editorForm.appendCheckBox( ORDER_REQUESTS, "Order Requests alphabetically in tree", false );
79  			editorForm.appendCheckBox( SHOW_DESCRIPTIONS, "Show description content when available", false );
80  			editorForm.appendSeparator();
81  
82  			editorForm.appendCheckBox( AUTOSAVE_ONEXIT, "Automatically save all projects on exit", true );
83  			backupCheckBox = editorForm.appendCheckBox( CREATE_BACKUP, "Backup project files before they are saved", true );
84  			backupFolder = editorForm.appendTextField( BACKUP_FOLDER,
85  					"Folder to backup to (can be both relative or absolute)" );
86  			backupCheckBox.addActionListener( new ActionListener()
87  			{
88  				public void actionPerformed( ActionEvent e )
89  				{
90  					backupFolder.setEnabled( backupCheckBox.isSelected() );
91  				}
92  			} );
93  
94  			editorForm.appendTextField( AUTOSAVE_INTERVAL,
95  					"Sets the autosave interval in minutes (0 means autosave is off)" );
96  
97  			if( SoapUI.isStandalone() )
98  			{
99  				editorForm.appendSeparator();
100 				editorForm.appendComboBox( DESKTOP_TYPE, DesktopRegistry.getInstance().getNames(),
101 						"Select the type of desktop to use" );
102 				editorForm.appendCheckBox( NATIVE_LAF, "Use native Look & Feel (requires restart)", true );
103 			}
104 
105 			editorForm.appendSeparator();
106 			editorForm.appendCheckBox( ENABLE_GROOVY_LOG_DURING_LOADTEST,
107 					"Do not disable the groovy log when running LoadTests", true );
108 
109 			if( SoapUI.isStandalone() )
110 			{
111 				editorForm.appendCheckBox( SHOW_LOGS_AT_STARTUP, "Shows log tabs when starting soapUI", false );
112 				editorForm.appendCheckBox( SHOW_STARTUP_PAGE, "Opens startup web page when starting soapUI", false );
113 			}
114 
115 			editorForm.appendSeparator();
116 			editorForm.appendCheckBox( LINEBRAK, "Normalize line-breaks when saving project", false );
117 			editorForm.appendSeparator();
118 			editorForm.appendTextField( GC_INTERVAL,
119 				"Sets the Garbage Collector interval in seconds (0 means garbage collection is only performed by JRE)" );
120 			editorForm.appendSeparator();
121 			editorForm.appendTextField( RAW_RESPONSE_MESSAGE_SIZE, "Sets the size of raw response mesage to show." );
122 			editorForm.appendTextField( RAW_REQUEST_MESSAGE_SIZE, "Sets the size of raw request mesage to show." );
123 		}
124 
125 		return editorForm;
126 	}
127 
128 	public void getFormValues( Settings settings )
129 	{
130 		StringToStringMap values = new StringToStringMap();
131 		editorForm.getValues( values );
132 		storeValues( values, settings );
133 	}
134 
135 	public void storeValues( StringToStringMap values, Settings settings )
136 	{
137 		settings.setBoolean( UISettings.CLOSE_PROJECTS, values.getBoolean( CLOSE_PROJECTS ) );
138 		settings.setBoolean( UISettings.ORDER_PROJECTS, values.getBoolean( ORDER_PROJECTS ) );
139 		settings.setBoolean( UISettings.ORDER_REQUESTS, values.getBoolean( ORDER_REQUESTS ) );
140 		settings.setBoolean( UISettings.SHOW_DESCRIPTIONS, values.getBoolean( SHOW_DESCRIPTIONS ) );
141 		settings.setBoolean( UISettings.CREATE_BACKUP, values.getBoolean( CREATE_BACKUP ) );
142 		settings.setString( UISettings.BACKUP_FOLDER, values.get( BACKUP_FOLDER ) );
143 		settings.setString( UISettings.AUTO_SAVE_INTERVAL, values.get( AUTOSAVE_INTERVAL ) );
144 		settings.setBoolean( UISettings.AUTO_SAVE_PROJECTS_ON_EXIT, values.getBoolean( AUTOSAVE_ONEXIT ) );
145 		settings.setBoolean( UISettings.LINEBREAK, values.getBoolean( LINEBRAK ) );
146 
147 		if( SoapUI.isStandalone() )
148 		{
149 			settings.setString( UISettings.DESKTOP_TYPE, values.get( DESKTOP_TYPE ) );
150 			settings.setBoolean( UISettings.NATIVE_LAF, values.getBoolean( NATIVE_LAF ) );
151 		}
152 
153 		settings.setBoolean( UISettings.DONT_DISABLE_GROOVY_LOG, values.getBoolean( ENABLE_GROOVY_LOG_DURING_LOADTEST ) );
154 		if( SoapUI.isStandalone() )
155 		{
156 			settings.setBoolean( UISettings.SHOW_LOGS_AT_STARTUP, values.getBoolean( SHOW_LOGS_AT_STARTUP ) );
157 			settings.setBoolean( UISettings.SHOW_STARTUP_PAGE, values.getBoolean( SHOW_STARTUP_PAGE ) );
158 		}
159 		
160 		settings.setString( UISettings.GC_INTERVAL, values.get( GC_INTERVAL ) );
161 		
162 		settings.setString( UISettings.RAW_RESPONSE_MESSAGE_SIZE, values.get( RAW_RESPONSE_MESSAGE_SIZE ));
163 		settings.setString( UISettings.RAW_REQUEST_MESSAGE_SIZE, values.get( RAW_REQUEST_MESSAGE_SIZE ));
164 		
165 		SoapUI.initAutoSaveTimer();
166 		SoapUI.initGCTimer();
167 	}
168 
169 	public void setFormValues( Settings settings )
170 	{
171 		editorForm.setValues( getValues( settings ) );
172 		backupFolder.setEnabled( settings.getBoolean( UISettings.CREATE_BACKUP ) );
173 	}
174 
175 	public StringToStringMap getValues( Settings settings )
176 	{
177 		StringToStringMap values = new StringToStringMap();
178 		values.put( CLOSE_PROJECTS, settings.getBoolean( UISettings.CLOSE_PROJECTS ) );
179 		values.put( ORDER_PROJECTS, settings.getBoolean( UISettings.ORDER_PROJECTS ) );
180 		values.put( ORDER_REQUESTS, settings.getBoolean( UISettings.ORDER_REQUESTS ) );
181 		values.put( SHOW_DESCRIPTIONS, settings.getBoolean( UISettings.SHOW_DESCRIPTIONS ) );
182 		values.put( CREATE_BACKUP, settings.getBoolean( UISettings.CREATE_BACKUP ) );
183 		values.put( BACKUP_FOLDER, settings.getString( UISettings.BACKUP_FOLDER, "" ) );
184 		values.put( AUTOSAVE_INTERVAL, settings.getString( UISettings.AUTO_SAVE_INTERVAL, "0" ) );
185 		values.put( AUTOSAVE_ONEXIT, settings.getBoolean( UISettings.AUTO_SAVE_PROJECTS_ON_EXIT ) );
186 		values.put( LINEBRAK, settings.getBoolean( UISettings.LINEBREAK ) );
187 
188 		if( SoapUI.isStandalone() )
189 		{
190 			values.put( DESKTOP_TYPE, settings.getString( UISettings.DESKTOP_TYPE, SoapUI.DEFAULT_DESKTOP ) );
191 			values.put( NATIVE_LAF, settings.getBoolean( UISettings.NATIVE_LAF ) );
192 		}
193 
194 		values.put( ENABLE_GROOVY_LOG_DURING_LOADTEST, settings.getBoolean( UISettings.DONT_DISABLE_GROOVY_LOG ) );
195 		if( SoapUI.isStandalone() )
196 		{
197 			values.put( SHOW_LOGS_AT_STARTUP, settings.getBoolean( UISettings.SHOW_LOGS_AT_STARTUP ) );
198 			values.put( SHOW_STARTUP_PAGE, settings.getBoolean( UISettings.SHOW_STARTUP_PAGE ) );
199 		}
200 		
201 		values.put( GC_INTERVAL, settings.getString( UISettings.GC_INTERVAL, "0" ) );
202 		values.put( RAW_RESPONSE_MESSAGE_SIZE, settings.getString( UISettings.RAW_RESPONSE_MESSAGE_SIZE, "10000" ) );
203 		values.put( RAW_REQUEST_MESSAGE_SIZE, settings.getString( UISettings.RAW_REQUEST_MESSAGE_SIZE, "10000" ) );
204 
205 		return values;
206 	}
207 }