Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 228739 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/net/ProxyType.java (-1 / +9 lines)
Lines 11-16 Link Here
11
package org.eclipse.core.internal.net;
11
package org.eclipse.core.internal.net;
12
12
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.util.ArrayList;
14
import java.util.Properties;
15
import java.util.Properties;
15
16
16
import org.eclipse.core.net.proxy.IProxyData;
17
import org.eclipse.core.net.proxy.IProxyData;
Lines 98-104 Link Here
98
	}
99
	}
99
100
100
	public static String[] convertPropertyStringToHosts(String property) {
101
	public static String[] convertPropertyStringToHosts(String property) {
101
		return property.split("\\|"); //$NON-NLS-1$
102
		String hosts[] = property.split("\\|"); //$NON-NLS-1$
103
		ArrayList ret = new ArrayList();
104
		for (int i = 0; i < hosts.length; i++) {
105
			if (hosts[i].length() != 0) {
106
				ret.add(hosts[i]);
107
			}
108
		}
109
		return (String[]) ret.toArray(new String[0]);
102
	}
110
	}
103
111
104
	public ProxyType(String name) {
112
	public ProxyType(String name) {
(-)src/org/eclipse/core/internal/net/ProxyData.java (+4 lines)
Lines 55-60 Link Here
55
	public String getUserId() {
55
	public String getUserId() {
56
		return user;
56
		return user;
57
	}
57
	}
58
	
59
	public void setType(String type) {
60
		this.type = type;
61
	}
58
62
59
	public void setHost(String host) {
63
	public void setHost(String host) {
60
		if (host.length() == 0)
64
		if (host.length() == 0)
(-)src/org/eclipse/core/internal/net/ProxySelector.java (-1 / +2 lines)
Lines 51-58 Link Here
51
		} else if (provider.equals(NATIVE_PROVIDER)) {
51
		} else if (provider.equals(NATIVE_PROVIDER)) {
52
			service.setProxiesEnabled(true);
52
			service.setProxiesEnabled(true);
53
			service.setSystemProxiesEnabled(true);
53
			service.setSystemProxiesEnabled(true);
54
		} else {
55
			throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
54
		}
56
		}
55
		throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
56
	}
57
	}
57
58
58
	public static IProxyData[] getProxyData(String provider) {
59
	public static IProxyData[] getProxyData(String provider) {
(-)src/org/eclipse/ui/internal/net/messages.properties (-31 / +37 lines)
Lines 15-53 Link Here
15
#
15
#
16
# Messages in InternetPreferencePage
16
# Messages in InternetPreferencePage
17
#
17
#
18
BUTTON_PREFERENCE_ADD=Add &Host...
18
ProxyPreferencePage_0=Active Provider:
19
BUTTON_PREFERENCE_EDIT=Ed&it...
19
ProxyPreferencePage_1=Proxy entries
20
BUTTON_PREFERENCE_REMOVE=&Remove
20
ProxyPreferencePage_2=Schema
21
TITLE_PREFERENCE_HOSTS_DIALOG=Non Proxy host names
21
ProxyPreferencePage_3=Host
22
LABEL_PREFERENCE_HOSTS_DIALOG=Enter host names separated by a vertical bar, space, or comma.
22
ProxyPreferencePage_4=Port
23
ProxyPreferencePage_5=Provider
24
ProxyPreferencePage_6=Auth
25
ProxyPreferencePage_7=User
26
ProxyPreferencePage_8=Password
27
ProxyPreferencePage_9=Add &Entry...
28
ProxyPreferencePage_10=Ed&it...
29
ProxyPreferencePage_11=&Clear
30
ProxyPreferencePage_12=Proxy bypass
31
ProxyPreferencePage_13=Host
32
ProxyPreferencePage_14=Provider
33
ProxyPreferencePage_15=Add &Host...
34
ProxyPreferencePage_16=Edi&t...
35
ProxyPreferencePage_17=Re&move
36
ProxyPreferencePage_18=Dynamic
37
38
ProxyEntryDialog_0=New Proxy Entry
39
ProxyEntryDialog_1=Edit Proxy Entry
40
ProxyEntryDialog_2=Schema:
41
ProxyEntryDialog_3=Host:
42
ProxyEntryDialog_4=Port:
43
ProxyEntryDialog_5=Provider:
44
ProxyEntryDialog_6=Requires Authentication:
45
ProxyEntryDialog_7=User:
46
ProxyEntryDialog_8=Password:
47
ProxyEntryDialog_9=Setting for provided type is already defined
48
ProxyEntryDialog_10=Invalid host name
49
ProxyEntryDialog_11=Invalid port number
50
ProxyEntryDialog_12=Invalid user ID
51
52
ProxyBypassDialog_0=Proxy bypass hosts
53
ProxyBypassDialog_1=Enter host names separated by a semicolon or a space.
54
ProxyBypassDialog_2=You can use the wildcard character * to specify a host name pattern and | to combine multiple patterns
23
55
24
ProxyPreferencePage_2=Proxy Preferences
25
ProxyPreferencePage_3=Direct &connection to the Internet
26
ProxyPreferencePage_4=&Manual proxy configuration:
27
ProxyPreferencePage_5=&Use this proxy server for SSL
28
ProxyPreferencePage_6=&No proxy for:
29
ProxyPreferencePage_7=&Enable proxy authentication:
30
ProxyPreferencePage_8=Us&er name:
31
ProxyPreferencePage_9=&Password:
32
ProxyPreferencePage_1=Specifies that no configuration is needed to access the Internet.
33
ProxyPreferencePage_0=Specifies that a proxy server is required to access the Internet.
34
ProxyPreferencePage_22=Port:
35
ProxyPreferencePage_23=Specifies that the HTTP protocol settings should be used for the protocols below.
36
ProxyPreferencePage_24=Specifies which hosts should not be routed via a proxy server.
37
ProxyPreferencePage_25=Specifies that basic authentication is required.
38
ProxyPreferencePage_26=Specifies the basic authentication user name.
39
ProxyPreferencePage_27=Specifies the basic authentication password
40
ProxyPreferencePage_37=&HTTP proxy:
41
ProxyPreferencePage_38=&SSL proxy:
42
ProxyPreferencePage_39=S&OCKS proxy:
43
ProxyPreferencePage_40=The proxy service is not available
44
ProxyPreferencePage_41=The host name cannot begin or end with a space character
45
ProxyPreferencePage_42=Invalid port
46
ProxyPreferencePage_43=The port must be an integer
47
ProxyPreferencePage_44=System proxy configuration (if available)
48
ProxyPreferencePage_45=Specifies that system proxy settings are used to access the Internet. If such settings can't be retrieved, no proxy should be used.
49
UserValidationDialog_0=Password Required
56
UserValidationDialog_0=Password Required
50
UserValidationDialog_1=Connect to: {0}
57
UserValidationDialog_1=Connect to: {0}
51
UserValidationDialog_2=&Password:
58
UserValidationDialog_2=&Password:
52
UserValidationDialog_3=&User name:
59
UserValidationDialog_3=&User name:
53
NonProxyHostsComposite_0=You can use the wildcard character * to specify a host name pattern and | to combine multiple patterns
(-)src/org/eclipse/ui/internal/net/NetUIMessages.java (-55 / +29 lines)
Lines 17-99 Link Here
17
17
18
public final class NetUIMessages extends NLS {
18
public final class NetUIMessages extends NLS {
19
19
20
	private static final String BUNDLE_NAME = "org.eclipse.ui.internal.net.messages";//$NON-NLS-1$
20
	private static final String BUNDLE_NAME = "org.eclipse.ui.internal.net.messages"; //$NON-NLS-1$
21
21
22
	private NetUIMessages() {
22
	private NetUIMessages() {
23
		// Do not instantiate
23
		// Do not instantiate
24
	}
24
	}
25
25
26
	public static String BUTTON_PREFERENCE_ADD;
27
28
	public static String BUTTON_PREFERENCE_EDIT;
29
30
	public static String BUTTON_PREFERENCE_REMOVE;
31
32
	public static String NonProxyHostsComposite_0;
33
34
	public static String ProxyPreferencePage_0;
26
	public static String ProxyPreferencePage_0;
35
36
	public static String ProxyPreferencePage_1;
27
	public static String ProxyPreferencePage_1;
37
38
	public static String ProxyPreferencePage_2;
28
	public static String ProxyPreferencePage_2;
39
40
	public static String ProxyPreferencePage_22;
41
42
	public static String ProxyPreferencePage_23;
43
44
	public static String ProxyPreferencePage_24;
45
46
	public static String ProxyPreferencePage_25;
47
48
	public static String ProxyPreferencePage_26;
49
50
	public static String ProxyPreferencePage_27;
51
52
	public static String ProxyPreferencePage_3;
29
	public static String ProxyPreferencePage_3;
53
54
	public static String ProxyPreferencePage_37;
55
56
	public static String ProxyPreferencePage_38;
57
58
	public static String ProxyPreferencePage_39;
59
60
	public static String ProxyPreferencePage_4;
30
	public static String ProxyPreferencePage_4;
61
62
	public static String ProxyPreferencePage_40;
63
64
	public static String ProxyPreferencePage_41;
65
66
	public static String ProxyPreferencePage_42;
67
68
	public static String ProxyPreferencePage_43;
69
70
	public static String ProxyPreferencePage_5;
31
	public static String ProxyPreferencePage_5;
71
72
	public static String ProxyPreferencePage_6;
32
	public static String ProxyPreferencePage_6;
73
74
	public static String ProxyPreferencePage_7;
33
	public static String ProxyPreferencePage_7;
75
76
	public static String ProxyPreferencePage_8;
34
	public static String ProxyPreferencePage_8;
77
78
	public static String ProxyPreferencePage_9;
35
	public static String ProxyPreferencePage_9;
79
	
36
	public static String ProxyPreferencePage_10;
80
	public static String ProxyPreferencePage_44;
37
	public static String ProxyPreferencePage_11;
81
	
38
	public static String ProxyPreferencePage_12;
82
	public static String ProxyPreferencePage_45;
39
	public static String ProxyPreferencePage_13;
83
40
	public static String ProxyPreferencePage_14;
84
	public static String TITLE_PREFERENCE_HOSTS_DIALOG;
41
	public static String ProxyPreferencePage_15;
85
42
	public static String ProxyPreferencePage_16;
86
	public static String LABEL_PREFERENCE_HOSTS_DIALOG;
43
	public static String ProxyPreferencePage_17;
44
	public static String ProxyPreferencePage_18;
45
46
	public static String ProxyEntryDialog_0;
47
	public static String ProxyEntryDialog_1;
48
	public static String ProxyEntryDialog_2;
49
	public static String ProxyEntryDialog_3;
50
	public static String ProxyEntryDialog_4;
51
	public static String ProxyEntryDialog_5;
52
	public static String ProxyEntryDialog_6;
53
	public static String ProxyEntryDialog_7;
54
	public static String ProxyEntryDialog_8;
55
	public static String ProxyEntryDialog_9;
56
	public static String ProxyEntryDialog_10;
57
	public static String ProxyEntryDialog_11;
58
	public static String ProxyEntryDialog_12;
59
60
	public static String ProxyBypassDialog_0;
61
	public static String ProxyBypassDialog_1;
62
	public static String ProxyBypassDialog_2;
87
63
88
	public static String UserValidationDialog_0;
64
	public static String UserValidationDialog_0;
89
90
	public static String UserValidationDialog_1;
65
	public static String UserValidationDialog_1;
91
92
	public static String UserValidationDialog_2;
66
	public static String UserValidationDialog_2;
93
94
	public static String UserValidationDialog_3;
67
	public static String UserValidationDialog_3;
95
68
96
	static {
69
	static {
97
		NLS.initializeMessages(BUNDLE_NAME, NetUIMessages.class);
70
		NLS.initializeMessages(BUNDLE_NAME, NetUIMessages.class);
98
	}
71
	}
72
99
}
73
}
(-)src/org/eclipse/ui/internal/net/ProxyPreferencePage.java (-593 / +54 lines)
Lines 18-40 Link Here
18
 *******************************************************************************/
18
 *******************************************************************************/
19
package org.eclipse.ui.internal.net;
19
package org.eclipse.ui.internal.net;
20
20
21
import org.eclipse.core.net.proxy.IProxyData;
21
import org.eclipse.core.internal.net.ProxySelector;
22
import org.eclipse.core.net.proxy.IProxyService;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.jface.dialogs.ErrorDialog;
25
import org.eclipse.jface.preference.PreferencePage;
22
import org.eclipse.jface.preference.PreferencePage;
26
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.ModifyEvent;
28
import org.eclipse.swt.events.ModifyListener;
29
import org.eclipse.swt.events.SelectionAdapter;
24
import org.eclipse.swt.events.SelectionAdapter;
30
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionEvent;
31
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridData;
32
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.layout.GridLayout;
33
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Combo;
34
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.swt.widgets.Label;
37
import org.eclipse.swt.widgets.Text;
38
import org.eclipse.ui.IWorkbench;
32
import org.eclipse.ui.IWorkbench;
39
import org.eclipse.ui.IWorkbenchPreferencePage;
33
import org.eclipse.ui.IWorkbenchPreferencePage;
40
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.PlatformUI;
Lines 42-281 Link Here
42
public class ProxyPreferencePage extends PreferencePage implements
36
public class ProxyPreferencePage extends PreferencePage implements
43
		IWorkbenchPreferencePage {
37
		IWorkbenchPreferencePage {
44
38
45
	private static final String PROXY_PREFERENCE_PAGE_CONTEXT_ID 
39
	private static final String PROXY_PREFERENCE_PAGE_CONTEXT_ID = "org.eclipse.ui.net.proxy_preference_page_context"; //$NON-NLS-1$
46
		= "org.eclipse.ui.net.proxy_preference_page_context"; //$NON-NLS-1$
47
	
48
	Entry[] entryList;
49
	Button directConnectionToButton;
50
	Button manualProxyConfigurationButton;
51
	Button useSameProxyButton;
52
	private Label nonHostLabel;
53
	private NonProxyHostsComposite nonHostComposite;
54
	Button enableProxyAuth;
55
	private Label useridLabel;
56
	private Label passwordLabel;
57
	Text userid;
58
	Text password;
59
	private IProxyService proxyService;
60
	Button systemProxyConfigurationButton;
61
62
	public ProxyPreferencePage() {
63
		super(NetUIMessages.ProxyPreferencePage_2);
64
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
65
	}
66
40
67
	public void init(IWorkbench workbench) {
41
	private Label providerLabel;
68
		// Nothing to do
42
	protected Combo providerCombo;
69
	}
43
	private ProxyEntriesComposite proxyEntriesComposite;
44
	private NonProxyHostsComposite nonProxyHostsComposite;
70
45
71
	protected Control createContents(Composite parent) {
46
	protected Control createContents(Composite parent) {
72
73
		proxyService = Activator.getDefault().getProxyService();
74
		if (proxyService == null) {
75
			Label l = new Label(parent, SWT.NONE);
76
			l.setText(NetUIMessages.ProxyPreferencePage_40);
77
			return l;
78
		}
79
80
		IProxyData[] proxyData = proxyService.getProxyData();
81
		entryList = new Entry[proxyData.length];
82
		for (int i = 0; i < proxyData.length; i++) {
83
			IProxyData pd = proxyData[i];
84
			entryList[i] = new Entry(pd);
85
		}
86
87
		Composite composite = new Composite(parent, SWT.NONE);
47
		Composite composite = new Composite(parent, SWT.NONE);
88
		GridLayout layout = new GridLayout();
48
		GridLayout layout = new GridLayout(1, false);
89
		layout.numColumns = 1;
90
		layout.marginRight = 5;
91
		layout.marginTop = 5;
92
		layout.marginWidth = 0;
49
		layout.marginWidth = 0;
50
		layout.marginHeight = 0;
93
		composite.setLayout(layout);
51
		composite.setLayout(layout);
94
		GridData data = new GridData(GridData.FILL_BOTH);
95
		composite.setLayoutData(data);
96
52
97
		systemProxyConfigurationButton = new Button(composite, SWT.RADIO);
53
		createProviderComposite(composite);
98
		systemProxyConfigurationButton.setLayoutData(new GridData());
54
		createProxyEntriesComposite(composite);
99
		systemProxyConfigurationButton.setText(NetUIMessages.ProxyPreferencePage_44);
55
		createNonProxiedHostsComposite(composite);
100
		systemProxyConfigurationButton
56
101
				.setToolTipText(NetUIMessages.ProxyPreferencePage_45);
57
		// Adding help accessible by F1
102
		systemProxyConfigurationButton.addSelectionListener(new SelectionAdapter() {
58
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
103
			public void widgetSelected(SelectionEvent e) {
59
				PROXY_PREFERENCE_PAGE_CONTEXT_ID);
104
				if (systemProxyConfigurationButton.getSelection())
105
				enableControls(false);
106
			}
107
		});
108
60
109
		directConnectionToButton = new Button(composite, SWT.RADIO);
61
		initializeValues();
110
		directConnectionToButton.setLayoutData(new GridData());
62
		return composite;
111
		directConnectionToButton.setText(NetUIMessages.ProxyPreferencePage_3);
63
	}
112
		directConnectionToButton
113
				.setToolTipText(NetUIMessages.ProxyPreferencePage_1);
114
		directConnectionToButton.addSelectionListener(new SelectionAdapter() {
115
			public void widgetSelected(SelectionEvent e) {
116
				if (directConnectionToButton.getSelection())
117
					enableControls(false);
118
			}
119
		});
120
121
		manualProxyConfigurationButton = new Button(composite, SWT.RADIO);
122
		manualProxyConfigurationButton
123
				.setText(NetUIMessages.ProxyPreferencePage_4);
124
		manualProxyConfigurationButton
125
				.setToolTipText(NetUIMessages.ProxyPreferencePage_0);
126
		manualProxyConfigurationButton.addSelectionListener(new SelectionAdapter() {
127
			public void widgetSelected(SelectionEvent e) {
128
				if (manualProxyConfigurationButton.getSelection())
129
					enableControls(true);
130
			}
131
		});
132
64
133
		final Composite manualProxyConfigurationComposite = new Composite(
65
	private void createProviderComposite(Composite parent) {
134
				composite, SWT.NONE);
66
		Composite composite = new Composite(parent, SWT.NONE);
135
		final GridLayout gridLayout = new GridLayout();
67
		composite.setLayout(new GridLayout(2, false));
136
		gridLayout.marginWidth = 0;
68
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
137
		gridLayout.marginHeight = 0;
138
		gridLayout.numColumns = 4;
139
		manualProxyConfigurationComposite.setLayout(gridLayout);
140
		final GridData gridData_2 = new GridData(GridData.FILL_BOTH);
141
		gridData_2.horizontalIndent = 17;
142
		manualProxyConfigurationComposite.setLayoutData(gridData_2);
143
144
		entryList[0].addProtocolEntry(manualProxyConfigurationComposite);
145
146
		new Label(manualProxyConfigurationComposite, SWT.NONE);
147
		useSameProxyButton = new Button(manualProxyConfigurationComposite,
148
				SWT.CHECK);
149
		useSameProxyButton.setText(NetUIMessages.ProxyPreferencePage_5);
150
		GridData gridData = new GridData();
151
		gridData.horizontalSpan = 3;
152
		useSameProxyButton.setLayoutData(gridData);
153
		useSameProxyButton.setToolTipText(NetUIMessages.ProxyPreferencePage_23);
154
		useSameProxyButton.addSelectionListener(new SelectionAdapter() {
155
			public void widgetSelected(SelectionEvent e) {
156
				toggleUseSameProtocol();
157
			}
158
		});
159
69
160
		for (int index = 1; index < entryList.length; index++) {
70
		providerLabel = new Label(composite, SWT.NONE);
161
			entryList[index]
71
		providerLabel.setText(NetUIMessages.ProxyPreferencePage_0);
162
					.addProtocolEntry(manualProxyConfigurationComposite);
72
		providerCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN);
163
		}
73
		providerCombo.addSelectionListener(new SelectionAdapter() {
164
165
		Label separator = new Label(manualProxyConfigurationComposite,
166
				SWT.HORIZONTAL | SWT.SEPARATOR);
167
		separator.setLayoutData(newGridData(4, 5, true, false));
168
		nonHostLabel = new Label(manualProxyConfigurationComposite, SWT.NONE);
169
		nonHostLabel.setText(NetUIMessages.ProxyPreferencePage_6);
170
		nonHostLabel.setToolTipText(NetUIMessages.ProxyPreferencePage_24);
171
		nonHostLabel.setLayoutData(newGridData(4, 5, true, false));
172
		nonHostComposite = new NonProxyHostsComposite(
173
				manualProxyConfigurationComposite, SWT.NONE);
174
		nonHostComposite.setLayoutData(newGridData(4, -1, true, true));
175
176
		Label separator2 = new Label(manualProxyConfigurationComposite,
177
				SWT.HORIZONTAL | SWT.SEPARATOR);
178
		separator2.setLayoutData(newGridData(4, 5, true, false));
179
		enableProxyAuth = new Button(manualProxyConfigurationComposite,
180
				SWT.CHECK);
181
		enableProxyAuth.setText(NetUIMessages.ProxyPreferencePage_7);
182
		enableProxyAuth.setLayoutData(newGridData(4, 5, true, false));
183
		enableProxyAuth.setToolTipText(NetUIMessages.ProxyPreferencePage_25);
184
		enableProxyAuth.addSelectionListener(new SelectionAdapter() {
185
			public void widgetSelected(SelectionEvent e) {
74
			public void widgetSelected(SelectionEvent e) {
186
				enableUseridPassword(enableProxyAuth.getSelection());
75
				setProvider(providerCombo.getText());
187
			}
76
			}
188
		});
77
		});
78
	}
189
79
190
		final Composite userIdPassword = new Composite(
80
	private void createProxyEntriesComposite(Composite parent) {
191
				manualProxyConfigurationComposite, SWT.NONE);
81
		proxyEntriesComposite = new ProxyEntriesComposite(parent, SWT.NONE);
192
		GridLayout layout2 = new GridLayout(2, false);
82
		proxyEntriesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
193
		layout2.marginWidth = 0;
83
				true, true));
194
		layout2.marginHeight = 0;
84
	}
195
		userIdPassword.setLayoutData(newGridData(4, -1, true, false));
196
		userIdPassword.setLayout(layout2);
197
198
		useridLabel = new Label(userIdPassword, SWT.NONE);
199
		useridLabel.setText(NetUIMessages.ProxyPreferencePage_8);
200
		userid = new Text(userIdPassword, SWT.BORDER);
201
		passwordLabel = new Label(userIdPassword, SWT.NONE);
202
		passwordLabel.setText(NetUIMessages.ProxyPreferencePage_9);
203
		password = new Text(userIdPassword, SWT.BORDER);
204
205
		userid.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
206
		userid.setToolTipText(NetUIMessages.ProxyPreferencePage_26);
207
		password.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
208
		password.setToolTipText(NetUIMessages.ProxyPreferencePage_27);
209
		password.setEchoChar('*');
210
211
		ModifyListener modifyListener = new ModifyListener() {
212
			public void modifyText(ModifyEvent e) {
213
				if (useSameProxyButton.getSelection()) {
214
					for (int index = 1; index < entryList.length; index++) {
215
						entryList[index].copyValuesFrom(entryList[0]);
216
					}
217
				}
218
			}
219
		};
220
221
		entryList[0].hostname.addModifyListener(modifyListener);
222
		entryList[0].port.addModifyListener(modifyListener);
223
85
224
		initializeValues(proxyService.isProxiesEnabled() , proxyService.isSystemProxiesEnabled());
86
	private void createNonProxiedHostsComposite(Composite parent) {
225
		applyDialogFont(composite);
87
		nonProxyHostsComposite = new NonProxyHostsComposite(parent, SWT.NONE);
226
		
88
		nonProxyHostsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
227
		// F1
89
				true, true));
228
		PlatformUI.getWorkbench().getHelpSystem().setHelp(
90
	}
229
				getControl(), PROXY_PREFERENCE_PAGE_CONTEXT_ID);
230
91
231
		return composite;
92
	public void init(IWorkbench workbench) {
93
		// Nothing to do
232
	}
94
	}
233
95
234
	protected void performApply() {
96
	protected void performApply() {
235
		if (proxyService == null)
97
		int sel = providerCombo.getSelectionIndex();
236
			return;
98
		ProxySelector.setDefaultProvider(providerCombo.getItem(sel));
237
		boolean manualProxiesEnabled = manualProxyConfigurationButton.getSelection();
99
		proxyEntriesComposite.performApply();
238
		boolean systemProxiesEnabled = systemProxyConfigurationButton.getSelection();
100
		nonProxyHostsComposite.performApply();
239
240
		// Save the contents of the text fields to the proxy data.
241
		IProxyData[] proxyData = new IProxyData[entryList.length];
242
		for (int index = 0; index < entryList.length; index++) {
243
			entryList[index].applyValues();
244
			proxyData[index] = entryList[index].getProxy();
245
		}
246
247
		proxyService.setProxiesEnabled(manualProxiesEnabled || systemProxiesEnabled);
248
		
249
		if (manualProxiesEnabled) {
250
			try {
251
				proxyService.setNonProxiedHosts(
252
						nonHostComposite.getList());
253
				proxyService.setProxyData(proxyData);
254
			} catch (CoreException e) {
255
				ErrorDialog.openError(getShell(), null, null, e.getStatus());
256
			}
257
		}
258
		
259
		proxyService.setSystemProxiesEnabled(systemProxiesEnabled);
260
261
		Activator.getDefault().savePluginPreferences();
262
	}
101
	}
263
102
264
	protected void performDefaults() {
103
	protected void performDefaults() {
265
		directConnectionToButton.setSelection(false);
104
		providerCombo.select(1);
266
		systemProxyConfigurationButton.setSelection(true);
105
		setProvider(providerCombo.getItem(1));
267
		manualProxyConfigurationButton.setSelection(false);
268
		useSameProxyButton.setSelection(false);
269
		enableProxyAuth.setSelection(false);
270
271
		for (int index = 0; index < entryList.length; index++) {
272
			entryList[index].reset();
273
		}
274
275
		nonHostComposite.setList(new String[] { "localhost", "127.0.0.1" }); //$NON-NLS-1$ //$NON-NLS-2$
276
		userid.setText(""); //$NON-NLS-1$
277
		password.setText(""); //$NON-NLS-1$
278
		enableControls(false);
279
	}
106
	}
280
107
281
	public boolean performOk() {
108
	public boolean performOk() {
Lines 283-663 Link Here
283
		return super.performOk();
110
		return super.performOk();
284
	}
111
	}
285
112
286
	/**
113
	private void initializeValues() {
287
	 * This method is run once when when this preference page is displayed. It
114
		providerCombo.setItems(ProxySelector.getProviders());
288
	 * will restore the state of this page using previously saved preferences.
115
		providerCombo.select(providerCombo.indexOf(ProxySelector
289
	 * 
116
				.getDefaultProvider()));
290
	 * @param proxiesEnabled indicates if manual proxies are enabled or not.
291
	 */
292
	private void initializeValues(boolean proxiesEnabled, boolean systemProxiesEnabled) {
293
		directConnectionToButton.setSelection(!proxiesEnabled);
294
		manualProxyConfigurationButton.setSelection(proxiesEnabled && !systemProxiesEnabled);
295
		systemProxyConfigurationButton.setSelection(proxiesEnabled && systemProxiesEnabled);
296
		
297
298
		String[] nonHostLists = null;
299
		if (proxyService != null)
300
			nonHostLists = proxyService.getNonProxiedHosts();
301
		this.nonHostComposite.setList(nonHostLists == null ? new String[] {
302
				"localhost", "127.0.0.1" } : nonHostLists); //$NON-NLS-1$ //$NON-NLS-2$
303
		if (!proxiesEnabled || systemProxiesEnabled) {
304
			this.useSameProxyButton.setSelection(false);
305
			this.enableProxyAuth.setSelection(false);
306
			this.userid.setText(""); //$NON-NLS-1$
307
			this.password.setText(""); //$NON-NLS-1$
308
		} else {
309
			// use the first entry which does need authentication
310
			IProxyData data = null;
311
			for (int i = 0; i < entryList.length; i++) {
312
				IProxyData idata = entryList[i].getProxy();
313
				if (idata.isRequiresAuthentication()) {
314
					data = idata;
315
					break;
316
				}
317
			}
318
			if (data == null) {
319
				// no entry needs authentication, just pick the first.
320
				data = entryList[0].getProxy();
321
			}
322
			this.enableProxyAuth.setSelection(data.isRequiresAuthentication());
323
			this.userid.setText(data.getUserId() == null ? "" : data //$NON-NLS-1$
324
					.getUserId());
325
			this.password.setText(data.getPassword() == null ? "" : data //$NON-NLS-1$
326
					.getPassword());
327
328
		}
329
		boolean useSameProtocol = true;
330
		for (int i = 1; i < entryList.length; i++) {
331
			Entry entry = entryList[i];
332
			if (!entry.isUseSameProtocol(entryList[0])) {
333
				useSameProtocol = false;
334
				break;
335
			}
336
		}
337
		this.useSameProxyButton.setSelection(useSameProtocol);
338
		for (int index = 1; index < entryList.length; index++) {
339
			Entry entry = entryList[index];
340
			entry.loadPreviousValues();
341
			entry.updateEnablement(proxiesEnabled && !systemProxiesEnabled, useSameProtocol);
342
		}
343
344
		enableControls(proxiesEnabled && !systemProxiesEnabled);
345
	}
346
347
	void enableControls(boolean enabled) {
348
		for (int index = 0; index < entryList.length; index++) {
349
			entryList[index].updateEnablement(enabled, useSameProxyButton.getSelection());
350
		}
351
352
		useSameProxyButton.setEnabled(enabled);
353
		nonHostLabel.setEnabled(enabled);
354
		nonHostComposite.setEnabled(enabled);
355
		enableProxyAuth.setEnabled(enabled);
356
357
		enableUseridPassword(enableProxyAuth.getSelection() && enabled);
358
	}
117
	}
359
118
360
	void enableUseridPassword(boolean enabled) {
119
	protected void setProvider(String name) {
361
		useridLabel.setEnabled(enabled);
120
		proxyEntriesComposite.setProvider(name);
362
		userid.setEnabled(enabled);
121
		nonProxyHostsComposite.setProvider(name);
363
		passwordLabel.setEnabled(enabled);
364
		password.setEnabled(enabled);
365
	}
366
367
	protected void toggleUseSameProtocol() {
368
		boolean useSameProtocol = useSameProxyButton.getSelection();
369
		for (int index = 1; index < entryList.length; index++) {
370
			entryList[index].setUseSameProtocol(useSameProtocol, entryList[0]);
371
		}
372
	}
373
	
374
	public void updateErrorMessage() {
375
		for (int index = 0; index < entryList.length; index++) {
376
			String message = entryList[index].getErrorMessage();
377
			if (message != null) {
378
				setErrorMessage(message);
379
				return;
380
			}
381
		}
382
		setErrorMessage(null);
383
	}
122
	}
384
123
385
	private GridData newGridData(int span, int verticalIndent,
386
			boolean horizontal, boolean vertical) {
387
		int style = 0;
388
389
		style |= horizontal ? GridData.FILL_HORIZONTAL : 0;
390
		style |= vertical ? GridData.FILL_VERTICAL : 0;
391
392
		GridData gridData = new GridData(style);
393
394
		if (span != -1) {
395
			gridData.horizontalSpan = span;
396
		}
397
398
		if (verticalIndent != -1) {
399
			gridData.verticalIndent = verticalIndent;
400
		}
401
402
		return gridData;
403
	}
404
405
	private class Entry {
406
		Label nameLabel;
407
		Text hostname;
408
		Label portLabel;
409
		Text port;
410
		String prevHostname;
411
		int prevPort;
412
		private final IProxyData proxyData;
413
		private String errorMessage;
414
415
		public Entry(IProxyData proxyData) {
416
			this.proxyData = proxyData;
417
		}
418
419
		public void updateEnablement(boolean proxiesEnabled, boolean useSameProtocol) {
420
			if (isHttpProxy()) {
421
				setEnabled(proxiesEnabled);
422
			} else {
423
				if (proxiesEnabled) {
424
					setUseSameProtocol(useSameProtocol);
425
				} else {
426
					setEnabled(false);
427
				}
428
			}
429
			updateMessage();
430
		}
431
432
		public void setUseSameProtocol(boolean useSameProtocol, Entry httpEntry) {
433
			setUseSameProtocol(useSameProtocol);
434
			if (isSocksProxy() || isHttpProxy())
435
				return;
436
			if (useSameProtocol) {
437
				recordPreviousValues();
438
				copyValuesFrom(entryList[0]);
439
			} else {
440
				restorePreviousValues();
441
			}
442
		}
443
		
444
		public void setUseSameProtocol(boolean useSameProtocol) {
445
			if (isSocksProxy()) {
446
				setEnabled(true);
447
			} else {
448
				setEnabled(!useSameProtocol);
449
			}
450
		}
451
452
		public void loadPreviousValues() {
453
			IProxyData proxy = getProxy();
454
			prevHostname = proxy.getHost();
455
			prevPort = proxy.getPort();
456
		}
457
		
458
		public void restorePreviousValues() {
459
			hostname.setText(prevHostname);
460
			port.setText(prevPort == -1 ? "" : String //$NON-NLS-1$
461
					.valueOf(prevPort));
462
		}
463
464
		public void recordPreviousValues() {
465
			prevHostname = hostname.getText();
466
			try {
467
				prevPort = Integer.parseInt(port.getText());
468
			} catch (NumberFormatException e) {
469
				prevPort = -1;
470
			}
471
		}
472
473
		/**
474
		 * The user has chosen to use the same entry for all protocols
475
		 * @param entry the entry (the http entry to be exact)
476
		 */
477
		public void copyValuesFrom(Entry entry) {
478
			// For SOCKS, don't use the general entry
479
			if (!isSocksProxy()){
480
	            hostname.setText( entry.hostname.getText() );
481
	            port.setText( entry.port.getText() );
482
			}
483
		}
484
		
485
		public boolean isUseSameProtocol(Entry entry) {
486
			// Always answer true for the SOCKS proxy since we never disable
487
			if (isSocksProxy())
488
				return true;
489
			return (hostsEqual(proxyData.getHost(), entry.getProxy().getHost()) 
490
					&& portsEqual(proxyData.getPort(), entry.getProxy().getPort()));
491
		}
492
493
		private boolean portsEqual(int port1, int port2) {
494
			return port1 == port2;
495
		}
496
497
		private boolean hostsEqual(String host1, String host2) {
498
			if (host1 == host2)
499
				// If there are no hosts, don't enable the use same hosts button
500
				return false;
501
			if (host1 == null || host2 == null)
502
				return false;
503
			return host1.equals(host2);
504
		}
505
		
506
		boolean isSocksProxy() {
507
			return getProxy().getType().equals(IProxyData.SOCKS_PROXY_TYPE);
508
		}
509
		
510
		boolean isHttpProxy() {
511
			return getProxy().getType().equals(IProxyData.HTTP_PROXY_TYPE);
512
		}
513
		
514
		boolean isHttpsProxy() {
515
			return getProxy().getType().equals(IProxyData.HTTPS_PROXY_TYPE);
516
		}
517
518
		public IProxyData getProxy() {
519
			return proxyData;
520
		}
521
522
		public boolean updateMessage() {
523
			if (hostname.isEnabled()) {
524
				if (isSocksProxy() || isHttpProxy()|| !useSameProxyButton.getSelection()) {
525
					String hostString = hostname.getText();
526
					if (hostString.startsWith(" ") || hostString.endsWith(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
527
						setErrorMessage(NetUIMessages.ProxyPreferencePage_41);
528
						return false;
529
					}
530
					String portString = port.getText();
531
					if (portString.length() > 0) {
532
						try {
533
							int port = Integer.valueOf(portString).intValue();
534
							if (port < 0) {
535
								setErrorMessage(NetUIMessages.ProxyPreferencePage_42);
536
								return false;
537
							}
538
						} catch (NumberFormatException e) {
539
							setErrorMessage(NetUIMessages.ProxyPreferencePage_43);
540
							return false;
541
						}
542
					}
543
				}
544
			}
545
			setErrorMessage(null);
546
			return true;
547
		}
548
		
549
		private void setErrorMessage(String message) {
550
			errorMessage = message;
551
			updateErrorMessage();
552
		}
553
		
554
		public void applyValues() {
555
			IProxyData proxy = getProxy();
556
			boolean enableAuth = enableProxyAuth.getSelection();
557
558
			String hostString;
559
			String portString;
560
			if (useSameProxyButton.getSelection() && !isSocksProxy()) {
561
				hostString = entryList[0].hostname.getText();
562
				portString = entryList[0].port.getText();
563
			} else {
564
				hostString = hostname.getText();
565
				portString = port.getText();
566
			}
567
			
568
			proxy.setHost(hostString);
569
			try {
570
				int port = Integer.valueOf(portString).intValue();
571
				proxy.setPort(port);
572
			} catch (NumberFormatException e) {
573
				proxy.setPort(-1);
574
			}
575
			proxy.setUserid(enableAuth ? userid.getText() : null);
576
			proxy.setPassword(enableAuth ? password.getText() : null);
577
			proxy.setSource(null);
578
		}
579
		
580
		public void addProtocolEntry(Composite parent) {
581
			GridData gridData;
582
			IProxyData proxy = getProxy();
583
584
			nameLabel = new Label(parent, SWT.NONE);
585
			nameLabel.setText(getLabel(proxy));
586
587
			hostname = new Text(parent, SWT.BORDER);
588
			gridData = new GridData(GridData.FILL_HORIZONTAL);
589
			gridData.widthHint = 120;
590
			hostname.setLayoutData(gridData);
591
			hostname.setText(getHostName(proxy));
592
			hostname.addModifyListener(new ModifyListener() {
593
				public void modifyText(ModifyEvent e) {
594
					Entry.this.updateMessage();
595
				}
596
			});
597
598
			portLabel = new Label(parent, SWT.NONE);
599
			portLabel.setText(NetUIMessages.ProxyPreferencePage_22);
600
601
			port = new Text(parent, SWT.BORDER);
602
			gridData = new GridData();
603
			gridData.widthHint = 50;
604
			port.setLayoutData(gridData);
605
			port.setText(getPortString(proxy));
606
			port.addModifyListener(new ModifyListener() {
607
				public void modifyText(ModifyEvent e) {
608
					Entry.this.updateMessage();
609
				}
610
			});
611
		}
612
613
		private String getLabel(IProxyData data) {
614
			if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
615
				return NetUIMessages.ProxyPreferencePage_37;
616
			}
617
			if (data.getType().equals(IProxyData.HTTPS_PROXY_TYPE)) {
618
				return NetUIMessages.ProxyPreferencePage_38;
619
			}
620
			if (data.getType().equals(IProxyData.SOCKS_PROXY_TYPE)) {
621
				return NetUIMessages.ProxyPreferencePage_39;
622
			}
623
			return ""; //$NON-NLS-1$
624
		}
625
		
626
		private String getPortString(IProxyData proxy) {
627
			int portInt = proxy.getPort();
628
			String portString;
629
			if (portInt == -1) {
630
				portString = ""; //$NON-NLS-1$
631
			} else {
632
				portString = String.valueOf(portInt);
633
			}
634
			return portString;
635
		}
636
637
		private String getHostName(IProxyData proxy) {
638
			String hostnameString = proxy.getHost();
639
			if (hostnameString == null) {
640
				hostnameString = ""; //$NON-NLS-1$
641
			}
642
			return hostnameString;
643
		}
644
		
645
		public void reset() {
646
			hostname.setText(""); //$NON-NLS-1$
647
			port.setText(""); //$NON-NLS-1$
648
			prevHostname = ""; //$NON-NLS-1$
649
			prevPort = -1;
650
		}
651
		
652
		private void setEnabled(boolean enabled) {
653
			hostname.setEnabled(enabled);
654
			nameLabel.setEnabled(enabled);
655
			portLabel.setEnabled(enabled);
656
			port.setEnabled(enabled);
657
		}
658
659
		public String getErrorMessage() {
660
			return errorMessage;
661
		}
662
	}
663
}
124
}
(-)src/org/eclipse/ui/internal/net/NonProxyHostsContentProvider.java (-35 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
9
 * IBM Corporation - initial API and implementation
10
 * yyyymmdd bug      Email and other contact information
10
 * yyyymmdd   bug    Email and other contact information
11
 * -------- -------- -----------------------------------------------------------
11
 * -------- -------- -----------------------------------------------------------
12
 * 20070201   154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
12
 * 20070201   154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
13
 *******************************************************************************/
13
 *******************************************************************************/
14
15
package org.eclipse.ui.internal.net;
14
package org.eclipse.ui.internal.net;
16
15
17
import java.util.Collection;
16
import java.util.Collection;
Lines 19-62 Link Here
19
import org.eclipse.jface.viewers.IStructuredContentProvider;
18
import org.eclipse.jface.viewers.IStructuredContentProvider;
20
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.jface.viewers.Viewer;
21
20
22
/**
21
public class NonProxyHostsContentProvider implements IStructuredContentProvider {
23
 * Monitor content provider.
22
24
 */
23
	public NonProxyHostsContentProvider() {
25
public class NonProxyHostsContentProvider implements IStructuredContentProvider 
26
{
27
	/**
28
	 * MonitorContentProvider constructor comment.
29
	 */
30
	public NonProxyHostsContentProvider() 
31
	{
32
		super();
24
		super();
33
	}
25
	}
34
26
35
	/*
27
	public void dispose() {
36
	 * Disposes of this content provider.  
28
		// Do nothing
37
	 */
38
	public void dispose() 
39
	{
40
		// do nothing
41
	}
29
	}
42
30
43
	/*
31
	public Object[] getElements(Object inputElement) {
44
	 * Returns the elements to display in the viewer 
32
		Collection coll = (Collection) inputElement;
45
	 * when its input is set to the given element. 
33
		return coll.toArray(new ProxyBypassData[0]);
46
	 */
47
	public Object[] getElements(Object inputElement) 
48
	{
49
		Collection coll = (Collection)inputElement;
50
    
51
		return coll.toArray( new String[0] );
52
	}
34
	}
53
35
54
	/*
36
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
55
	 * Notifies this content provider that the given viewer's input
37
		// Do nothing
56
	 * has been switched to a different element.
57
	 */
58
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) 
59
	{
60
		// do nothing
61
	}
38
	}
39
62
}
40
}
(-)src/org/eclipse/ui/internal/net/NonProxyHostsLabelProvider.java (-90 / +61 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-117 Link Here
11
 * -------- -------- -----------------------------------------------------------
11
 * -------- -------- -----------------------------------------------------------
12
 * 20070201   154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
12
 * 20070201   154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
13
 *******************************************************************************/
13
 *******************************************************************************/
14
15
package org.eclipse.ui.internal.net;
14
package org.eclipse.ui.internal.net;
16
15
17
import org.eclipse.jface.viewers.ILabelProviderListener;
16
import org.eclipse.core.internal.net.ProxySelector;
18
17
import org.eclipse.jface.viewers.BaseLabelProvider;
19
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.jface.viewers.IColorProvider;
20
import org.eclipse.jface.viewers.ITableLabelProvider;
19
import org.eclipse.jface.viewers.ITableLabelProvider;
20
import org.eclipse.jface.viewers.TableViewer;
21
import org.eclipse.jface.viewers.TableViewerColumn;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.graphics.Color;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.widgets.Display;
26
import org.eclipse.swt.widgets.TableColumn;
27
28
public class NonProxyHostsLabelProvider extends BaseLabelProvider implements
29
		ITableLabelProvider, IColorProvider {
21
30
22
/**
31
	public NonProxyHostsLabelProvider() {
23
 * Monitor table label provider.
24
 */
25
public class NonProxyHostsLabelProvider implements ITableLabelProvider 
26
{
27
	/**
28
	 * MonitorTableLabelProvider constructor comment.
29
	 */
30
	public NonProxyHostsLabelProvider() 
31
	{
32
		super();
32
		super();
33
	}
33
	}
34
34
35
	/**
35
	public Image getColumnImage(Object element, int columnIndex) {
36
	 * Adds a listener to this label provider. 
37
	 * Has no effect if an identical listener is already registered.
38
	 * <p>
39
	 * Label provider listeners are informed about state changes 
40
	 * that affect the rendering of the viewer that uses this label provider.
41
	 * </p>
42
	 *
43
	 * @param listener a label provider listener
44
	 */
45
	public void addListener(ILabelProviderListener listener) 
46
	{
47
		// do nothing
48
	}
49
50
	/**
51
	 * Disposes of this label provider.  When a label provider is
52
	 * attached to a viewer, the viewer will automatically call
53
	 * this method when the viewer is being closed.  When label providers
54
	 * are used outside of the context of a viewer, it is the client's
55
	 * responsibility to ensure that this method is called when the
56
	 * provider is no longer needed.
57
	 */
58
	public void dispose() 
59
	{
60
		// do nothing
61
	}
62
63
	/**
64
	 * Returns the label image for the given column of the given element.
65
	 *
66
	 * @param element the object representing the entire row, or 
67
	 *    <code>null</code> indicating that no input object is set
68
	 *    in the viewer
69
	 * @param columnIndex the zero-based index of the column in which
70
	 *   the label appears
71
	 */
72
	public Image getColumnImage(Object element, int columnIndex) 
73
	{
74
		return null;
36
		return null;
75
	}
37
	}
76
38
77
	/**
39
	public String getColumnText(Object element, int columnIndex) {
78
	 * Returns the label text for the given column of the given element.
40
		if (element == null) {
79
	 *
41
			return null;
80
	 * @param element the object representing the entire row, or
42
		}
81
	 *   <code>null</code> indicating that no input object is set
43
		ProxyBypassData data = (ProxyBypassData) element;
82
	 *   in the viewer
44
		switch (columnIndex) {
83
	 * @param columnIndex the zero-based index of the column in which the label appears
45
		case 0:
84
	 */
46
			return null;
85
	public String getColumnText(Object element, int columnIndex) 
47
		case 1:
86
	{
48
			return data.getHost();
87
		return (String)element;
49
		case 2:
88
	}
50
			return data.getSource();
89
	
51
		default:
90
	/**
52
			return null;
91
	 * Returns whether the label would be affected 
53
		}
92
	 * by a change to the given property of the given element.
54
	}
93
	 * This can be used to optimize a non-structural viewer update.
55
94
	 * If the property mentioned in the update does not affect the label,
56
	public boolean isLabelProperty(Object element, String property) {
95
	 * then the viewer need not update the label.
96
	 *
97
	 * @param element the element
98
	 * @param property the property
99
	 * @return <code>true</code> if the label would be affected,
100
	 *    and <code>false</code> if it would be unaffected
101
	 */
102
	public boolean isLabelProperty(Object element, String property) 
103
	{
104
		return false;
57
		return false;
105
	}
58
	}
106
59
107
	/**
60
	public void createColumns(TableViewer viewer) {
108
	 * Removes a listener to this label provider.
61
		String[] titles = {
109
	 * Has no affect if an identical listener is not registered.
62
				"", //$NON-NLS-1$
110
	 *
63
				NetUIMessages.ProxyPreferencePage_13,
111
	 * @param listener a label provider listener
64
				NetUIMessages.ProxyPreferencePage_14 };
112
	 */
65
		for (int i = 0; i < titles.length; i++) {
113
	public void removeListener(ILabelProviderListener listener) 
66
			TableColumn column = new TableViewerColumn(viewer, SWT.NONE)
114
	{
67
					.getColumn();
115
		// do nothing
68
			column.setText(titles[i]);
69
			column.setResizable(true);
70
		}
71
	}
72
73
	public Color getBackground(Object element) {
74
		if (element instanceof ProxyBypassData) {
75
			String provider = ((ProxyBypassData) element).getSource();
76
			if (!ProxySelector.canSetBypassHosts(provider)) {
77
				return Display.getCurrent().getSystemColor(
78
						SWT.COLOR_INFO_BACKGROUND);
79
			}
80
		}
81
		return null;
82
	}
83
84
	public Color getForeground(Object element) {
85
		return null;
116
	}
86
	}
87
117
}
88
}
(-)src/org/eclipse/ui/internal/net/NonProxyHostsComposite.java (-154 / +221 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-254 Link Here
12
 * 20060217   127138 pmoogk@ca.ibm.com - Peter Moogk
12
 * 20060217   127138 pmoogk@ca.ibm.com - Peter Moogk
13
 * 20070201   154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
13
 * 20070201   154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base.
14
 *******************************************************************************/
14
 *******************************************************************************/
15
16
package org.eclipse.ui.internal.net;
15
package org.eclipse.ui.internal.net;
17
16
18
import java.util.Arrays;
17
import java.util.ArrayList;
19
import java.util.Iterator;
18
import java.util.Iterator;
20
import java.util.TreeSet;
19
20
import org.eclipse.core.internal.net.ProxySelector;
21
import org.eclipse.jface.dialogs.InputDialog;
21
import org.eclipse.jface.dialogs.InputDialog;
22
import org.eclipse.jface.fieldassist.ControlDecoration;
22
import org.eclipse.jface.fieldassist.ControlDecoration;
23
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
23
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
24
import org.eclipse.jface.viewers.*;
24
import org.eclipse.jface.viewers.CheckStateChangedEvent;
25
import org.eclipse.jface.viewers.CheckboxTableViewer;
26
import org.eclipse.jface.viewers.ColumnPixelData;
27
import org.eclipse.jface.viewers.ColumnWeightData;
28
import org.eclipse.jface.viewers.DoubleClickEvent;
29
import org.eclipse.jface.viewers.ICheckStateListener;
30
import org.eclipse.jface.viewers.IDoubleClickListener;
31
import org.eclipse.jface.viewers.ISelectionChangedListener;
32
import org.eclipse.jface.viewers.IStructuredSelection;
33
import org.eclipse.jface.viewers.SelectionChangedEvent;
34
import org.eclipse.jface.viewers.TableLayout;
25
import org.eclipse.jface.window.Window;
35
import org.eclipse.jface.window.Window;
26
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.SelectionAdapter;
37
import org.eclipse.swt.events.SelectionAdapter;
28
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.layout.GridData;
39
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
40
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.*;
41
import org.eclipse.swt.widgets.Button;
42
import org.eclipse.swt.widgets.Composite;
43
import org.eclipse.swt.widgets.Control;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Table;
32
46
33
/**
47
/**
34
 * This class is the Composite that consists of the controls for
48
 * This class is the Composite that consists of controls for proxy bypass hosts
35
 * "http.nonProxyHosts" and is used by InternetPreferencesPage.
49
 * and is used by ProxyPreferencesPage.
36
 */
50
 */
37
public class NonProxyHostsComposite extends Composite {
51
public class NonProxyHostsComposite extends Composite {
38
	private Table table_;
39
	TableViewer tableViewer_;
40
	private TreeSet tableValues_;
41
	private Button add_;
42
	private Button edit_;
43
	private Button remove_;
44
52
45
	public NonProxyHostsComposite(Composite parent, int style) {
53
	private Label hostsLabel;
54
	CheckboxTableViewer hostsViewer;
55
	private Button addButton;
56
	private Button editButton;
57
	private Button removeButton;
58
59
	protected String currentProvider;
60
	private ArrayList bypassHosts = new ArrayList();
61
62
	NonProxyHostsComposite(Composite parent, int style) {
46
		super(parent, style);
63
		super(parent, style);
47
		createWidgets();
64
		createWidgets();
48
	}
65
	}
49
66
50
	protected void createWidgets() {
67
	protected void createWidgets() {
51
		GridLayout layout = new GridLayout();
68
		setLayout(new GridLayout(2, false));
52
		layout.horizontalSpacing = 6;
53
		layout.verticalSpacing = 6;
54
		layout.marginWidth = 0;
55
		layout.marginHeight = 0;
56
		layout.numColumns = 2;
57
		setLayout(layout);
58
59
		table_ = new Table(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL
60
				| SWT.MULTI | SWT.FULL_SELECTION);
61
		GridData data = new GridData(GridData.FILL_BOTH
62
				| GridData.VERTICAL_ALIGN_FILL);
63
64
		table_.setLayoutData(data);
65
		table_.setHeaderVisible(false);
66
		table_.setLinesVisible(true);
67
68
		TableLayout tableLayout = new TableLayout();
69
70
		new TableColumn(table_, SWT.NONE);
71
		ColumnWeightData colData = new ColumnWeightData(100, 60, false);
72
		tableLayout.addColumnData(colData);
73
69
74
		table_.setLayout(tableLayout);
70
		hostsLabel = new Label(this, SWT.NONE);
71
		hostsLabel.setText(NetUIMessages.ProxyPreferencePage_12);
72
		hostsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false,
73
				2, 1));
74
75
		Table hostsTable = new Table(this, SWT.BORDER | SWT.V_SCROLL
76
				| SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
77
		hostsTable.setHeaderVisible(true);
78
		hostsTable.setLinesVisible(true);
79
		hostsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
80
				1, 3));
81
82
		hostsViewer = new CheckboxTableViewer(hostsTable);
83
		NonProxyHostsLabelProvider labelProvider = new NonProxyHostsLabelProvider();
84
		NonProxyHostsContentProvider contentProvider = new NonProxyHostsContentProvider();
85
		labelProvider.createColumns(hostsViewer);
86
		hostsViewer.setContentProvider(contentProvider);
87
		hostsViewer.setLabelProvider(labelProvider);
75
88
76
		tableViewer_ = new TableViewer(table_);
89
		TableLayout tableLayout = new TableLayout();
77
		tableViewer_.setContentProvider(new NonProxyHostsContentProvider());
90
		tableLayout.addColumnData(new ColumnPixelData(18));
78
		tableViewer_.setLabelProvider(new NonProxyHostsLabelProvider());
91
		tableLayout.addColumnData(new ColumnWeightData(50, 50, true));
92
		tableLayout.addColumnData(new ColumnWeightData(50, 50, true));
93
		hostsTable.setLayout(tableLayout);
94
95
		addButton = createButton(NetUIMessages.ProxyPreferencePage_15);
96
		editButton = createButton(NetUIMessages.ProxyPreferencePage_16);
97
		removeButton = createButton(NetUIMessages.ProxyPreferencePage_17);
79
98
80
		tableViewer_
99
		hostsViewer
81
				.addSelectionChangedListener(new ISelectionChangedListener() {
100
				.addSelectionChangedListener(new ISelectionChangedListener() {
82
					public void selectionChanged(SelectionChangedEvent event) {
101
					public void selectionChanged(SelectionChangedEvent event) {
83
						enableButtons();
102
						enableButtons();
84
					}
103
					}
85
				});
104
				});
86
105
		hostsViewer.addCheckStateListener(new ICheckStateListener() {
87
		tableViewer_.addDoubleClickListener(new IDoubleClickListener() {
106
			public void checkStateChanged(CheckStateChangedEvent event) {
107
				setProvider(currentProvider);
108
			}
109
		});
110
		hostsViewer.addDoubleClickListener(new IDoubleClickListener() {
88
			public void doubleClick(DoubleClickEvent event) {
111
			public void doubleClick(DoubleClickEvent event) {
89
				editSelection();
112
				editSelection();
90
			}
113
			}
91
		});
114
		});
92
115
		addButton.addSelectionListener(new SelectionAdapter() {
93
		Composite buttonComp = new Composite(this, SWT.NONE);
94
		layout = new GridLayout();
95
		layout.horizontalSpacing = 0;
96
		layout.verticalSpacing = 8;
97
		layout.marginWidth = 0;
98
		layout.marginHeight = 0;
99
		layout.numColumns = 1;
100
		buttonComp.setLayout(layout);
101
		data = new GridData(GridData.HORIZONTAL_ALIGN_END
102
				| GridData.VERTICAL_ALIGN_FILL);
103
		buttonComp.setLayoutData(data);
104
105
		add_ = createButton(buttonComp, NetUIMessages.BUTTON_PREFERENCE_ADD);
106
107
		add_.addSelectionListener(new SelectionAdapter() {
108
			public void widgetSelected(SelectionEvent e) {
116
			public void widgetSelected(SelectionEvent e) {
109
				addHost();
117
				addHost();
110
			}
118
			}
111
		});
119
		});
112
120
		editButton.addSelectionListener(new SelectionAdapter() {
113
		edit_ = createButton(buttonComp, NetUIMessages.BUTTON_PREFERENCE_EDIT);
114
115
		edit_.addSelectionListener(new SelectionAdapter() {
116
			public void widgetSelected(SelectionEvent e) {
121
			public void widgetSelected(SelectionEvent e) {
117
				editSelection();
122
				editSelection();
118
			}
123
			}
119
		});
124
		});
120
		edit_.setEnabled(false);
125
		removeButton.addSelectionListener(new SelectionAdapter() {
121
122
		remove_ = createButton(buttonComp,
123
				NetUIMessages.BUTTON_PREFERENCE_REMOVE);
124
125
		remove_.addSelectionListener(new SelectionAdapter() {
126
			public void widgetSelected(SelectionEvent e) {
126
			public void widgetSelected(SelectionEvent e) {
127
				removeFromList((IStructuredSelection) tableViewer_
127
				removeSelection();
128
						.getSelection());
129
				tableViewer_.refresh();
130
			}
128
			}
131
		});
129
		});
132
		remove_.setEnabled(false);
133
	}
134
130
135
	private Button createButton(Composite comp, String label) {
131
		initializeValues();
136
		Button button = new Button(comp, SWT.PUSH);
132
		enableButtons();
137
		button.setText(label);
138
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
139
				| GridData.VERTICAL_ALIGN_BEGINNING);
140
		button.setLayoutData(data);
141
		return button;
142
	}
133
	}
143
134
144
	/* (non-Javadoc)
145
	 * @see org.eclipse.swt.widgets.Control#setEnabled(boolean)
146
	 */
147
	public void setEnabled(boolean enabled) {
135
	public void setEnabled(boolean enabled) {
148
		super.setEnabled(enabled);
136
		super.setEnabled(enabled);
149
		table_.setEnabled(enabled);
137
		hostsViewer.getTable().setEnabled(enabled);
150
		enableButtons();
138
		enableButtons();
151
	}
139
	}
152
140
153
	public void setList(String[] hosts) {
141
	protected void enableButtons() {
154
		tableValues_ = new TreeSet(Arrays.asList(hosts));
142
		boolean enabled = getEnabled();
155
143
		if (enabled) {
156
		tableViewer_.setInput(tableValues_);
144
			IStructuredSelection selection = (IStructuredSelection) hostsViewer
157
		tableViewer_.refresh();
145
					.getSelection();
158
	}
146
			Iterator iterator = selection.iterator();
159
147
			boolean editable = iterator.hasNext();
160
	public String[] getList() {
148
			while (iterator.hasNext()) {
161
		return (String[]) tableValues_.toArray(new String[0]);
149
				String provider = ((ProxyBypassData) iterator.next())
162
	}
150
						.getSource();
163
151
				if (!ProxySelector.canSetBypassHosts(provider)) {
164
	String getStringList(Iterator iterator) {
152
					editable = false;
165
		StringBuffer buffer = new StringBuffer();
153
				}
166
154
			}
167
		if (iterator.hasNext()) {
155
			addButton.setEnabled(true);
168
			buffer.append((String) iterator.next());
156
			editButton.setEnabled(editable);
169
		}
157
			removeButton.setEnabled(editable);
170
158
		} else {
171
		while (iterator.hasNext()) {
159
			addButton.setEnabled(false);
172
			buffer.append(',');
160
			editButton.setEnabled(false);
173
			buffer.append((String) iterator.next());
161
			removeButton.setEnabled(false);
174
		}
162
		}
175
176
		return buffer.toString();
177
	}
163
	}
178
164
179
	void removeFromList(IStructuredSelection selection) {
165
	protected void addHost() {
180
		tableValues_.removeAll(selection.toList());
166
		String hosts[] = promptForHost(null);
167
		if (hosts != null) {
168
			for (int i = 0; i < hosts.length; i++) {
169
				bypassHosts.add(0, new ProxyBypassData(hosts[i],
170
						getEditableProvider()));
171
			}
172
			hostsViewer.refresh();
173
			setProvider(currentProvider);
174
		}
181
	}
175
	}
182
176
183
	void updateList(String value) {
177
	private String getEditableProvider() {
184
		// Split the string with a delimiter of either a vertical bar, a space,
178
		String providers[] = ProxySelector.getProviders();
185
		// or a comma.
179
		for (int i = 0; i < providers.length; i++) {
186
		String[] hosts = value.split("\\|| |,"); //$NON-NLS-1$
180
			if (ProxySelector.canSetBypassHosts(providers[i])) {
187
181
				return providers[i];
188
		tableValues_.addAll(Arrays.asList(hosts));
182
			}
189
		tableValues_.remove(""); //$NON-NLS-1$
183
		}
190
		tableViewer_.refresh();
184
		return null;
191
	}
185
	}
192
186
193
	void enableButtons() {
187
	protected void removeSelection() {
194
		boolean enabled = getEnabled();
188
		IStructuredSelection selection = (IStructuredSelection) hostsViewer
195
189
				.getSelection();
196
		if (enabled) {
190
		Iterator it = selection.iterator();
197
			boolean itemsSelected = !tableViewer_.getSelection().isEmpty();
191
		while (it.hasNext()) {
198
192
			ProxyBypassData data = (ProxyBypassData) it.next();
199
			add_.setEnabled(true);
193
			bypassHosts.remove(data);
200
			edit_.setEnabled(itemsSelected);
201
			remove_.setEnabled(itemsSelected);
202
		} else {
203
			add_.setEnabled(false);
204
			edit_.setEnabled(false);
205
			remove_.setEnabled(false);
206
		}
194
		}
195
		hostsViewer.refresh();
207
	}
196
	}
208
197
209
	void editSelection() {
198
	protected void editSelection() {
210
		IStructuredSelection selection = (IStructuredSelection) tableViewer_.getSelection();
199
		IStructuredSelection selection = (IStructuredSelection) hostsViewer
200
				.getSelection();
211
		String selectedHosts = getStringList(selection.iterator());
201
		String selectedHosts = getStringList(selection.iterator());
212
		String value = promptForHost(selectedHosts);
202
		String hosts[] = promptForHost(selectedHosts);
213
		if (value != null) {
203
		if (hosts != null) {
214
			removeFromList(selection);
204
			Iterator it = selection.iterator();
215
			updateList(value);
205
			while (it.hasNext()) {
206
				ProxyBypassData data = (ProxyBypassData) it.next();
207
				bypassHosts.remove(data);
208
			}
209
			for (int i = 0; i < hosts.length; i++) {
210
				bypassHosts.add(0, new ProxyBypassData(hosts[i],
211
						getEditableProvider()));
212
			}
213
			hostsViewer.refresh();
216
		}
214
		}
217
	}
215
	}
218
216
219
	void addHost() {
217
	String getStringList(Iterator iterator) {
220
		String value = promptForHost(null);
218
		StringBuffer buffer = new StringBuffer();
221
		if (value != null) {
219
		if (iterator.hasNext()) {
222
			updateList(value);
220
			ProxyBypassData data = (ProxyBypassData) iterator.next();
221
			buffer.append(data.getHost());
223
		}
222
		}
223
		while (iterator.hasNext()) {
224
			buffer.append(';');
225
			ProxyBypassData data = (ProxyBypassData) iterator.next();
226
			buffer.append(data.getHost());
227
		}
228
		return buffer.toString();
224
	}
229
	}
225
	
230
226
	private String promptForHost(String selectedHosts) {
231
	private String[] promptForHost(String selectedHosts) {
227
		InputDialog dialog = new InputDialog(getShell(),
232
		InputDialog dialog = new InputDialog(getShell(),
228
				NetUIMessages.TITLE_PREFERENCE_HOSTS_DIALOG,
233
				NetUIMessages.ProxyBypassDialog_0,
229
				NetUIMessages.LABEL_PREFERENCE_HOSTS_DIALOG, selectedHosts,
234
				NetUIMessages.ProxyBypassDialog_1, selectedHosts, null) {
230
				null) {
231
			private ControlDecoration decorator;
235
			private ControlDecoration decorator;
236
232
			protected Control createDialogArea(Composite parent) {
237
			protected Control createDialogArea(Composite parent) {
233
				Control createDialogArea = super.createDialogArea(parent);
238
				Control createDialogArea = super.createDialogArea(parent);
234
				decorator = new ControlDecoration(getText(), SWT.TOP | SWT.LEFT);
239
				decorator = new ControlDecoration(getText(), SWT.TOP | SWT.LEFT);
235
				decorator.setDescriptionText(NetUIMessages.NonProxyHostsComposite_0);
240
				decorator.setDescriptionText(NetUIMessages.ProxyBypassDialog_2);
236
				decorator.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(
241
				decorator.setImage(FieldDecorationRegistry.getDefault()
237
				FieldDecorationRegistry.DEC_INFORMATION).getImage());
242
						.getFieldDecoration(
243
								FieldDecorationRegistry.DEC_INFORMATION)
244
						.getImage());
238
				return createDialogArea;
245
				return createDialogArea;
239
			}
246
			}
247
240
			public boolean close() {
248
			public boolean close() {
241
				decorator.dispose();
249
				decorator.dispose();
242
				return super.close();
250
				return super.close();
243
			}
251
			}
244
		};
252
		};
245
		int result = dialog.open();
253
		int result = dialog.open();
246
		String value;
247
		if (result != Window.CANCEL) {
254
		if (result != Window.CANCEL) {
248
			value = dialog.getValue();
255
			String value = dialog.getValue();
256
			String hosts[] = value.split("\\;| "); //$NON-NLS-1$
257
			ArrayList filtered = new ArrayList();
258
			for (int i = 0; i < hosts.length; i++) {
259
				if (hosts[i].length() != 0) {
260
					filtered.add(hosts[i]);
261
				}
262
			}
263
			return (String[]) filtered.toArray(new String[0]);
264
		}
265
		return null;
266
	}
267
268
	private Button createButton(String message) {
269
		Button button = new Button(this, SWT.PUSH);
270
		button.setText(message);
271
		button.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
272
		return button;
273
	}
274
275
	public void initializeValues() {
276
		String providers[] = ProxySelector.getProviders();
277
		for (int i = 0; i < providers.length; i++) {
278
			String[] hosts = ProxySelector.getBypassHosts(providers[i]);
279
			for (int j = 0; hosts != null && j < hosts.length; j++) {
280
				ProxyBypassData data = new ProxyBypassData(hosts[j],
281
						providers[i]);
282
				bypassHosts.add(data);
283
			}
284
		}
285
		hostsViewer.setInput(bypassHosts);
286
		setProvider(ProxySelector.getDefaultProvider());
287
	}
288
289
	public void setProvider(String item) {
290
		if (item == null) {
291
			item = currentProvider;
249
		} else {
292
		} else {
250
			value = null;
293
			currentProvider = item;
251
		}
294
		}
252
		return value;
295
		ArrayList selected = new ArrayList();
296
		Iterator it = bypassHosts.iterator();
297
		while (it.hasNext()) {
298
			ProxyBypassData data = (ProxyBypassData) it.next();
299
			if (data.getSource().equalsIgnoreCase(item)) {
300
				selected.add(data);
301
			}
302
		}
303
		hostsViewer
304
				.setCheckedElements(selected.toArray(new ProxyBypassData[0]));
253
	}
305
	}
306
307
	public void performApply() {
308
		String provider = getEditableProvider();
309
		Iterator it = bypassHosts.iterator();
310
		ArrayList hosts = new ArrayList();
311
		while (it.hasNext()) {
312
			ProxyBypassData data = (ProxyBypassData) it.next();
313
			if (data.getSource().equals(provider)) {
314
				hosts.add(data.getHost());
315
			}
316
		}
317
		String data[] = (String[]) hosts.toArray(new String[0]);
318
		ProxySelector.setBypassHosts(provider, data);
319
	}
320
254
}
321
}
(-)src/org/eclipse/ui/internal/net/Activator.java (-19 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-22 Link Here
13
 *******************************************************************************/
13
 *******************************************************************************/
14
package org.eclipse.ui.internal.net;
14
package org.eclipse.ui.internal.net;
15
15
16
import org.eclipse.core.net.proxy.IProxyService;
17
import org.eclipse.ui.plugin.AbstractUIPlugin;
16
import org.eclipse.ui.plugin.AbstractUIPlugin;
18
import org.osgi.framework.BundleContext;
17
import org.osgi.framework.BundleContext;
19
import org.osgi.util.tracker.ServiceTracker;
20
18
21
/**
19
/**
22
 * The activator class controls the plug-in life cycle
20
 * The activator class controls the plug-in life cycle
Lines 29-36 Link Here
29
	// The shared instance
27
	// The shared instance
30
	private static Activator plugin;
28
	private static Activator plugin;
31
29
32
	private ServiceTracker tracker;
33
34
	/**
30
	/**
35
	 * The constructor
31
	 * The constructor
36
	 */
32
	 */
Lines 47-72 Link Here
47
		return plugin;
43
		return plugin;
48
	}
44
	}
49
45
50
	/**
51
	 * Return the {@link IProxyService} or <code>null</code> if the service is
52
	 * not available.
53
	 * 
54
	 * @return the {@link IProxyService} or <code>null</code>
55
	 */
56
	public IProxyService getProxyService() {
57
		return (IProxyService) tracker.getService();
58
	}
59
60
	public void start(BundleContext context) throws Exception {
46
	public void start(BundleContext context) throws Exception {
61
		super.start(context);
47
		super.start(context);
62
		tracker = new ServiceTracker(getBundle().getBundleContext(),
63
				IProxyService.class.getName(), null);
64
		tracker.open();
65
	}
48
	}
66
49
67
	public void stop(BundleContext context) throws Exception {
50
	public void stop(BundleContext context) throws Exception {
68
		plugin = null;
51
		plugin = null;
69
		super.stop(context);
52
		super.stop(context);
70
		tracker.close();
71
	}
53
	}
54
72
}
55
}
(-)src/org/eclipse/ui/internal/net/ProxyEntryDialog.java (+241 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import java.net.URI;
14
import java.net.URISyntaxException;
15
16
import org.eclipse.core.internal.net.ProxyData;
17
import org.eclipse.core.net.proxy.IProxyData;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.jface.dialogs.Dialog;
21
import org.eclipse.jface.dialogs.StatusDialog;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.ModifyEvent;
24
import org.eclipse.swt.events.ModifyListener;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.SelectionListener;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Button;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.swt.widgets.Label;
33
import org.eclipse.swt.widgets.Shell;
34
import org.eclipse.swt.widgets.Text;
35
36
public class ProxyEntryDialog extends StatusDialog {
37
38
	private IProxyData data;
39
	private String[] addedTypes;
40
41
	private Label typeLabel;
42
	private Text typeText;
43
	private Label hostLabel;
44
	private Text hostText;
45
	private Label portLabel;
46
	private Text portText;
47
48
	private Button requiresAuthentificationButton;
49
	private Label userIdLabel;
50
	private Text userIdText;
51
	private Label passwordLabel;
52
	private Text passwordText;
53
54
	public ProxyEntryDialog(Shell parent, IProxyData data, String[] addedArray,
55
			String title) {
56
		super(parent);
57
		if (data == null) {
58
			this.data = new ProxyData("", "", 0, false, ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
59
		} else {
60
			this.data = data;
61
		}
62
		this.addedTypes = addedArray;
63
		this.setTitle(title);
64
	}
65
66
	public IProxyData getValue() {
67
		return data;
68
	}
69
70
	protected Control createDialogArea(Composite parent) {
71
		Composite composite = new Composite(parent, SWT.NONE);
72
		composite.setLayout(new GridLayout(4, false));
73
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
74
				| GridData.FILL_VERTICAL));
75
76
		typeLabel = new Label(composite, SWT.NONE);
77
		typeLabel.setText(NetUIMessages.ProxyEntryDialog_2);
78
		typeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false,
79
				1, 1));
80
		typeText = new Text(composite, SWT.BORDER);
81
		typeText.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 3,
82
				1));
83
		typeText.setEditable(false);
84
85
		hostLabel = new Label(composite, SWT.NONE);
86
		hostLabel.setText(NetUIMessages.ProxyEntryDialog_3);
87
		hostLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false,
88
				1, 1));
89
		hostText = new Text(composite, SWT.BORDER);
90
		GridData gdata = new GridData(SWT.FILL, SWT.TOP, true, false);
91
		gdata.widthHint = 250;
92
		hostText.setLayoutData(gdata);
93
94
		portLabel = new Label(composite, SWT.NONE);
95
		portLabel.setText(NetUIMessages.ProxyEntryDialog_4);
96
		portText = new Text(composite, SWT.BORDER);
97
		gdata = new GridData();
98
		gdata.widthHint = 25;
99
		portText.setLayoutData(gdata);
100
101
		requiresAuthentificationButton = new Button(composite, SWT.CHECK);
102
		requiresAuthentificationButton
103
				.setText(NetUIMessages.ProxyEntryDialog_6);
104
		requiresAuthentificationButton.setLayoutData(new GridData(SWT.LEFT,
105
				SWT.CENTER, false, false, 4, 1));
106
107
		userIdLabel = new Label(composite, SWT.NONE);
108
		userIdLabel.setText(NetUIMessages.ProxyEntryDialog_7);
109
		userIdLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false,
110
				1, 1));
111
		userIdText = new Text(composite, SWT.BORDER);
112
		userIdText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,
113
				3, 1));
114
115
		passwordLabel = new Label(composite, SWT.NONE);
116
		passwordLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
117
				true, 1, 1));
118
		passwordLabel.setText(NetUIMessages.ProxyEntryDialog_8);
119
		passwordText = new Text(composite, SWT.BORDER);
120
		passwordText.setEchoChar('*');
121
		passwordText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true,
122
				3, 1));
123
124
		ModifyListener validationListener = new ModifyListener() {
125
			public void modifyText(ModifyEvent e) {
126
				updateStatus();
127
			}
128
		};
129
		typeText.addModifyListener(validationListener);
130
		hostText.addModifyListener(validationListener);
131
		portText.addModifyListener(validationListener);
132
		userIdText.addModifyListener(validationListener);
133
		passwordText.addModifyListener(validationListener);
134
		requiresAuthentificationButton
135
				.addSelectionListener(new SelectionListener() {
136
					public void widgetDefaultSelected(SelectionEvent e) {
137
						enableButtons();
138
						updateStatus();
139
					}
140
141
					public void widgetSelected(SelectionEvent e) {
142
						enableButtons();
143
						updateStatus();
144
					}
145
				});
146
147
		Dialog.applyDialogFont(composite);
148
		applyData();
149
		enableButtons();
150
		return composite;
151
	}
152
153
	public boolean isHelpAvailable() {
154
		return false;
155
	}
156
157
	public boolean isResizable() {
158
		return true;
159
	}
160
161
	private String toString(String str) {
162
		return str == null ? "" : str; //$NON-NLS-1$
163
	}
164
165
	private void applyData() {
166
		typeText.setText(toString(data.getType()));
167
		hostText.setText(toString(data.getHost()));
168
		if (data.getPort() != -1) {
169
			portText.setText(toString(Integer.toString(data.getPort())));
170
		} else {
171
			portText.setText(""); //$NON-NLS-1$
172
		}
173
		boolean auth = data.isRequiresAuthentication();
174
		requiresAuthentificationButton.setSelection(auth);
175
		userIdText.setText(toString(data.getUserId()));
176
		passwordText.setText(toString(data.getPassword()));
177
	}
178
179
	protected void okPressed() {
180
		((ProxyData) data).setType(typeText.getText());
181
		data.setHost(hostText.getText());
182
		data.setPort(Integer.parseInt(portText.getText()));
183
		if (requiresAuthentificationButton.getSelection()) {
184
			data.setUserid(userIdText.getText());
185
			data.setPassword(passwordText.getText());
186
		} else {
187
			data.setUserid(null);
188
			data.setPassword(null);
189
		}
190
		super.okPressed();
191
	}
192
193
	protected void enableButtons() {
194
		boolean auth = requiresAuthentificationButton.getSelection();
195
		userIdText.setEnabled(auth);
196
		passwordText.setEnabled(auth);
197
	}
198
199
	protected void updateStatus() {
200
		String type = typeText.getText();
201
		for (int i = 0; i < addedTypes.length; i++) {
202
			if (addedTypes[i].equalsIgnoreCase(type)) {
203
				updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
204
						IStatus.OK, NetUIMessages.ProxyEntryDialog_9, null));
205
				return;
206
			}
207
		}
208
		try {
209
			new URI(hostText.getText());
210
		} catch (URISyntaxException e) {
211
			updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
212
					IStatus.OK, NetUIMessages.ProxyEntryDialog_10, null));
213
			return;
214
		}
215
		if (hostText.getText().length() == 0) {
216
			updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
217
					IStatus.OK, NetUIMessages.ProxyEntryDialog_10, null));
218
			return;
219
		}
220
		try {
221
			int port = Integer.parseInt(portText.getText());
222
			if (port < 0) {
223
				updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
224
						IStatus.OK, NetUIMessages.ProxyEntryDialog_11, null));
225
				return;
226
			}
227
		} catch (NumberFormatException e) {
228
			updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
229
					IStatus.OK, NetUIMessages.ProxyEntryDialog_11, null));
230
			return;
231
		}
232
		if (requiresAuthentificationButton.getSelection()) {
233
			if (userIdText.getText().length() == 0) {
234
				updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
235
						IStatus.OK, NetUIMessages.ProxyEntryDialog_12, null));
236
				return;
237
			}
238
		}
239
		updateStatus(Status.OK_STATUS);
240
	}
241
}
(-)src/org/eclipse/ui/internal/net/ProxyEntriesLabelProvider.java (+110 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import org.eclipse.core.internal.net.ProxySelector;
14
import org.eclipse.core.net.proxy.IProxyData;
15
import org.eclipse.jface.viewers.BaseLabelProvider;
16
import org.eclipse.jface.viewers.IColorProvider;
17
import org.eclipse.jface.viewers.ITableLabelProvider;
18
import org.eclipse.jface.viewers.TableViewer;
19
import org.eclipse.jface.viewers.TableViewerColumn;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.graphics.Color;
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.widgets.Display;
24
import org.eclipse.swt.widgets.TableColumn;
25
26
public class ProxyEntriesLabelProvider extends BaseLabelProvider implements
27
		ITableLabelProvider, IColorProvider {
28
29
	public ProxyEntriesLabelProvider() {
30
		super();
31
	}
32
33
	public Image getColumnImage(Object element, int columnIndex) {
34
		return null;
35
	}
36
37
	public String getColumnText(Object element, int columnIndex) {
38
		if (element == null) {
39
			return null;
40
		}
41
		IProxyData data = (IProxyData) element;
42
		switch (columnIndex) {
43
		case 0:
44
			return null;
45
		case 1:
46
			return data.getType();
47
		case 2:
48
			if (data.isDynamic()) {
49
				return NetUIMessages.ProxyPreferencePage_18;
50
			}
51
			return data.getHost();
52
		case 3:
53
			if (data.isDynamic()) {
54
				return NetUIMessages.ProxyPreferencePage_18;
55
			}
56
			if (data.getPort() == -1) {
57
				return ""; //$NON-NLS-1$
58
			}
59
			return Integer.toString(data.getPort());
60
		case 4:
61
			return data.getSource();
62
		case 5:
63
			return Boolean.toString(data.isRequiresAuthentication());
64
		case 6:
65
			return data.getUserId();
66
		case 7:
67
			return data.getPassword();
68
		default:
69
			return null;
70
		}
71
	}
72
73
	public boolean isLabelProperty(Object element, String property) {
74
		return false;
75
	}
76
77
	public void createColumns(TableViewer viewer) {
78
		String[] titles = {
79
				"", //$NON-NLS-1$
80
				NetUIMessages.ProxyPreferencePage_2,
81
				NetUIMessages.ProxyPreferencePage_3,
82
				NetUIMessages.ProxyPreferencePage_4,
83
				NetUIMessages.ProxyPreferencePage_5,
84
				NetUIMessages.ProxyPreferencePage_6,
85
				NetUIMessages.ProxyPreferencePage_7,
86
				NetUIMessages.ProxyPreferencePage_8 };
87
		for (int i = 0; i < titles.length; i++) {
88
			TableColumn column = new TableViewerColumn(viewer, SWT.NONE)
89
					.getColumn();
90
			column.setText(titles[i]);
91
			column.setResizable(true);
92
		}
93
	}
94
95
	public Color getBackground(Object element) {
96
		if (element instanceof IProxyData) {
97
			String provider = ((IProxyData) element).getSource();
98
			if (!ProxySelector.canSetProxyData(provider)) {
99
				return Display.getCurrent().getSystemColor(
100
						SWT.COLOR_INFO_BACKGROUND);
101
			}
102
		}
103
		return null;
104
	}
105
106
	public Color getForeground(Object element) {
107
		return null;
108
	}
109
110
}
(-)src/org/eclipse/ui/internal/net/ProxyEntriesComposite.java (+291 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
16
import org.eclipse.core.internal.net.ProxySelector;
17
import org.eclipse.core.net.proxy.IProxyData;
18
import org.eclipse.jface.viewers.CheckStateChangedEvent;
19
import org.eclipse.jface.viewers.CheckboxTableViewer;
20
import org.eclipse.jface.viewers.ColumnPixelData;
21
import org.eclipse.jface.viewers.ColumnWeightData;
22
import org.eclipse.jface.viewers.DoubleClickEvent;
23
import org.eclipse.jface.viewers.ICheckStateListener;
24
import org.eclipse.jface.viewers.IDoubleClickListener;
25
import org.eclipse.jface.viewers.ISelectionChangedListener;
26
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.viewers.SelectionChangedEvent;
28
import org.eclipse.jface.viewers.TableLayout;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Table;
39
40
/**
41
 * This class is the Composite that consists of the controls for proxy entries
42
 * and is used by ProxyPreferencesPage.
43
 */
44
public class ProxyEntriesComposite extends Composite {
45
46
	private Label entriesLabel;
47
	private CheckboxTableViewer entriesViewer;
48
	// private Button addButton;
49
	private Button editButton;
50
	private Button removeButton;
51
52
	protected String currentProvider;
53
	private ArrayList proxyEntries = new ArrayList();
54
55
	ProxyEntriesComposite(Composite parent, int style) {
56
		super(parent, style);
57
		createWidgets();
58
	}
59
60
	protected void createWidgets() {
61
		setLayout(new GridLayout(2, false));
62
63
		entriesLabel = new Label(this, SWT.NONE);
64
		entriesLabel.setText(NetUIMessages.ProxyPreferencePage_1);
65
		entriesLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
66
				false, false, 2, 1));
67
68
		Table entriesTable = new Table(this, SWT.BORDER | SWT.V_SCROLL
69
				| SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
70
		entriesTable.setHeaderVisible(true);
71
		entriesTable.setLinesVisible(true);
72
		entriesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
73
				1, 3));
74
75
		entriesViewer = new CheckboxTableViewer(entriesTable);
76
		ProxyEntriesLabelProvider labelProvider = new ProxyEntriesLabelProvider();
77
		ProxyEntriesContentProvider contentProvider = new ProxyEntriesContentProvider();
78
		labelProvider.createColumns(entriesViewer);
79
		entriesViewer.setContentProvider(contentProvider);
80
		entriesViewer.setLabelProvider(labelProvider);
81
82
		TableLayout tableLayout = new TableLayout();
83
		tableLayout.addColumnData(new ColumnPixelData(18));
84
		tableLayout.addColumnData(new ColumnWeightData(20, 50, true));
85
		tableLayout.addColumnData(new ColumnWeightData(50, 50, true));
86
		tableLayout.addColumnData(new ColumnWeightData(20, 50, true));
87
		tableLayout.addColumnData(new ColumnWeightData(20, 50, true));
88
		tableLayout.addColumnData(new ColumnWeightData(20, 50, true));
89
		tableLayout.addColumnData(new ColumnWeightData(50, 50, true));
90
		tableLayout.addColumnData(new ColumnWeightData(50, 50, true));
91
92
		entriesTable.setLayout(tableLayout);
93
94
		// addButton = createButton(NetUIMessages.ProxyPreferencePage_9);
95
		editButton = createButton(NetUIMessages.ProxyPreferencePage_10);
96
		removeButton = createButton(NetUIMessages.ProxyPreferencePage_11);
97
98
		entriesViewer
99
				.addSelectionChangedListener(new ISelectionChangedListener() {
100
					public void selectionChanged(SelectionChangedEvent event) {
101
						enableButtons();
102
					}
103
				});
104
		entriesViewer.addCheckStateListener(new ICheckStateListener() {
105
			public void checkStateChanged(CheckStateChangedEvent event) {
106
				setProvider(currentProvider);
107
			}
108
		});
109
		entriesViewer.addDoubleClickListener(new IDoubleClickListener() {
110
			public void doubleClick(DoubleClickEvent event) {
111
				editSelection();
112
			}
113
		});
114
		// addButton.addSelectionListener(new SelectionAdapter() {
115
		// public void widgetSelected(SelectionEvent e) {
116
		// addEntry();
117
		// }
118
		// });
119
		editButton.addSelectionListener(new SelectionAdapter() {
120
			public void widgetSelected(SelectionEvent e) {
121
				editSelection();
122
			}
123
		});
124
		removeButton.addSelectionListener(new SelectionAdapter() {
125
			public void widgetSelected(SelectionEvent e) {
126
				removeSelection();
127
			}
128
		});
129
130
		initializeValues();
131
		enableButtons();
132
	}
133
134
	protected void enableButtons() {
135
		boolean enabled = getEnabled();
136
		if (enabled) {
137
			IStructuredSelection selection = (IStructuredSelection) entriesViewer
138
					.getSelection();
139
			Iterator iterator = selection.iterator();
140
			boolean editable = iterator.hasNext();
141
			while (iterator.hasNext()) {
142
				String provider = ((IProxyData) iterator.next()).getSource();
143
				if (!ProxySelector.canSetProxyData(provider)) {
144
					editable = false;
145
				}
146
			}
147
			// addButton.setEnabled(true);
148
			editButton.setEnabled(editable && selection.size() == 1);
149
			removeButton.setEnabled(editable);
150
		} else {
151
			// addButton.setEnabled(false);
152
			editButton.setEnabled(false);
153
			removeButton.setEnabled(false);
154
		}
155
	}
156
157
	protected void addEntry() {
158
		Iterator it = proxyEntries.iterator();
159
		ArrayList added = new ArrayList();
160
		String editableProvider = getEditableProvider();
161
		while (it.hasNext()) {
162
			IProxyData data = (IProxyData) it.next();
163
			if (data.getSource().equalsIgnoreCase(editableProvider)) {
164
				added.add(data.getType());
165
			}
166
		}
167
		String addedArray[] = (String[]) added.toArray(new String[0]);
168
		IProxyData data = promptForEntry(null, addedArray,
169
				NetUIMessages.ProxyEntryDialog_0);
170
		if (data != null) {
171
			data.setSource(editableProvider);
172
			proxyEntries.add(0, data);
173
			entriesViewer.refresh();
174
		}
175
	}
176
177
	private String getEditableProvider() {
178
		String providers[] = ProxySelector.getProviders();
179
		for (int i = 0; i < providers.length; i++) {
180
			if (ProxySelector.canSetProxyData(providers[i])) {
181
				return providers[i];
182
			}
183
		}
184
		return null;
185
	}
186
187
	private IProxyData promptForEntry(IProxyData entry, String[] addedArray,
188
			String title) {
189
		ProxyEntryDialog dialog = new ProxyEntryDialog(getShell(), entry,
190
				addedArray, title);
191
		int result = dialog.open();
192
		if (result != Window.CANCEL) {
193
			return dialog.getValue();
194
		}
195
		return null;
196
	}
197
198
	protected void editSelection() {
199
		Iterator itsel = ((IStructuredSelection) entriesViewer.getSelection())
200
				.iterator();
201
		IProxyData toEdit = null;
202
		if (itsel.hasNext()) {
203
			toEdit = ((IProxyData) itsel.next());
204
		} else {
205
			return;
206
		}
207
		Iterator it = proxyEntries.iterator();
208
		ArrayList added = new ArrayList();
209
		String editableProvider = getEditableProvider();
210
		while (it.hasNext()) {
211
			IProxyData data = (IProxyData) it.next();
212
			if (data.getSource().equalsIgnoreCase(editableProvider)) {
213
				if (data.getType() != toEdit.getType()) {
214
					added.add(data.getType());
215
				}
216
			}
217
		}
218
		String addedArray[] = (String[]) added.toArray(new String[0]);
219
		IProxyData data = promptForEntry(toEdit, addedArray,
220
				NetUIMessages.ProxyEntryDialog_1);
221
		if (data != null) {
222
			entriesViewer.refresh();
223
		}
224
	}
225
226
	protected void removeSelection() {
227
		IStructuredSelection selection = (IStructuredSelection) entriesViewer
228
				.getSelection();
229
		Iterator it = selection.iterator();
230
		while (it.hasNext()) {
231
			IProxyData data = (IProxyData) it.next();
232
			data.setHost(""); //$NON-NLS-1$
233
			data.setPort(-1);
234
			data.setUserid(null);
235
			data.setPassword(null);
236
		}
237
		entriesViewer.refresh();
238
	}
239
240
	private Button createButton(String message) {
241
		Button button = new Button(this, SWT.PUSH);
242
		button.setText(message);
243
		button.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
244
		return button;
245
	}
246
247
	public void initializeValues() {
248
		String providers[] = ProxySelector.getProviders();
249
		for (int i = 0; i < providers.length; i++) {
250
			IProxyData[] entries = ProxySelector.getProxyData(providers[i]);
251
			for (int j = 0; j < entries.length; j++) {
252
				entries[j].setSource(providers[i]);
253
				proxyEntries.add(entries[j]);
254
			}
255
		}
256
		entriesViewer.setInput(proxyEntries);
257
		setProvider(ProxySelector.getDefaultProvider());
258
	}
259
260
	public void setProvider(String item) {
261
		if (item == null) {
262
			item = currentProvider;
263
		} else {
264
			currentProvider = item;
265
		}
266
		ArrayList checked = new ArrayList();
267
		Iterator it = proxyEntries.iterator();
268
		while (it.hasNext()) {
269
			IProxyData data = (IProxyData) it.next();
270
			if (data.getSource().equalsIgnoreCase(item)) {
271
				checked.add(data);
272
			}
273
		}
274
		entriesViewer.setCheckedElements(checked.toArray(new IProxyData[0]));
275
	}
276
277
	public void performApply() {
278
		String provider = getEditableProvider();
279
		Iterator it = proxyEntries.iterator();
280
		ArrayList proxies = new ArrayList();
281
		while (it.hasNext()) {
282
			IProxyData data = (IProxyData) it.next();
283
			if (data.getSource().equals(provider)) {
284
				proxies.add(data);
285
			}
286
		}
287
		IProxyData data[] = (IProxyData[]) proxies.toArray(new IProxyData[0]);
288
		ProxySelector.setProxyData(provider, data);
289
	}
290
291
}
(-)src/org/eclipse/ui/internal/net/ProxyBypassData.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
public class ProxyBypassData {
14
15
	private String host;
16
	private String source;
17
18
	public ProxyBypassData(String host, String source) {
19
		super();
20
		this.host = host;
21
		this.source = source;
22
	}
23
24
	public String getHost() {
25
		return host;
26
	}
27
28
	public void setHost(String host) {
29
		this.host = host;
30
	}
31
32
	public String getSource() {
33
		return source;
34
	}
35
36
	public void setSource(String source) {
37
		this.source = source;
38
	}
39
40
}
(-)src/org/eclipse/ui/internal/net/ProxyEntriesContentProvider.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import java.util.Collection;
14
15
import org.eclipse.core.net.proxy.IProxyData;
16
import org.eclipse.jface.viewers.IStructuredContentProvider;
17
import org.eclipse.jface.viewers.Viewer;
18
19
public class ProxyEntriesContentProvider implements IStructuredContentProvider {
20
21
	public ProxyEntriesContentProvider() {
22
		super();
23
	}
24
25
	public void dispose() {
26
		// Do nothing
27
	}
28
29
	public Object[] getElements(Object inputElement) {
30
		Collection coll = (Collection) inputElement;
31
		return coll.toArray(new IProxyData[0]);
32
	}
33
34
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
35
		// Do nothing
36
	}
37
38
}

Return to bug 228739