From 468e07f0623799716e0f3f5ee80d1cc4208c1e5d Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Tue, 9 Jun 2015 11:40:51 +0200 Subject: [PATCH] Adapt fix for Bug 469415 (Allow user set the title explicitly) for all existing connectors --- .../local/launcher/LocalLauncherDelegate.java | 5 +++ .../launcher/RemoteLauncherDelegate.java | 31 +++++++------------ .../launcher/SerialLauncherDelegate.java | 5 +++ .../ssh/launcher/SshLauncherDelegate.java | 7 ++--- .../launcher/TelnetLauncherDelegate.java | 9 +++--- .../ui/launcher/AbstractLauncherDelegate.java | 7 ++--- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java index 36396b7723f..c8db0707793 100644 --- a/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.connector.local/src/org/eclipse/tm/terminal/connector/local/launcher/LocalLauncherDelegate.java @@ -220,12 +220,17 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate { * @return The terminal title string or null. */ private String getTerminalTitle(Map properties) { + // Try to see if the user set a title explicitly via the properties map. + String title = getDefaultTerminalTitle(properties); + if (title != null) return title; + try { String hostname = InetAddress.getLocalHost().getHostName(); if (hostname != null && !"".equals(hostname.trim())) { //$NON-NLS-1$ return hostname; } } catch (UnknownHostException e) { /* ignored on purpose */ } + return "Local"; //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java index 72c4f424f08..587d425a786 100644 --- a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java @@ -43,9 +43,7 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { // The Remote terminal connection memento handler private final IMementoHandler mementoHandler = new RemoteMementoHandler(); - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#needsUserConfiguration() */ @Override @@ -53,22 +51,16 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { 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 public IConfigurationPanel getPanel(IConfigurationPanelContainer 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 public void execute(Map properties, ITerminalService.Done done) { @@ -90,6 +82,10 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { * @return The terminal title string or null. */ private String getTerminalTitle(Map properties) { + // Try to see if the user set a title explicitly via the properties map. + String title = getDefaultTerminalTitle(properties); + if (title != null) return title; + String connection = (String) properties.get(IRemoteSettings.CONNECTION_NAME); if (connection != null) { @@ -97,12 +93,11 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { String date = format.format(new Date(System.currentTimeMillis())); return NLS.bind(Messages.RemoteLauncherDelegate_terminalTitle, new String[] { connection, date }); } + return Messages.RemoteLauncherDelegate_terminalTitle_default; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) */ @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -114,9 +109,7 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { return super.getAdapter(adapter); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map) */ @Override diff --git a/plugins/org.eclipse.tm.terminal.connector.serial/src/org/eclipse/tm/terminal/connector/serial/launcher/SerialLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.connector.serial/src/org/eclipse/tm/terminal/connector/serial/launcher/SerialLauncherDelegate.java index 39a551b9081..7e947b8920c 100644 --- a/plugins/org.eclipse.tm.terminal.connector.serial/src/org/eclipse/tm/terminal/connector/serial/launcher/SerialLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.connector.serial/src/org/eclipse/tm/terminal/connector/serial/launcher/SerialLauncherDelegate.java @@ -83,6 +83,10 @@ public class SerialLauncherDelegate extends AbstractLauncherDelegate { * @return The terminal title string or null. */ private String getTerminalTitle(Map properties) { + // Try to see if the user set a title explicitly via the properties map. + String title = getDefaultTerminalTitle(properties); + if (title != null) return title; + String device = (String)properties.get(ITerminalsConnectorConstants.PROP_SERIAL_DEVICE); if (device != null) { @@ -90,6 +94,7 @@ public class SerialLauncherDelegate extends AbstractLauncherDelegate { String date = format.format(new Date(System.currentTimeMillis())); return NLS.bind(Messages.SerialLauncherDelegate_terminalTitle, new String[]{device, date}); } + return Messages.SerialLauncherDelegate_terminalTitle_default; } diff --git a/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java index 8a42867bd63..a7e4aedd448 100644 --- a/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.connector.ssh/src/org/eclipse/tm/terminal/connector/ssh/launcher/SshLauncherDelegate.java @@ -91,11 +91,9 @@ public class SshLauncherDelegate extends AbstractLauncherDelegate { * @return The terminal title string or null. */ private String getTerminalTitle(Map properties) { - //Try to see if the user set a title explicitly via the properties map. + // Try to see if the user set a title explicitly via the properties map. String title = getDefaultTerminalTitle(properties); - if(title!=null){ - return title; - } + if (title != null) return title; //No title,try to calculate the title String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); @@ -111,6 +109,7 @@ public class SshLauncherDelegate extends AbstractLauncherDelegate { } return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[]{user, host, date}); } + return Messages.SshLauncherDelegate_terminalTitle_default; } diff --git a/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java index 5063882c475..370dea26589 100644 --- a/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.connector.telnet/src/org/eclipse/tm/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java @@ -85,16 +85,14 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate { /** * Returns the terminal title string. *

- * The default implementation constructs a title like "SSH @ host (Start time) ". + * The default implementation constructs a title like "Telnet @ host (Start time) ". * * @return The terminal title string or null. */ private String getTerminalTitle(Map properties) { - //Try to see if the user set a title explicitly via the properties map. + // Try to see if the user set a title explicitly via the properties map. String title = getDefaultTerminalTitle(properties); - if(title!=null){ - return title; - } + if (title != null) return title; //No title,try to calculate the title String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); @@ -104,6 +102,7 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate { String date = format.format(new Date(System.currentTimeMillis())); return NLS.bind(Messages.TelnetLauncherDelegate_terminalTitle, new String[]{host, date}); } + return Messages.TelnetLauncherDelegate_terminalTitle_default; } diff --git a/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java index 0059bdef1dd..6cca5ad5dac 100644 --- a/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/launcher/AbstractLauncherDelegate.java @@ -146,15 +146,12 @@ public abstract class AbstractLauncherDelegate extends PlatformObject implements /** * Get the title from the settings, and use it as the default title. + * * @param properties the setting properties map. * @return the value retrieved via the @see {@link ITerminalsConnectorConstants#PROP_TITLE}, or null if the key hasn't been set. */ protected String getDefaultTerminalTitle(Map properties) { String title = (String)properties.get(ITerminalsConnectorConstants.PROP_TITLE); - - if (title != null) { - return title; - } - return null; + return title != null ? title : null; } }