http proxy configurable reworked

This commit is contained in:
nik
2010-09-01 15:32:25 +04:00
parent 5a28fcc09c
commit de57d873ba
4 changed files with 66 additions and 90 deletions
@@ -55,7 +55,7 @@ public class HTTPProxySettingsDialog extends DialogWrapper {
}
protected JComponent createCenterPanel() {
return panel.getComponent();
return panel.createComponent();
}
protected Action[] createActions() {
@@ -15,7 +15,10 @@
*/
package com.intellij.util.net;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.util.Comparing;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.DocumentListener;
@@ -30,7 +33,7 @@ import java.awt.event.ActionListener;
* Time: 3:52:47 PM
* To change this template use Options | File Templates.
*/
public class HTTPProxySettingsPanel{
public class HTTPProxySettingsPanel implements SearchableConfigurable {
private JPanel myMainPanel;
private JTextField myProxyLoginTextField;
@@ -134,10 +137,32 @@ public class HTTPProxySettingsPanel{
myRememberProxyPasswordCheckBox.setEnabled(enabled);
}
public JComponent getComponent() {
public JComponent createComponent() {
return myMainPanel;
}
@NotNull
public String getId() {
return getHelpTopic();
}
public Runnable enableSearch(final String option) {
return null;
}
@Nls
public String getDisplayName() {
return "HTTP Proxy";
}
public Icon getIcon() {
return null;
}
public String getHelpTopic() {
return "http.proxy";
}
public void addActionListener(final ActionListener actionListener) {
myProxyLoginTextField.addActionListener(actionListener);
DocumentListener docListener = new DocumentListener() {
@@ -161,4 +186,8 @@ public class HTTPProxySettingsPanel{
myRememberProxyPasswordCheckBox.addActionListener(actionListener);
}
@Override
public void disposeUIResources() {
}
}
@@ -15,18 +15,14 @@
*/
package com.intellij.util.net;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.ui.GuiUtils;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.apache.commons.codec.binary.Base64;
import org.jdom.Element;
import org.jetbrains.annotations.Nls;
import javax.swing.*;
import java.io.IOException;
@@ -39,7 +35,13 @@ import java.net.*;
* Time: 3:58:23 PM
* To change this template use Options | File Templates.
*/
public class HttpConfigurable implements JDOMExternalizable, ApplicationComponent, SearchableConfigurable {
@State(
name = "HttpConfigurable",
storages = {
@Storage(id = "other", file = "$APP_CONFIG$/other.xml")
}
)
public class HttpConfigurable implements PersistentStateComponent<HttpConfigurable> {
public boolean USE_HTTP_PROXY = false;
public String PROXY_HOST = "";
public int PROXY_PORT = 80;
@@ -49,39 +51,33 @@ public class HttpConfigurable implements JDOMExternalizable, ApplicationComponen
public String PROXY_PASSWORD_CRYPT = "";
public boolean KEEP_PROXY_PASSWORD = false;
private HTTPProxySettingsPanel myPanel;
public static HttpConfigurable getInstance() {
return ServiceManager.getService(HttpConfigurable.class);
}
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
if (!KEEP_PROXY_PASSWORD)
public static boolean editConfigurable(final JComponent parent) {
return ShowSettingsUtil.getInstance().editConfigurable(parent, new HTTPProxySettingsPanel(getInstance()));
}
@Override
public HttpConfigurable getState() {
final HttpConfigurable state = new HttpConfigurable();
XmlSerializerUtil.copyBean(this, state);
if (!KEEP_PROXY_PASSWORD) {
state.PROXY_PASSWORD_CRYPT = "";
}
return state;
}
@Override
public void loadState(HttpConfigurable state) {
XmlSerializerUtil.copyBean(state, this);
if (!KEEP_PROXY_PASSWORD) {
PROXY_PASSWORD_CRYPT = "";
}
}
public void writeExternal(Element element) throws WriteExternalException {
String proxyPassword = PROXY_PASSWORD_CRYPT;
if (!KEEP_PROXY_PASSWORD)
PROXY_PASSWORD_CRYPT = "";
DefaultJDOMExternalizer.writeExternal(this, element);
PROXY_PASSWORD_CRYPT = proxyPassword;
}
public String getComponentName() {
return "HttpConfigurable";
}
public void initComponent() {
}
public void disposeComponent() {
}
public String getPlainProxyPassword () {
public String getPlainProxyPassword() {
return new String(new Base64().decode(PROXY_PASSWORD_CRYPT.getBytes()));
}
@@ -90,8 +86,7 @@ public class HttpConfigurable implements JDOMExternalizable, ApplicationComponen
}
public PasswordAuthentication getPromptedAuthentication(final String host, final String prompt) {
if (PROXY_AUTHENTICATION &&
! KEEP_PROXY_PASSWORD) {
if (PROXY_AUTHENTICATION && !KEEP_PROXY_PASSWORD) {
Runnable runnable = new Runnable() {
public void run() {
AuthenticationDialog dlg = new AuthenticationDialog(host, prompt);
@@ -158,52 +153,4 @@ public class HttpConfigurable implements JDOMExternalizable, ApplicationComponen
Authenticator.setDefault(null);
}
}
public String getId() {
return getHelpTopic();
}
public Runnable enableSearch(final String option) {
return null;
}
@Nls
public String getDisplayName() {
return "HTTP Proxy";
}
public Icon getIcon() {
return null;
}
public String getHelpTopic() {
return "http.proxy";
}
public JComponent createComponent() {
if (myPanel == null) {
myPanel = new HTTPProxySettingsPanel(getInstance());
}
return myPanel.getComponent();
}
public boolean isModified() {
return myPanel != null && myPanel.isModified();
}
public void apply() throws ConfigurationException {
if (myPanel != null) {
myPanel.apply();
}
}
public void reset() {
if (myPanel != null) {
myPanel.reset();
}
}
public void disposeUIResources() {
myPanel = null;
}
}
@@ -176,7 +176,7 @@
<!-- Plugins -->
<applicationConfigurable instance="com.intellij.ide.plugins.PluginManagerConfigurable"/>
<applicationConfigurable implementation="com.intellij.util.net.HttpConfigurable"/>
<applicationConfigurable instance="com.intellij.util.net.HTTPProxySettingsPanel"/>
<applicationConfigurable instance="com.intellij.openapi.diff.impl.external.DiffOptionsForm"/>
<fileTypeFactory implementation="com.intellij.openapi.fileTypes.impl.PlatformFileTypeFactory"/>