How launch a terminal SSH in my RCP application [message #671939] |
Thu, 19 May 2011 11:59 |
chantal.orient Messages: 4 Registered: May 2011 |
Junior Member |
|
|
I am developing a RCP application with a view containing a treview and I wish to launch a terminal SSH from a pull-down menu to execute scripts shell or c programms interactives with arguments. Is it possible to do this with RSE ? having an other solution ?
I tried to use org.eclipse.tm.terminal, org.eclipse.tm.terminal.ssh, org.eclipse.tm.terminal.connectors but I don't know how to implement it my code.
I write thess classes and it's not OK ?
Could you help me ?
public class MyTerminalView extends ViewPart implements ITerminalListener {
public void setState(TerminalState state) {
if (state == TerminalState.CONNECTED) {
terminal.pasteString("cd /tmp\n");
}
}
private ITerminalViewControl terminal;
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
ITerminalConnector[] conn = TerminalConnectorExtension
.makeTerminalConnectors();
terminal = TerminalViewControlFactory.makeControl(this, parent, conn);
TerminalSettings settings = new TerminalSettings();
settings.put("Host", "myhost");
settings.put("User", "user");
settings.put("Password", "motdepasse");
settings.put("Port", "22");
settings.put("Timeout", "3000");
for (ITerminalConnector element : conn) {
if (element.getId().equals(
"org.eclipse.tm.internal.terminal.ssh.SshConnector")) {
element.load(settings);
terminal.setConnector(element);
break;
}
}
terminal.connectTerminal();
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
public void setTerminalTitle(String title) {
setPartName(title);
}
}
public class TerminalSettings implements ISettingsStore {
public String get(String key) {
return properties.getProperty(key);
}
public String get(String key, String defaultValue) {
return properties.getProperty(key, defaultValue);
}
public void put(String key, String value) {
properties.put(key, value);
}
private final Properties properties = new Properties();
}
Could-you help me?
|
|
|
|
Re: How launch a terminal SSH in my RCP application [message #675215 is a reply to message #671939] |
Mon, 30 May 2011 15:43 |
David McKnight Messages: 244 Registered: July 2009 |
Senior Member |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.6082" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Yes, it's possible to launch an SSH terminal from a
pull-down menu. The basic idea is that you'll need to get to the
terminal subsystem given an IHost. For example:</FONT></DIV>
<DIV>
<P><FONT face=Arial size=2>ITerminalSubSystem terminalSubSystem =
TerminalServiceHelper.getTerminalSubSystem(remoteFile.getHost());</FONT></P></DIV>
<DIV><FONT face=Arial size=2>Given a terminal subsystem, you could do something
along these lines:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>...</FONT></DIV>
<DIV><FONT face=Arial size=2>if (terminalSubSystem.isConnected()) {</FONT></DIV>
<DIV>
<P align=left><FONT face=Arial size=2> TerminalViewer termViewer = //
activate and get the viewer</FONT></P>
<P align=left><FONT face=Arial size=2> // create tab for this
terminal session</FONT></P>
<P align=left><FONT face=Arial size=2>CTabItem tab =
termViewer.getTabFolder().createTabItem(terminalSubSystem.getHost(),
getWorkingDirectory(remoteFile));</FONT></P>
<P align=left><FONT face=Arial size=2> // create a terminal
</FONT></P>
<P align=left><FONT face=Arial size=2> TerminalElement element =
TerminalServiceHelper.createTerminalElement(tab, terminalSubSystem);</FONT></P>
<P align=left><FONT face=Arial size=2>
terminalSubSystem.addChild(element);</FONT></P>
<P align=left><FONT face=Arial size=2>...</FONT></P></DIV>
<DIV><FONT face=Arial size=2>Hopefully that helps.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><</FONT><A
href="mailto:forums-noreply@eclipse.org"><FONT face=Arial
size=2>forums-noreply@eclipse.org</FONT></A><FONT face=Arial size=2>> wrote
in message </FONT><A href="news:ir306o$774$1@news.eclipse.org"><FONT face=Arial
size=2>news:ir306o$774$1@news.eclipse.org</FONT></A><FONT face=Arial
size=2>...</FONT></DIV><FONT face=Arial size=2>>I am developing a RCP
application with a view containing a treview and I wish to launch a terminal SSH
from a pull-down menu to execute scripts shell or c programms interactives with
arguments. Is it possible to do this with RSE ? having an other solution
?<BR>> I tried to use org.eclipse.tm.terminal, org.eclipse.tm.terminal.ssh,
org.eclipse.tm.terminal.connectors but I don't know how to implement it my
code.<BR>> I write thess classes and it's not OK ?<BR>> Could you help me
?<BR>> <BR>> public class MyTerminalView extends ViewPart implements
ITerminalListener {<BR>> <BR>> public void setState(TerminalState state)
{<BR>> if (state == TerminalState.CONNECTED) {<BR>>
terminal.pasteString("cd /tmp\n");<BR>> }<BR>> }<BR>> <BR>> private
ITerminalViewControl terminal;<BR>> <BR>> public void
createPartControl(Composite parent) {<BR>> // TODO Auto-generated method
stub<BR>> ITerminalConnector[] conn = TerminalConnectorExtension<BR>>
..makeTerminalConnectors();<BR>> <BR>> terminal =
TerminalViewControlFactory.makeControl(this, parent, conn);<BR>>
TerminalSettings settings = new TerminalSettings();<BR>> settings.put("Host",
"myhost");<BR>> settings.put("User", "user");<BR>>
settings.put("Password", "motdepasse");<BR>> settings.put("Port",
"22");<BR>> settings.put("Timeout", "3000");<BR>> <BR>> for
(ITerminalConnector element : conn) {<BR>> if
(element.getId().equals(<BR>>
"org.eclipse.tm.internal.terminal.ssh.SshConnector")) {<BR>>
element.load(settings);<BR>> terminal.setConnector(element);<BR>>
break;<BR>> }<BR>> }<BR>> terminal.connectTerminal();<BR>> <BR>>
}<BR>> @Override<BR>> public void setFocus() {<BR>> // TODO
Auto-generated method stub<BR>> <BR>> }<BR>> <BR>> public void
setTerminalTitle(String title) {<BR>> setPartName(title);<BR>> }<BR>>
<BR>> }<BR>> public class TerminalSettings implements ISettingsStore
{<BR>> <BR>> public String get(String key) {<BR>> return
properties.getProperty(key);<BR>> }<BR>> <BR>> public String get(String
key, String defaultValue) {<BR>> return properties.getProperty(key,
defaultValue);<BR>> }<BR>> <BR>> public void put(String key, String
value) {<BR>> properties.put(key, value);<BR>> }<BR>> <BR>> private
final Properties properties = new Properties();<BR>> }<BR>> <BR>>
<BR>> Could-you help me? <BR>></FONT></BODY></HTML>
|
|
|
Powered by
FUDForum. Page generated in 0.03003 seconds