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 PROXY_SETTINGS = "Proxy Settings";
    46  	public static final String HTTP_SETTINGS = "HTTP Settings";
    47  	public static final String SSL_SETTINGS = "SSL Settings";
    48  	public static final String INTEGRATED_TOOLS = "Tools";
    49  	private SwingConfigurationDialogImpl dialog;
    50  	private JTabbedPane tabs;
    51  	private List<Prefs> prefs = new ArrayList<Prefs>();
    52
    53  	private static SoapUIPreferencesAction instance;
    54
    55  	public SoapUIPreferencesAction()
    56  	{
    57  		super( "Preferences" );
    58
    59  		putValue( Action.SHORT_DESCRIPTION, "Sets global soapUI preferences" );
    60  		putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu alt P"));
    61
    62  		addPrefs( new HttpPrefs( HTTP_SETTINGS));
    63  		addPrefs( new AnnotatedSettingsPrefs( ProxySettings.class, PROXY_SETTINGS ));
    64  		addPrefs( new AnnotatedSettingsPrefs( SSLSettings.class, SSL_SETTINGS ));
    65  		addPrefs( new AnnotatedSettingsPrefs( WsdlSettings.class, WSDL_SETTINGS ));
    66  		addPrefs( new UIPrefs( UI_SETTINGS ));
    67  		addPrefs( new ToolsPrefs( INTEGRATED_TOOLS ));
    68  		addPrefs( new AnnotatedSettingsPrefs( WSISettings.class, WS_I_SETTINGS ));
    69
    70  		instance = this;
    71  	}
    72
    73  	public void addPrefs( Prefs pref )
    74  	{
    75  		prefs.add( pref );
    76  	}
    77
    78  	public static SoapUIPreferencesAction getInstance()
    79  	{
    80  		if( instance == null )
    81  			instance = new SoapUIPreferencesAction();
    82
    83  		return instance;
    84  	}
    85
    86  	public void actionPerformed(ActionEvent e)
    87  	{
    88  		show( HTTP_SETTINGS );
    89  	}
    90
    91  	public boolean show( String initialTab )
    92  	{
    93  		if( dialog == null )
    94  			buildDialog();
    95
    96  		Settings settings = SoapUI.getSettings();
    97  		for( Prefs pref : prefs )
    98  			pref.setFormValues( settings );
    99
    100 		if( initialTab != null )
    101 		{
    102 			int ix = tabs.indexOfTab( initialTab );
    103 			if( ix != -1 )
    104 				tabs.setSelectedIndex( ix );
    105 		}
    106
    107 		if( dialog.show( new StringToStringMap() ))
    108 		{
    109 			for( Prefs pref : prefs )
    110 				pref.getFormValues( settings );
    111
    112          return true;
    113 		}
    114
    115 		return false;
    116 	}
    117
    118    private void buildDialog()
    119 	{
    120 		dialog = new SwingConfigurationDialogImpl( "soapUI Preferences", HelpUrls.PREFERENCES_HELP_URL,
    121 				"Set global soapUI settings", UISupport.OPTIONS_ICON );
    122
    123 		tabs = new JTabbedPane();
    124 		tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    125 		tabs.setTabPlacement( JTabbedPane.LEFT );
    126 		for( Prefs pref : prefs )
    127 		{
    128 			tabs.addTab( pref.getTitle(), pref.getForm().getPanel() );
    129 		}
    130
    131 		dialog.setContent( UISupport.createTabPanel( tabs, false ) );
    132
    133 //		dialog.setSize( new Dimension( 450, 390 ));
    134 		// Increased size for MacOSX
    135 		//dialog.setSize( new Dimension( 670, 450 ));
    136 	}
    137
    138 }