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