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