diff options
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java')
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java new file mode 100644 index 000000000..0281ea235 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * 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.tcf.te.ui.terminals.ssh.launcher; + +import java.text.DateFormat; +import java.util.Date; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.tcf.te.ui.terminals.ssh.controls.SshWizardConfigurationPanel; +import org.eclipse.tcf.te.ui.terminals.ssh.nls.Messages; +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.runtime.services.interfaces.ITerminalService; +import org.eclipse.tcf.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants; +import org.eclipse.tcf.te.ui.controls.BaseDialogPageControl; +import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanel; +import org.eclipse.tcf.te.ui.terminals.launcher.AbstractLauncherDelegate; + +/** + * SSH launcher delegate implementation. + */ +public class SshLauncherDelegate extends AbstractLauncherDelegate { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#needsUserConfiguration() + */ + @Override + public boolean needsUserConfiguration() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#getPanel(org.eclipse.tcf.te.ui.controls.BaseDialogPageControl) + */ + @Override + public IConfigurationPanel getPanel(BaseDialogPageControl parentControl) { + return new SshWizardConfigurationPanel(parentControl); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#execute(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.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 "SSH @ host (Start time) ". + * + * @return The terminal title string or <code>null</code>. + */ + private String getTerminalTitle(IPropertiesContainer properties) { + String host = properties.getStringProperty(ITerminalsConnectorConstants.PROP_IP_HOST); + String user = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SSH_USER); + + if (host != null && user!= null) { + DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); + String date = format.format(new Date(System.currentTimeMillis())); + return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[]{user, host, date}); + } + return Messages.SshLauncherDelegate_terminalTitle_default; + } +} |