aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Weninger2011-11-10 02:25:47 (EST)
committerUwe Stieber2011-11-10 02:30:00 (EST)
commit5407ffdf6ead4a83ddc5bc0132e2d37b12df735e (patch)
treee0c5dde217a43a0bf9512091f0b797c9a3058372
parent3ca2c7df4e670e8ffa23dd865c8d1dc2935afeda (diff)
downloadorg.eclipse.tcf-5407ffdf6ead4a83ddc5bc0132e2d37b12df735e.zip
org.eclipse.tcf-5407ffdf6ead4a83ddc5bc0132e2d37b12df735e.tar.gz
org.eclipse.tcf-5407ffdf6ead4a83ddc5bc0132e2d37b12df735e.tar.bz2
Target Explorer: Bug 361352 - [TERMINALS][SSH] Add SSH terminal support
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.runtime.services/src/org/eclipse/tm/te/runtime/services/interfaces/constants/ITerminalsConnectorConstants.java18
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/META-INF/MANIFEST.MF8
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/build.properties3
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.properties8
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.xml29
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java279
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java84
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.java35
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.properties7
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/types/SshConnectorType.java117
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java28
11 files changed, 609 insertions, 7 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.runtime.services/src/org/eclipse/tm/te/runtime/services/interfaces/constants/ITerminalsConnectorConstants.java b/target_explorer/plugins/org.eclipse.tm.te.runtime.services/src/org/eclipse/tm/te/runtime/services/interfaces/constants/ITerminalsConnectorConstants.java
index 25419c9..e03d2d5 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.runtime.services/src/org/eclipse/tm/te/runtime/services/interfaces/constants/ITerminalsConnectorConstants.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.runtime.services/src/org/eclipse/tm/te/runtime/services/interfaces/constants/ITerminalsConnectorConstants.java
@@ -6,6 +6,7 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
*******************************************************************************/
package org.eclipse.tm.te.runtime.services.interfaces.constants;
@@ -127,4 +128,21 @@ public interface ITerminalsConnectorConstants {
* <p>Typical for streams terminals.
*/
public static final String PROP_STREAMS_STDERR = "streams.stderr"; //$NON-NLS-1$
+
+ // ****** Ssh specific properties ****
+
+ /**
+ * Property: ssh keep alive value.
+ */
+ public static final String PROP_SSH_KEEP_ALIVE = "ssh.keep_alive"; //$NON-NLS-1$
+
+ /**
+ * Property: Ssh password.
+ */
+ public static final String PROP_SSH_PASSWORD = "ssh.password"; //$NON-NLS-1$
+
+ /**
+ * Property: Ssh user.
+ */
+ public static final String PROP_SSH_USER = "ssh.user"; //$NON-NLS-1$
}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/META-INF/MANIFEST.MF
index aaa6924..f9ba7c8 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/META-INF/MANIFEST.MF
@@ -13,7 +13,13 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.tm.te.ui;bundle-version="1.0.0",
org.eclipse.tm.te.ui.terminals;bundle-version="1.0.0",
org.eclipse.tm.te.ui.controls;bundle-version="1.0.0",
- org.eclipse.tm.te.ui.swt;bundle-version="1.0.0"
+ org.eclipse.tm.te.ui.swt;bundle-version="1.0.0",
+ org.eclipse.tm.terminal.ssh;bundle-version="2.1.0",
+ org.eclipse.tm.terminal;bundle-version="3.1.1",
+ org.eclipse.tm.te.runtime.services;bundle-version="1.0.0",
+ org.eclipse.tm.te.tcf.locator;bundle-version="1.0.0",
+ org.eclipse.tm.tcf.core;bundle-version="0.5.0",
+ org.eclipse.equinox.security;bundle-version="1.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/build.properties b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/build.properties
index f4ae970..73a5119 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/build.properties
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/build.properties
@@ -2,4 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- plugin.properties
+ plugin.properties,\
+ plugin.xml
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.properties b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.properties
index be27816..2e56601 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.properties
@@ -10,3 +10,11 @@
pluginName = Target Explorer, SSH Terminals Extensions
providerName = Eclipse.org
+
+# ----- Terminal Connector Types -----
+
+SshConnectorType.label=SSH Connector Type
+
+# ***** Terminal Launcher Delegates ****
+
+SshLauncherDelegate.label=SSH Terminal \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.xml b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.xml
new file mode 100644
index 0000000..95e05df
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/plugin.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+<!-- Terminal connector type contributions -->
+ <extension point="org.eclipse.tm.te.ui.terminals.connectorTypes">
+ <connectorType
+ class="org.eclipse.tm.te.ui.terminals.ssh.types.SshConnectorType"
+ id="org.eclipse.tm.te.ui.terminals.type.ssh"
+ label="%SshConnectorType.label">
+ </connectorType>
+ </extension>
+
+ <extension
+ point="org.eclipse.tm.te.ui.terminals.launcherDelegates">
+ <delegate
+ class="org.eclipse.tm.te.ui.terminals.ssh.launcher.SshLauncherDelegate"
+ id="org.eclipse.tm.te.ui.terminals.ssh.launcher.ssh"
+ label="%SshLauncherDelegate.label">
+ <enablement>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate operator="and" ifEmpty="false">
+ <instanceof value="org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ </iterate>
+ </with>
+ </enablement>
+ </delegate>
+ </extension>
+</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java
new file mode 100644
index 0000000..d55595c
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java
@@ -0,0 +1,279 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tm.te.ui.terminals.ssh.controls;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.TypedEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
+import org.eclipse.tm.internal.terminal.ssh.SshConnector;
+import org.eclipse.tm.internal.terminal.ssh.SshSettings;
+import org.eclipse.tm.tcf.protocol.IPeer;
+import org.eclipse.tm.tcf.protocol.Protocol;
+import org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tm.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tm.te.ui.controls.BaseDialogPageControl;
+import org.eclipse.tm.te.ui.terminals.panels.AbstractConfigurationPanel;
+import org.eclipse.tm.te.ui.wizards.interfaces.ISharedDataWizardPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * SSH wizard configuration panel implementation.
+ */
+@SuppressWarnings("restriction")
+public class SshWizardConfigurationPanel extends AbstractConfigurationPanel implements ISharedDataWizardPage {
+
+ private SshSettings sshSettings;
+ private ISettingsPage sshSettingsPage;
+
+ /**
+ * Constructor.
+ *
+ * @param parentControl The parent control. Must not be <code>null</code>!
+ */
+ public SshWizardConfigurationPanel(BaseDialogPageControl parentControl) {
+ super(parentControl);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.controls.interfaces.IWizardConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
+ */
+ @Override
+ public void setupPanel(Composite parent, FormToolkit toolkit) {
+ Composite panel = new Composite(parent, SWT.NONE);
+ panel.setLayout(new GridLayout());
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ panel.setLayoutData(data);
+
+ SshConnector conn = new SshConnector();
+ sshSettings = (SshSettings) conn.getSshSettings();
+ sshSettings.setHost(getHost());
+ sshSettings.setUser(getDefaultUser());
+ sshSettingsPage = conn.makeSettingsPage();
+ sshSettingsPage.createControl(panel);
+
+ setControl(panel);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.controls.interfaces.IWizardConfigurationPanel#dataChanged(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.swt.events.TypedEvent)
+ */
+ @Override
+ public boolean dataChanged(IPropertiesContainer data, TypedEvent e) {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.interfaces.ISharedDataWizardPage#setupData(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ public void setupData(IPropertiesContainer data) {
+ }
+
+ /**
+ * Returns the default user name.
+ *
+ * @return The default user name.
+ */
+ private String getDefaultUser(){
+ return System.getProperty("user.name");
+ }
+
+ /**
+ * Returns the host name or IP from the current selection.
+ *
+ * @return The host name or IP.
+ */
+ private String getHost() {
+ ISelection selection = getSelection();
+ final AtomicReference<String> result = new AtomicReference<String>();
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Object element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof IPeerModel) {
+ final IPeerModel peerModel = (IPeerModel) element;
+ if (Protocol.isDispatchThread()) {
+ result.set(peerModel.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST));
+ }
+ else {
+ Protocol.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ result.set(peerModel.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST));
+ }
+ });
+ }
+ }
+ }
+
+ return result.get();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.interfaces.ISharedDataWizardPage#extractData(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ public void extractData(IPropertiesContainer data) {
+ // set the terminal connector id for ssh
+ data.setProperty(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.internal.terminal.ssh.SshConnector");
+
+ // set the connector type for ssh
+ data.setProperty(ITerminalsConnectorConstants.PROP_CONNECTOR_TYPE_ID, "org.eclipse.tm.te.ui.terminals.type.ssh");
+
+ sshSettingsPage.saveSettings();
+ data.setProperty(ITerminalsConnectorConstants.PROP_IP_HOST,sshSettings.getHost());
+ data.setProperty(ITerminalsConnectorConstants.PROP_IP_PORT, sshSettings.getPort());
+ data.setProperty(ITerminalsConnectorConstants.PROP_TIMEOUT, sshSettings.getTimeout());
+ data.setProperty(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, sshSettings.getKeepalive());
+ data.setProperty(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, sshSettings.getPassword());
+ data.setProperty(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.interfaces.ISharedDataWizardPage#initializeData(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ public void initializeData(IPropertiesContainer data) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.wizards.interfaces.ISharedDataWizardPage#removeData(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ public void removeData(IPropertiesContainer data) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.controls.interfaces.IWizardConfigurationPanel#doRestoreWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
+ */
+ @Override
+ public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) {
+ String host = getHost();
+ if (settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_IP_HOST)) != null) {
+ sshSettings.setHost(settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_IP_HOST)));
+ }
+ if (settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_IP_PORT)) != null) {
+ sshSettings.setPort(settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_IP_PORT)));
+ }
+ if (settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_TIMEOUT)) != null) {
+ sshSettings.setTimeout(settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_TIMEOUT)));
+ }
+ if (settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE)) != null) {
+ sshSettings.setKeepalive(settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE)));
+ }
+ if (settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_SSH_USER)) != null) {
+ sshSettings.setUser(settings.get(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_SSH_USER)));
+ }
+ String password = accessSecurePassword(sshSettings.getHost());
+ if (password != null) {
+ sshSettings.setPassword(password);
+ }
+ // set settings in page
+ sshSettingsPage.loadSettings();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.controls.interfaces.IWizardConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
+ */
+ @Override
+ public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
+ // make sure the values are saved
+ // actually not needed since this is done before in extractData
+ sshSettingsPage.saveSettings();
+ String host = getHost();
+ settings.put(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_IP_HOST), sshSettings.getHost());
+ settings.put(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_IP_PORT), sshSettings.getPort());
+ settings.put(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_TIMEOUT), sshSettings.getTimeout());
+ settings.put(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE), sshSettings.getKeepalive());
+ settings.put(getSettingsKeyWithPrefix(host, ITerminalsConnectorConstants.PROP_SSH_USER), sshSettings.getUser());
+
+ saveSecurePassword(sshSettings.getHost(), sshSettings.getPassword());
+ }
+
+ /**
+ * Constructs the full settings key.
+ */
+ private String getSettingsKeyWithPrefix(String host, String value) {
+ return host + "." + value;
+ }
+
+ /**
+ * Save the password to the secure storage.
+ *
+ * @param host The host. Must not be <code>null</code>.
+ * @param password The password. Must not be <code>null</code>.
+ */
+ private void saveSecurePassword(String host, String password) {
+ Assert.isNotNull(host);
+ Assert.isNotNull(password);
+
+ // To access the secure storage, we need the preference instance
+ ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
+ if (preferences != null) {
+ // Construct the secure preferences node key
+ String nodeKey = "/Target Explorer SSH Password/" + host;
+ ISecurePreferences node = preferences.node(nodeKey);
+ if (node != null) {
+ try {
+ node.put("password", password, true);
+ }
+ catch (StorageException ex) { /* ignored on purpose */ }
+ }
+ }
+ }
+
+ /**
+ * Reads the password from the secure storage.
+ *
+ * @param host The host. Must not be <code>null</code>.
+ * @return The password or <code>null</code>.
+ */
+ private String accessSecurePassword(String host) {
+ Assert.isNotNull(host);
+
+ // To access the secure storage, we need the preference instance
+ ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
+ if (preferences != null) {
+ // Construct the secure preferences node key
+ String nodeKey = "/Target Explorer SSH Password/" + host;
+ ISecurePreferences node = preferences.node(nodeKey);
+ if (node != null) {
+ String password = null;
+ try {
+ password = node.get("password", null);
+ }
+ catch (StorageException ex) { /* ignored on purpose */ }
+
+ return password;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.controls.panels.AbstractWizardConfigurationPanel#isValid()
+ */
+ @Override
+ public boolean isValid(){
+ return sshSettingsPage.validateSettings();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java
new file mode 100644
index 0000000..0be9929
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tm.te.ui.terminals.ssh.launcher;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tm.te.runtime.interfaces.callback.ICallback;
+import org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tm.te.runtime.services.ServiceManager;
+import org.eclipse.tm.te.runtime.services.interfaces.ITerminalService;
+import org.eclipse.tm.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tm.te.ui.controls.BaseDialogPageControl;
+import org.eclipse.tm.te.ui.terminals.interfaces.IConfigurationPanel;
+import org.eclipse.tm.te.ui.terminals.launcher.AbstractLauncherDelegate;
+import org.eclipse.tm.te.ui.terminals.ssh.controls.SshWizardConfigurationPanel;
+import org.eclipse.tm.te.ui.terminals.ssh.nls.Messages;
+
+/**
+ * SSH launcher delegate implementation.
+ */
+public class SshLauncherDelegate extends AbstractLauncherDelegate {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate#needsUserConfiguration()
+ */
+ @Override
+ public boolean needsUserConfiguration() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate#getPanel(org.eclipse.tm.te.ui.controls.BaseDialogPageControl)
+ */
+ @Override
+ public IConfigurationPanel getPanel(BaseDialogPageControl parentControl) {
+ return new SshWizardConfigurationPanel(parentControl);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate#execute(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tm.te.runtime.interfaces.callback.ICallback)
+ */
+ @Override
+ public void execute(IPropertiesContainer properties, ICallback callback) {
+ // Set the terminal tab title
+ String terminalTitle = getTerminalTitle(properties);
+ if (terminalTitle != null) {
+ properties.setProperty(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle);
+ }
+
+ // Get the terminal service
+ ITerminalService terminal = ServiceManager.getInstance().getService(ITerminalService.class);
+ // If not available, we cannot fulfill this request
+ if (terminal != null) {
+ terminal.openConsole(properties, callback);
+ }
+ }
+
+ /**
+ * Returns the terminal title string.
+ * <p>
+ * The default implementation constructs a title like &quot;SSH @ host (Start time) &quot;.
+ *
+ * @return The terminal title string or <code>null</code>.
+ */
+ private String getTerminalTitle(IPropertiesContainer properties) {
+ String host = properties.getStringProperty(ITerminalsConnectorConstants.PROP_IP_HOST);
+ if (host != null) {
+ DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
+ String date = format.format(new Date(System.currentTimeMillis()));
+ return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, host, date);
+ }
+ return Messages.SshLauncherDelegate_terminalTitle_default;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.java
new file mode 100644
index 0000000..a68509d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tm.te.ui.terminals.ssh.nls;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Target Explorer TCF terminals extensions UI plug-in externalized strings management.
+ */
+public class Messages extends NLS {
+
+ // The plug-in resource bundle name
+ private static final String BUNDLE_NAME = "org.eclipse.tm.te.ui.terminals.ssh.nls.Messages"; //$NON-NLS-1$
+
+ /**
+ * Static constructor.
+ */
+ static {
+ // Load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ // **** Declare externalized string id's down here *****
+
+ public static String SshLauncherDelegate_terminalTitle;
+ public static String SshLauncherDelegate_terminalTitle_default;
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.properties
new file mode 100644
index 0000000..8b0211a
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/nls/Messages.properties
@@ -0,0 +1,7 @@
+#
+# org.eclipse.tm.te.ui.terminals.ssh
+# Externalized Strings.
+#
+
+SshLauncherDelegate_terminalTitle=SSH @ {0} ({1})
+SshLauncherDelegate_terminalTitle_default=SSH Terminal
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/types/SshConnectorType.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/types/SshConnectorType.java
new file mode 100644
index 0000000..b264b49
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.ssh/src/org/eclipse/tm/te/ui/terminals/ssh/types/SshConnectorType.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tm.te.ui.terminals.ssh.types;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
+import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension;
+import org.eclipse.tm.internal.terminal.ssh.SshSettings;
+import org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tm.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tm.te.ui.terminals.internal.SettingsStore;
+import org.eclipse.tm.te.ui.terminals.types.AbstractConnectorType;
+
+/**
+ * Ssh terminal connector type implementation.
+ */
+@SuppressWarnings("restriction")
+public class SshConnectorType extends AbstractConnectorType {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.terminals.interfaces.IConnectorType#createTerminalConnector(org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ public ITerminalConnector createTerminalConnector(IPropertiesContainer properties) {
+ Assert.isNotNull(properties);
+
+ // Check for the terminal connector id
+ String connectorId = properties.getStringProperty(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
+
+ // Extract the ssh properties
+ String host = properties.getStringProperty(ITerminalsConnectorConstants.PROP_IP_HOST);
+ String port = properties.getStringProperty(ITerminalsConnectorConstants.PROP_IP_PORT);
+ String timeout = properties.getStringProperty(ITerminalsConnectorConstants.PROP_TIMEOUT);
+ String keepAlive=properties.getStringProperty(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
+ String password=properties.getStringProperty(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
+ String user=properties.getStringProperty(ITerminalsConnectorConstants.PROP_SSH_USER);
+
+ int portOffset = 0;
+ if (properties.getProperty(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) != null) {
+ portOffset = properties.getIntProperty(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET);
+ if (portOffset < 0) portOffset = 0;
+ }
+
+ return host != null && port != null ? createSshConnector(connectorId, new String[] { host, port, timeout, keepAlive, password, user }, portOffset) : null;
+ }
+
+ /**
+ * Creates a ssh connector object based on the given ssh server attributes.
+ * <p>
+ * The ssh server attributes must contain at least 2 elements:
+ * <ul>
+ * <li>attributes[0] --> ssh server host name</li>
+ * <li>attributes[1] --> ssh port</li>
+ * <li>attributes[2] --> timeout</li>
+ * <li>attributes[3] --> keep alive</li>
+ * <li>attributes[4] --> ssh password</li>
+ * <li>attributes[5] --> ssh user</li>
+ * </ul>
+ *
+ * @param connectorId The terminal connector id or <code>null</code>.
+ * @param attributes The ssh server attributes. Must not be <code>null</code>.
+ * @param portOffset Offset to add to the port.
+ *
+ * @return The terminal connector object instance or <code>null</code>.
+ */
+ protected ITerminalConnector createSshConnector(String connectorId, String[] attributes, int portOffset) {
+ Assert.isNotNull(attributes);
+ Assert.isTrue(attributes.length == 6);
+
+ if (connectorId == null) connectorId = "org.eclipse.tm.internal.terminal.ssh.SshConnector"; //$NON-NLS-1$
+
+ final String serverName = attributes[0];
+ final String serverPort = Integer.toString(Integer.decode(attributes[1]).intValue() + portOffset);
+ final String timeout = attributes[2];
+ final String keepAlive=attributes[3];
+ final String password=attributes[4];
+ final String user=attributes[5];
+
+ // Construct the ssh settings store
+ ISettingsStore store = new SettingsStore();
+
+ // Construct the telnet settings
+ SshSettings sshSettings = new SshSettings();
+ sshSettings.setHost(serverName);
+ sshSettings.setPort(serverPort);
+ sshSettings.setTimeout(timeout);
+ sshSettings.setKeepalive(keepAlive);
+ sshSettings.setPassword(password);
+ sshSettings.setUser(user);
+
+ // And save the settings to the store
+ sshSettings.save(store);
+
+ // MWE TODO make sure this is NOT passed outside as this is plain text
+ store.put("Password", password);
+
+ // Construct the terminal connector instance
+ ITerminalConnector connector = TerminalConnectorExtension.makeTerminalConnector(connectorId);
+ if (connector != null) {
+ // Apply default settings
+ connector.makeSettingsPage();
+ // And load the real settings
+ connector.load(store);
+ }
+
+ return connector;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java
index 584d66e..023d198 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java
@@ -6,6 +6,7 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
*******************************************************************************/
package org.eclipse.tm.te.ui.terminals.internal.dialogs;
@@ -30,7 +31,9 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tm.internal.terminal.view.ViewMessages;
import org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tm.te.runtime.properties.PropertiesContainer;
import org.eclipse.tm.te.ui.controls.BaseDialogPageControl;
@@ -50,6 +53,7 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* Launch terminal settings dialog implementation.
*/
+@SuppressWarnings("restriction")
public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
// The parent selection
private ISelection selection = null;
@@ -106,12 +110,19 @@ public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
/* (non-Javadoc)
* @see org.eclipse.tm.te.ui.controls.interfaces.IWizardConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite, org.eclipse.tm.te.ui.controls.interfaces.FormToolkit)
*/
- @Override
+ @SuppressWarnings("synthetic-access")
+ @Override
public void setupPanel(Composite parent, FormToolkit toolkit) {
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ Label label = new Label(panel, SWT.HORIZONTAL);
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ layoutData.widthHint = convertWidthInCharsToPixels(30);
+ layoutData.heightHint = convertHeightInCharsToPixels(5);
+ label.setLayoutData(layoutData);
+
setControl(panel);
}
@@ -173,7 +184,7 @@ public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0; layout.marginWidth = 0;
panel.setLayout(layout);
- panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
Label label = new Label(panel, SWT.HORIZONTAL);
label.setText(Messages.LaunchTerminalSettingsDialog_combo_label);
@@ -212,8 +223,6 @@ public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
settings.setupPanel(panel, terminals.getItems(), new FormToolkit(panel.getDisplay()));
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
layoutData.horizontalSpan = 2;
- layoutData.widthHint = convertWidthInCharsToPixels(30);
- layoutData.heightHint = convertHeightInCharsToPixels(5);
settings.getPanel().setLayoutData(layoutData);
// Preselect the first terminal launcher
@@ -286,6 +295,16 @@ public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
*/
@Override
protected void okPressed() {
+ IWizardConfigurationPanel panel = this.settings.getConfigurationPanel(terminals.getText());
+
+ if(!panel.isValid()){
+ String strTitle = ViewMessages.TERMINALSETTINGS;
+ MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
+ mb.setText(strTitle);
+ mb.setMessage(ViewMessages.INVALID_SETTINGS);
+ mb.open();
+ return;
+ }
data = new PropertiesContainer();
// Store the id of the selected delegate
@@ -294,7 +313,6 @@ public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
data.setProperty("selection", selection); //$NON-NLS-1$
// Store the delegate specific settings
- IWizardConfigurationPanel panel = this.settings.getConfigurationPanel(terminals.getText());
if (panel instanceof ISharedDataWizardPage) {
((ISharedDataWizardPage)panel).extractData(data);
}