diff options
author | Michael Valenta | 2007-02-19 16:10:50 +0000 |
---|---|---|
committer | Michael Valenta | 2007-02-19 16:10:50 +0000 |
commit | ec9e1a92c0ccb03f6da49ceba984c878366c5e77 (patch) | |
tree | 13854a54af938eb798ede1651ab523aea2904956 /bundles | |
parent | a809daca8e35b07e70a75a9d46ccc9121fb329c4 (diff) | |
download | eclipse.platform.team-ec9e1a92c0ccb03f6da49ceba984c878366c5e77.tar.gz eclipse.platform.team-ec9e1a92c0ccb03f6da49ceba984c878366c5e77.tar.xz eclipse.platform.team-ec9e1a92c0ccb03f6da49ceba984c878366c5e77.zip |
Bug 154100 Platform level proxy settings
Diffstat (limited to 'bundles')
19 files changed, 1536 insertions, 0 deletions
diff --git a/bundles/org.eclipse.ui.net/.classpath b/bundles/org.eclipse.ui.net/.classpath new file mode 100644 index 000000000..ce7393340 --- /dev/null +++ b/bundles/org.eclipse.ui.net/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/bundles/org.eclipse.ui.net/.cvsignore b/bundles/org.eclipse.ui.net/.cvsignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/bundles/org.eclipse.ui.net/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/bundles/org.eclipse.ui.net/.project b/bundles/org.eclipse.ui.net/.project new file mode 100644 index 000000000..3269c643e --- /dev/null +++ b/bundles/org.eclipse.ui.net/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.net.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/bundles/org.eclipse.ui.net/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.ui.net/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..a10563e70 --- /dev/null +++ b/bundles/org.eclipse.ui.net/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,73 @@ +#Mon Feb 19 11:07:17 EST 2007 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.autoboxing=error +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.problem.fallthroughCase=error +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=error +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error +org.eclipse.jdt.core.compiler.problem.nullReference=error +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=error +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error +org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled +org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,NORMAL +org.eclipse.jdt.core.compiler.taskTags=TODO,XXX diff --git a/bundles/org.eclipse.ui.net/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.net/META-INF/MANIFEST.MF new file mode 100644 index 000000000..13aa27687 --- /dev/null +++ b/bundles/org.eclipse.ui.net/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %PLUGIN_NAME +Bundle-SymbolicName: org.eclipse.net.ui; singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.net.internal.ui.Activator +Bundle-Vendor: %PLUGIN_PROVIDER +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui;bundle-version="[3.3.0,4.0.0)", + org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)", + org.eclipse.net.core;bundle-version="[1.0.0,2.0.0)" +Eclipse-LazyStart: true +Bundle-RequiredExecutionEnvironment: J2SE-1.4, + CDC-1.0/Foundation-1.0, + J2SE-1.3 diff --git a/bundles/org.eclipse.ui.net/build.properties b/bundles/org.eclipse.ui.net/build.properties new file mode 100644 index 000000000..29d3da55f --- /dev/null +++ b/bundles/org.eclipse.ui.net/build.properties @@ -0,0 +1,10 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + plugin.xml +src.includes = META-INF/,\ + plugin.properties,\ + plugin.xml,\ + src/ diff --git a/bundles/org.eclipse.ui.net/plugin.properties b/bundles/org.eclipse.ui.net/plugin.properties new file mode 100644 index 000000000..e967e617f --- /dev/null +++ b/bundles/org.eclipse.ui.net/plugin.properties @@ -0,0 +1,20 @@ +############################################################################### +# Copyright (c) 2000, 2007 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +# yyyymmdd bug Email and other contact information +# -------- -------- ----------------------------------------------------------- +# 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. +############################################################################### + +# +# Messages in plugin.xml. +# +PLUGIN_NAME=Internet Connection Management UI +PLUGIN_PROVIDER=Eclipse.org +PLUGIN_INTERNET_PREFERENCE_TITLE=Network Connections diff --git a/bundles/org.eclipse.ui.net/plugin.xml b/bundles/org.eclipse.ui.net/plugin.xml new file mode 100644 index 000000000..df8edd818 --- /dev/null +++ b/bundles/org.eclipse.ui.net/plugin.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<plugin> + + <extension point="org.eclipse.ui.preferencePages"> + <page + id = "org.eclipse.net.ui.NetPreferences" + class = "org.eclipse.net.internal.ui.ProxyPreferencePage" + category = "org.eclipse.ui.preferencePages.Workbench" + name = "%PLUGIN_INTERNET_PREFERENCE_TITLE"/> + </extension> + +</plugin> diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/Activator.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/Activator.java new file mode 100644 index 000000000..ca4ad0bf7 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/Activator.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. + *******************************************************************************/ +package org.eclipse.net.internal.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin +{ + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.net.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NetUIMessages.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NetUIMessages.java new file mode 100644 index 000000000..b23bc4c45 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NetUIMessages.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. + *******************************************************************************/ +package org.eclipse.net.internal.ui; + +import org.eclipse.osgi.util.NLS; + +public final class NetUIMessages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.net.internal.ui.messages";//$NON-NLS-1$ + + private NetUIMessages() { + // Do not instantiate + } + + public static String BUTTON_PREFERENCE_ADD; + public static String BUTTON_PREFERENCE_EDIT; + public static String BUTTON_PREFERENCE_REMOVE; + public static String InternetCategoryPage_0; + public static String InternetCategoryPage_1; +public static String ProxyPreferencePage_0; +public static String ProxyPreferencePage_1; + public static String ProxyPreferencePage_2; + public static String ProxyPreferencePage_22; +public static String ProxyPreferencePage_23; +public static String ProxyPreferencePage_24; +public static String ProxyPreferencePage_25; +public static String ProxyPreferencePage_26; +public static String ProxyPreferencePage_27; + public static String ProxyPreferencePage_3; +public static String ProxyPreferencePage_37; +public static String ProxyPreferencePage_38; +public static String ProxyPreferencePage_39; + public static String ProxyPreferencePage_4; + public static String ProxyPreferencePage_5; + public static String ProxyPreferencePage_6; + public static String ProxyPreferencePage_7; + public static String ProxyPreferencePage_8; + public static String ProxyPreferencePage_9; + public static String TITLE_PREFERENCE_HOSTS_DIALOG; + public static String LABEL_PREFERENCE_HOSTS_DIALOG; +public static String UserValidationDialog_0; +public static String UserValidationDialog_1; +public static String UserValidationDialog_2; +public static String UserValidationDialog_3; + + static { + NLS.initializeMessages(BUNDLE_NAME, NetUIMessages.class); + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsComposite.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsComposite.java new file mode 100644 index 000000000..7d113b85d --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsComposite.java @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20060217 127138 pmoogk@ca.ibm.com - Peter Moogk + * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. + *******************************************************************************/ + +package org.eclipse.net.internal.ui; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.TreeSet; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +/** + * This class is the Composite that consists of the controls for + * "http.nonProxyHosts" and is used by InternetPreferencesPage. + */ +public class NonProxyHostsComposite extends Composite +{ + private Table table_; + TableViewer tableViewer_; + private TreeSet tableValues_; + + private Button add_; + private Button edit_; + private Button remove_; + + public NonProxyHostsComposite(Composite parent, int style ) + { + super(parent, style); + createWidgets(); + } + + public void enableComposite( boolean enabled ) + { + table_.setEnabled( enabled ); + add_.setEnabled( enabled ); + edit_.setEnabled( enabled ); + remove_.setEnabled( enabled ); + } + + protected void createWidgets() + { + GridLayout layout = new GridLayout(); + layout.horizontalSpacing = 6; + layout.verticalSpacing = 6; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.numColumns = 2; + setLayout(layout); + + table_ = new Table(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); + GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); + + table_.setLayoutData(data); + table_.setHeaderVisible(false); + table_.setLinesVisible(true); + + TableLayout tableLayout = new TableLayout(); + + new TableColumn(table_, SWT.NONE); + ColumnWeightData colData = new ColumnWeightData(100, 60, false); + tableLayout.addColumnData(colData); + + table_.setLayout(tableLayout); + + tableViewer_ = new TableViewer(table_); + tableViewer_.setContentProvider(new NonProxyHostsContentProvider()); + tableViewer_.setLabelProvider(new NonProxyHostsLabelProvider()); + + tableViewer_.addSelectionChangedListener(new ISelectionChangedListener() + { + public void selectionChanged(SelectionChangedEvent event) + { + enableButtons(); + } + }); + + Composite buttonComp = new Composite(this, SWT.NONE); + layout = new GridLayout(); + layout.horizontalSpacing = 0; + layout.verticalSpacing = 8; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.numColumns = 1; + buttonComp.setLayout(layout); + data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL); + buttonComp.setLayoutData(data); + + add_ = createButton( buttonComp, NetUIMessages.BUTTON_PREFERENCE_ADD ); + + add_.addSelectionListener(new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + InputDialog dialog = new InputDialog( getShell(), + NetUIMessages.TITLE_PREFERENCE_HOSTS_DIALOG, + NetUIMessages.LABEL_PREFERENCE_HOSTS_DIALOG, + "", //$NON-NLS-1$ + null ); + + if (dialog.open() != Window.CANCEL) + { + updateList( dialog.getValue() ); + } + } + }); + + edit_ = createButton(buttonComp, NetUIMessages.BUTTON_PREFERENCE_EDIT ); + + edit_.addSelectionListener(new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + IStructuredSelection selection = (IStructuredSelection)tableViewer_.getSelection(); + String selectedHosts = getStringList( selection.iterator() ); + + InputDialog dialog = new InputDialog( getShell(), + NetUIMessages.TITLE_PREFERENCE_HOSTS_DIALOG, + NetUIMessages.LABEL_PREFERENCE_HOSTS_DIALOG, + selectedHosts, + null ); + + if (dialog.open() != Window.CANCEL) + { + removeFromList( selection ); + updateList( dialog.getValue() ); + } + } + }); + edit_.setEnabled(false); + + remove_ = createButton(buttonComp, NetUIMessages.BUTTON_PREFERENCE_REMOVE); + + remove_.addSelectionListener(new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + removeFromList( (IStructuredSelection)tableViewer_.getSelection() ); + tableViewer_.refresh(); + } + }); + remove_.setEnabled(false); + } + + private Button createButton(Composite comp, String label) + { + Button button = new Button(comp, SWT.PUSH); + button.setText(label); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); + button.setLayoutData(data); + return button; + } + + /* (non-Javadoc) + * @see org.eclipse.swt.widgets.Control#setEnabled(boolean) + */ + public void setEnabled(boolean enabled) + { + super.setEnabled(enabled); + enableButtons(); + } + + public void setList( String[] hosts ) + { + tableValues_ = new TreeSet( Arrays.asList( hosts ) ); + + tableViewer_.setInput( tableValues_ ); + tableViewer_.refresh(); + } + + public String[] getList() + { + return (String[])tableValues_.toArray( new String[0] ); + } + + String getStringList( Iterator iterator ) + { + StringBuffer buffer = new StringBuffer(); + + if( iterator.hasNext() ) + { + buffer.append( (String)iterator.next() ); + } + + while( iterator.hasNext() ) + { + buffer.append( ',' ); + buffer.append( (String)iterator.next() ); + } + + return buffer.toString(); + } + + void removeFromList( IStructuredSelection selection ) + { + tableValues_.removeAll( selection.toList() ); + } + + void updateList( String value ) + { + // Split the string with a delimiter of either a vertical bar, a space, + // or a comma. + String[] hosts = value.split( "\\|| |," ); //$NON-NLS-1$ + + tableValues_.addAll( Arrays.asList( hosts ) ); + tableValues_.remove( "" ); //$NON-NLS-1$ + tableViewer_.refresh(); + } + + void enableButtons() + { + boolean enabled = getEnabled(); + + if( enabled ) + { + boolean itemsSelected = !tableViewer_.getSelection().isEmpty(); + + add_.setEnabled( true ); + edit_.setEnabled( itemsSelected ); + remove_.setEnabled( itemsSelected ); + } + else + { + add_.setEnabled( false ); + edit_.setEnabled( false ); + remove_.setEnabled( false ); + } + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsContentProvider.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsContentProvider.java new file mode 100644 index 000000000..fa0691564 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsContentProvider.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. + *******************************************************************************/ + +package org.eclipse.net.internal.ui; + +import java.util.Collection; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * Monitor content provider. + */ +public class NonProxyHostsContentProvider implements IStructuredContentProvider +{ + /** + * MonitorContentProvider constructor comment. + */ + public NonProxyHostsContentProvider() + { + super(); + } + + /* + * Disposes of this content provider. + */ + public void dispose() + { + // do nothing + } + + /* + * Returns the elements to display in the viewer + * when its input is set to the given element. + */ + public Object[] getElements(Object inputElement) + { + Collection coll = (Collection)inputElement; + + return coll.toArray( new String[0] ); + } + + /* + * Notifies this content provider that the given viewer's input + * has been switched to a different element. + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) + { + // do nothing + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsLabelProvider.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsLabelProvider.java new file mode 100644 index 000000000..5001dfb7f --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/NonProxyHostsLabelProvider.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. + *******************************************************************************/ + +package org.eclipse.net.internal.ui; + +import org.eclipse.jface.viewers.ILabelProviderListener; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.viewers.ITableLabelProvider; + +/** + * Monitor table label provider. + */ +public class NonProxyHostsLabelProvider implements ITableLabelProvider +{ + /** + * MonitorTableLabelProvider constructor comment. + */ + public NonProxyHostsLabelProvider() + { + super(); + } + + /** + * Adds a listener to this label provider. + * Has no effect if an identical listener is already registered. + * <p> + * Label provider listeners are informed about state changes + * that affect the rendering of the viewer that uses this label provider. + * </p> + * + * @param listener a label provider listener + */ + public void addListener(ILabelProviderListener listener) + { + // do nothing + } + + /** + * Disposes of this label provider. When a label provider is + * attached to a viewer, the viewer will automatically call + * this method when the viewer is being closed. When label providers + * are used outside of the context of a viewer, it is the client's + * responsibility to ensure that this method is called when the + * provider is no longer needed. + */ + public void dispose() + { + // do nothing + } + + /** + * Returns the label image for the given column of the given element. + * + * @param element the object representing the entire row, or + * <code>null</code> indicating that no input object is set + * in the viewer + * @param columnIndex the zero-based index of the column in which + * the label appears + */ + public Image getColumnImage(Object element, int columnIndex) + { + return null; + } + + /** + * Returns the label text for the given column of the given element. + * + * @param element the object representing the entire row, or + * <code>null</code> indicating that no input object is set + * in the viewer + * @param columnIndex the zero-based index of the column in which the label appears + */ + public String getColumnText(Object element, int columnIndex) + { + return (String)element; + } + + /** + * Returns whether the label would be affected + * by a change to the given property of the given element. + * This can be used to optimize a non-structural viewer update. + * If the property mentioned in the update does not affect the label, + * then the viewer need not update the label. + * + * @param element the element + * @param property the property + * @return <code>true</code> if the label would be affected, + * and <code>false</code> if it would be unaffected + */ + public boolean isLabelProperty(Object element, String property) + { + return false; + } + + /** + * Removes a listener to this label provider. + * Has no affect if an identical listener is not registered. + * + * @param listener a label provider listener + */ + public void removeListener(ILabelProviderListener listener) + { + // do nothing + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/ProxyPreferencePage.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/ProxyPreferencePage.java new file mode 100644 index 000000000..de4292c75 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/ProxyPreferencePage.java @@ -0,0 +1,475 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20070123 154100 eu@md.pp.ru - Eugene Kuleshov, Initial UI coding + * 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. + *******************************************************************************/ +package org.eclipse.net.internal.ui; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.net.core.IProxyData; +import org.eclipse.net.core.NetCore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class ProxyPreferencePage extends PreferencePage implements + IWorkbenchPreferencePage { + IProxyData[] proxyData; + + Entry[] entryList; + + Button directConnectionToButton; + + private Button manualProxyConfigurationButton; + + Button useSameProxyButton; + + private Text nonHostLabel; + + private NonProxyHostsComposite nonHostComposite; + + Button enableProxyAuth; + + private Label useridLabel; + + private Label passwordLabel; + + Text userid; + + Text password; + + public ProxyPreferencePage() { + super(NetUIMessages.ProxyPreferencePage_2); + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + public void init(IWorkbench workbench) { + // Nothing to do + } + + protected Control createContents(Composite parent) { + + proxyData = NetCore.getProxyManager().getProxyData(); + entryList = new Entry[proxyData.length]; + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginRight = 5; + layout.marginTop = 5; + layout.marginWidth = 0; + composite.setLayout(layout); + GridData data = new GridData(GridData.FILL_BOTH); + composite.setLayoutData(data); + + directConnectionToButton = new Button(composite, SWT.RADIO); + directConnectionToButton.setLayoutData(new GridData()); + directConnectionToButton.setText(NetUIMessages.ProxyPreferencePage_3); + directConnectionToButton + .setToolTipText(NetUIMessages.ProxyPreferencePage_1); + directConnectionToButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + enableControls(!directConnectionToButton.getSelection()); + } + }); + + manualProxyConfigurationButton = new Button(composite, SWT.RADIO); + manualProxyConfigurationButton + .setText(NetUIMessages.ProxyPreferencePage_4); + manualProxyConfigurationButton + .setToolTipText(NetUIMessages.ProxyPreferencePage_0); + + final Composite manualProxyConfigurationComposite = new Composite( + composite, SWT.NONE); + final GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + gridLayout.numColumns = 4; + manualProxyConfigurationComposite.setLayout(gridLayout); + final GridData gridData_2 = new GridData(); + gridData_2.horizontalIndent = 17; + manualProxyConfigurationComposite.setLayoutData(gridData_2); + + addProtocolEntry(manualProxyConfigurationComposite, 0); + + new Label(manualProxyConfigurationComposite, SWT.NONE); + useSameProxyButton = new Button(manualProxyConfigurationComposite, + SWT.CHECK); + useSameProxyButton.setText(NetUIMessages.ProxyPreferencePage_5); + GridData gridData = new GridData(); + gridData.horizontalSpan = 3; + useSameProxyButton.setLayoutData(gridData); + useSameProxyButton + .setToolTipText(NetUIMessages.ProxyPreferencePage_23); + useSameProxyButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + handleUseSameProtocol(false); + } + }); + + for (int index = 1; index < proxyData.length; index++) { + addProtocolEntry(manualProxyConfigurationComposite, index); + } + + Label separator = new Label(manualProxyConfigurationComposite, + SWT.HORIZONTAL | SWT.SEPARATOR); + separator.setLayoutData(newGridData(4, 5, true, false)); + nonHostLabel = new Text(manualProxyConfigurationComposite, + SWT.READ_ONLY); + nonHostLabel.setText(NetUIMessages.ProxyPreferencePage_6); + nonHostLabel + .setToolTipText(NetUIMessages.ProxyPreferencePage_24); + nonHostLabel.setLayoutData(newGridData(4, 5, true, false)); + nonHostComposite = new NonProxyHostsComposite( + manualProxyConfigurationComposite, SWT.NONE); + nonHostComposite.setLayoutData(newGridData(4, -1, true, false)); + + Label separator2 = new Label(manualProxyConfigurationComposite, + SWT.HORIZONTAL | SWT.SEPARATOR); + separator2.setLayoutData(newGridData(4, 5, true, false)); + enableProxyAuth = new Button(manualProxyConfigurationComposite, + SWT.CHECK); + enableProxyAuth.setText(NetUIMessages.ProxyPreferencePage_7); + enableProxyAuth.setLayoutData(newGridData(4, 5, true, false)); + enableProxyAuth + .setToolTipText(NetUIMessages.ProxyPreferencePage_25); + enableProxyAuth.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + enableUseridPassword(enableProxyAuth.getSelection()); + } + }); + + final Composite userIdPassword = new Composite( + manualProxyConfigurationComposite, SWT.NONE); + GridLayout layout2 = new GridLayout(2, false); + layout2.marginWidth = 0; + layout2.marginHeight = 0; + userIdPassword.setLayoutData(newGridData(4, -1, true, false)); + userIdPassword.setLayout(layout2); + + useridLabel = new Label(userIdPassword, SWT.NONE); + useridLabel.setText(NetUIMessages.ProxyPreferencePage_8); + userid = new Text(userIdPassword, SWT.BORDER); + passwordLabel = new Label(userIdPassword, SWT.NONE); + passwordLabel.setText(NetUIMessages.ProxyPreferencePage_9); + password = new Text(userIdPassword, SWT.BORDER); + + userid.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + userid.setToolTipText(NetUIMessages.ProxyPreferencePage_26); + password.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + password.setToolTipText(NetUIMessages.ProxyPreferencePage_27); + password.setEchoChar('*'); + + restoreState(NetCore.getProxyManager().isProxiesEnabled()); + applyDialogFont(composite); + + return composite; + } + + protected void performApply() { + boolean proxiesEnabled = manualProxyConfigurationButton.getSelection(); + + // Save the contents of the text fields to the proxy data. + for (int index = 0; index < entryList.length; index++) { + entryList[index].applyValues(); + } + + NetCore.getProxyManager().setProxiesEnabled(proxiesEnabled); + if (proxiesEnabled) { + NetCore.getProxyManager().setProxyData(proxyData); + NetCore.getProxyManager().setNonProxiedHosts( + nonHostComposite.getList()); + } + Activator.getDefault().savePluginPreferences(); + } + + protected void performDefaults() { + directConnectionToButton.setSelection(true); + manualProxyConfigurationButton.setSelection(false); + useSameProxyButton.setSelection(false); + enableProxyAuth.setSelection(false); + + for (int index = 0; index < entryList.length; index++) { + Entry entry = entryList[index]; + + entry.hostname.setText(""); //$NON-NLS-1$ + entry.port.setText(""); //$NON-NLS-1$ + entry.prevHostname = ""; //$NON-NLS-1$ + entry.prevPort = -1; + } + + nonHostComposite.setList(new String[] { "localhost", "127.0.0.1" }); //$NON-NLS-1$ //$NON-NLS-2$ + userid.setText(""); //$NON-NLS-1$ + password.setText(""); //$NON-NLS-1$ + enableControls(false); + } + + public boolean performOk() { + performApply(); + return super.performOk(); + } + + /** + * This method is run once when when this preference page is displayed. It + * will restore the state of this page using previously saved preferences. + * + * @param proxiesEnabled indicates if manual proxies are enabled or not. + */ + private void restoreState(boolean proxiesEnabled) { + + directConnectionToButton.setSelection(!proxiesEnabled); + manualProxyConfigurationButton.setSelection(proxiesEnabled); + + String[] nonHostLists = NetCore.getProxyManager().getNonProxiedHosts(); + this.nonHostComposite.setList(nonHostLists == null ? new String[] { + "localhost", "127.0.0.1" } : nonHostLists); //$NON-NLS-1$ //$NON-NLS-2$ + if (!proxiesEnabled) { + this.useSameProxyButton.setSelection(false); + this.enableProxyAuth.setSelection(false); + this.userid.setText(""); //$NON-NLS-1$ + this.password.setText(""); //$NON-NLS-1$ + } else { + boolean useSameProtocol = true; + for (int i = 1; i < proxyData.length; i++) { + IProxyData data = proxyData[i]; + boolean same = (hostsEqual(data.getHost(), proxyData[0] + .getHost()) && portsEqual(data.getPort(), proxyData[0] + .getPort())); + if (!same) { + useSameProtocol = false; + break; + } + } + this.useSameProxyButton.setSelection(useSameProtocol); + IProxyData data = entryList[0].getProxy(); + this.enableProxyAuth.setSelection(data.isRequiresAuthentication()); + this.userid.setText(data.getUserId() == null ? "" : data //$NON-NLS-1$ + .getUserId()); + this.password.setText(data.getPassword() == null ? "" : data //$NON-NLS-1$ + .getPassword()); + + // TODO: Why does this loop from 1 and not 0? + for (int index = 1; index < entryList.length; index++) { + entryList[index].restoreValues(); + } + } + + enableControls(proxiesEnabled); + handleUseSameProtocol(true); + } + + private boolean portsEqual(int port1, int port2) { + return port1 == port2; + } + + private boolean hostsEqual(String host1, String host2) { + if (host1 == host2) + // If there are no hosts, don't enable the use same hosts button + return false; + if (host1 == null || host2 == null) + return false; + return host1.equals(host2); + } + + void enableControls(boolean enabled) { + for (int index = 0; index < entryList.length; index++) { + Entry entry = entryList[index]; + + entry.hostname.setEnabled(enabled); + entry.nameLabel.setEnabled(enabled); + entry.portLabel.setEnabled(enabled); + entry.port.setEnabled(enabled); + } + + useSameProxyButton.setEnabled(enabled); + nonHostLabel.setEnabled(enabled); + nonHostComposite.enableComposite(enabled); + enableProxyAuth.setEnabled(enabled); + + enableUseridPassword(enableProxyAuth.getSelection() && enabled); + } + + void enableUseridPassword(boolean enabled) { + useridLabel.setEnabled(enabled); + userid.setEnabled(enabled); + passwordLabel.setEnabled(enabled); + password.setEnabled(enabled); + } + + void handleUseSameProtocol(boolean init) { + String httpHostname = entryList[0].hostname.getText(); + String httpPort = entryList[0].port.getText(); + boolean proxiesEnabled = manualProxyConfigurationButton.getSelection(); + boolean useSameProtocol = useSameProxyButton.getSelection(); + boolean controlEnabled = proxiesEnabled && !useSameProtocol; + + for (int index = 1; index < entryList.length; index++) { + Entry entry = entryList[index]; + + entry.hostname.setEnabled(controlEnabled); + entry.nameLabel.setEnabled(controlEnabled); + entry.portLabel.setEnabled(controlEnabled); + entry.port.setEnabled(controlEnabled); + + if (useSameProtocol) { + if (!init) { + entry.prevHostname = entry.hostname.getText(); + try { + entry.prevPort = Integer.parseInt(entry.port.getText()); + } catch (NumberFormatException e) { + entry.prevPort = -1; + } + } + + entry.hostname.setText(httpHostname); + entry.port.setText(httpPort); + } else { + if (!init) { + entry.hostname.setText(entry.prevHostname); + entry.port.setText(entry.prevPort == -1 ? "" : String //$NON-NLS-1$ + .valueOf(entry.prevPort)); + } + } + } + } + + private void addProtocolEntry(Composite parent, int index) { + Entry entry = new Entry(index); + GridData gridData = null; + IProxyData proxy = entry.getProxy(); + String name = getLabel(proxy); + + String hostname = proxy.getHost(); + if (hostname == null) { + hostname = ""; //$NON-NLS-1$ + } + + int portInt = proxy.getPort(); + String port; + if (portInt == -1) { + port = ""; //$NON-NLS-1$ + } else { + port = String.valueOf(portInt); + } + + entry.nameLabel = new Label(parent, SWT.NONE); + entry.nameLabel.setText(name); + + entry.hostname = new Text(parent, SWT.BORDER); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 120; + entry.hostname.setLayoutData(gridData); + entry.hostname.setText(hostname); + + entry.portLabel = new Label(parent, SWT.NONE); + entry.portLabel.setText(NetUIMessages.ProxyPreferencePage_22); + + entry.port = new Text(parent, SWT.BORDER); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = 50; + entry.port.setLayoutData(gridData); + entry.port.setText(port); + entryList[index] = entry; + } + + private String getLabel(IProxyData data) { + if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { + return NetUIMessages.ProxyPreferencePage_37; + } + if (data.getType().equals(IProxyData.HTTPS_PROXY_TYPE)) { + return NetUIMessages.ProxyPreferencePage_38; + } + if (data.getType().equals(IProxyData.SOCKS_PROXY_TYPE)) { + return NetUIMessages.ProxyPreferencePage_39; + } + return ""; //$NON-NLS-1$ + } + + private GridData newGridData(int span, int verticalIndent, + boolean horizontal, boolean vertical) { + int style = 0; + + style |= horizontal ? GridData.FILL_HORIZONTAL : 0; + style |= vertical ? GridData.FILL_VERTICAL : 0; + + GridData gridData = new GridData(style); + + if (span != -1) { + gridData.horizontalSpan = span; + } + + if (verticalIndent != -1) { + gridData.verticalIndent = verticalIndent; + } + + return gridData; + } + + private class Entry { + Label nameLabel; + + Text hostname; + + String prevHostname; + + Label portLabel; + + Text port; + + int prevPort; + + private int proxyIndex; + + public Entry(int index) { + this.proxyIndex = index; + } + + public IProxyData getProxy() { + return proxyData[proxyIndex]; + } + + public void restoreValues() { + IProxyData proxy = getProxy(); + prevHostname = proxy.getHost(); + prevPort = proxy.getPort(); + } + + public void applyValues() { + IProxyData proxy = getProxy(); + boolean enableAuth = enableProxyAuth.getSelection(); + + String hostString; + String portString; + if (useSameProxyButton.getSelection()) { + hostString = entryList[0].hostname.getText(); + portString = entryList[0].port.getText(); + } else { + hostString = hostname.getText(); + portString = port.getText(); + } + proxy.setHost(hostString); + try { + int port = Integer.valueOf(portString).intValue(); + proxy.setPort(port); + } catch (NumberFormatException e) { + proxy.setPort(-1); + } + proxy.setUserid(enableAuth ? userid.getText() : null); + proxy.setPassword(enableAuth ? password.getText() : null); + } + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/Authentication.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/Authentication.java new file mode 100644 index 000000000..0ad270e9b --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/Authentication.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.net.internal.ui.auth; + +/** + * Keeps user and password strings. + */ +public class Authentication { + protected String user; + protected String password; + public Authentication(String user, String password){ + this.user = user; + this.password = password; + } + + /** + * @return Returns the password. + */ + public String getPassword() { + return password; + } + /** + * @return Returns the user. + */ + public String getUser() { + return user; + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/NetAuthenticator.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/NetAuthenticator.java new file mode 100644 index 000000000..e32fc0f75 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/NetAuthenticator.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.net.internal.ui.auth; + +import java.net.*; + +public class NetAuthenticator extends Authenticator { + + /* + * @see Authenticator#getPasswordAuthentication() + */ + protected PasswordAuthentication getPasswordAuthentication() { + // String protocol = getRequestingProtocol(); + InetAddress address = getRequestingSite(); // can be null; + // int port = getRequestingPort(); + String prompt = getRequestingPrompt(); // realm or message, not documented that can be null + // String scheme = getRequestingScheme(); // not documented that can be null + + // get the host name from the address since #getRequestingHost + // is not available in the foundation 1.0 class libraries + String hostString = null; + if (address != null) { + hostString = address.getHostName(); + } + if (hostString == null) { + hostString = ""; //$NON-NLS-1$ + } + String promptString = prompt; + if (prompt == null) { + promptString = ""; //$NON-NLS-1$ + } + + Authentication auth = UserValidationDialog.getAuthentication( + hostString, promptString); + if (auth != null) + return new PasswordAuthentication(auth.getUser(), auth + .getPassword().toCharArray()); + else + return null; + } +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/UserValidationDialog.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/UserValidationDialog.java new file mode 100644 index 000000000..1c6eb5272 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/auth/UserValidationDialog.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.net.internal.ui.auth; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.net.internal.ui.NetUIMessages; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.PlatformUI; + +/** + * User authentication dialog + */ +public class UserValidationDialog extends Dialog { + protected Text usernameField; + protected Text passwordField; + + protected String host; + protected String message; + protected Authentication userAuthentication = null; + /** + * Gets user and password from a user. May be called from any thread + * @param host the host name + * @param message the message to be displayed when prompting + * + * @return UserAuthentication that contains the userid and the password or + * <code>null</code> if the dialog has been cancelled + */ + public static Authentication getAuthentication(final String host, + final String message) { + class UIOperation implements Runnable { + public Authentication authentication; + public void run() { + authentication = UserValidationDialog.askForAuthentication( + host, message); + } + } + + UIOperation uio = new UIOperation(); + if (Display.getCurrent() != null) { + uio.run(); + } else { + Display.getDefault().syncExec(uio); + } + return uio.authentication; + } + /** + * Gets user and password from a user Must be called from UI thread + * + * @return UserAuthentication that contains the userid and the password or + * <code>null</code> if the dialog has been cancelled + */ + protected static Authentication askForAuthentication(String host, + String message) { + UserValidationDialog ui = new UserValidationDialog(null, host, message); + ui.open(); + return ui.getAuthentication(); + } + /** + * Creates a new UserValidationDialog. + * + * @param parentShell + * parent Shell or null + */ + protected UserValidationDialog(Shell parentShell, String host, + String message) { + super(parentShell); + this.host = host; + this.message = message; + setBlockOnOpen(true); + } + /** + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(NetUIMessages.UserValidationDialog_0); + } + /** + */ + public void create() { + super.create(); + //give focus to username field + usernameField.selectAll(); + usernameField.setFocus(); + } + /** + */ + protected Control createDialogArea(Composite parent) { + Composite main = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label label = new Label(main, SWT.WRAP); + String text = NLS.bind(NetUIMessages.UserValidationDialog_1, host); + text += "\n\n" + message; //$NON-NLS-1$ + label.setText(text); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + label.setLayoutData(data); + + createUsernameFields(main); + createPasswordFields(main); + PlatformUI.getWorkbench().getHelpSystem().setHelp(main, + "org.eclipse.update.ui.UserValidationDialog"); //$NON-NLS-1$ + return main; + } + /** + * Creates the three widgets that represent the user name entry area. + */ + protected void createPasswordFields(Composite parent) { + new Label(parent, SWT.NONE).setText(NetUIMessages.UserValidationDialog_2); + + passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + passwordField.setLayoutData(data); + + new Label(parent, SWT.NONE); //spacer + } + /** + * Creates the three widgets that represent the user name entry area. + */ + protected void createUsernameFields(Composite parent) { + new Label(parent, SWT.NONE).setText(NetUIMessages.UserValidationDialog_3); + + usernameField = new Text(parent, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + usernameField.setLayoutData(data); + + new Label(parent, SWT.NONE); //spacer + } + /** + * Returns the UserAuthentication entered by the user, or null if the user + * canceled. + * @return the authentication information + */ + public Authentication getAuthentication() { + return userAuthentication; + } + /** + * Notifies that the ok button of this dialog has been pressed. + */ + protected void okPressed() { + userAuthentication = new Authentication(usernameField.getText(), + passwordField.getText()); + super.okPressed(); + } + +} diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/messages.properties b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/messages.properties new file mode 100644 index 000000000..e25fae0d8 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/internal/ui/messages.properties @@ -0,0 +1,46 @@ +############################################################################### +# Copyright (c) 2000, 2007 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +# yyyymmdd bug Email and other contact information +# -------- -------- ----------------------------------------------------------- +# 20070201 154100 pmoogk@ca.ibm.com - Peter Moogk, Port internet code from WTP to Eclipse base. +############################################################################### + +# +# Messages in InternetPreferencePage +# +BUTTON_PREFERENCE_ADD=Add... +BUTTON_PREFERENCE_EDIT=Edit... +BUTTON_PREFERENCE_REMOVE=Remove +TITLE_PREFERENCE_HOSTS_DIALOG=Non Proxy host names +LABEL_PREFERENCE_HOSTS_DIALOG=Enter host names separated by a vertical bar, space, or comma. + +ProxyPreferencePage_2=Proxy Preferences +ProxyPreferencePage_3=Direct connection to the Internet +ProxyPreferencePage_4=Manual proxy configuration: +ProxyPreferencePage_5=Use this proxy server for all protocols +ProxyPreferencePage_6=No Proxy for: +ProxyPreferencePage_7=Enable proxy authentication: +ProxyPreferencePage_8=Userid: +ProxyPreferencePage_9=Password: +ProxyPreferencePage_1=Specifies that no configuration is needed to access the internet. +ProxyPreferencePage_0=Specifies that a proxy server is required to access the internet. +ProxyPreferencePage_22=Port: +ProxyPreferencePage_23=Specifies that the HTTP protocol settings should be used for the protocols below. +ProxyPreferencePage_24=Specifies which hosts should not be routed via a proxy server. +ProxyPreferencePage_25=Specifies that basic authentication is required. +ProxyPreferencePage_26=Specifies the basic authentication userid. +ProxyPreferencePage_27=Specifies the basic authentication password +ProxyPreferencePage_37=&HTTP proxy: +ProxyPreferencePage_38=&SSL proxy: +ProxyPreferencePage_39=S&OCKS proxy: +UserValidationDialog_0=Password Required +UserValidationDialog_1=Connect to: {0} +UserValidationDialog_2=&Password: +UserValidationDialog_3=&User name: diff --git a/bundles/org.eclipse.ui.net/src/org/eclipse/net/ui/NetUI.java b/bundles/org.eclipse.ui.net/src/org/eclipse/net/ui/NetUI.java new file mode 100644 index 000000000..575528524 --- /dev/null +++ b/bundles/org.eclipse.ui.net/src/org/eclipse/net/ui/NetUI.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.net.ui; + +import java.net.Authenticator; + +import org.eclipse.net.core.*; +import org.eclipse.net.internal.ui.auth.NetAuthenticator; + +/** + * Provides access to the UI functionality associated with networking. + * <p> + * This class is not intended to be subclasses or instantiated by clients. + * @since 1.0 + */ +public final class NetUI { + + private NetUI() { + super(); + } + + /** + * Method to be called by the application to ensure that the Java system + * properties related to proxies are set along with the default {@link Authenticator}. + */ + public static void initialize() { + // Prime the core to set the system properties + NetCore.getProxyManager(); + // Set the authenticator + Authenticator.setDefault(new NetAuthenticator()); + } + +} |