blob: 6a3dde91c539e2b2efe6f08b03db0c4ae0d11ccb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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.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;
import org.eclipse.tcf.te.ui.terminals.ssh.controls.SshWizardConfigurationPanel;
import org.eclipse.tcf.te.ui.terminals.ssh.nls.Messages;
/**
* 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;
}
}
|