Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Target Management » How launch a terminal SSH in my RCP application(I want execute interactives script shell and C programs on a remote server)
How launch a terminal SSH in my RCP application [message #671939] Thu, 19 May 2011 07:59 Go to next message
chantal.orient is currently offline 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 #672166 is a reply to message #671939] Fri, 20 May 2011 03:01 Go to previous messageGo to next message
chantal.orient is currently offline chantal.orient
Messages: 4
Registered: May 2011
Junior Member
Now it's ok, I wrote a new classes for replacing TerminalViewControlFactory and VT100Emulator because in VT100 emulator I had a problem with method WaitforConnect() in VT100emulator .
Re: How launch a terminal SSH in my RCP application [message #675215 is a reply to message #671939] Mon, 30 May 2011 11:43 Go to previous message
David McKnight is currently offline 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.&nbsp; The basic idea is that you'll need to get&nbsp;to the
terminal subsystem given an IHost.&nbsp; 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>&nbsp;</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>&nbsp;TerminalViewer termViewer = //
activate and get the viewer</FONT></P>
<P align=left><FONT face=Arial size=2>&nbsp; // create&nbsp; 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>&nbsp; // create a terminal&nbsp;
</FONT></P>
<P align=left><FONT face=Arial size=2>&nbsp;&nbsp; TerminalElement element =
TerminalServiceHelper.createTerminalElement(tab, terminalSubSystem);</FONT></P>
<P align=left><FONT face=Arial size=2>&nbsp;
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>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&lt;</FONT><A
href="mailto:forums-noreply@eclipse.org"><FONT face=Arial
size=2>forums-noreply@eclipse.org</FONT></A><FONT face=Arial size=2>&gt; 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>&gt;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>&gt; 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>&gt; I write thess classes and it's not OK ?<BR>&gt; Could you help me
?<BR>&gt; <BR>&gt; public&nbsp; class MyTerminalView extends ViewPart implements
ITerminalListener {<BR>&gt; <BR>&gt; public void setState(TerminalState state)
{<BR>&gt; if (state == TerminalState.CONNECTED) {<BR>&gt;
terminal.pasteString("cd /tmp\n");<BR>&gt; }<BR>&gt; }<BR>&gt; <BR>&gt; private
ITerminalViewControl terminal;<BR>&gt; <BR>&gt; public void
createPartControl(Composite parent) {<BR>&gt; // TODO Auto-generated method
stub<BR>&gt; ITerminalConnector[] conn = TerminalConnectorExtension<BR>&gt;
..makeTerminalConnectors();<BR>&gt; <BR>&gt; terminal =
TerminalViewControlFactory.makeControl(this, parent, conn);<BR>&gt;
TerminalSettings settings = new TerminalSettings();<BR>&gt; settings.put("Host",
"myhost");<BR>&gt; settings.put("User", "user");<BR>&gt;
settings.put("Password", "motdepasse");<BR>&gt; settings.put("Port",
"22");<BR>&gt; settings.put("Timeout", "3000");<BR>&gt; <BR>&gt; for
(ITerminalConnector element : conn) {<BR>&gt; if
(element.getId().equals(<BR>&gt;
"org.eclipse.tm.internal.terminal.ssh.SshConnector")) {<BR>&gt;
element.load(settings);<BR>&gt; terminal.setConnector(element);<BR>&gt;
break;<BR>&gt; }<BR>&gt; }<BR>&gt; terminal.connectTerminal();<BR>&gt; <BR>&gt;
}<BR>&gt; @Override<BR>&gt; public void setFocus() {<BR>&gt; // TODO
Auto-generated method stub<BR>&gt; <BR>&gt; }<BR>&gt; <BR>&gt; public void
setTerminalTitle(String title) {<BR>&gt; setPartName(title);<BR>&gt; }<BR>&gt;
<BR>&gt; }<BR>&gt; public class TerminalSettings implements ISettingsStore
{<BR>&gt; <BR>&gt; public String get(String key) {<BR>&gt; return
properties.getProperty(key);<BR>&gt; }<BR>&gt; <BR>&gt; public String get(String
key, String defaultValue) {<BR>&gt; return properties.getProperty(key,
defaultValue);<BR>&gt; }<BR>&gt; <BR>&gt; public void put(String key, String
value) {<BR>&gt; properties.put(key, value);<BR>&gt; }<BR>&gt; <BR>&gt; private
final Properties properties = new Properties();<BR>&gt; }<BR>&gt; <BR>&gt;
<BR>&gt; Could-you help me? <BR>&gt;</FONT></BODY></HTML>
Previous Topic:SFTP sync local project with remote.
Next Topic:RSE perspective: host properties default encoding
Goto Forum:
  


Current Time: Thu Jul 24 19:08:11 EDT 2014

Powered by FUDForum. Page generated in 0.02330 seconds