View Javadoc

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