From 0f1d75b0adf7aafb76b2051a4a4522830d0c6d74 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Wed, 11 Sep 2013 11:38:26 -0400 Subject: [PATCH] Add JSch UI support Signed-off-by: Greg Watson --- org.eclipse.remote.jsch.ui/.classpath | 7 + org.eclipse.remote.jsch.ui/.project | 34 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 + .../META-INF/MANIFEST.MF | 23 ++ org.eclipse.remote.jsch.ui/about.html | 22 ++ org.eclipse.remote.jsch.ui/build.properties | 7 + .../icons/full/obj16/connection.gif | Bin 0 -> 160 bytes org.eclipse.remote.jsch.ui/plugin.properties | 13 + org.eclipse.remote.jsch.ui/plugin.xml | 38 ++ org.eclipse.remote.jsch.ui/pom.xml | 16 + .../internal/remote/jsch/ui/Activator.java | 112 ++++++ .../jsch/ui/JSchFileSystemContributor.java | 81 ++++ .../jsch/ui/JSchUIConnectionManager.java | 85 ++++ .../remote/jsch/ui/JSchUIFileManager.java | 130 ++++++ .../remote/jsch/ui/JSchUIServices.java | 74 ++++ .../remote/jsch/ui/JSchUIServicesFactory.java | 26 ++ .../remote/jsch/ui/messages/Messages.java | 55 +++ .../jsch/ui/messages/messages.properties | 37 ++ .../jsch/ui/wizards/JSchConnectionPage.java | 370 ++++++++++++++++++ .../jsch/ui/wizards/JSchConnectionWizard.java | 65 +++ 20 files changed, 1206 insertions(+) create mode 100644 org.eclipse.remote.jsch.ui/.classpath create mode 100644 org.eclipse.remote.jsch.ui/.project create mode 100644 org.eclipse.remote.jsch.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.remote.jsch.ui/META-INF/MANIFEST.MF create mode 100644 org.eclipse.remote.jsch.ui/about.html create mode 100644 org.eclipse.remote.jsch.ui/build.properties create mode 100644 org.eclipse.remote.jsch.ui/icons/full/obj16/connection.gif create mode 100644 org.eclipse.remote.jsch.ui/plugin.properties create mode 100644 org.eclipse.remote.jsch.ui/plugin.xml create mode 100644 org.eclipse.remote.jsch.ui/pom.xml create mode 100644 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/Activator.java create mode 100644 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchFileSystemContributor.java create mode 100644 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIConnectionManager.java create mode 100644 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIFileManager.java create mode 100644 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServices.java create mode 100644 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServicesFactory.java create mode 100755 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/Messages.java create mode 100755 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/messages.properties create mode 100755 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionPage.java create mode 100755 org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionWizard.java diff --git a/org.eclipse.remote.jsch.ui/.classpath b/org.eclipse.remote.jsch.ui/.classpath new file mode 100644 index 00000000000..64c5e31b7a2 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.remote.jsch.ui/.project b/org.eclipse.remote.jsch.ui/.project new file mode 100644 index 00000000000..05c0dc929b6 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/.project @@ -0,0 +1,34 @@ + + + org.eclipse.remote.jsch.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/org.eclipse.remote.jsch.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.remote.jsch.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..416f4fb6960 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/org.eclipse.remote.jsch.ui/META-INF/MANIFEST.MF b/org.eclipse.remote.jsch.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..9cfe410ec89 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.remote.jsch.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.internal.remote.jsch.ui.Activator +Bundle-Vendor: %pluginProvider +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.core.filesystem, + org.eclipse.remote.core, + org.eclipse.remote.ui, + org.eclipse.remote.jsch.core, + org.eclipse.jsch.core, + com.jcraft.jsch, + org.eclipse.ui.forms, + org.eclipse.ui.ide, + org.eclipse.ui, + org.eclipse.jface +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.internal.remote.jsch.ui;x-internal:=true, + org.eclipse.internal.remote.jsch.ui.messages;x-internal:=true +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/org.eclipse.remote.jsch.ui/about.html b/org.eclipse.remote.jsch.ui/about.html new file mode 100644 index 00000000000..3f810933b39 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

May 2, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.remote.jsch.ui/build.properties b/org.eclipse.remote.jsch.ui/build.properties new file mode 100644 index 00000000000..aca5ac03c49 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html \ No newline at end of file diff --git a/org.eclipse.remote.jsch.ui/icons/full/obj16/connection.gif b/org.eclipse.remote.jsch.ui/icons/full/obj16/connection.gif new file mode 100644 index 0000000000000000000000000000000000000000..870934b6934844102afd508e067750591ccc34c0 GIT binary patch literal 160 zcmV;R0AK${Nk%w1VGsZi0J9GOy@VF3ZxE(y5d7@1`{kGX@x%S`!~Xs6{OYOw_SL$V zCjR)|{`lSf_}%;LvH$=7A^8LW000jFEC2ui01yBW000C{@W}_jyqF%FF*sXy0Zg-0 zXf+mw!4@wZTmfPScs^qRLF}SQ4@gmna3g>*IQghNsY+tXkpKpcfp)vCJ_O*fz()`; OzdrMMtX{Vt5db^*GD&v; literal 0 HcmV?d00001 diff --git a/org.eclipse.remote.jsch.ui/plugin.properties b/org.eclipse.remote.jsch.ui/plugin.properties new file mode 100644 index 00000000000..03714bd8990 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/plugin.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2013 IBM Corporation. +# 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 +# +############################################################################### + +pluginName=JSch UI Remote Support +pluginProvider=Eclipse PTP +JSchTransferConnections.name=Remote Connections +JSchTransferConnections.description=All remote ssh connections \ No newline at end of file diff --git a/org.eclipse.remote.jsch.ui/plugin.xml b/org.eclipse.remote.jsch.ui/plugin.xml new file mode 100644 index 00000000000..9ed74901ac7 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/plugin.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + %JSchTransferConnections.description + + + + + diff --git a/org.eclipse.remote.jsch.ui/pom.xml b/org.eclipse.remote.jsch.ui/pom.xml new file mode 100644 index 00000000000..0f40b499496 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + + org.eclipse.ptp + ptp-parent + 7.0.1-SNAPSHOT + ../../pom.xml + + + org.eclipse.remote.jsch.core + 1.0.0-SNAPSHOT + eclipse-plugin + diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/Activator.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/Activator.java new file mode 100644 index 00000000000..8f070085e27 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/Activator.java @@ -0,0 +1,112 @@ +package org.eclipse.internal.remote.jsch.ui; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.eclipse.jsch.core.IJSchService; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin { + + // The plug-in ID + private static final String PLUGIN_ID = "org.eclipse.remote.jsch.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Get unique identifier + * + * @return + * @since 5.0 + */ + public static String getUniqueIdentifier() { + if (getDefault() == null) { + return PLUGIN_ID; + } + return getDefault().getBundle().getSymbolicName(); + } + + /** + * Logs the specified status with this plug-in's log. + * + * @param status + * status to log + */ + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + + /** + * Logs an internal error with the specified message. + * + * @param message + * the error message to log + */ + public static void log(String message) { + log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null)); + } + + /** + * Logs an internal error with the specified throwable + * + * @param e + * the exception to be logged + */ + public static void log(Throwable e) { + log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, e.getMessage(), e)); + } + + private IJSchService fJSchService; + + /** + * The constructor + */ + public Activator() { + } + + public IJSchService getService() { + return fJSchService; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + ServiceReference reference = context.getServiceReference(IJSchService.class); + fJSchService = context.getService(reference); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchFileSystemContributor.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchFileSystemContributor.java new file mode 100644 index 00000000000..7bef6c5651c --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchFileSystemContributor.java @@ -0,0 +1,81 @@ +/******************************************************************************** + * Copyright (c) 2002, 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * Kushal Munir (IBM) - moved to internal package. + * Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams, + * - Fix early startup issues by deferring FileStore evaluation and classloading, + * - Improve performance by RSEFileStore instance factory and caching IRemoteFile. + * - Also remove unnecessary class RSEFileCache and obsolete branding files. + * Martin Oberhuber (Wind River) - [188360] renamed from plugin org.eclipse.rse.eclipse.filesystem + * Martin Oberhuber (Wind River) - [189441] fix EFS operations on Windows (Local) systems + * David Dykstal (IBM) - [235840] externalizing dialog title + ********************************************************************************/ + +package org.eclipse.internal.remote.jsch.ui; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.eclipse.internal.remote.jsch.core.JSchFileSystem; +import org.eclipse.internal.remote.jsch.core.JSchServices; +import org.eclipse.internal.remote.jsch.ui.messages.Messages; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.ui.IRemoteUIFileManager; +import org.eclipse.remote.ui.IRemoteUIServices; +import org.eclipse.remote.ui.RemoteUIServices; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.ide.fileSystem.FileSystemContributor; + +public class JSchFileSystemContributor extends FileSystemContributor { + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.ide.fileSystem.FileSystemContributor#browseFileSystem( + * java.lang.String, org.eclipse.swt.widgets.Shell) + */ + @Override + public URI browseFileSystem(String initialPath, Shell shell) { + IRemoteServices services = RemoteServices.getRemoteServices(JSchServices.JSCH_ID); + IRemoteUIServices uiServices = RemoteUIServices.getRemoteUIServices(services); + IRemoteUIFileManager uiFileMgr = uiServices.getUIFileManager(); + uiFileMgr.showConnections(true); + String path = uiFileMgr.browseDirectory(shell, Messages.JSchFileSystemContributor_0, initialPath, 0); + if (path != null) { + IRemoteConnection conn = uiFileMgr.getConnection(); + if (conn != null) { + return JSchFileSystem.getURIFor(conn.getName(), path); + } + } + + return null; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.ide.fileSystem.FileSystemContributor#getURI(java.lang. + * String) + */ + @Override + public URI getURI(String string) { + try { + return new URI(string); + } catch (URISyntaxException e) { + } + return null; + } +} \ No newline at end of file diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIConnectionManager.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIConnectionManager.java new file mode 100644 index 00000000000..65a25548d81 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIConnectionManager.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2013 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.internal.remote.jsch.ui; + +import org.eclipse.internal.remote.jsch.core.JSchConnectionManager; +import org.eclipse.internal.remote.jsch.core.JSchConnectionWorkingCopy; +import org.eclipse.internal.remote.jsch.ui.wizards.JSchConnectionWizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.ui.AbstractRemoteUIConnectionManager; +import org.eclipse.swt.widgets.Shell; + +public class JSchUIConnectionManager extends AbstractRemoteUIConnectionManager { + private final JSchConnectionManager connMgr; + + public JSchUIConnectionManager(IRemoteServices services) { + connMgr = (JSchConnectionManager) services.getConnectionManager(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.core.IRemoteUIConnectionManager#newConnection() + */ + public IRemoteConnectionWorkingCopy newConnection(Shell shell) { + return newConnection(shell, null, null); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager#newConnection(org + * .eclipse.swt.widgets.Shell, + * org.eclipse.ptp.remote.ui.IRemoteUIConnectionManager + * .IRemoteConnectionAttributeHint[], java.lang.String[]) + */ + public IRemoteConnectionWorkingCopy newConnection(Shell shell, String[] attrHints, String[] attrHintValues) { + JSchConnectionWorkingCopy conn = createConnection(shell, attrHints, attrHintValues); + if (conn != null) { + return conn; + } + return null; + } + + public JSchConnectionWorkingCopy createConnection(Shell shell, String[] attrHints, String[] attrHintValues) { + JSchConnectionWizard wizard = new JSchConnectionWizard(connMgr); + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.setBlockOnOpen(true); + if (dialog.open() == WizardDialog.OK) { + return wizard.getConnection(); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.remote.ui.IRemoteUIConnectionManager#updateConnection(org.eclipse.swt.widgets.Shell, + * org.eclipse.remote.core.IRemoteConnectionWorkingCopy) + */ + public boolean updateConnection(Shell shell, IRemoteConnectionWorkingCopy connection) { + if (connection instanceof JSchConnectionWorkingCopy) { + JSchConnectionWorkingCopy jSchConn = (JSchConnectionWorkingCopy) connection; + JSchConnectionWizard wizard = new JSchConnectionWizard(connMgr, jSchConn); + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.setBlockOnOpen(true); + if (dialog.open() == WizardDialog.OK) { + return true; + } + } + return false; + } + +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIFileManager.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIFileManager.java new file mode 100644 index 00000000000..7ab2fbf2b1e --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIFileManager.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * 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.internal.remote.jsch.ui; + +import org.eclipse.jface.window.Window; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.ui.IRemoteUIFileManager; +import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser; +import org.eclipse.swt.widgets.Shell; + +public class JSchUIFileManager implements IRemoteUIFileManager { + private IRemoteServices services = null; + private IRemoteConnection connection = null; + private boolean showConnections = false; + + public JSchUIFileManager(IRemoteServices services) { + this.services = services; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.core.IRemoteFileManager#browseDirectory(org.eclipse + * .swt.widgets.Shell, java.lang.String, java.lang.String) + */ + public String browseDirectory(Shell shell, String message, String filterPath, int flags) { + RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.SINGLE); + browser.setType(RemoteResourceBrowser.DIRECTORY_BROWSER); + browser.setInitialPath(filterPath); + browser.setTitle(message); + browser.showConnections(showConnections); + if (browser.open() == Window.CANCEL) { + return null; + } + connection = browser.getConnection(); + String path = browser.getPath(); + if (path == null) { + return null; + } + return path; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.core.IRemoteFileManager#browseFile(org.eclipse + * .swt.widgets.Shell, java.lang.String, java.lang.String) + */ + public String browseFile(Shell shell, String message, String filterPath, int flags) { + RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.SINGLE); + browser.setType(RemoteResourceBrowser.FILE_BROWSER); + browser.setInitialPath(filterPath); + browser.setTitle(message); + browser.showConnections(showConnections); + if (browser.open() == Window.CANCEL) { + return null; + } + connection = browser.getConnection(); + String path = browser.getPath(); + if (path == null) { + return null; + } + return path; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.core.IRemoteFileManager#browseFile(org.eclipse + * .swt.widgets.Shell, java.lang.String, java.lang.String) + */ + public String[] browseFiles(Shell shell, String message, String filterPath, int flags) { + RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.MULTI); + browser.setType(RemoteResourceBrowser.FILE_BROWSER); + browser.setInitialPath(filterPath); + browser.setTitle(message); + browser.showConnections(showConnections); + if (browser.open() == Window.CANCEL) { + return null; + } + connection = browser.getConnection(); + String path[] = browser.getPaths(); + if (path == null) { + return null; + } + return path; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ptp.remote.ui.IRemoteUIFileManager#getConnection() + */ + public IRemoteConnection getConnection() { + return connection; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.ui.IRemoteUIFileManager#setConnection(org.eclipse + * .ptp.remote.core.IRemoteConnection) + */ + public void setConnection(IRemoteConnection connection) { + this.connection = connection; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ptp.remote.ui.IRemoteUIFileManager#showConnections(boolean) + */ + public void showConnections(boolean enable) { + showConnections = enable; + } +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServices.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServices.java new file mode 100644 index 00000000000..0ac7097942a --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServices.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2013 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.internal.remote.jsch.ui; + +import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.ui.IRemoteUIConnectionManager; +import org.eclipse.remote.ui.IRemoteUIFileManager; +import org.eclipse.remote.ui.IRemoteUIServices; + +public class JSchUIServices implements IRemoteUIServices { + private static JSchUIServices fInstance = null; + + /** + * Get shared instance of this class + * + * @return instance + */ + public static JSchUIServices getInstance(IRemoteServices services) { + if (fInstance == null) { + fInstance = new JSchUIServices(services); + } + return fInstance; + } + + private final IRemoteServices fServices; + + public JSchUIServices(IRemoteServices services) { + fServices = services; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getId() + */ + public String getId() { + return fServices.getId(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getName() + */ + public String getName() { + return fServices.getName(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIConnectionManager() + */ + public IRemoteUIConnectionManager getUIConnectionManager() { + return new JSchUIConnectionManager(fServices); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIFileManager() + */ + public IRemoteUIFileManager getUIFileManager() { + return new JSchUIFileManager(fServices); + } +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServicesFactory.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServicesFactory.java new file mode 100644 index 00000000000..7ec75dc82a7 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/JSchUIServicesFactory.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 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.internal.remote.jsch.ui; + +import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.ui.IRemoteUIServices; +import org.eclipse.remote.ui.IRemoteUIServicesFactory; + +public class JSchUIServicesFactory implements IRemoteUIServicesFactory { + /* + * (non-Javadoc) + * + * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesFactory#getServices(org.eclipse.ptp.remote.core.IRemoteServices) + */ + public IRemoteUIServices getServices(IRemoteServices services) { + return JSchUIServices.getInstance(services); + } +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/Messages.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/Messages.java new file mode 100755 index 00000000000..92097ccfc07 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/Messages.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2013 IBM Corporation. + * 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 Implementation + * + */ +package org.eclipse.internal.remote.jsch.ui.messages; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_ID = "org.eclipse.internal.remote.jsch.ui.messages.messages"; //$NON-NLS-1$ + + static { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_ID, Messages.class); + } + + private Messages() { + // cannot create new instance + } + + public static String JSchConnectionPage_A_connection_with_that_name_already_exists; + public static String JSchConnectionPage_Edit_Connection; + public static String JSchConnectionPage_Edit_properties_of_an_existing_connection; + public static String JSchFileSystemContributor_0; + public static String JSchNewConnectionPage_Advanced; + public static String JSchNewConnectionPage_Connection_name; + public static String JSchNewConnectionPage_File_with_private_key; + public static String JSchNewConnectionPage_Host; + public static String JSchNewConnectionPage_Host_information; + public static String JSchNewConnectionPage_Host_name_cannot_be_empty; + public static String JSchNewConnectionPage_New_Connection; + public static String JSchNewConnectionPage_New_connection_properties; + public static String JSchNewConnectionPage_Passphrase; + public static String JSchNewConnectionPage_Password; + public static String JSchNewConnectionPage_Password_based_authentication; + public static String JSchNewConnectionPage_Please_enter_a_connection_name; + public static String JSchNewConnectionPage_Port; + public static String JSchNewConnectionPage_Port_is_not_valid; + public static String JSchNewConnectionPage_Private_key_file_cannot_be_read; + public static String JSchNewConnectionPage_Private_key_file_does_not_exist; + public static String JSchNewConnectionPage_Private_key_file_is_invalid; + public static String JSchNewConnectionPage_Private_key_path_cannot_be_empty; + public static String JSchNewConnectionPage_Public_key_based_authentication; + public static String JSchNewConnectionPage_Timeout; + public static String JSchNewConnectionPage_Timeout_is_not_valid; + public static String JSchNewConnectionPage_User; + public static String JSchNewConnectionPage_User_name_cannot_be_empty; +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/messages.properties b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/messages.properties new file mode 100755 index 00000000000..fe65c058d93 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/messages/messages.properties @@ -0,0 +1,37 @@ +############################################################################### +# Copyright (c) 2013 IBM Corporation. +# 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 implementation +############################################################################### +JSchConnectionPage_A_connection_with_that_name_already_exists=A connection with that name already exists +JSchConnectionPage_Edit_Connection=Edit Connection +JSchConnectionPage_Edit_properties_of_an_existing_connection=Edit properties of an existing connection +JSchFileSystemContributor_0=Browse File System +JSchNewConnectionPage_Advanced=Advanced +JSchNewConnectionPage_Connection_name=Connection name: +JSchNewConnectionPage_File_with_private_key=File with private key: +JSchNewConnectionPage_Host=Host: +JSchNewConnectionPage_Host_information=Host information +JSchNewConnectionPage_Host_name_cannot_be_empty=Host name cannot be empty +JSchNewConnectionPage_New_Connection=New Connection +JSchNewConnectionPage_New_connection_properties=New connection properties +JSchNewConnectionPage_Passphrase=Passphrase: +JSchNewConnectionPage_Password=Password: +JSchNewConnectionPage_Password_based_authentication=Password based authentication +JSchNewConnectionPage_Please_enter_a_connection_name=Please enter a connection name +JSchNewConnectionPage_Port=Port: +JSchNewConnectionPage_Port_is_not_valid=Port is not valid +JSchNewConnectionPage_Private_key_file_cannot_be_read=Private key file cannot be read +JSchNewConnectionPage_Private_key_file_does_not_exist=Private key file does not exist +JSchNewConnectionPage_Private_key_file_is_invalid=Private key file is invalid +JSchNewConnectionPage_Private_key_path_cannot_be_empty=Private key path cannot be empty +JSchNewConnectionPage_Public_key_based_authentication=Public key based authentication +JSchNewConnectionPage_Timeout=Timeout: +JSchNewConnectionPage_Timeout_is_not_valid=Timeout is not valid +JSchNewConnectionPage_User=User: +JSchNewConnectionPage_User_name_cannot_be_empty=User name cannot be empty diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionPage.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionPage.java new file mode 100755 index 00000000000..e4765f13b64 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionPage.java @@ -0,0 +1,370 @@ +/** + * Copyright (c) 2013 IBM Corporation. + * 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 Implementation + * + */ +package org.eclipse.internal.remote.jsch.ui.wizards; + +import java.io.File; + +import org.eclipse.internal.remote.jsch.core.Activator; +import org.eclipse.internal.remote.jsch.core.JSchConnection; +import org.eclipse.internal.remote.jsch.core.JSchConnectionWorkingCopy; +import org.eclipse.internal.remote.jsch.ui.messages.Messages; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.ui.widgets.RemoteFileWidget; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.events.IExpansionListener; +import org.eclipse.ui.forms.widgets.ExpandableComposite; + +public class JSchConnectionPage extends WizardPage { + private class DataModifyListener implements ModifyListener { + public synchronized void modifyText(ModifyEvent e) { + validateFields(); + getContainer().updateButtons(); + } + } + + private Text fConnectionName; + private Button fPasswordButton; + private Button fPublicKeyButton; + private Text fHostText; + private Text fUserText; + private Text fPasswordText; + private Text fPassphraseText; + private Text fPortText; + private Text fTimeoutText; + private Combo fCipherCombo; + private RemoteFileWidget fFileWidget; + + private String fName; + + private final IRemoteConnectionManager fConnectionManager; + private JSchConnectionWorkingCopy fConnection; + + private final DataModifyListener fDataModifyListener = new DataModifyListener(); + + public JSchConnectionPage(IRemoteConnectionManager connMgr) { + super(Messages.JSchNewConnectionPage_New_Connection); + fConnectionManager = connMgr; + fConnection = null; + setPageComplete(false); + } + + public JSchConnectionPage(IRemoteConnectionManager connMgr, JSchConnectionWorkingCopy conn) { + super(Messages.JSchConnectionPage_Edit_Connection); + fConnectionManager = connMgr; + fConnection = conn; + setPageComplete(false); + } + + /** + * Create controls for the bottom (hideable) composite + * + * @param mold + * + */ + private void createAdvancedControls(final Composite parent) { + ExpandableComposite expComp = new ExpandableComposite(parent, ExpandableComposite.TWISTIE); + expComp.setText(Messages.JSchNewConnectionPage_Advanced); + expComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + expComp.setExpanded(false); + expComp.addExpansionListener(new IExpansionListener() { + + public void expansionStateChanged(ExpansionEvent e) { + Point newSize = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT); + Point currentSize = parent.getSize(); + int deltaY = newSize.y - currentSize.y; + Point shellSize = getShell().getSize(); + shellSize.y += deltaY; + getShell().setSize(shellSize); + getShell().layout(true, true); + } + + public void expansionStateChanging(ExpansionEvent e) { + // Ignore + } + }); + + Composite advancedComp = new Composite(expComp, SWT.NONE); + advancedComp.setLayout(new GridLayout(2, false)); + advancedComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + + Label portLabel = new Label(advancedComp, SWT.NONE); + portLabel.setText(Messages.JSchNewConnectionPage_Port); + portLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + fPortText = new Text(advancedComp, SWT.BORDER | SWT.SINGLE); + fPortText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + fPortText.setTextLimit(5); + + Label timeoutLabel = new Label(advancedComp, SWT.NONE); + timeoutLabel.setText(Messages.JSchNewConnectionPage_Timeout); + timeoutLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + fTimeoutText = new Text(advancedComp, SWT.BORDER | SWT.SINGLE); + fTimeoutText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + fTimeoutText.setTextLimit(5); + + // Label cipherLabel = new Label(advancedComp, SWT.NONE); + // cipherLabel.setText("Cipher type:"); + // cipherLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + // fCipherCombo = new Combo(advancedComp, SWT.NONE); + // fCipherCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + + expComp.setClient(advancedComp); + } + + private void createAuthControls(Composite parent) { + Composite controls = new Composite(parent, SWT.NONE); + controls.setLayout(new GridLayout(2, false)); + controls.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + Label hostLabel = new Label(controls, SWT.NONE); + hostLabel.setText(Messages.JSchNewConnectionPage_Host); + hostLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + fHostText = new Text(controls, SWT.BORDER | SWT.SINGLE); + fHostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label userLabel = new Label(controls, SWT.NONE); + userLabel.setText(Messages.JSchNewConnectionPage_User); + userLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + fUserText = new Text(controls, SWT.BORDER | SWT.SINGLE); + fUserText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // User option box + fPasswordButton = new Button(controls, SWT.RADIO); + fPasswordButton.setText(Messages.JSchNewConnectionPage_Password_based_authentication); + fPasswordButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1)); + fPasswordButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateEnablement(); + } + }); + + // Password field + Label passwordLabel = new Label(controls, SWT.NONE); + passwordLabel.setText(Messages.JSchNewConnectionPage_Password); + passwordLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + fPasswordText = new Text(controls, SWT.BORDER | SWT.SINGLE); + fPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + // Key option box + fPublicKeyButton = new Button(controls, SWT.RADIO); + fPublicKeyButton.setText(Messages.JSchNewConnectionPage_Public_key_based_authentication); + fPublicKeyButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1)); + fPublicKeyButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateEnablement(); + } + }); + + // Key file selection + fFileWidget = new RemoteFileWidget(controls, SWT.NONE, 0, null, ""); //$NON-NLS-1$ + fFileWidget.setConnection(RemoteServices.getLocalServices().getConnectionManager() + .getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME)); + fFileWidget.setLabel(Messages.JSchNewConnectionPage_File_with_private_key); + fFileWidget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); + + // Passphrase field + Label passphraseLabel = new Label(controls, SWT.NONE); + passphraseLabel.setText(Messages.JSchNewConnectionPage_Passphrase); + passphraseLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + fPassphraseText = new Text(controls, SWT.BORDER | SWT.SINGLE); + fPassphraseText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + fPasswordButton.setSelection(true); + fPublicKeyButton.setSelection(false); + updateEnablement(); + } + + public void createControl(Composite parent) { + if (fConnection == null) { + this.setDescription(Messages.JSchNewConnectionPage_New_connection_properties); + this.setTitle(Messages.JSchNewConnectionPage_New_Connection); + } else { + this.setDescription(Messages.JSchConnectionPage_Edit_properties_of_an_existing_connection); + this.setTitle(Messages.JSchConnectionPage_Edit_Connection); + } + this.setErrorMessage(null); + + GridLayout topLayout = new GridLayout(2, false); + final Composite topControl = new Composite(parent, SWT.NONE); + setControl(topControl); + topControl.setLayout(topLayout); + + Label label = new Label(topControl, SWT.NONE); + label.setText(Messages.JSchNewConnectionPage_Connection_name); + label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + + fConnectionName = new Text(topControl, SWT.BORDER | SWT.SINGLE); + fConnectionName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + fConnectionName.setEnabled(fConnection == null); + + final Group authGroup = new Group(topControl, SWT.NONE); + authGroup.setText(Messages.JSchNewConnectionPage_Host_information); + authGroup.setLayout(new GridLayout(1, false)); + authGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + + createAuthControls(authGroup); + createAdvancedControls(authGroup); + + registerListeners(); + loadValues(); + } + + public JSchConnectionWorkingCopy getConnection() { + return fConnection; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.WizardPage#getName() + */ + @Override + public String getName() { + return fName; + } + + private void loadValues() { + if (fConnection != null) { + fConnectionName.setText(fConnection.getName()); + fHostText.setText(fConnection.getAddress()); + fUserText.setText(fConnection.getUsername()); + fPortText.setText(Integer.toString(fConnection.getPort())); + fTimeoutText.setText(Integer.toString(fConnection.getTimeout())); + fPasswordButton.setSelection(fConnection.isPasswordAuth()); + if (fConnection.isPasswordAuth()) { + fPasswordText.setText(fConnection.getPassword()); + } else { + fPassphraseText.setText(fConnection.getPassphrase()); + fFileWidget.setLocationPath(fConnection.getKeyFile()); + } + } + } + + private void registerListeners() { + fConnectionName.addModifyListener(fDataModifyListener); + fHostText.addModifyListener(fDataModifyListener); + fUserText.addModifyListener(fDataModifyListener); + fPortText.addModifyListener(fDataModifyListener); + fTimeoutText.addModifyListener(fDataModifyListener); + } + + @Override + public void setPageComplete(boolean complete) { + super.setPageComplete(complete); + if (complete) { + storeValues(); + } + } + + private void storeValues() { + if (fConnection == null) { + try { + JSchConnection conn = (JSchConnection) fConnectionManager.newConnection(fConnectionName.getText().trim()); + fConnection = (JSchConnectionWorkingCopy) conn.getWorkingCopy(); + } catch (RemoteConnectionException e) { + Activator.log(e); + } + } + if (fConnection != null) { + fConnection.setAddress(fHostText.getText().trim()); + fConnection.setUsername(fUserText.getText().trim()); + fConnection.setPassword(fPasswordText.getText().trim()); + fConnection.setPassphrase(fPassphraseText.getText().trim()); + fConnection.setKeyFile(fFileWidget.getLocationPath()); + fConnection.setIsPasswordAuth(fPasswordButton.getSelection()); + fConnection.setTimeout(Integer.parseInt(fTimeoutText.getText().trim())); + fConnection.setPort(Integer.parseInt(fPortText.getText().trim())); + } + } + + private void updateEnablement() { + boolean isPasswordAuth = fPasswordButton.getSelection(); + fPasswordText.setEnabled(isPasswordAuth); + fPassphraseText.setEnabled(!isPasswordAuth); + fFileWidget.setEnabled(!isPasswordAuth); + } + + private String validateAdvanced() { + try { + Integer.parseInt(fPortText.getText().trim()); + } catch (NumberFormatException ne) { + return Messages.JSchNewConnectionPage_Port_is_not_valid; + } + try { + Integer.parseInt(fTimeoutText.getText().trim()); + } catch (NumberFormatException ne) { + return Messages.JSchNewConnectionPage_Timeout_is_not_valid; + } + // if (fCipherCombo.getSelectionIndex() == -1) { + // return "Invalid cipher type"; + // } + return null; + } + + private void validateFields() { + String message = null; + if (fConnectionName.getText().trim().length() == 0) { + message = Messages.JSchNewConnectionPage_Please_enter_a_connection_name; + } else if (fConnection == null && fConnectionManager.getConnection(fConnectionName.getText().trim()) != null) { + message = Messages.JSchConnectionPage_A_connection_with_that_name_already_exists; + } else if (fHostText.getText().trim().length() == 0) { + message = Messages.JSchNewConnectionPage_Host_name_cannot_be_empty; + } else if (fUserText.getText().trim().length() == 0) { + message = Messages.JSchNewConnectionPage_User_name_cannot_be_empty; + } + if (message == null) { + message = validatePasskey(); + } + if (message == null) { + message = validateAdvanced(); + } + setErrorMessage(message); + setPageComplete(message == null); + } + + private String validatePasskey() { + if (!fPasswordButton.getSelection()) { + if (fFileWidget.getLocationPath().trim().length() == 0) { + return Messages.JSchNewConnectionPage_Private_key_path_cannot_be_empty; + } + File path = new File(fFileWidget.getLocationPath().trim()); + if (!path.exists()) { + return Messages.JSchNewConnectionPage_Private_key_file_does_not_exist; + } + if (!path.isFile()) { + return Messages.JSchNewConnectionPage_Private_key_file_is_invalid; + } + if (!path.canRead()) { + return Messages.JSchNewConnectionPage_Private_key_file_cannot_be_read; + } + } + return null; + } +} diff --git a/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionWizard.java b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionWizard.java new file mode 100755 index 00000000000..9b38cbe09d6 --- /dev/null +++ b/org.eclipse.remote.jsch.ui/src/org/eclipse/internal/remote/jsch/ui/wizards/JSchConnectionWizard.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2013 IBM Corporation. + * 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 Implementation + * + */ +package org.eclipse.internal.remote.jsch.ui.wizards; + +import org.eclipse.internal.remote.jsch.core.JSchConnectionWorkingCopy; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.remote.core.IRemoteConnectionManager; + +public class JSchConnectionWizard extends Wizard { + + private final JSchConnectionPage fPage; + + public JSchConnectionWizard(IRemoteConnectionManager connMgr) { + fPage = new JSchConnectionPage(connMgr); + } + + public JSchConnectionWizard(IRemoteConnectionManager connMgr, JSchConnectionWorkingCopy conn) { + fPage = new JSchConnectionPage(connMgr, conn); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + @Override + public void addPages() { + super.addPages(); + addPage(fPage); + } + + public JSchConnectionWorkingCopy getConnection() { + return fPage.getConnection(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#performCancel() + */ + @Override + public boolean performCancel() { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + @Override + public boolean performFinish() { + return true; + } + +}