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