Programatically creating a connection? [message #14123] |
Thu, 16 August 2007 16:10  |
Eclipse User |
|
|
|
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 06:14  |
Eclipse User |
|
|
|
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 06:14  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 1.04661 seconds