diff options
author | Pascal Rapicault | 2009-09-08 14:53:56 +0000 |
---|---|---|
committer | Pascal Rapicault | 2009-09-08 14:53:56 +0000 |
commit | 04cf4a74c1c1a8f7adab47b3bd87d8f2ddac4045 (patch) | |
tree | 5f8591ee4efee2d4a15c2839902fab873708a8e4 /bundles/org.eclipse.equinox.p2.installer | |
parent | 131e203694916971bc5224539edccab21698815f (diff) | |
download | rt.equinox.p2-04cf4a74c1c1a8f7adab47b3bd87d8f2ddac4045.tar.gz rt.equinox.p2-04cf4a74c1c1a8f7adab47b3bd87d8f2ddac4045.tar.xz rt.equinox.p2-04cf4a74c1c1a8f7adab47b3bd87d8f2ddac4045.zip |
Bug 288664 - [installer] Extension of P2 Installer for full proxy support
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.installer')
4 files changed, 419 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/Messages.java b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/Messages.java index dd03c2a7b..803a99c19 100644 --- a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/Messages.java +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/Messages.java @@ -37,8 +37,11 @@ public class Messages extends NLS { public static String Dialog_LocationField; public static String Dialog_LocationLabel; public static String Dialog_LocationPrompt; + public static String Dialog_ManualProxyCheckBox; public static String Dialog_PromptStart; + public static String Dialog_ProxiesGroup; public static String Dialog_SelectLocation; + public static String Dialog_SettingsButton; public static String Dialog_SharedButton; public static String Dialog_ShellTitle; public static String Dialog_StandaloneButton; @@ -52,6 +55,26 @@ public class Messages extends NLS { public static String Op_Preparing; public static String Op_UpdateComplete; public static String Op_Updating; + public static String ProxiesDialog_DialogTitle; + public static String ProxiesDialog_EmptyHostMessage; + public static String ProxiesDialog_EmptyPasswordMessage; + public static String ProxiesDialog_EmptyProtMessage; + public static String ProxiesDialog_EmptyUserMessage; + public static String ProxiesDialog_FailedToReadProxySettingsMessage; + public static String ProxiesDialog_FailedTorSetProxySettings; + public static String ProxiesDialog_FailedToSetProxyMessage; + public static String ProxiesDialog_HostLabel; + public static String ProxiesDialog_InvalitHostMessage; + public static String ProxiesDialog_NegativValue; + public static String ProxiesDialog_OkLabel; + public static String ProxiesDialog_PasswordLabel; + public static String ProxiesDialog_PortLabel; + public static String ProxiesDialog_ServiceNotAvailableMessage; + public static String ProxiesDialog_ShemaLabel; + public static String ProxiesDialog_StatusPrefix; + public static String ProxiesDialog_UnknownProxyTypeMessage; + public static String ProxiesDialog_UserLabel; + public static String ProxiesDialog_WrongFormat; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/messages.properties b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/messages.properties index cda5bbde1..67dc69364 100644 --- a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/messages.properties +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/messages.properties @@ -28,8 +28,11 @@ Dialog_LayoutGroup=Layout Dialog_LocationField=Location Dialog_LocationLabel=Select the product install directory: Dialog_LocationPrompt=Select where you want {0} to be installed +Dialog_ManualProxyCheckBox=Use manual proxy settings Dialog_PromptStart=Install complete. Do you want to start {0} immediately? +Dialog_ProxiesGroup=Proxy Settings Dialog_SelectLocation=Select the install location +Dialog_SettingsButton=Settings... Dialog_SharedButton=&Shared install Dialog_ShellTitle=Installer Dialog_StandaloneButton=Stand-&alone install @@ -43,3 +46,23 @@ Op_NoServiceImpl=Install requires a service implementation that is not available Op_Preparing=Preparing to install Op_UpdateComplete=Update complete Op_Updating=Updating {0} +ProxiesDialog_DialogTitle=Proxy Settings Dialog +ProxiesDialog_EmptyHostMessage=Empty host +ProxiesDialog_EmptyPasswordMessage=Empty password +ProxiesDialog_EmptyProtMessage=Empty port +ProxiesDialog_EmptyUserMessage=Empty user +ProxiesDialog_FailedToReadProxySettingsMessage=Failed to read proxy settings +ProxiesDialog_FailedTorSetProxySettings=Failed to set proxy settings. +ProxiesDialog_FailedToSetProxyMessage=Failed to set proxy +ProxiesDialog_HostLabel=Host: +ProxiesDialog_InvalitHostMessage=Invalid host +ProxiesDialog_NegativValue=Proxy value can not be negativ +ProxiesDialog_OkLabel=OK +ProxiesDialog_PasswordLabel=Password: +ProxiesDialog_PortLabel=Port: +ProxiesDialog_ServiceNotAvailableMessage=Failed to set proxy settings. Service not available +ProxiesDialog_ShemaLabel=Schema: +ProxiesDialog_StatusPrefix=Status: +ProxiesDialog_UnknownProxyTypeMessage=Not applied because proxy type unknown. +ProxiesDialog_UserLabel=User: +ProxiesDialog_WrongFormat=Wrong proxy format diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/InstallDialog.java b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/InstallDialog.java index 7e1e062f8..e744396cc 100644 --- a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/InstallDialog.java +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/InstallDialog.java @@ -10,9 +10,11 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.installer.ui; -import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.p2.installer.InstallerActivator; import org.eclipse.equinox.internal.p2.installer.Messages; + +import org.eclipse.core.net.proxy.IProxyService; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.installer.*; import org.eclipse.equinox.internal.provisional.p2.installer.IInstallOperation; import org.eclipse.equinox.internal.provisional.p2.installer.InstallDescription; import org.eclipse.osgi.util.NLS; @@ -160,6 +162,8 @@ public class InstallDialog { private Shell shell; private boolean waitingForClose = false; + private Button proxySettingsButton; + private Button manualProxyTypeCheckBox; /** * Creates and opens a progress monitor dialog. @@ -172,6 +176,7 @@ public class InstallDialog { createProgressControls(); createButtonBar(); + shell.pack(); shell.layout(); shell.open(); } @@ -306,6 +311,54 @@ public class InstallDialog { settingsExplain.setLayoutData(data); settingsExplain.setText(Messages.Dialog_ExplainStandalone); + //The group asking for the product proxy configuration + Group proxySettingsGroup = new Group(settingsGroup, SWT.NONE); + proxySettingsGroup.setLayout(new GridLayout()); + proxySettingsGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + proxySettingsGroup.setText(Messages.Dialog_ProxiesGroup); + + //The sub-group with check box, label entry field and settings button + Composite proxySettingsFieldGroup = new Composite(proxySettingsGroup, SWT.NONE); + proxySettingsFieldGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + layout = new GridLayout(); + layout.numColumns = 3; + layout.makeColumnsEqualWidth = false; + proxySettingsFieldGroup.setLayout(layout); + + manualProxyTypeCheckBox = new Button(proxySettingsFieldGroup, SWT.CHECK); + manualProxyTypeCheckBox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + manualProxyTypeCheckBox.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + IProxyService proxies = (IProxyService) InstallApplication.getService(InstallerActivator.getDefault().getContext(), IProxyService.class.getName()); + if (proxies != null) { + //When the manual check box is selected the system properties should be disabled. + //This cases the net component to switch to manual proxy provider. + proxies.setSystemProxiesEnabled(!manualProxyTypeCheckBox.getSelection()); + if (proxySettingsButton != null) { + proxySettingsButton.setEnabled(manualProxyTypeCheckBox.getSelection()); + } + } else { + openMessage(Messages.ProxiesDialog_ServiceNotAvailableMessage, SWT.ICON_ERROR | SWT.OK); + } + } + }); + manualProxyTypeCheckBox.setText(Messages.Dialog_ManualProxyCheckBox); + proxySettingsButton = new Button(proxySettingsFieldGroup, SWT.PUSH); + proxySettingsButton.setLayoutData(new GridData(BUTTON_WIDTH, SWT.DEFAULT)); + proxySettingsButton.setText(Messages.Dialog_SettingsButton); + proxySettingsButton.setEnabled(manualProxyTypeCheckBox.getSelection()); + proxySettingsButton.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + IProxyService proxies = (IProxyService) InstallApplication.getService(InstallerActivator.getDefault().getContext(), IProxyService.class.getName()); + if (proxies != null) { + ProxiesDialog proxiesDialog = new ProxiesDialog(proxies); + proxiesDialog.open(); + } else { + openMessage(Messages.ProxiesDialog_ServiceNotAvailableMessage, SWT.ICON_ERROR | SWT.OK); + } + } + }); + //make the entire group invisible until we actually need to prompt for locations settingsGroup.setVisible(false); } @@ -504,4 +557,10 @@ public class InstallDialog { else settingsExplain.setText(Messages.Dialog_ExplainShared); } + + private void openMessage(String msg, int style) { + MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(), style); + messageBox.setMessage(msg); + messageBox.open(); + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/ProxiesDialog.java b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/ProxiesDialog.java new file mode 100644 index 000000000..eaa0be727 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.installer/src/org/eclipse/equinox/internal/p2/installer/ui/ProxiesDialog.java @@ -0,0 +1,312 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 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: + * EclipseSource + *******************************************************************************/ + +package org.eclipse.equinox.internal.p2.installer.ui; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.net.proxy.IProxyData; +import org.eclipse.core.net.proxy.IProxyService; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.internal.p2.installer.InstallerActivator; +import org.eclipse.equinox.internal.p2.installer.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; + +public final class ProxiesDialog { + + private IProxyData data; + private Label typeLabel; + private Combo typeCombo; + private Label hostLabel; + private Text hostText; + private Label portLabel; + private Text portText; + + private Label userIdLabel; + private Text userIdText; + private Label passwordLabel; + private Text passwordText; + private Button okButton; + private Button cancelButton; + private final IProxyService service; + private Shell shell; + private List types; + private Label statuslabel; + + public ProxiesDialog(IProxyService service) { + if (service == null) { + throw new IllegalArgumentException(); + } + + this.service = service; + initTypes(); + } + + public IProxyData getValue() { + return data; + } + + public void open() { + this.data = service.getProxyData(IProxyData.HTTP_PROXY_TYPE); + if (data == null) { + openMessage(Messages.ProxiesDialog_FailedToReadProxySettingsMessage, SWT.ICON_ERROR | SWT.OK); + return; + } + + Shell activeShell = Display.getDefault().getActiveShell(); + shell = new Shell(activeShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MIN | SWT.RESIZE); + //Computes the bounds + Rectangle bounds = null; + if (activeShell == null) { + bounds = new Rectangle(300, 200, 600, 400); + } else { + Rectangle parentBounds = activeShell.getBounds(); + bounds = new Rectangle(parentBounds.x + 100, parentBounds.y + 100, 600, 400); + } + shell.setBounds(bounds); + + shell.setText(Messages.ProxiesDialog_DialogTitle); + shell.setLayout(new GridLayout()); + + createDialogArea(shell); + createButtonBar(shell); + + shell.pack(); + shell.open(); + } + + protected Control createDialogArea(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(4, false)); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); + + typeLabel = new Label(composite, SWT.NONE); + typeLabel.setText(Messages.ProxiesDialog_ShemaLabel); + typeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1)); + typeCombo = new Combo(composite, SWT.BORDER); + typeCombo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 3, 1)); + //Currently only these three proxy types are supported. + for (int i = 0; i < types.size(); i++) { + typeCombo.add((String) types.get(i)); + } + + typeCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + String selection = typeCombo.getText(); + IProxyData selectedProxy = service.getProxyData(selection); + if (selectedProxy == null) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_UnknownProxyTypeMessage, null)); + } else { + data = selectedProxy; + applyData(); + } + } + }); + + hostLabel = new Label(composite, SWT.NONE); + hostLabel.setText(Messages.ProxiesDialog_HostLabel); + hostLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1)); + hostText = new Text(composite, SWT.BORDER); + GridData gdata = new GridData(SWT.FILL, SWT.TOP, true, false); + gdata.widthHint = 250; + hostText.setLayoutData(gdata); + + portLabel = new Label(composite, SWT.NONE); + portLabel.setText(Messages.ProxiesDialog_PortLabel); + portText = new Text(composite, SWT.BORDER); + gdata = new GridData(); + gdata.widthHint = 30; + portText.setLayoutData(gdata); + + userIdLabel = new Label(composite, SWT.NONE); + userIdLabel.setText(Messages.ProxiesDialog_UserLabel); + userIdLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1)); + userIdText = new Text(composite, SWT.BORDER); + userIdText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); + + passwordLabel = new Label(composite, SWT.NONE); + passwordLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, true, 1, 1)); + passwordLabel.setText(Messages.ProxiesDialog_PasswordLabel); + passwordText = new Text(composite, SWT.BORDER); + passwordText.setEchoChar('*'); + passwordText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 3, 1)); + + ModifyListener validationListener = new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateStatus(); + } + }; + typeCombo.addModifyListener(validationListener); + hostText.addModifyListener(validationListener); + portText.addModifyListener(validationListener); + userIdText.addModifyListener(validationListener); + passwordText.addModifyListener(validationListener); + + //Initialize the UI with the selected data + applyData(); + hostText.setFocus(); + updateStatus(); + return composite; + } + + private void createButtonBar(Composite parent) { + Composite buttonBar = new Composite(parent, SWT.NONE); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalAlignment = SWT.RIGHT; + buttonBar.setLayoutData(gridData); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.makeColumnsEqualWidth = false; + layout.marginHeight = 0; + layout.marginWidth = 0; + buttonBar.setLayout(layout); + + statuslabel = new Label(buttonBar, SWT.NONE); + gridData = new GridData(300, SWT.DEFAULT); + statuslabel.setLayoutData(gridData); + + okButton = new Button(buttonBar, SWT.PUSH); + gridData = new GridData(100, SWT.DEFAULT); + okButton.setLayoutData(gridData); + okButton.setText(Messages.ProxiesDialog_OkLabel); + okButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + okPressed(); + shell.dispose(); + } + }); + + cancelButton = new Button(buttonBar, SWT.PUSH); + cancelButton.setLayoutData(gridData); + cancelButton.setText(Messages.Dialog_CancelButton); + cancelButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + shell.dispose(); + } + }); + } + + public void create() { + validateHostName(); + } + + private String toString(String str) { + return str == null ? "" : str; //$NON-NLS-1$ + } + + private void applyData() { + typeCombo.setText(toString(data.getType())); + hostText.setText(toString(data.getHost())); + if (data.getPort() != -1) { + portText.setText(toString(Integer.toString(data.getPort()))); + } else { + portText.setText(""); //$NON-NLS-1$ + } + userIdText.setText(toString(data.getUserId())); + passwordText.setText(toString(data.getPassword())); + } + + private boolean validateHostName() { + try { + new URI(hostText.getText()); + } catch (URISyntaxException e) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_InvalitHostMessage, null)); + return false; + } + return true; + } + + protected void okPressed() { + data.setHost(hostText.getText()); + data.setPort(Integer.parseInt(portText.getText())); + data.setUserid(userIdText.getText()); + data.setPassword(passwordText.getText()); + try { + if (service != null) { + service.setProxyData(new IProxyData[] {data}); + } else { + openMessage(Messages.ProxiesDialog_ServiceNotAvailableMessage, SWT.ICON_ERROR | SWT.OK); + } + } catch (Exception e) { + openMessage(Messages.ProxiesDialog_FailedTorSetProxySettings + e.getLocalizedMessage(), SWT.ICON_ERROR | SWT.OK); + } + } + + protected void updateStatus() { + if (!validateHostName()) { + return; + } + if (hostText.getText().length() == 0) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_EmptyHostMessage, null)); + return; + } + + if (userIdText.getText().length() == 0) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_EmptyUserMessage, null)); + return; + } + + if (passwordText.getText().length() == 0) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_EmptyPasswordMessage, null)); + return; + } + + try { + //Port checks + String portAsString = portText.getText(); + if (portAsString == null || portAsString.length() == 0) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_EmptyProtMessage, null)); + return; + } + int port = Integer.parseInt(portAsString); + if (port < 0) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_NegativValue, null)); + return; + } + } catch (NumberFormatException e) { + updateStatus(new Status(IStatus.ERROR, InstallerActivator.PI_INSTALLER, IStatus.OK, Messages.ProxiesDialog_WrongFormat, null)); + return; + } + updateStatus(Status.OK_STATUS); + } + + private void updateStatus(IStatus status) { + + if (okButton != null) { + okButton.setEnabled(status.isOK()); + } + if (statuslabel != null) { + String statusText = status.isOK() ? "" : Messages.ProxiesDialog_StatusPrefix + status.getMessage(); //$NON-NLS-1$ + statuslabel.setText(statusText); + } + } + + private void openMessage(String msg, int style) { + MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(), style); + messageBox.setMessage(msg); + messageBox.open(); + } + + private void initTypes() { + types = new ArrayList(); + types.add(IProxyData.HTTP_PROXY_TYPE); + types.add(IProxyData.HTTPS_PROXY_TYPE); + types.add(IProxyData.SOCKS_PROXY_TYPE); + } +} |