|
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 |
} |