1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Bug 468857, bug 468858, bug 468859 - Various fixes for remote terminal.

Change-Id: I0b05724722a0fe55f45cad5c4edff9398fbb352d
Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2015-05-29 18:05:17 -04:00
parent 6e8a57dcc3
commit 7b12ea8e37
10 changed files with 219 additions and 144 deletions

View file

@ -9,19 +9,19 @@ package org.eclipse.tm.terminal.connector.remote;
public interface IRemoteSettings { public interface IRemoteSettings {
public static final String CONNECTION_NAME = "ConnectionName"; //$NON-NLS-1$ public static final String CONNECTION_NAME = "ConnectionName"; //$NON-NLS-1$
public static final String REMOTE_SERVICES = "RemoteServices"; //$NON-NLS-1$ public static final String CONNECTION_TYPE_ID = "ConnectionTypeId"; //$NON-NLS-1$
/** /**
* Get the host name or IP address of remote system to connect. * Get the connection type ID for the connection (e.g. local, ssh, etc.)
* *
* @return host name or IP address of the remote system. * @return connection type ID.
*/ */
String getRemoteServices(); String getConnectionTypeId();
/** /**
* Get the login name for connecting to the remote system. * Get the connection name for the target system.
* *
* @return remote login name * @return connection name
*/ */
String getConnectionName(); String getConnectionName();
} }

View file

@ -9,4 +9,5 @@ package org.eclipse.tm.terminal.connector.remote;
public interface IRemoteTerminalConstants { public interface IRemoteTerminalConstants {
public static final String PREF_TERMINAL_SHELL_COMMAND = "TERMINAL_SHELL_COMMAND"; //$NON-NLS-1$ public static final String PREF_TERMINAL_SHELL_COMMAND = "TERMINAL_SHELL_COMMAND"; //$NON-NLS-1$
public static final String PREF_TERMINAL_TYPE = "TERMINAL_TYPE"; //$NON-NLS-1$
} }

View file

@ -33,19 +33,22 @@ import org.eclipse.tm.terminal.view.ui.panels.AbstractExtendedConfigurationPanel
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class RemoteWizardConfigurationPanel extends AbstractExtendedConfigurationPanel { public class RemoteWizardConfigurationPanel extends AbstractExtendedConfigurationPanel {
public RemoteSettings remoteSettings; private RemoteSettings remoteSettings;
private ISettingsPage remoteSettingsPage; private ISettingsPage remoteSettingsPage;
/** /**
* Constructor. * Constructor.
* *
* @param container The configuration panel container or <code>null</code>. * @param container
* The configuration panel container or <code>null</code>.
*/ */
public RemoteWizardConfigurationPanel(IConfigurationPanelContainer container) { public RemoteWizardConfigurationPanel(IConfigurationPanelContainer container) {
super(container); super(container);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite) * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite)
*/ */
@Override @Override
@ -60,7 +63,7 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio
remoteSettingsPage = new RemoteSettingsPage(remoteSettings); remoteSettingsPage = new RemoteSettingsPage(remoteSettings);
if (remoteSettingsPage instanceof AbstractSettingsPage) { if (remoteSettingsPage instanceof AbstractSettingsPage) {
((AbstractSettingsPage)remoteSettingsPage).setHasControlDecoration(true); ((AbstractSettingsPage) remoteSettingsPage).setHasControlDecoration(true);
} }
remoteSettingsPage.createControl(panel); remoteSettingsPage.createControl(panel);
@ -69,7 +72,9 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio
@Override @Override
public void onSettingsPageChanged(Control control) { public void onSettingsPageChanged(Control control) {
if (getContainer() != null) getContainer().validate(); if (getContainer() != null) {
getContainer().validate();
}
} }
}); });
@ -79,79 +84,107 @@ public class RemoteWizardConfigurationPanel extends AbstractExtendedConfiguratio
setControl(panel); setControl(panel);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#setupData(java.util.Map) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#setupData(java.util.Map)
*/ */
@Override @Override
public void setupData(Map<String, Object> data) { public void setupData(Map<String, Object> data) {
if (data == null || remoteSettings == null || remoteSettingsPage == null) return; if (data == null || remoteSettings == null || remoteSettingsPage == null) {
return;
}
String value = (String)data.get(IRemoteSettings.REMOTE_SERVICES); String value = (String) data.get(IRemoteSettings.CONNECTION_TYPE_ID);
if (value != null) remoteSettings.setRemoteServices(value); if (value != null) {
remoteSettings.setConnectionTypeId(value);
}
value = (String)data.get(IRemoteSettings.CONNECTION_NAME); value = (String) data.get(IRemoteSettings.CONNECTION_NAME);
if (value != null) remoteSettings.setConnectionName(value); if (value != null) {
remoteSettings.setConnectionName(value);
}
value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING); value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
if (value != null) setEncoding(value); if (value != null) {
setEncoding(value);
}
remoteSettingsPage.loadSettings(); remoteSettingsPage.loadSettings();
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#extractData(java.util.Map) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#extractData(java.util.Map)
*/ */
@Override @Override
public void extractData(Map<String, Object> data) { public void extractData(Map<String, Object> data) {
if (data == null) return; if (data == null) {
return;
}
// set the terminal connector id for remote // set the terminal connector id for remote
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.remote.RemoteConnector"); //$NON-NLS-1$ data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
"org.eclipse.tm.terminal.connector.remote.RemoteConnector"); //$NON-NLS-1$
remoteSettingsPage.saveSettings(); remoteSettingsPage.saveSettings();
data.put(IRemoteSettings.REMOTE_SERVICES, remoteSettings.getRemoteServices());
data.put(IRemoteSettings.CONNECTION_NAME, remoteSettings.getConnectionName());
data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
}
/* (non-Javadoc) data.put(IRemoteSettings.CONNECTION_TYPE_ID, remoteSettings.getConnectionTypeId());
data.put(IRemoteSettings.CONNECTION_NAME, remoteSettings.getConnectionName());
if (getEncoding() != null) {
data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String)
*/ */
@Override @Override
protected void fillSettingsForHost(String host){ protected void fillSettingsForHost(String host) {
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean)
*/ */
@Override @Override
protected void saveSettingsForHost(boolean add){ protected void saveSettingsForHost(boolean add) {
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid() * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid()
*/ */
@Override @Override
public boolean isValid(){ public boolean isValid() {
return isEncodingValid() && remoteSettingsPage.validateSettings(); return isEncodingValid() && remoteSettingsPage.validateSettings();
} }
/* (non-Javadoc) /*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) * (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.
* IDialogSettings, java.lang.String)
*/ */
@Override @Override
public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
saveSettingsForHost(true); saveSettingsForHost(true);
super.doSaveWidgetValues(settings, idPrefix); super.doSaveWidgetValues(settings, idPrefix);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings() * @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#getHostFromSettings()
*/ */
@Override @Override
protected String getHostFromSettings() { protected String getHostFromSettings() {
remoteSettingsPage.saveSettings(); remoteSettingsPage.saveSettings();
return null; return null;
} }
} }

View file

@ -28,6 +28,7 @@ import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcess;
import org.eclipse.remote.core.IRemoteProcessBuilder; import org.eclipse.remote.core.IRemoteProcessBuilder;
import org.eclipse.remote.core.IRemoteProcessService; import org.eclipse.remote.core.IRemoteProcessService;
import org.eclipse.remote.core.IRemoteProcessTerminalService;
import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
@ -40,12 +41,14 @@ import org.eclipse.tm.terminal.connector.remote.nls.Messages;
public class RemoteConnectionManager extends Job { public class RemoteConnectionManager extends Job {
private final static String PARSERS_EXTENSION_POINT = "parsers"; //$NON-NLS-1$ private final static String PARSERS_EXTENSION_POINT = "parsers"; //$NON-NLS-1$
private final static String PARSER_ELEMENT = "parser"; //$NON-NLS-1$ private final static String PARSER_ELEMENT = "parser"; //$NON-NLS-1$
private static int fgNo; private static int fgNo;
private final ITerminalControl control; private final ITerminalControl control;
private final RemoteConnector connector; private final RemoteConnector connector;
private IRemoteTerminalParser parser; private IRemoteTerminalParser parser;
private IRemoteProcess remoteProcess;
protected RemoteConnectionManager(RemoteConnector conn, ITerminalControl control) { protected RemoteConnectionManager(RemoteConnector conn, ITerminalControl control) {
super("Remote Terminal-" + fgNo++); //$NON-NLS-1$ super("Remote Terminal-" + fgNo++); //$NON-NLS-1$
@ -62,31 +65,32 @@ public class RemoteConnectionManager extends Job {
*/ */
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
IRemoteProcess remoteProcess = null;
IRemoteConnection remoteConnection = null; IRemoteConnection remoteConnection = null;
try { try {
IRemoteServicesManager svcMgr = Activator.getService(IRemoteServicesManager.class); IRemoteServicesManager svcMgr = Activator.getService(IRemoteServicesManager.class);
String connTypeId = connector.getRemoteSettings().getRemoteServices(); String connTypeId = connector.getRemoteSettings().getConnectionTypeId();
IRemoteConnectionType connType = svcMgr.getConnectionType(connTypeId); IRemoteConnectionType connType = svcMgr.getConnectionType(connTypeId);
if (connType != null) { if (connType != null) {
remoteConnection = connType.getConnection(connector.getRemoteSettings().getConnectionName()); remoteConnection = connType.getConnection(connector.getRemoteSettings().getConnectionName());
} }
if (remoteConnection == null) { if (remoteConnection == null) {
throw new RemoteConnectionException(NLS.bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings() throw new RemoteConnectionException(
.getConnectionName())); NLS.bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings().getConnectionName()));
} }
if (!remoteConnection.isOpen()) { if (!remoteConnection.isOpen()) {
remoteConnection.open(monitor); remoteConnection.open(monitor);
if (!remoteConnection.isOpen()) { if (!remoteConnection.isOpen()) {
throw new RemoteConnectionException(NLS.bind(Messages.RemoteConnectionManager_1, connector.getRemoteSettings() throw new RemoteConnectionException(
.getConnectionName())); NLS.bind(Messages.RemoteConnectionManager_1, connector.getRemoteSettings().getConnectionName()));
} }
} }
if (parser != null) { if (parser != null) {
remoteProcess = parser.initialize(remoteConnection); synchronized (this) {
remoteProcess = parser.initialize(remoteConnection);
}
} else { } else {
/* /*
* Check the terminal shell command preference. If the preference is empty and we support a command shell, * Check the terminal shell command preference. If the preference is empty and we support a command shell,
@ -97,18 +101,23 @@ public class RemoteConnectionManager extends Job {
if (!("".equals(terminalShellCommand)) //$NON-NLS-1$ if (!("".equals(terminalShellCommand)) //$NON-NLS-1$
&& remoteConnection.hasService(IRemoteCommandShellService.class)) { && remoteConnection.hasService(IRemoteCommandShellService.class)) {
IRemoteCommandShellService cmdShellSvc = remoteConnection.getService(IRemoteCommandShellService.class); IRemoteCommandShellService cmdShellSvc = remoteConnection.getService(IRemoteCommandShellService.class);
remoteProcess = cmdShellSvc.getCommandShell(IRemoteProcessBuilder.ALLOCATE_PTY); synchronized (this) {
remoteProcess = cmdShellSvc.getCommandShell(IRemoteProcessBuilder.ALLOCATE_PTY);
}
} else { } else {
if ("".equals(terminalShellCommand)) { //$NON-NLS-1$ if ("".equals(terminalShellCommand)) { //$NON-NLS-1$
terminalShellCommand = "/bin/bash -l"; //$NON-NLS-1$ terminalShellCommand = "/bin/bash -l"; //$NON-NLS-1$
} }
IRemoteProcessService procSvc = remoteConnection.getService(IRemoteProcessService.class); IRemoteProcessService procSvc = remoteConnection.getService(IRemoteProcessService.class);
IRemoteProcessBuilder processBuilder = procSvc.getProcessBuilder(new ArgumentParser(terminalShellCommand) IRemoteProcessBuilder processBuilder = procSvc
.getTokenList()); .getProcessBuilder(new ArgumentParser(terminalShellCommand).getTokenList());
remoteProcess = processBuilder.start(IRemoteProcessBuilder.ALLOCATE_PTY); synchronized (this) {
remoteProcess = processBuilder.start(IRemoteProcessBuilder.ALLOCATE_PTY);
}
} }
} }
control.setVT100LineWrapping(true);
connector.setInputStream(remoteProcess.getInputStream()); connector.setInputStream(remoteProcess.getInputStream());
control.setState(TerminalState.CONNECTED); control.setState(TerminalState.CONNECTED);
control.setTerminalTitle(remoteConnection.getName()); control.setTerminalTitle(remoteConnection.getName());
@ -123,20 +132,27 @@ public class RemoteConnectionManager extends Job {
} finally { } finally {
// make sure the terminal is disconnected when the thread ends // make sure the terminal is disconnected when the thread ends
connector.disconnect(); connector.disconnect();
synchronized (this) {
if (remoteProcess != null && !remoteProcess.isCompleted()) {
remoteProcess.destroy();
}
}
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} }
@Override
protected void canceling() {
super.canceling();
synchronized (this) {
if (remoteProcess != null && !remoteProcess.isCompleted()) {
remoteProcess.destroy();
}
}
}
public void setTerminalSize(int cols, int rows, int width, int height) { public void setTerminalSize(int cols, int rows, int width, int height) {
// Enable for org.eclipse.remote v1.2 if (remoteProcess != null) {
// if (remoteProcess instanceof IRemoteTerminal) { IRemoteProcessTerminalService termSvc = remoteProcess.getService(IRemoteProcessTerminalService.class);
// ((IRemoteTerminal) remoteProcess).setTerminalSize(cols, rows, width, height); if (termSvc != null) {
// } termSvc.setTerminalSize(cols, rows, width, height);
}
}
} }
/** /**
@ -147,11 +163,8 @@ public class RemoteConnectionManager extends Job {
*/ */
private void readData(InputStream in) throws IOException { private void readData(InputStream in) throws IOException {
byte[] buf = new byte[32 * 1024]; byte[] buf = new byte[32 * 1024];
while (getState() == Job.RUNNING) { int n;
int n = in.read(buf, 0, buf.length); while ((n = in.read(buf, 0, buf.length)) > 0) {
if (n <= 0) {
break;
}
if (parser == null || parser.parse(buf)) { if (parser == null || parser.parse(buf)) {
control.getRemoteToTerminalOutputStream().write(buf, 0, n); control.getRemoteToTerminalOutputStream().write(buf, 0, n);
} }

View file

@ -56,22 +56,6 @@ public class RemoteConnector extends TerminalConnectorImpl {
*/ */
@Override @Override
public synchronized void doDisconnect() { public synchronized void doDisconnect() {
if (getInputStream() != null) {
try {
getInputStream().close();
} catch (Exception exception) {
Activator.log(exception);
}
}
if (getTerminalToRemoteStream() != null) {
try {
getTerminalToRemoteStream().close();
} catch (Exception exception) {
Activator.log(exception);
}
}
fConnection.cancel(); fConnection.cancel();
} }
@ -117,7 +101,7 @@ public class RemoteConnector extends TerminalConnectorImpl {
public void setDefaultSettings() { public void setDefaultSettings() {
fSettings.load(new NullSettingsStore()); fSettings.load(new NullSettingsStore());
} }
@Override @Override
public void save(ISettingsStore store) { public void save(ISettingsStore store) {
fSettings.save(store); fSettings.save(store);

View file

@ -12,22 +12,24 @@ import org.eclipse.tm.terminal.connector.remote.IRemoteSettings;
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class RemoteSettings implements IRemoteSettings { public class RemoteSettings implements IRemoteSettings {
protected String fRemoteServices; protected String connectionTypeId;
protected String fConnectionName; protected String connectionName;
public RemoteSettings() { public RemoteSettings() {
} }
@Override
public String getConnectionName() { public String getConnectionName() {
return fConnectionName; return connectionName;
} }
public String getRemoteServices() { @Override
return fRemoteServices; public String getConnectionTypeId() {
return connectionTypeId;
} }
public String getSummary() { public String getSummary() {
return "Remote:" + getRemoteServices() + '_' + getConnectionName(); //$NON-NLS-1$ return "Remote:" + getConnectionTypeId() + '_' + getConnectionName(); //$NON-NLS-1$
} }
@Override @Override
@ -39,23 +41,23 @@ public class RemoteSettings implements IRemoteSettings {
* Load information into the RemoteSettings object. * Load information into the RemoteSettings object.
*/ */
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fRemoteServices = store.get(REMOTE_SERVICES, ""); //$NON-NLS-1$ connectionTypeId = store.get(CONNECTION_TYPE_ID, ""); //$NON-NLS-1$
fConnectionName = store.get(CONNECTION_NAME, ""); //$NON-NLS-1$ connectionName = store.get(CONNECTION_NAME, ""); //$NON-NLS-1$
} }
/** /**
* Extract information from the RemoteSettings object. * Extract information from the RemoteSettings object.
*/ */
public void save(ISettingsStore store) { public void save(ISettingsStore store) {
store.put(REMOTE_SERVICES, fRemoteServices); store.put(CONNECTION_TYPE_ID, connectionTypeId);
store.put(CONNECTION_NAME, fConnectionName); store.put(CONNECTION_NAME, connectionName);
} }
public void setConnectionName(String name) { public void setConnectionName(String name) {
fConnectionName = name; connectionName = name;
} }
public void setRemoteServices(String remoteServices) { public void setConnectionTypeId(String id) {
fRemoteServices = remoteServices; connectionTypeId = id;
} }
} }

View file

@ -30,7 +30,7 @@ public class RemoteSettingsPage extends AbstractSettingsPage {
if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) { if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) {
if (fRemoteConnectionWidget.getConnection() != null) { if (fRemoteConnectionWidget.getConnection() != null) {
if (fRemoteConnectionWidget.getConnection().getConnectionType() != null) { if (fRemoteConnectionWidget.getConnection().getConnectionType() != null) {
fTerminalSettings.setRemoteServices(fRemoteConnectionWidget.getConnection().getConnectionType().getId()); fTerminalSettings.setConnectionTypeId(fRemoteConnectionWidget.getConnection().getConnectionType().getId());
} }
fTerminalSettings.setConnectionName(fRemoteConnectionWidget.getConnection().getName()); fTerminalSettings.setConnectionName(fRemoteConnectionWidget.getConnection().getName());
} }
@ -40,7 +40,7 @@ public class RemoteSettingsPage extends AbstractSettingsPage {
@Override @Override
public void loadSettings() { public void loadSettings() {
if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) { if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) {
fRemoteConnectionWidget.setConnection(fTerminalSettings.getRemoteServices(), fTerminalSettings.getConnectionName()); fRemoteConnectionWidget.setConnection(fTerminalSettings.getConnectionTypeId(), fTerminalSettings.getConnectionName());
} }
} }
@ -53,7 +53,8 @@ public class RemoteSettingsPage extends AbstractSettingsPage {
@Override @Override
public boolean validateSettings() { public boolean validateSettings() {
if (fRemoteConnectionWidget == null || fRemoteConnectionWidget.isDisposed() || fRemoteConnectionWidget.getConnection() == null) { if (fRemoteConnectionWidget == null || fRemoteConnectionWidget.isDisposed()
|| fRemoteConnectionWidget.getConnection() == null) {
return false; return false;
} }
return true; return true;

View file

@ -20,8 +20,10 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.eclipse.ui.preferences.ScopedPreferenceStore;
public class RemoteTerminalPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public class RemoteTerminalPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
@Override
protected void createFieldEditors() { protected void createFieldEditors() {
Composite parent = getFieldEditorParent(); Composite parent = getFieldEditorParent();
addField(new StringFieldEditor(IRemoteTerminalConstants.PREF_TERMINAL_TYPE, "Terminal Type", parent));
addField(new StringFieldEditor(IRemoteTerminalConstants.PREF_TERMINAL_SHELL_COMMAND, addField(new StringFieldEditor(IRemoteTerminalConstants.PREF_TERMINAL_SHELL_COMMAND,
Messages.RemoteTerminalPreferencePage_0, parent)); Messages.RemoteTerminalPreferencePage_0, parent));
} }
@ -31,6 +33,7 @@ public class RemoteTerminalPreferencePage extends FieldEditorPreferencePage impl
return new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.getUniqueIdentifier()); return new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.getUniqueIdentifier());
} }
@Override
public void init(IWorkbench workbench) { public void init(IWorkbench workbench) {
// Nothing // Nothing
} }

View file

@ -15,11 +15,15 @@ import java.util.Map;
import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.Assert;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension; import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension;
import org.eclipse.tm.terminal.connector.remote.IRemoteSettings; import org.eclipse.tm.terminal.connector.remote.IRemoteSettings;
import org.eclipse.tm.terminal.connector.remote.controls.RemoteWizardConfigurationPanel; import org.eclipse.tm.terminal.connector.remote.controls.RemoteWizardConfigurationPanel;
import org.eclipse.tm.terminal.connector.remote.internal.Activator;
import org.eclipse.tm.terminal.connector.remote.internal.RemoteSettings; import org.eclipse.tm.terminal.connector.remote.internal.RemoteSettings;
import org.eclipse.tm.terminal.connector.remote.nls.Messages; import org.eclipse.tm.terminal.connector.remote.nls.Messages;
import org.eclipse.tm.terminal.view.core.TerminalServiceFactory; import org.eclipse.tm.terminal.view.core.TerminalServiceFactory;
@ -39,7 +43,9 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate {
// The Remote terminal connection memento handler // The Remote terminal connection memento handler
private final IMementoHandler mementoHandler = new RemoteMementoHandler(); private final IMementoHandler mementoHandler = new RemoteMementoHandler();
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#needsUserConfiguration() * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#needsUserConfiguration()
*/ */
@Override @Override
@ -47,33 +53,27 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate {
return true; return true;
} }
/* (non-Javadoc) /*
* @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#getPanel(org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanelContainer) * (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#getPanel(org.eclipse.tm.terminal.view.ui.interfaces.
* IConfigurationPanelContainer)
*/ */
@Override @Override
public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
return new RemoteWizardConfigurationPanel(container); return new RemoteWizardConfigurationPanel(container);
} }
/* (non-Javadoc) /*
* @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#execute(java.util.Map, org.eclipse.tm.terminal.view.core.interfaces.ITerminalService.Done) * (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#execute(java.util.Map,
* org.eclipse.tm.terminal.view.core.interfaces.ITerminalService.Done)
*/ */
@Override @Override
public void execute(Map<String, Object> properties, ITerminalService.Done done) { public void execute(Map<String, Object> properties, ITerminalService.Done done) {
Assert.isNotNull(properties); Assert.isNotNull(properties);
// Set the terminal tab title
String terminalTitle = getTerminalTitle(properties);
if (terminalTitle != null) {
properties.put(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle);
}
// For Telnet terminals, force a new terminal tab each time it is launched,
// if not set otherwise from outside
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) {
properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE);
}
// Get the terminal service // Get the terminal service
ITerminalService terminal = TerminalServiceFactory.getService(); ITerminalService terminal = TerminalServiceFactory.getService();
// If not available, we cannot fulfill this request // If not available, we cannot fulfill this request
@ -90,50 +90,56 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate {
* @return The terminal title string or <code>null</code>. * @return The terminal title string or <code>null</code>.
*/ */
private String getTerminalTitle(Map<String, Object> properties) { private String getTerminalTitle(Map<String, Object> properties) {
String connection = (String)properties.get(IRemoteSettings.CONNECTION_NAME); String connection = (String) properties.get(IRemoteSettings.CONNECTION_NAME);
if (connection != null) { if (connection != null) {
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String date = format.format(new Date(System.currentTimeMillis())); String date = format.format(new Date(System.currentTimeMillis()));
return NLS.bind(Messages.RemoteLauncherDelegate_terminalTitle, new String[]{connection, date}); return NLS.bind(Messages.RemoteLauncherDelegate_terminalTitle, new String[] { connection, date });
} }
return Messages.RemoteLauncherDelegate_terminalTitle_default; return Messages.RemoteLauncherDelegate_terminalTitle_default;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
public Object getAdapter(Class adapter) { public Object getAdapter(Class adapter) {
if (IMementoHandler.class.equals(adapter)) { if (IMementoHandler.class.equals(adapter)) {
return mementoHandler; return mementoHandler;
} }
return super.getAdapter(adapter); return super.getAdapter(adapter);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map)
*/ */
@Override @Override
public ITerminalConnector createTerminalConnector(Map<String, Object> properties) { public ITerminalConnector createTerminalConnector(Map<String, Object> properties) {
Assert.isNotNull(properties); Assert.isNotNull(properties);
// Check for the terminal connector id // Check for the terminal connector id
String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.remote.RemoteConnector"; //$NON-NLS-1$ if (connectorId == null) {
connectorId = "org.eclipse.tm.terminal.connector.remote.RemoteConnector"; //$NON-NLS-1$
}
// Extract the remote properties // Extract the remote properties
String services = (String)properties.get(IRemoteSettings.REMOTE_SERVICES); String connTypeId = (String) properties.get(IRemoteSettings.CONNECTION_TYPE_ID);
String connection = (String)properties.get(IRemoteSettings.CONNECTION_NAME); String connName = (String) properties.get(IRemoteSettings.CONNECTION_NAME);
// Construct the terminal settings store // Construct the terminal settings store
ISettingsStore store = new SettingsStore(); ISettingsStore store = new SettingsStore();
// Construct the remote settings // Construct the remote settings
RemoteSettings remoteSettings = new RemoteSettings(); RemoteSettings remoteSettings = new RemoteSettings();
remoteSettings.setRemoteServices(services); remoteSettings.setConnectionTypeId(connTypeId);
remoteSettings.setConnectionName(connection); remoteSettings.setConnectionName(connName);
// And save the settings to the store // And save the settings to the store
remoteSettings.save(store); remoteSettings.save(store);
@ -146,6 +152,33 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate {
connector.load(store); connector.load(store);
} }
// Set the terminal tab title
String terminalTitle = getTerminalTitle(properties);
if (terminalTitle != null) {
properties.put(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle);
}
// For Telnet terminals, force a new terminal tab each time it is launched,
// if not set otherwise from outside
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) {
properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE);
}
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_ENCODING)) {
IRemoteServicesManager svcMgr = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType connType = svcMgr.getConnectionType(connTypeId);
if (connType != null) {
IRemoteConnection remoteConnection = connType.getConnection(connName);
if (remoteConnection != null && remoteConnection.isOpen()) {
properties.put(ITerminalsConnectorConstants.PROP_ENCODING,
remoteConnection.getProperty(IRemoteConnection.LOCALE_CHARMAP_PROPERTY));
}
}
}
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, "/tmp"); //$NON-NLS-1$
return connector; return connector;
} }
} }

View file

@ -22,7 +22,9 @@ import org.eclipse.ui.IMemento;
*/ */
public class RemoteMementoHandler implements IMementoHandler { public class RemoteMementoHandler implements IMementoHandler {
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#saveState(org.eclipse.ui.IMemento, java.util.Map) * @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#saveState(org.eclipse.ui.IMemento, java.util.Map)
*/ */
@Override @Override
@ -32,12 +34,15 @@ public class RemoteMementoHandler implements IMementoHandler {
// Do not write the terminal title to the memento -> needs to // Do not write the terminal title to the memento -> needs to
// be recreated at the time of restoration. // be recreated at the time of restoration.
memento.putString(IRemoteSettings.CONNECTION_NAME, (String)properties.get(IRemoteSettings.CONNECTION_NAME)); memento.putString(IRemoteSettings.CONNECTION_NAME, (String) properties.get(IRemoteSettings.CONNECTION_NAME));
memento.putString(IRemoteSettings.REMOTE_SERVICES, (String)properties.get(IRemoteSettings.REMOTE_SERVICES)); memento.putString(IRemoteSettings.CONNECTION_TYPE_ID, (String) properties.get(IRemoteSettings.CONNECTION_TYPE_ID));
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING)); memento.putString(ITerminalsConnectorConstants.PROP_ENCODING,
(String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#restoreState(org.eclipse.ui.IMemento, java.util.Map) * @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#restoreState(org.eclipse.ui.IMemento, java.util.Map)
*/ */
@Override @Override
@ -47,7 +52,7 @@ public class RemoteMementoHandler implements IMementoHandler {
// Restore the terminal properties from the memento // Restore the terminal properties from the memento
properties.put(IRemoteSettings.CONNECTION_NAME, memento.getString(IRemoteSettings.CONNECTION_NAME)); properties.put(IRemoteSettings.CONNECTION_NAME, memento.getString(IRemoteSettings.CONNECTION_NAME));
properties.put(IRemoteSettings.REMOTE_SERVICES, memento.getString(IRemoteSettings.REMOTE_SERVICES)); properties.put(IRemoteSettings.CONNECTION_TYPE_ID, memento.getString(IRemoteSettings.CONNECTION_TYPE_ID));
properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING)); properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
} }
} }