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