001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.actions;
014:
015: import java.awt.event.ActionEvent;
016: import java.util.ArrayList;
017: import java.util.List;
018:
019: import javax.swing.AbstractAction;
020: import javax.swing.Action;
021: import javax.swing.JTabbedPane;
022:
023: import com.eviware.soapui.SoapUI;
024: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
025: import com.eviware.soapui.model.settings.Settings;
026: import com.eviware.soapui.settings.ProxySettings;
027: import com.eviware.soapui.settings.SSLSettings;
028: import com.eviware.soapui.settings.WSISettings;
029: import com.eviware.soapui.settings.WsdlSettings;
030: import com.eviware.soapui.support.UISupport;
031: import com.eviware.soapui.support.components.SwingConfigurationDialogImpl;
032: import com.eviware.soapui.support.types.StringToStringMap;
033:
034: /**
035: * Action for managing SoapUI preferences
036: *
037: * @author Ole.Matzura
038: */
039:
040: public class SoapUIPreferencesAction extends AbstractAction {
041: public static final String WS_I_SETTINGS = "WS-I Settings";
042: public static final String WSDL_SETTINGS = "WSDL Settings";
043: public static final String UI_SETTINGS = "UI Settings";
044: public static final String PROXY_SETTINGS = "Proxy Settings";
045: public static final String HTTP_SETTINGS = "HTTP Settings";
046: public static final String SSL_SETTINGS = "SSL Settings";
047: public static final String INTEGRATED_TOOLS = "Tools";
048: private SwingConfigurationDialogImpl dialog;
049: private JTabbedPane tabs;
050: private List<Prefs> prefs = new ArrayList<Prefs>();
051:
052: private static SoapUIPreferencesAction instance;
053:
054: public SoapUIPreferencesAction() {
055: super ("Preferences");
056:
057: putValue(Action.SHORT_DESCRIPTION,
058: "Sets global soapUI preferences");
059: putValue(Action.ACCELERATOR_KEY, UISupport
060: .getKeyStroke("menu alt P"));
061:
062: addPrefs(new HttpPrefs(HTTP_SETTINGS));
063: addPrefs(new AnnotatedSettingsPrefs(ProxySettings.class,
064: PROXY_SETTINGS));
065: addPrefs(new AnnotatedSettingsPrefs(SSLSettings.class,
066: SSL_SETTINGS));
067: addPrefs(new AnnotatedSettingsPrefs(WsdlSettings.class,
068: WSDL_SETTINGS));
069: addPrefs(new UIPrefs(UI_SETTINGS));
070: addPrefs(new ToolsPrefs(INTEGRATED_TOOLS));
071: addPrefs(new AnnotatedSettingsPrefs(WSISettings.class,
072: WS_I_SETTINGS));
073:
074: instance = this ;
075: }
076:
077: public void addPrefs(Prefs pref) {
078: prefs.add(pref);
079: }
080:
081: public static SoapUIPreferencesAction getInstance() {
082: if (instance == null)
083: instance = new SoapUIPreferencesAction();
084:
085: return instance;
086: }
087:
088: public void actionPerformed(ActionEvent e) {
089: show(HTTP_SETTINGS);
090: }
091:
092: public boolean show(String initialTab) {
093: if (dialog == null)
094: buildDialog();
095:
096: Settings settings = SoapUI.getSettings();
097: for (Prefs pref : prefs)
098: pref.setFormValues(settings);
099:
100: if (initialTab != null) {
101: int ix = tabs.indexOfTab(initialTab);
102: if (ix != -1)
103: tabs.setSelectedIndex(ix);
104: }
105:
106: if (dialog.show(new StringToStringMap())) {
107: for (Prefs pref : prefs)
108: pref.getFormValues(settings);
109:
110: return true;
111: }
112:
113: return false;
114: }
115:
116: private void buildDialog() {
117: dialog = new SwingConfigurationDialogImpl("soapUI Preferences",
118: HelpUrls.PREFERENCES_HELP_URL,
119: "Set global soapUI settings", UISupport.OPTIONS_ICON);
120:
121: tabs = new JTabbedPane();
122: tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
123: tabs.setTabPlacement(JTabbedPane.LEFT);
124: for (Prefs pref : prefs) {
125: tabs.addTab(pref.getTitle(), pref.getForm().getPanel());
126: }
127:
128: dialog.setContent(UISupport.createTabPanel(tabs, false));
129:
130: // dialog.setSize( new Dimension( 450, 390 ));
131: // Increased size for MacOSX
132: //dialog.setSize( new Dimension( 670, 450 ));
133: }
134:
135: }
|