View | Details | Raw Unified | Return to bug 299020
Collapse All | Expand All

(-)plugin.xml (+1 lines)
Lines 2-7 Link Here
2
<?eclipse version="3.2"?>
2
<?eclipse version="3.2"?>
3
<plugin>
3
<plugin>
4
   <extension-point id="authenticator" name="Authenticator" schema="schema/authenticator.exsd"/>
4
   <extension-point id="authenticator" name="Authenticator" schema="schema/authenticator.exsd"/>
5
   <extension-point id="proxyTester" name="Proxy Tester" schema="schema/proxyTester.exsd"/>
5
   <extension
6
   <extension
6
         point="org.eclipse.equinox.preferences.preferences">
7
         point="org.eclipse.equinox.preferences.preferences">
7
      <initializer
8
      <initializer
(-)schema/proxyTester.exsd (+102 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.core.net" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.core.net" id="proxyTester" name="Proxy Tester"/>
7
      </appInfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <choice minOccurs="1" maxOccurs="unbounded">
21
            <element ref="proxyTestProvider"/>
22
         </choice>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="proxyTestProvider">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="java" basedOn=":org.eclipse.core.net.proxy.IProxyTestProvider"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
      </complexType>
63
   </element>
64
65
   <annotation>
66
      <appInfo>
67
         <meta.section type="since"/>
68
      </appInfo>
69
      <documentation>
70
         [Enter the first release in which this extension point appears.]
71
      </documentation>
72
   </annotation>
73
74
   <annotation>
75
      <appInfo>
76
         <meta.section type="examples"/>
77
      </appInfo>
78
      <documentation>
79
         [Enter extension point usage example here.]
80
      </documentation>
81
   </annotation>
82
83
   <annotation>
84
      <appInfo>
85
         <meta.section type="apiinfo"/>
86
      </appInfo>
87
      <documentation>
88
         [Enter API information here.]
89
      </documentation>
90
   </annotation>
91
92
   <annotation>
93
      <appInfo>
94
         <meta.section type="implementation"/>
95
      </appInfo>
96
      <documentation>
97
         [Enter information about supplied implementation of this extension point.]
98
      </documentation>
99
   </annotation>
100
101
102
</schema>
(-)src/org/eclipse/core/net/proxy/IProxyTestProvider.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.core.net.proxy;
12
13
import org.eclipse.core.runtime.IStatus;
14
15
public interface IProxyTestProvider {
16
17
	/**
18
	 * This method should test connection with a given host. Implementors should
19
	 * test connection and return IStatus instance in result. If connection is
20
	 * established correctly, it should return
21
	 * org.eclipse.core.runtime.Status.Status(int, String, String) with severity
22
	 * IStatus.OK. If connection cannot be established, severity should be
23
	 * IStatus.ERROR. If any Throwable object is available as a result of any
24
	 * error or exception, it should return
25
	 * org.eclipse.core.runtime.Status.Status(int, String, int, String,
26
	 * Throwable). In org.eclipse.core.runtime.Status constructor as a message
27
	 * parameter should be set host for which connection was tested.
28
	 * 
29
	 * @param host for which connection is tested.
30
	 * @return IStatus result of a test
31
	 */
32
	IStatus testConnection(String host);
33
}
(-)plugin.xml (+6 lines)
Lines 25-29 Link Here
25
           class="org.eclipse.ui.internal.net.auth.NetAuthenticator">
25
           class="org.eclipse.ui.internal.net.auth.NetAuthenticator">
26
     </authenticator>
26
     </authenticator>
27
  </extension>
27
  </extension>
28
  <extension
29
        point="org.eclipse.core.net.proxyTester">
30
     <proxyTestProvider
31
           class="org.eclipse.ui.internal.net.DefaultProxyTestProvider">
32
     </proxyTestProvider>
33
  </extension>
28
34
29
</plugin>
35
</plugin>
(-)src/org/eclipse/ui/internal/net/DefaultProxyTestProvider.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.io.IOException;
14
import java.net.HttpURLConnection;
15
import java.net.URL;
16
17
import org.eclipse.core.net.proxy.IProxyTestProvider;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
21
public class DefaultProxyTestProvider implements IProxyTestProvider {
22
23
	public IStatus testConnection(String host) {
24
		try {
25
			URL url = new URL(host);
26
			int responseCode = ((HttpURLConnection) url.openConnection())
27
					.getResponseCode();	
28
			if (responseCode == 200) {
29
				return new Status(IStatus.OK, Activator.PLUGIN_ID, host);
30
			} else {
31
				return new Status(IStatus.ERROR, Activator.PLUGIN_ID, host);
32
			}
33
		} catch (IOException e) {
34
			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, host, e);
35
		}
36
	}
37
38
}
(-)src/org/eclipse/ui/internal/net/NetUIMessages.java (+13 lines)
Lines 42-47 Link Here
42
	public static String ProxyPreferencePage_16;
42
	public static String ProxyPreferencePage_16;
43
	public static String ProxyPreferencePage_17;
43
	public static String ProxyPreferencePage_17;
44
	public static String ProxyPreferencePage_18;
44
	public static String ProxyPreferencePage_18;
45
	public static String ProxyPreferencePage_19;
45
46
46
	public static String ProxyEntryDialog_0;
47
	public static String ProxyEntryDialog_0;
47
	public static String ProxyEntryDialog_1;
48
	public static String ProxyEntryDialog_1;
Lines 66-71 Link Here
66
	public static String UserValidationDialog_1;
67
	public static String UserValidationDialog_1;
67
	public static String UserValidationDialog_2;
68
	public static String UserValidationDialog_2;
68
	public static String UserValidationDialog_3;
69
	public static String UserValidationDialog_3;
70
	
71
	public static String ProxyTestDialog_0;
72
	public static String ProxyTestDialog_1;
73
	public static String ProxyTestDialog_2;
74
	public static String ProxyTestDialog_3;
75
	public static String ProxyTestDialog_4;
76
	public static String ProxyTestDialog_5;
77
	public static String ProxyTestDialog_6;
78
	public static String ProxyTestDialog_7;
79
	public static String ProxyTestDialog_8;
80
	public static String ProxyTestDialog_9;
81
	public static String ProxyTestDialog_10;
69
82
70
	static {
83
	static {
71
		NLS.initializeMessages(BUNDLE_NAME, NetUIMessages.class);
84
		NLS.initializeMessages(BUNDLE_NAME, NetUIMessages.class);
(-)src/org/eclipse/ui/internal/net/ProxyPreferencePage.java (+9 lines)
Lines 25-30 Link Here
25
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Control;
31
import org.eclipse.swt.widgets.Control;
Lines 53-58 Link Here
53
		createProviderComposite(composite);
54
		createProviderComposite(composite);
54
		createProxyEntriesComposite(composite);
55
		createProxyEntriesComposite(composite);
55
		createNonProxiedHostsComposite(composite);
56
		createNonProxiedHostsComposite(composite);
57
		createTestButton(composite);
56
58
57
		// Adding help accessible by F1
59
		// Adding help accessible by F1
58
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
60
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
Lines 90-95 Link Here
90
		nonProxyHostsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
92
		nonProxyHostsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
91
				true, true));
93
				true, true));
92
	}
94
	}
95
	
96
	private void createTestButton(Composite parent) {
97
		Button test = new Button(parent, SWT.PUSH);
98
		test.setText(NetUIMessages.ProxyPreferencePage_19);
99
		final ProxyTester tester = new ProxyTester();
100
		test.addSelectionListener(tester);
101
	}
93
102
94
	public void init(IWorkbench workbench) {
103
	public void init(IWorkbench workbench) {
95
		// Nothing to do
104
		// Nothing to do
(-)src/org/eclipse/ui/internal/net/ProxyTestResultDialog.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.Iterator;
14
import java.util.List;
15
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.dialogs.StatusDialog;
19
import org.eclipse.jface.viewers.ColumnWeightData;
20
import org.eclipse.jface.viewers.TableLayout;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.custom.TableEditor;
23
import org.eclipse.swt.events.SelectionAdapter;
24
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.layout.FillLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.swt.widgets.Table;
31
import org.eclipse.swt.widgets.TableColumn;
32
import org.eclipse.swt.widgets.TableItem;
33
34
public class ProxyTestResultDialog extends StatusDialog {
35
36
	private List testResults;
37
	
38
	public ProxyTestResultDialog(Shell parent, List testResults) {
39
		super(parent);
40
		this.testResults = testResults;
41
		this.setTitle(NetUIMessages.ProxyTestDialog_0);
42
		this.setHelpAvailable(false);
43
	}
44
	
45
	
46
	protected Control createDialogArea(Composite parent) {
47
		Composite composite = new Composite(parent, SWT.NONE);
48
		FillLayout fillLayout = new FillLayout();
49
		fillLayout.marginHeight = 10;
50
		fillLayout.marginWidth = 10;
51
		composite.setLayout(fillLayout);
52
		
53
		Table resultsTable = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
54
		resultsTable.setHeaderVisible(true);
55
		resultsTable.setLinesVisible(true);
56
		
57
		TableLayout tableLayout = new TableLayout();
58
		tableLayout.addColumnData(new ColumnWeightData(20, 120, true));
59
		tableLayout.addColumnData(new ColumnWeightData(20, 150, true));
60
		tableLayout.addColumnData(new ColumnWeightData(20, 150, true));
61
		tableLayout.addColumnData(new ColumnWeightData(20, 50, true));
62
		tableLayout.addColumnData(new ColumnWeightData(20, 50, true));
63
		resultsTable.setLayout(tableLayout);
64
		
65
		TableColumn providerColumn = new TableColumn(resultsTable, SWT.NONE);
66
		providerColumn.setText(NetUIMessages.ProxyTestDialog_1);	
67
		TableColumn descColumn = new TableColumn(resultsTable, SWT.NONE);
68
		descColumn.setText(NetUIMessages.ProxyTestDialog_2);	
69
		TableColumn hostColumn = new TableColumn(resultsTable, SWT.NONE);
70
		hostColumn.setText(NetUIMessages.ProxyTestDialog_3);
71
		TableColumn resultColumn = new TableColumn(resultsTable, SWT.NONE);
72
		resultColumn.setText(NetUIMessages.ProxyTestDialog_4);	
73
		TableColumn errorColumn = new TableColumn(resultsTable, SWT.NONE);
74
		errorColumn.setText(NetUIMessages.ProxyTestDialog_5);
75
		
76
		if (testResults != null) {
77
			Iterator it = testResults.iterator();
78
			while(it.hasNext()) {
79
				final IStatus s = (IStatus) it.next();
80
				TableItem item = new TableItem(resultsTable, SWT.NONE);
81
				item.setText(0, s.getPlugin());
82
				item.setText(2, s.getMessage());
83
				if (s.getSeverity() == IStatus.OK) {
84
					item.setText(3, NetUIMessages.ProxyTestDialog_6);
85
				} else {
86
					item.setText(3, NetUIMessages.ProxyTestDialog_7);
87
				}
88
				if (s.getException() != null) {
89
					TableEditor editor = new TableEditor(resultsTable);
90
					Button details = new Button(resultsTable, SWT.NONE);
91
					editor.grabHorizontal = true;
92
					details.setText(NetUIMessages.ProxyTestDialog_8);
93
					editor.setEditor(details, item, 4);
94
					details.addSelectionListener(new SelectionAdapter() {
95
						public void widgetSelected(SelectionEvent e) {
96
							MessageDialog.openInformation(getShell(), NetUIMessages.ProxyTestDialog_9, s.getException().getMessage());
97
						}
98
					});
99
				}
100
			}
101
		}
102
		resultsTable.pack();
103
		return composite;
104
	}
105
}
(-)src/org/eclipse/ui/internal/net/ProxyTester.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.internal.net.Activator;
24
import org.eclipse.core.net.proxy.IProxyTestProvider;
25
import org.eclipse.jface.dialogs.Dialog;
26
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
27
import org.eclipse.jface.operation.IRunnableWithProgress;
28
import org.eclipse.swt.events.SelectionAdapter;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Shell;
32
33
public class ProxyTester extends SelectionAdapter {
34
	
35
	private static final String EXTENSION_NAME = "org.eclipse.core.net.proxyTester"; //$NON-NLS-1$
36
	private static final String[] TEST_HOSTS = { "http://www.eclipse.org" }; //$NON-NLS-1$
37
	
38
	private List testProviders = new ArrayList();
39
	
40
	private List results;
41
42
	List getResults() {
43
		return results;
44
	}
45
	
46
	public void widgetSelected(SelectionEvent event) {
47
		final Shell shell = event.display.getActiveShell();
48
		ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
49
		try {
50
			progressDialog.run(true, true, new IRunnableWithProgress() {
51
						public void run(IProgressMonitor monitor) {
52
							execute(monitor);
53
						}
54
					});
55
		} catch (InvocationTargetException e) {
56
			Activator.logError("Exception during proxy testing", e); //$NON-NLS-1$
57
		} catch (InterruptedException e) {
58
			Activator.logError("Exception during proxy testing", e); //$NON-NLS-1$
59
		}
60
		if (results != null) {
61
			Display.getDefault().asyncExec(new Runnable() {
62
				public void run() {
63
					Dialog dialog = new ProxyTestResultDialog(shell, getResults());
64
					dialog.open();
65
				}
66
			});
67
		}
68
	}
69
70
	public void execute(IProgressMonitor monitor) {
71
		initialize();
72
		monitor.beginTask(NetUIMessages.ProxyTestDialog_10, testProviders.size() * TEST_HOSTS.length);
73
		Iterator it = testProviders.iterator();
74
		List results = new ArrayList();
75
		while (it.hasNext()) {
76
			if (monitor.isCanceled()) {
77
				return;
78
			}
79
			IProxyTestProvider test = (IProxyTestProvider) it.next();
80
			for (int i = 0; i < TEST_HOSTS.length; i++) {
81
				IStatus httpStatus = test.testConnection(TEST_HOSTS[i]);
82
				results.add(httpStatus);
83
				monitor.worked(1);
84
			}
85
		}
86
		this.results = results;
87
		monitor.done();
88
	}
89
90
	private void initialize() {
91
		testProviders.clear();
92
		IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_NAME);
93
		for (int i = 0; i < extensions.length; i++) {
94
			try {
95
				Object object = extensions[i].createExecutableExtension("class"); //$NON-NLS-1$
96
				if (object instanceof IProxyTestProvider) {
97
					testProviders.add(object);
98
				}
99
			} catch (CoreException e) {
100
				Activator.logError("Cannot initialize proxy testers", e); //$NON-NLS-1$
101
			}
102
		}
103
	}
104
	
105
}
(-)src/org/eclipse/ui/internal/net/messages.properties (-1 / +14 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
2
# Copyright (c) 2000, 2010 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 34-39 Link Here
34
ProxyPreferencePage_16=Edi&t...
34
ProxyPreferencePage_16=Edi&t...
35
ProxyPreferencePage_17=Re&move
35
ProxyPreferencePage_17=Re&move
36
ProxyPreferencePage_18=Dynamic
36
ProxyPreferencePage_18=Dynamic
37
ProxyPreferencePage_19=Test
37
38
38
ProxyEntryDialog_0=New Proxy Entry
39
ProxyEntryDialog_0=New Proxy Entry
39
ProxyEntryDialog_1=Edit Proxy Entry
40
ProxyEntryDialog_1=Edit Proxy Entry
Lines 58-60 Link Here
58
UserValidationDialog_1=Connect to: {0}
59
UserValidationDialog_1=Connect to: {0}
59
UserValidationDialog_2=&Password:
60
UserValidationDialog_2=&Password:
60
UserValidationDialog_3=&User name:
61
UserValidationDialog_3=&User name:
62
63
ProxyTestDialog_0=Proxy Test Results
64
ProxyTestDialog_1=Provider
65
ProxyTestDialog_2=Description
66
ProxyTestDialog_3=Tested host
67
ProxyTestDialog_4=Result
68
ProxyTestDialog_5=Error
69
ProxyTestDialog_6=Success
70
ProxyTestDialog_7=Fail
71
ProxyTestDialog_8=Details
72
ProxyTestDialog_9=Error Details
73
ProxyTestDialog_10=Testing proxy settings...

Return to bug 299020