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.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_TESTSUITES = "Order TestSuites";
    39  	public static final String ORDER_REQUESTS = "Order Requests";
    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
    46  	private SimpleForm editorForm;
    47  	private final String title;
    48  	private JCheckBox backupCheckBox;
    49  	private JTextField backupFolder;
    50
    51  	public UIPrefs(String title)
    52  	{
    53  		this.title = title;
    54  	}
    55
    56  	public String getTitle()
    57  	{
    58  		return title;
    59  	}
    60
    61  	public SimpleForm getForm()
    62  	{
    63  		if( editorForm == null )
    64  		{
    65  			editorForm = new SimpleForm();
    66  			editorForm.addSpace( 5 );
    67  			editorForm.appendCheckBox( CLOSE_PROJECTS, "(close all projects on startup)", false );
    68  			editorForm.appendSeparator();
    69  			editorForm.appendCheckBox( ORDER_PROJECTS, "(orders Projects alphabetically in tree)", false );
    70  			editorForm.appendCheckBox( ORDER_REQUESTS, "(orders Requests alphabetically in tree)", false );
    71  			editorForm.appendCheckBox( ORDER_TESTSUITES, "(orders TestSuites alphabetically in tree)", false );
    72  			editorForm.appendSeparator();
    73
    74  			backupCheckBox = editorForm.appendCheckBox( CREATE_BACKUP, "(backup project files before they are saved)", true );
    75  			backupFolder = editorForm.appendTextField( BACKUP_FOLDER, "(folder to backup to, can be both relative or absolut)" );
    76  			backupCheckBox.addActionListener( new ActionListener() {
    77
    78  				public void actionPerformed(ActionEvent e)
    79  				{
    80  					backupFolder.setEnabled( backupCheckBox.isSelected() );
    81  				}} );
    82
    83  			if( SoapUI.isStandalone())
    84  			{
    85  				editorForm.appendSeparator();
    86  				editorForm.appendComboBox( DESKTOP_TYPE, DesktopRegistry.getInstance().getNames(),
    87  							"Select the type of desktop to use" );
    88  				editorForm.appendCheckBox( NATIVE_LAF, "(use native Look & Feel - requires restart)", true );
    89  			}
    90
    91  			editorForm.appendSeparator();
    92  			editorForm.appendCheckBox( ENABLE_GROOVY_LOG_DURING_LOADTEST, "(do not disable the groovy log when running LoadTests)", true );
    93  		}
    94
    95  		return editorForm;
    96  	}
    97
    98  	public void getFormValues(Settings settings)
    99  	{
    100 		StringToStringMap values = new StringToStringMap();
    101 		editorForm.getValues( values );
    102 		storeValues(values, settings);
    103 	}
    104
    105 	public void storeValues(StringToStringMap values, Settings settings)
    106 	{
    107 		settings.setBoolean( UISettings.CLOSE_PROJECTS, values.getBoolean( CLOSE_PROJECTS ));
    108 		settings.setBoolean( UISettings.ORDER_PROJECTS, values.getBoolean( ORDER_PROJECTS ));
    109 		settings.setBoolean( UISettings.ORDER_REQUESTS, values.getBoolean( ORDER_REQUESTS ));
    110 		settings.setBoolean( UISettings.ORDER_TESTSUITES, values.getBoolean( ORDER_TESTSUITES ));
    111 		settings.setBoolean( UISettings.CREATE_BACKUP, values.getBoolean( CREATE_BACKUP ));
    112 		settings.setString( UISettings.BACKUP_FOLDER, values.get( BACKUP_FOLDER ));
    113
    114 		if( SoapUI.isStandalone())
    115 		{
    116 			settings.setString( UISettings.DESKTOP_TYPE, values.get( DESKTOP_TYPE ));
    117 			settings.setBoolean( UISettings.NATIVE_LAF, values.getBoolean( NATIVE_LAF ));
    118 		}
    119
    120 		settings.setBoolean( UISettings.DONT_DISABLE_GROOVY_LOG, values.getBoolean( ENABLE_GROOVY_LOG_DURING_LOADTEST ));
    121 	}
    122
    123 	public void setFormValues(Settings settings)
    124 	{
    125 		editorForm.setValues( getValues(settings) );
    126 		backupFolder.setEnabled( settings.getBoolean( UISettings.CREATE_BACKUP ) );
    127 	}
    128
    129 	public StringToStringMap getValues(Settings settings)
    130 	{
    131 		StringToStringMap values = new StringToStringMap();
    132 		values.put( CLOSE_PROJECTS, settings.getBoolean( UISettings.CLOSE_PROJECTS ));
    133 		values.put( ORDER_PROJECTS, settings.getBoolean( UISettings.ORDER_PROJECTS ));
    134 		values.put( ORDER_REQUESTS, settings.getBoolean( UISettings.ORDER_REQUESTS ));
    135 		values.put( ORDER_TESTSUITES, settings.getBoolean( UISettings.ORDER_TESTSUITES ));
    136 		values.put( CREATE_BACKUP, settings.getBoolean( UISettings.CREATE_BACKUP ));
    137 		values.put( BACKUP_FOLDER, settings.getString( UISettings.BACKUP_FOLDER, "" ));
    138
    139 		if( SoapUI.isStandalone())
    140 		{
    141 			values.put( DESKTOP_TYPE, settings.getString( UISettings.DESKTOP_TYPE, SoapUI.DEFAULT_DESKTOP ));
    142 			values.put( NATIVE_LAF, settings.getBoolean( UISettings.NATIVE_LAF ));
    143 		}
    144
    145 		values.put( ENABLE_GROOVY_LOG_DURING_LOADTEST, settings.getBoolean( UISettings.DONT_DISABLE_GROOVY_LOG ));
    146
    147 		return values;
    148 	}
    149 }