View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 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.Font;
    16  import java.awt.event.ActionEvent;
    17  import java.awt.event.ActionListener;
    18
    19  import javax.swing.AbstractAction;
    20  import javax.swing.JButton;
    21  import javax.swing.JCheckBox;
    22  import javax.swing.JTextField;
    23
    24  import com.eviware.soapui.SoapUI;
    25  import com.eviware.soapui.model.settings.Settings;
    26  import com.eviware.soapui.settings.UISettings;
    27  import com.eviware.soapui.support.components.SimpleForm;
    28  import com.eviware.soapui.support.types.StringToStringMap;
    29  import com.eviware.soapui.ui.desktop.DesktopRegistry;
    30  import com.jgoodies.forms.builder.ButtonBarBuilder;
    31  import com.l2fprod.common.swing.JFontChooser;
    32
    33  /***
    34   * Preferences class for UISettings
    35   *
    36   * @author ole.matzura
    37   */
    38
    39  public class UIPrefs implements Prefs
    40  {
    41  	public static final String ORDER_PROJECTS = "Order Projects";
    42  	public static final String ORDER_TESTSUITES = "Order TestSuites";
    43  	public static final String ORDER_REQUESTS = "Order Requests";
    44  	public static final String NO_RESIZE_REQUEST_EDITOR = "Disable auto-resize";
    45  	public static final String START_WITH_REQUEST_TABS = "Tabbed request view";
    46  	public static final String AUTO_VALIDATE_REQUEST = "Validate Requests";
    47  	public static final String ABORT_ON_INVALID_REQUEST = "Abort on invalid";
    48  	public static final String AUTO_VALIDATE_RESPONSE = "Validate Responses";
    49  	public static final String CREATE_BACKUP = "Create Backup";
    50  	public static final String BACKUP_FOLDER = "Backup Folder";
    51  	public static final String DESKTOP_TYPE = "Desktop Type";
    52  	public static final String NATIVE_LAF = "Native L&F";
    53  	public static final String ENABLE_GROOVY_LOG_DURING_LOADTEST = "Do not disable Groovy Log";
    54
    55  	private JTextField editorFontTextField;
    56  	private SimpleForm editorForm;
    57  	private final String title;
    58  	private JCheckBox abortCheckBox;
    59  	private JCheckBox autoValidateCheckBox;
    60  	private JCheckBox backupCheckBox;
    61  	private JTextField backupFolder;
    62
    63  	public UIPrefs(String title)
    64  	{
    65  		this.title = title;
    66  	}
    67
    68  	public String getTitle()
    69  	{
    70  		return title;
    71  	}
    72
    73  	public SimpleForm getForm()
    74  	{
    75  		if( editorForm == null )
    76  		{
    77  			ButtonBarBuilder builder = new ButtonBarBuilder();
    78  			editorFontTextField = new JTextField( 20 );
    79  			editorFontTextField.setEnabled( false );
    80  			builder.addFixed( editorFontTextField );
    81  			builder.addRelatedGap();
    82  			builder.addFixed( new JButton( new AbstractAction("Select Font..")
    83  					{
    84  						public void actionPerformed(ActionEvent e)
    85  						{
    86  							Font font = JFontChooser.showDialog( null, "Select XML Editor Font",
    87  									Font.decode( editorFontTextField.getText() ));
    88
    89  							if( font != null )
    90  								editorFontTextField.setText( font.getFontName() + "-plain-" + font.getSize() );
    91  						}}));
    92
    93  			editorForm = new SimpleForm();
    94  			editorForm.addSpace( 5 );
    95  			editorForm.append( "Editor Font", builder.getPanel() );
    96  			editorForm.appendSeparator();
    97
    98  			editorForm.appendCheckBox( ORDER_PROJECTS, "(orders Projects alphabetically in tree)", false );
    99  			editorForm.appendCheckBox( ORDER_REQUESTS, "(orders Requests alphabetically in tree)", false );
    100 			editorForm.appendCheckBox( ORDER_TESTSUITES, "(orders TestSuites alphabetically in tree)", false );
    101 			editorForm.appendSeparator();
    102
    103 			editorForm.appendCheckBox( NO_RESIZE_REQUEST_EDITOR, "(disables automatic resizing of request editors)", true );
    104 			editorForm.appendCheckBox( START_WITH_REQUEST_TABS, "(defaults the request editor to the tabbed layout)", true );
    105 			editorForm.appendSeparator();
    106
    107 			autoValidateCheckBox = editorForm.appendCheckBox( AUTO_VALIDATE_REQUEST, "(always validate request messages before they are sent)", true );
    108 			abortCheckBox = editorForm.appendCheckBox( ABORT_ON_INVALID_REQUEST, "(aborts invalid requests)", true );
    109 			editorForm.appendCheckBox( AUTO_VALIDATE_RESPONSE, "(always validate response messages)", true );
    110
    111 			autoValidateCheckBox.addActionListener( new ActionListener() {
    112
    113 				public void actionPerformed(ActionEvent e)
    114 				{
    115 					abortCheckBox.setEnabled( autoValidateCheckBox.isSelected() );
    116 				}} );
    117
    118 			editorForm.appendSeparator();
    119 			backupCheckBox = editorForm.appendCheckBox( CREATE_BACKUP, "(backup project files before they are saved)", true );
    120 			backupFolder = editorForm.appendTextField( BACKUP_FOLDER, "(folder to backup to, can be both relative or absolut)" );
    121 			backupCheckBox.addActionListener( new ActionListener() {
    122
    123 				public void actionPerformed(ActionEvent e)
    124 				{
    125 					backupFolder.setEnabled( backupCheckBox.isSelected() );
    126 				}} );
    127
    128 			if( SoapUI.isStandalone())
    129 			{
    130 				editorForm.appendSeparator();
    131 				editorForm.appendComboBox( DESKTOP_TYPE, DesktopRegistry.getInstance().getNames(),
    132 							"Select the type of desktop to use" );
    133 				editorForm.appendCheckBox( NATIVE_LAF, "(use native Look & Feel - requires restart)", true );
    134 			}
    135
    136 			editorForm.appendSeparator();
    137 			editorForm.appendCheckBox( ENABLE_GROOVY_LOG_DURING_LOADTEST, "(do not disable the groovy log when running LoadTests)", true );
    138 		}
    139
    140 		return editorForm;
    141 	}
    142
    143 	public void getFormValues(Settings settings)
    144 	{
    145 		StringToStringMap values = new StringToStringMap();
    146 		editorForm.getValues( values );
    147 		storeValues(values, settings);
    148 	}
    149
    150 	public void storeValues(StringToStringMap values, Settings settings)
    151 	{
    152 		if( editorFontTextField != null )
    153 			settings.setString( UISettings.EDITOR_FONT, editorFontTextField.getText() );
    154
    155 		settings.setBoolean( UISettings.ORDER_PROJECTS, values.getBoolean( ORDER_PROJECTS ));
    156 		settings.setBoolean( UISettings.ORDER_REQUESTS, values.getBoolean( ORDER_REQUESTS ));
    157 		settings.setBoolean( UISettings.ORDER_TESTSUITES, values.getBoolean( ORDER_TESTSUITES ));
    158 		settings.setBoolean( UISettings.NO_RESIZE_REQUEST_EDITOR, values.getBoolean( NO_RESIZE_REQUEST_EDITOR ));
    159 		settings.setBoolean( UISettings.START_WITH_REQUEST_TABS, values.getBoolean( START_WITH_REQUEST_TABS ));
    160 		settings.setBoolean( UISettings.AUTO_VALIDATE_REQUEST, values.getBoolean( AUTO_VALIDATE_REQUEST ));
    161 		settings.setBoolean( UISettings.ABORT_ON_INVALID_REQUEST, values.getBoolean( ABORT_ON_INVALID_REQUEST ));
    162 		settings.setBoolean( UISettings.AUTO_VALIDATE_RESPONSE, values.getBoolean( AUTO_VALIDATE_RESPONSE ));
    163 		settings.setBoolean( UISettings.CREATE_BACKUP, values.getBoolean( CREATE_BACKUP ));
    164 		settings.setString( UISettings.BACKUP_FOLDER, values.get( BACKUP_FOLDER ));
    165
    166 		if( SoapUI.isStandalone())
    167 		{
    168 			settings.setString( UISettings.DESKTOP_TYPE, values.get( DESKTOP_TYPE ));
    169 			settings.setBoolean( UISettings.NATIVE_LAF, values.getBoolean( NATIVE_LAF ));
    170 		}
    171
    172 		settings.setBoolean( UISettings.DONT_DISABLE_GROOVY_LOG, values.getBoolean( ENABLE_GROOVY_LOG_DURING_LOADTEST ));
    173 	}
    174
    175 	public void setFormValues(Settings settings)
    176 	{
    177 		String editorFont = settings.getString( UISettings.EDITOR_FONT, UISettings.DEFAULT_EDITOR_FONT );
    178 		if( editorFont == null || editorFont.length() == 0 )
    179 			editorFont = UISettings.DEFAULT_EDITOR_FONT;
    180
    181 		editorFontTextField.setText( editorFont );
    182 		editorForm.setValues( getValues(settings) );
    183
    184 		abortCheckBox.setEnabled( settings.getBoolean( UISettings.AUTO_VALIDATE_REQUEST ) );
    185 		backupFolder.setEnabled( settings.getBoolean( UISettings.CREATE_BACKUP ) );
    186 	}
    187
    188 	public StringToStringMap getValues(Settings settings)
    189 	{
    190 		StringToStringMap values = new StringToStringMap();
    191 		values.put( ORDER_PROJECTS, settings.getBoolean( UISettings.ORDER_PROJECTS ));
    192 		values.put( ORDER_REQUESTS, settings.getBoolean( UISettings.ORDER_REQUESTS ));
    193 		values.put( ORDER_TESTSUITES, settings.getBoolean( UISettings.ORDER_TESTSUITES ));
    194 		values.put( NO_RESIZE_REQUEST_EDITOR, settings.getBoolean( UISettings.NO_RESIZE_REQUEST_EDITOR ));
    195 		values.put( START_WITH_REQUEST_TABS, settings.getBoolean( UISettings.START_WITH_REQUEST_TABS ));
    196 		values.put( AUTO_VALIDATE_REQUEST, settings.getBoolean( UISettings.AUTO_VALIDATE_REQUEST ));
    197 		values.put( ABORT_ON_INVALID_REQUEST, settings.getBoolean( UISettings.ABORT_ON_INVALID_REQUEST ));
    198 		values.put( AUTO_VALIDATE_RESPONSE, settings.getBoolean( UISettings.AUTO_VALIDATE_RESPONSE ));
    199 		values.put( CREATE_BACKUP, settings.getBoolean( UISettings.CREATE_BACKUP ));
    200 		values.put( BACKUP_FOLDER, settings.getString( UISettings.BACKUP_FOLDER, "" ));
    201
    202 		if( SoapUI.isStandalone())
    203 		{
    204 			values.put( DESKTOP_TYPE, settings.getString( UISettings.DESKTOP_TYPE, "Windows" ));
    205 			values.put( NATIVE_LAF, settings.getBoolean( UISettings.NATIVE_LAF ));
    206 		}
    207
    208 		values.put( ENABLE_GROOVY_LOG_DURING_LOADTEST, settings.getBoolean( UISettings.DONT_DISABLE_GROOVY_LOG ));
    209
    210 		return values;
    211 	}
    212 }