Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-04-16 20:19:06 +0000
committerMichael Valenta2007-04-16 20:19:06 +0000
commit0cf790315aeb464653087b5d52c27b6ebac8382f (patch)
tree8f1dbfed418aa7ddf19283855861b9c10eee545f /bundles/org.eclipse.ui.net
parent25c6ad2eb19eb8b43a0602546c6546582bdf718d (diff)
downloadeclipse.platform.team-0cf790315aeb464653087b5d52c27b6ebac8382f.tar.gz
eclipse.platform.team-0cf790315aeb464653087b5d52c27b6ebac8382f.tar.xz
eclipse.platform.team-0cf790315aeb464653087b5d52c27b6ebac8382f.zip
177897 [Proxy] Improve UI of Proxy Preferences Page
Diffstat (limited to 'bundles/org.eclipse.ui.net')
-rw-r--r--bundles/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/ProxyPreferencePage.java404
-rw-r--r--bundles/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/messages.properties20
2 files changed, 225 insertions, 199 deletions
diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/ProxyPreferencePage.java b/bundles/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/ProxyPreferencePage.java
index ffd4f40eb..181017c37 100644
--- a/bundles/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/ProxyPreferencePage.java
+++ b/bundles/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/ProxyPreferencePage.java
@@ -13,6 +13,7 @@
* 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
* 20070219 174674 pmoogk@ca.ibm.com - Peter Moogk
* 20070402 180622 brockj@tpg.com.au - Brock Janiczak, Inconsistent enablement states in network preference page
+ * 20070416 177897 ymnk@jcraft.com - Atsuhiko Yamanaka, Improve UI of Proxy Preferences Page
*******************************************************************************/
package org.eclipse.ui.internal.net;
@@ -31,30 +32,18 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class ProxyPreferencePage extends PreferencePage implements
IWorkbenchPreferencePage {
- IProxyData[] proxyData;
Entry[] entryList;
-
Button directConnectionToButton;
-
private Button manualProxyConfigurationButton;
-
Button useSameProxyButton;
-
private Label nonHostLabel;
-
private NonProxyHostsComposite nonHostComposite;
-
Button enableProxyAuth;
-
private Label useridLabel;
-
private Label passwordLabel;
-
Text userid;
-
Text password;
-
private IProxyService proxyService;
public ProxyPreferencePage() {
@@ -74,8 +63,13 @@ public class ProxyPreferencePage extends PreferencePage implements
l.setText(NetUIMessages.ProxyPreferencePage_40);
return l;
}
- proxyData = proxyService.getProxyData();
+
+ IProxyData[] proxyData = proxyService.getProxyData();
entryList = new Entry[proxyData.length];
+ for (int i = 0; i < proxyData.length; i++) {
+ IProxyData pd = proxyData[i];
+ entryList[i] = new Entry(pd);
+ }
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
@@ -115,7 +109,7 @@ public class ProxyPreferencePage extends PreferencePage implements
gridData_2.horizontalIndent = 17;
manualProxyConfigurationComposite.setLayoutData(gridData_2);
- addProtocolEntry(manualProxyConfigurationComposite, 0);
+ entryList[0].addProtocolEntry(manualProxyConfigurationComposite);
new Label(manualProxyConfigurationComposite, SWT.NONE);
useSameProxyButton = new Button(manualProxyConfigurationComposite,
@@ -124,26 +118,24 @@ public class ProxyPreferencePage extends PreferencePage implements
GridData gridData = new GridData();
gridData.horizontalSpan = 3;
useSameProxyButton.setLayoutData(gridData);
- useSameProxyButton
- .setToolTipText(NetUIMessages.ProxyPreferencePage_23);
+ useSameProxyButton.setToolTipText(NetUIMessages.ProxyPreferencePage_23);
useSameProxyButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- handleUseSameProtocol(false);
+ toggleUseSameProtocol();
}
});
- for (int index = 1; index < proxyData.length; index++) {
- addProtocolEntry(manualProxyConfigurationComposite, index);
+ for (int index = 1; index < entryList.length; index++) {
+ entryList[index]
+ .addProtocolEntry(manualProxyConfigurationComposite);
}
Label separator = new Label(manualProxyConfigurationComposite,
SWT.HORIZONTAL | SWT.SEPARATOR);
separator.setLayoutData(newGridData(4, 5, true, false));
- nonHostLabel = new Label(manualProxyConfigurationComposite,
- SWT.NONE);
+ nonHostLabel = new Label(manualProxyConfigurationComposite, SWT.NONE);
nonHostLabel.setText(NetUIMessages.ProxyPreferencePage_6);
- nonHostLabel
- .setToolTipText(NetUIMessages.ProxyPreferencePage_24);
+ nonHostLabel.setToolTipText(NetUIMessages.ProxyPreferencePage_24);
nonHostLabel.setLayoutData(newGridData(4, 5, true, false));
nonHostComposite = new NonProxyHostsComposite(
manualProxyConfigurationComposite, SWT.NONE);
@@ -156,8 +148,7 @@ public class ProxyPreferencePage extends PreferencePage implements
SWT.CHECK);
enableProxyAuth.setText(NetUIMessages.ProxyPreferencePage_7);
enableProxyAuth.setLayoutData(newGridData(4, 5, true, false));
- enableProxyAuth
- .setToolTipText(NetUIMessages.ProxyPreferencePage_25);
+ enableProxyAuth.setToolTipText(NetUIMessages.ProxyPreferencePage_25);
enableProxyAuth.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
enableUseridPassword(enableProxyAuth.getSelection());
@@ -185,31 +176,20 @@ public class ProxyPreferencePage extends PreferencePage implements
password.setToolTipText(NetUIMessages.ProxyPreferencePage_27);
password.setEchoChar('*');
- ModifyListener modifyListener = new ModifyListener()
- {
- public void modifyText(ModifyEvent e)
- {
- if( useSameProxyButton.getSelection() )
- {
- Entry httpEntry = entryList[0];
- String httpHostname = httpEntry.hostname.getText();
- String httpPort = httpEntry.port.getText();
-
- for( int index = 1; index < entryList.length; index++ )
- {
- Entry entry = entryList[index];
-
- entry.hostname.setText( httpHostname );
- entry.port.setText( httpPort );
- }
- }
- }
- };
-
- entryList[0].hostname.addModifyListener( modifyListener );
- entryList[0].port.addModifyListener( modifyListener );
-
- restoreState(proxyService.isProxiesEnabled());
+ ModifyListener modifyListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (useSameProxyButton.getSelection()) {
+ for (int index = 1; index < entryList.length; index++) {
+ entryList[index].copyValuesFrom(entryList[0]);
+ }
+ }
+ }
+ };
+
+ entryList[0].hostname.addModifyListener(modifyListener);
+ entryList[0].port.addModifyListener(modifyListener);
+
+ initializeValues(proxyService.isProxiesEnabled());
applyDialogFont(composite);
return composite;
@@ -221,8 +201,10 @@ public class ProxyPreferencePage extends PreferencePage implements
boolean proxiesEnabled = manualProxyConfigurationButton.getSelection();
// Save the contents of the text fields to the proxy data.
+ IProxyData[] proxyData = new IProxyData[entryList.length];
for (int index = 0; index < entryList.length; index++) {
entryList[index].applyValues();
+ proxyData[index] = entryList[index].getProxy();
}
proxyService.setProxiesEnabled(proxiesEnabled);
@@ -245,12 +227,7 @@ public class ProxyPreferencePage extends PreferencePage implements
enableProxyAuth.setSelection(false);
for (int index = 0; index < entryList.length; index++) {
- Entry entry = entryList[index];
-
- entry.hostname.setText(""); //$NON-NLS-1$
- entry.port.setText(""); //$NON-NLS-1$
- entry.prevHostname = ""; //$NON-NLS-1$
- entry.prevPort = -1;
+ entryList[index].reset();
}
nonHostComposite.setList(new String[] { "localhost", "127.0.0.1" }); //$NON-NLS-1$ //$NON-NLS-2$
@@ -270,7 +247,7 @@ public class ProxyPreferencePage extends PreferencePage implements
*
* @param proxiesEnabled indicates if manual proxies are enabled or not.
*/
- private void restoreState(boolean proxiesEnabled) {
+ private void initializeValues(boolean proxiesEnabled) {
directConnectionToButton.setSelection(!proxiesEnabled);
manualProxyConfigurationButton.setSelection(proxiesEnabled);
@@ -286,18 +263,6 @@ public class ProxyPreferencePage extends PreferencePage implements
this.userid.setText(""); //$NON-NLS-1$
this.password.setText(""); //$NON-NLS-1$
} else {
- boolean useSameProtocol = true;
- for (int i = 1; i < proxyData.length; i++) {
- IProxyData data = proxyData[i];
- boolean same = (hostsEqual(data.getHost(), proxyData[0]
- .getHost()) && portsEqual(data.getPort(), proxyData[0]
- .getPort()));
- if (!same) {
- useSameProtocol = false;
- break;
- }
- }
- this.useSameProxyButton.setSelection(useSameProtocol);
IProxyData data = entryList[0].getProxy();
this.enableProxyAuth.setSelection(data.isRequiresAuthentication());
this.userid.setText(data.getUserId() == null ? "" : data //$NON-NLS-1$
@@ -305,37 +270,28 @@ public class ProxyPreferencePage extends PreferencePage implements
this.password.setText(data.getPassword() == null ? "" : data //$NON-NLS-1$
.getPassword());
- // TODO: Why does this loop from 1 and not 0?
- for (int index = 1; index < entryList.length; index++) {
- entryList[index].restoreValues();
+ }
+ boolean useSameProtocol = true;
+ for (int i = 1; i < entryList.length; i++) {
+ Entry entry = entryList[i];
+ if (!entry.isUseSameProtocol(entryList[0])) {
+ useSameProtocol = false;
+ break;
}
}
+ this.useSameProxyButton.setSelection(useSameProtocol);
+ for (int index = 1; index < entryList.length; index++) {
+ Entry entry = entryList[index];
+ entry.loadPreviousValues();
+ entry.updateEnablement(proxiesEnabled, useSameProtocol);
+ }
enableControls(proxiesEnabled);
- handleUseSameProtocol(true);
- }
-
- private boolean portsEqual(int port1, int port2) {
- return port1 == port2;
- }
-
- private boolean hostsEqual(String host1, String host2) {
- if (host1 == host2)
- // If there are no hosts, don't enable the use same hosts button
- return false;
- if (host1 == null || host2 == null)
- return false;
- return host1.equals(host2);
}
void enableControls(boolean enabled) {
for (int index = 0; index < entryList.length; index++) {
- Entry entry = entryList[index];
-
- entry.hostname.setEnabled((index == 0 && enabled) || (index != 0 && !useSameProxyButton.getSelection() && enabled));
- entry.nameLabel.setEnabled((index == 0 && enabled) || (index != 0 && !useSameProxyButton.getSelection() && enabled));
- entry.portLabel.setEnabled((index == 0 && enabled) || (index != 0 && !useSameProxyButton.getSelection() && enabled));
- entry.port.setEnabled((index == 0 && enabled) || (index != 0 && !useSameProxyButton.getSelection() && enabled));
+ entryList[index].updateEnablement(enabled, useSameProxyButton.getSelection());
}
useSameProxyButton.setEnabled(enabled);
@@ -353,95 +309,13 @@ public class ProxyPreferencePage extends PreferencePage implements
password.setEnabled(enabled);
}
- void handleUseSameProtocol(boolean init) {
- String httpHostname = entryList[0].hostname.getText();
- String httpPort = entryList[0].port.getText();
- boolean proxiesEnabled = manualProxyConfigurationButton.getSelection();
+ protected void toggleUseSameProtocol() {
boolean useSameProtocol = useSameProxyButton.getSelection();
- boolean controlEnabled = proxiesEnabled && !useSameProtocol;
-
for (int index = 1; index < entryList.length; index++) {
- Entry entry = entryList[index];
-
- entry.hostname.setEnabled(controlEnabled);
- entry.nameLabel.setEnabled(controlEnabled);
- entry.portLabel.setEnabled(controlEnabled);
- entry.port.setEnabled(controlEnabled);
-
- if (useSameProtocol) {
- if (!init) {
- entry.prevHostname = entry.hostname.getText();
- try {
- entry.prevPort = Integer.parseInt(entry.port.getText());
- } catch (NumberFormatException e) {
- entry.prevPort = -1;
- }
- }
-
- entry.hostname.setText(httpHostname);
- entry.port.setText(httpPort);
- } else {
- if (!init) {
- entry.hostname.setText(entry.prevHostname);
- entry.port.setText(entry.prevPort == -1 ? "" : String //$NON-NLS-1$
- .valueOf(entry.prevPort));
- }
- }
+ entryList[index].setUseSameProtocol(useSameProtocol, entryList[0]);
}
}
- private void addProtocolEntry(Composite parent, int index) {
- Entry entry = new Entry(index);
- GridData gridData = null;
- IProxyData proxy = entry.getProxy();
- String name = getLabel(proxy);
-
- String hostname = proxy.getHost();
- if (hostname == null) {
- hostname = ""; //$NON-NLS-1$
- }
-
- int portInt = proxy.getPort();
- String port;
- if (portInt == -1) {
- port = ""; //$NON-NLS-1$
- } else {
- port = String.valueOf(portInt);
- }
-
- entry.nameLabel = new Label(parent, SWT.NONE);
- entry.nameLabel.setText(name);
-
- entry.hostname = new Text(parent, SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.widthHint = 120;
- entry.hostname.setLayoutData(gridData);
- entry.hostname.setText(hostname);
-
- entry.portLabel = new Label(parent, SWT.NONE);
- entry.portLabel.setText(NetUIMessages.ProxyPreferencePage_22);
-
- entry.port = new Text(parent, SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.widthHint = 50;
- entry.port.setLayoutData(gridData);
- entry.port.setText(port);
- entryList[index] = entry;
- }
-
- private String getLabel(IProxyData data) {
- if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
- return NetUIMessages.ProxyPreferencePage_37;
- }
- if (data.getType().equals(IProxyData.HTTPS_PROXY_TYPE)) {
- return NetUIMessages.ProxyPreferencePage_38;
- }
- if (data.getType().equals(IProxyData.SOCKS_PROXY_TYPE)) {
- return NetUIMessages.ProxyPreferencePage_39;
- }
- return ""; //$NON-NLS-1$
- }
-
private GridData newGridData(int span, int verticalIndent,
boolean horizontal, boolean vertical) {
int style = 0;
@@ -464,32 +338,114 @@ public class ProxyPreferencePage extends PreferencePage implements
private class Entry {
Label nameLabel;
-
Text hostname;
-
- String prevHostname;
-
Label portLabel;
-
Text port;
-
+ String prevHostname;
int prevPort;
+ private final IProxyData proxyData;
- private int proxyIndex;
+ public Entry(IProxyData proxyData) {
+ this.proxyData = proxyData;
+ }
- public Entry(int index) {
- this.proxyIndex = index;
+ public void updateEnablement(boolean proxiesEnabled, boolean useSameProtocol) {
+ if (isHttpProxy()) {
+ setEnabled(proxiesEnabled);
+ } else {
+ if (proxiesEnabled) {
+ setUseSameProtocol(useSameProtocol);
+ } else {
+ setEnabled(false);
+ }
+ }
}
- public IProxyData getProxy() {
- return proxyData[proxyIndex];
+ public void setUseSameProtocol(boolean useSameProtocol, Entry httpEntry) {
+ setUseSameProtocol(useSameProtocol);
+ if (isSocksProxy() || isHttpProxy())
+ return;
+ if (useSameProtocol) {
+ recordPreviousValues();
+ copyValuesFrom(entryList[0]);
+ } else {
+ restorePreviousValues();
+ }
+ }
+
+ public void setUseSameProtocol(boolean useSameProtocol) {
+ if (isSocksProxy()) {
+ setEnabled(true);
+ } else {
+ setEnabled(!useSameProtocol);
+ }
}
- public void restoreValues() {
+ public void loadPreviousValues() {
IProxyData proxy = getProxy();
prevHostname = proxy.getHost();
prevPort = proxy.getPort();
}
+
+ public void restorePreviousValues() {
+ hostname.setText(prevHostname);
+ port.setText(prevPort == -1 ? "" : String //$NON-NLS-1$
+ .valueOf(prevPort));
+ }
+
+ public void recordPreviousValues() {
+ prevHostname = hostname.getText();
+ try {
+ prevPort = Integer.parseInt(port.getText());
+ } catch (NumberFormatException e) {
+ prevPort = -1;
+ }
+ }
+
+ /**
+ * The user has chosen to use the same entry for all protocols
+ * @param entry the entry (the http entry to be exact)
+ */
+ public void copyValuesFrom(Entry entry) {
+ // For SOCKS, don't use the general entry
+ if (!isSocksProxy()){
+ hostname.setText( entry.hostname.getText() );
+ port.setText( entry.port.getText() );
+ }
+ }
+
+ public boolean isUseSameProtocol(Entry entry) {
+ // Always answer true for the SOCKS proxy since we never disable
+ if (isSocksProxy())
+ return true;
+ return (hostsEqual(proxyData.getHost(), entry.getProxy().getHost())
+ && portsEqual(proxyData.getPort(), entry.getProxy().getPort()));
+ }
+
+ private boolean portsEqual(int port1, int port2) {
+ return port1 == port2;
+ }
+
+ private boolean hostsEqual(String host1, String host2) {
+ if (host1 == host2)
+ // If there are no hosts, don't enable the use same hosts button
+ return false;
+ if (host1 == null || host2 == null)
+ return false;
+ return host1.equals(host2);
+ }
+
+ boolean isSocksProxy() {
+ return getProxy().getType().equals(IProxyData.SOCKS_PROXY_TYPE);
+ }
+
+ boolean isHttpProxy() {
+ return getProxy().getType().equals(IProxyData.HTTP_PROXY_TYPE);
+ }
+
+ public IProxyData getProxy() {
+ return proxyData;
+ }
public void applyValues() {
IProxyData proxy = getProxy();
@@ -497,13 +453,14 @@ public class ProxyPreferencePage extends PreferencePage implements
String hostString;
String portString;
- if (useSameProxyButton.getSelection()) {
+ if (useSameProxyButton.getSelection() && !isSocksProxy()) {
hostString = entryList[0].hostname.getText();
portString = entryList[0].port.getText();
} else {
hostString = hostname.getText();
portString = port.getText();
}
+
proxy.setHost(hostString);
try {
int port = Integer.valueOf(portString).intValue();
@@ -514,5 +471,74 @@ public class ProxyPreferencePage extends PreferencePage implements
proxy.setUserid(enableAuth ? userid.getText() : null);
proxy.setPassword(enableAuth ? password.getText() : null);
}
+
+ public void addProtocolEntry(Composite parent) {
+ GridData gridData;
+ IProxyData proxy = getProxy();
+
+ nameLabel = new Label(parent, SWT.NONE);
+ nameLabel.setText(getLabel(proxy));
+
+ hostname = new Text(parent, SWT.BORDER);
+ gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.widthHint = 120;
+ hostname.setLayoutData(gridData);
+ hostname.setText(getHostName(proxy));
+
+ portLabel = new Label(parent, SWT.NONE);
+ portLabel.setText(NetUIMessages.ProxyPreferencePage_22);
+
+ port = new Text(parent, SWT.BORDER);
+ gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.widthHint = 50;
+ port.setLayoutData(gridData);
+ port.setText(getPortString(proxy));
+ }
+
+ private String getLabel(IProxyData data) {
+ if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
+ return NetUIMessages.ProxyPreferencePage_37;
+ }
+ if (data.getType().equals(IProxyData.HTTPS_PROXY_TYPE)) {
+ return NetUIMessages.ProxyPreferencePage_38;
+ }
+ if (data.getType().equals(IProxyData.SOCKS_PROXY_TYPE)) {
+ return NetUIMessages.ProxyPreferencePage_39;
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private String getPortString(IProxyData proxy) {
+ int portInt = proxy.getPort();
+ String portString;
+ if (portInt == -1) {
+ portString = ""; //$NON-NLS-1$
+ } else {
+ portString = String.valueOf(portInt);
+ }
+ return portString;
+ }
+
+ private String getHostName(IProxyData proxy) {
+ String hostnameString = proxy.getHost();
+ if (hostnameString == null) {
+