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.util.ArrayList;
    17  import java.util.List;
    18
    19  import javax.swing.AbstractAction;
    20  import javax.swing.Action;
    21  import javax.swing.JTabbedPane;
    22
    23  import com.eviware.soapui.SoapUI;
    24  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
    25  import com.eviware.soapui.model.settings.Settings;
    26  import com.eviware.soapui.settings.ProxySettings;
    27  import com.eviware.soapui.settings.SSLSettings;
    28  import com.eviware.soapui.settings.WSISettings;
    29  import com.eviware.soapui.settings.WsdlSettings;
    30  import com.eviware.soapui.support.UISupport;
    31  import com.eviware.soapui.support.components.SwingConfigurationDialogImpl;
    32  import com.eviware.soapui.support.types.StringToStringMap;
    33
    34  /***
    35   * Action for managing SoapUI preferences
    36   *
    37   * @author Ole.Matzura
    38   */
    39
    40  public class SoapUIPreferencesAction extends AbstractAction
    41  {
    42  	public static final String WS_I_SETTINGS = "WS-I Settings";
    43  	public static final String WSDL_SETTINGS = "WSDL Settings";
    44  	public static final String UI_SETTINGS = "UI Settings";
    45  	public static final String EDITOR_SETTINGS = "Editor Settings";
    46  	public static final String PROXY_SETTINGS = "Proxy Settings";
    47  	public static final String HTTP_SETTINGS = "HTTP Settings";
    48  	public static final String SSL_SETTINGS = "SSL Settings";
    49  	public static final String INTEGRATED_TOOLS = "Tools";
    50  	private SwingConfigurationDialogImpl dialog;
    51  	private JTabbedPane tabs;
    52  	private List<Prefs> prefs = new ArrayList<Prefs>();
    53
    54  	private static SoapUIPreferencesAction instance;
    55
    56  	public SoapUIPreferencesAction()
    57  	{
    58  		super( "Preferences" );
    59
    60  		putValue( Action.SHORT_DESCRIPTION, "Sets global soapUI preferences" );
    61  		putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu alt P"));
    62
    63  		addPrefs( new HttpPrefs( HTTP_SETTINGS));
    64  		addPrefs( new AnnotatedSettingsPrefs( ProxySettings.class, PROXY_SETTINGS ));
    65  		addPrefs( new AnnotatedSettingsPrefs( SSLSettings.class, SSL_SETTINGS ));
    66  		addPrefs( new AnnotatedSettingsPrefs( WsdlSettings.class, WSDL_SETTINGS ));
    67  		addPrefs( new UIPrefs( UI_SETTINGS ));
    68  		addPrefs( new EditorPrefs( EDITOR_SETTINGS ));
    69  		addPrefs( new ToolsPrefs( INTEGRATED_TOOLS ));
    70  		addPrefs( new AnnotatedSettingsPrefs( WSISettings.class, WS_I_SETTINGS ));
    71
    72  		instance = this;
    73  	}
    74
    75  	public void addPrefs( Prefs pref )
    76  	{
    77  		prefs.add( pref );
    78  	}
    79
    80  	public static SoapUIPreferencesAction getInstance()
    81  	{
    82  		if( instance == null )
    83  			instance = new SoapUIPreferencesAction();
    84
    85  		return instance;
    86  	}
    87
    88  	public void actionPerformed(ActionEvent e)
    89  	{
    90  		show( HTTP_SETTINGS );
    91  	}
    92
    93  	public boolean show( String initialTab )
    94  	{
    95  		if( dialog == null )
    96  			buildDialog();
    97
    98  		Settings settings = SoapUI.getSettings();
    99  		for( Prefs pref : prefs )
    100 			pref.setFormValues( settings );
    101
    102 		if( initialTab != null )
    103 		{
    104 			int ix = tabs.indexOfTab( initialTab );
    105 			if( ix != -1 )
    106 				tabs.setSelectedIndex( ix );
    107 		}
    108
    109 		if( dialog.show( new StringToStringMap() ))
    110 		{
    111 			for( Prefs pref : prefs )
    112 				pref.getFormValues( settings );
    113
    114          return true;
    115 		}
    116
    117 		return false;
    118 	}
    119
    120    private void buildDialog()
    121 	{
    122 		dialog = new SwingConfigurationDialogImpl( "soapUI Preferences", HelpUrls.PREFERENCES_HELP_URL,
    123 				"Set global soapUI settings", UISupport.OPTIONS_ICON );
    124
    125 		tabs = new JTabbedPane();
    126 		tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    127 		tabs.setTabPlacement( JTabbedPane.LEFT );
    128 		for( Prefs pref : prefs )
    129 		{
    130 			tabs.addTab( pref.getTitle(), pref.getForm().getPanel() );
    131 		}
    132
    133 		dialog.setContent( UISupport.createTabPanel( tabs, false ) );
    134 	}
    135
    136 }