Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Target Management » Programatically creating a connection?
Programatically creating a connection? [message #14123] Thu, 16 August 2007 20:10 Go to next message
Bryan Hunt is currently offline Bryan HuntFriend
Messages: 366
Registered: July 2009
Senior Member
I need to programatically show a terminal and create a connection
without user input except for maybe a password and even that's a maybe.
I've managed to get an ssh connection to work but I had to modify the
SshSettings.java. Here are my changes:

public void load(ISettingsStore store)
{
fHost = store.get("Host");//$NON-NLS-1$
fUser = store.get("User");//$NON-NLS-1$
fPort = store.get("Port");//$NON-NLS-1$
fPassword = store.get("Password");//$NON-NLS-1$
fTimeout = store.get("Timeout");//$NON-NLS-1$
}


And here is how I'm creating my terminal view:

package test.terminal;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
import org.eclipse.tm.internal.terminal.control.ITerminalViewContro l;
import org.eclipse.tm.internal.terminal.control.TerminalViewControl Factory;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalCo nnectorInfo;
import
org.eclipse.tm.internal.terminal.provisional.api.TerminalCon nectorExtension;
import

org.eclipse.tm.internal.terminal.provisional.api.TerminalSta te;
import org.eclipse.ui.part.ViewPart;

@SuppressWarnings("restriction")
public class TrackerTerminal extends ViewPart implements ITerminalListener
{
public void setState(TerminalState state)
{
if (state == TerminalState.CONNECTED)
{
terminal.pasteString("cd /tmp\n");
}
}

@Override
public void createPartControl(Composite parent)
{
ITerminalConnectorInfo[] connectors =
TerminalConnectorExtension.getTerminalConnectors();
terminal = TerminalViewControlFactory.makeControl(this, parent, connectors);
TerminalSettings settings = new TerminalSettings();
settings.put("Host", "****************");
settings.put("User", "*****");
settings.put("Password", "********");
settings.put("Port", "22");
settings.put("Timeout", "0");

for (ITerminalConnectorInfo element : connectors)
{
if
(element.getId().equals("org.eclipse.tm.internal.terminal.ssh.SshConnector "))
{
element.getConnector().load(settings);
terminal.setConnector(element);
}
}

terminal.connectTerminal();
}

@Override
public

void setFocus()
{
// TODO Auto-generated method stub

}

public void setTerminalTitle(String title)
{
setPartName(title);
}

private ITerminalViewControl terminal;
}

package test.terminal;

import java.util.Properties;

import org.eclipse.tm.internal.terminal.provisional.api.ISettingsSt ore;

@SuppressWarnings("restriction")
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();
}

As you can see, I'm using the API in a completely non-normal way. Is
there a better way to do this?

Bryan
Re: Programatically creating a connection? [message #14141 is a reply to message #14123] Fri, 17 August 2007 10:14 Go to previous message
Martin Oberhuber is currently offline Martin OberhuberFriend
Messages: 1007
Registered: July 2009
Senior Member
Hello Bryan,

we have an existing enhancement request for creating API to
programmatically make a terminal connection:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=185348

Feel free to discuss, and vote for that bug, or provide
a patch to implement the desired functionality.

In your concrete case, I think there is another way you
can set the SSH password without having to modify SshSettings.java
and without creating your own TerminalSettings class:

if (element.getId().equals(
"org.eclipse.tm.internal.terminal.ssh.SshConnector"))
{
SshConnector conn = (SshConnector)element.getConnector();
SshSettings settings = conn.getTelnetSettings();
settings.setHost("host");
settings.setUser("user");
settings.setPassword("password");
terminal.setConnector(element);
break;
}

Thanks,
--
Martin Oberhuber
Target Management Project Lead, DSDP PMC Member
http://www.eclipse.org/dsdp/tm
Re: Programatically creating a connection? [message #569808 is a reply to message #14123] Fri, 17 August 2007 10:14 Go to previous message
Martin Oberhuber is currently offline Martin OberhuberFriend
Messages: 1007
Registered: July 2009
Senior Member
Hello Bryan,

we have an existing enhancement request for creating API to
programmatically make a terminal connection:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=185348

Feel free to discuss, and vote for that bug, or provide
a patch to implement the desired functionality.

In your concrete case, I think there is another way you
can set the SSH password without having to modify SshSettings.java
and without creating your own TerminalSettings class:

if (element.getId().equals(
"org.eclipse.tm.internal.terminal.ssh.SshConnector"))
{
SshConnector conn = (SshConnector)element.getConnector();
SshSettings settings = conn.getTelnetSettings();
settings.setHost("host");
settings.setUser("user");
settings.setPassword("password");
terminal.setConnector(element);
break;
}

Thanks,
--
Martin Oberhuber
Target Management Project Lead, DSDP PMC Member
http://www.eclipse.org/dsdp/tm
Previous Topic:RSE 2.0.0 (TM 2.0.1) FTP STOR ignores ASCII/binary preferences saving remote files
Next Topic:slow connection to Linux sever
Goto Forum:
  


Current Time: Thu Apr 25 23:29:13 GMT 2024

Powered by FUDForum. Page generated in 0.03216 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top