1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 18:55:38 +02:00

Bug 518121 - Support multiple terminal connectors with identical label

In case multiple terminal launcher delegates are registered with
identical label, the ID of a delegate is used as fallback instead
of the label in order to disambiguate.

This doesn't look pretty in the UI but it works and it's a generic
solution for an atypical problem.

Change-Id: I4028e1819f7405c2cb65eacf4e84f437900d884e
Signed-off-by: Martin Oberhuber <mober.at+eclipse@gmail.com>
This commit is contained in:
Martin Oberhuber 2017-06-13 10:44:54 +02:00
parent 3e539b7331
commit 7b52e3974c
3 changed files with 339 additions and 339 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: %pluginName Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal.view.ui;singleton:=true Bundle-SymbolicName: org.eclipse.tm.terminal.view.ui;singleton:=true
Bundle-Version: 4.2.100.qualifier Bundle-Version: 4.3.0.qualifier
Bundle-Activator: org.eclipse.tm.terminal.view.ui.activator.UIPlugin Bundle-Activator: org.eclipse.tm.terminal.view.ui.activator.UIPlugin
Bundle-Vendor: %providerName Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400", Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400",

View file

@ -11,7 +11,7 @@
<relativePath>../../admin/pom-build.xml</relativePath> <relativePath>../../admin/pom-build.xml</relativePath>
</parent> </parent>
<version>4.2.100-SNAPSHOT</version> <version>4.3.0-SNAPSHOT</version>
<artifactId>org.eclipse.tm.terminal.view.ui</artifactId> <artifactId>org.eclipse.tm.terminal.view.ui</artifactId>
<packaging>eclipse-plugin</packaging> <packaging>eclipse-plugin</packaging>
</project> </project>

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2011, 2016 Wind River Systems, Inc. and others. All rights reserved. * Copyright (c) 2011, 2017 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms * This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is * of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html * available at http://www.eclipse.org/legal/epl-v10.html
@ -87,138 +87,138 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
/** /**
* Constructor. * Constructor.
*/ */
public SettingsPanelControl() { public SettingsPanelControl() {
setPanelIsGroup(true); setPanelIsGroup(true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.tm.terminal.view.ui.controls.ConfigurationPanelControl#getGroupLabel() * @see org.eclipse.tm.terminal.view.ui.controls.ConfigurationPanelControl#getGroupLabel()
*/ */
@Override @Override
public String getGroupLabel() { public String getGroupLabel() {
return Messages.LaunchTerminalSettingsDialog_group_label; return Messages.LaunchTerminalSettingsDialog_group_label;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.tm.terminal.view.ui.controls.ConfigurationPanelControl#showConfigurationPanel(java.lang.String) * @see org.eclipse.tm.terminal.view.ui.controls.ConfigurationPanelControl#showConfigurationPanel(java.lang.String)
*/ */
@Override @Override
public void showConfigurationPanel(String key) { public void showConfigurationPanel(String key) {
// Check if we have to create the panel first // Check if we have to create the panel first
IConfigurationPanel configPanel = getConfigurationPanel(key); IConfigurationPanel configPanel = getConfigurationPanel(key);
if (isEmptyConfigurationPanel(configPanel)) { if (isEmptyConfigurationPanel(configPanel)) {
// Get the corresponding delegate // Get the corresponding delegate
ILauncherDelegate delegate = label2delegate.get(key); ILauncherDelegate delegate = label2delegate.get(key);
Assert.isNotNull(delegate); Assert.isNotNull(delegate);
// Create the wizard configuration panel instance // Create the wizard configuration panel instance
configPanel = delegate.getPanel(this); configPanel = delegate.getPanel(this);
if (configPanel != null) { if (configPanel != null) {
// Add it to the settings panel control // Add it to the settings panel control
settings.addConfigurationPanel(key, configPanel); settings.addConfigurationPanel(key, configPanel);
// Push the selection to the configuration panel // Push the selection to the configuration panel
configPanel.setSelection(getSelection()); configPanel.setSelection(getSelection());
// Create the panel controls // Create the panel controls
configPanel.setupPanel(getPanel()); configPanel.setupPanel(getPanel());
// Restore widget values // Restore widget values
IDialogSettings dialogSettings = LaunchTerminalSettingsDialog.this.settings.getDialogSettings(LaunchTerminalSettingsDialog.this.getDialogSettings()); IDialogSettings dialogSettings = LaunchTerminalSettingsDialog.this.settings.getDialogSettings(LaunchTerminalSettingsDialog.this.getDialogSettings());
IDialogSettings configPanelSettings = dialogSettings != null ? dialogSettings.getSection(key) : null; IDialogSettings configPanelSettings = dialogSettings != null ? dialogSettings.getSection(key) : null;
if (configPanelSettings != null) configPanel.doRestoreWidgetValues(configPanelSettings, null); if (configPanelSettings != null) configPanel.doRestoreWidgetValues(configPanelSettings, null);
} }
} }
super.showConfigurationPanel(key); super.showConfigurationPanel(key);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanelContainer#validate() * @see org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanelContainer#validate()
*/ */
@Override @Override
public void validate() { public void validate() {
LaunchTerminalSettingsDialog.this.validate(); LaunchTerminalSettingsDialog.this.validate();
} }
} }
/** /**
* Constructor. * Constructor.
* *
* @param shell The parent shell or <code>null</code>. * @param shell The parent shell or <code>null</code>.
*/ */
public LaunchTerminalSettingsDialog(Shell shell) { public LaunchTerminalSettingsDialog(Shell shell) {
this(shell, 0); this(shell, 0);
} }
private long start = 0; private long start = 0;
/** /**
* Constructor. * Constructor.
* *
* @param shell The parent shell or <code>null</code>. * @param shell The parent shell or <code>null</code>.
*/ */
public LaunchTerminalSettingsDialog(Shell shell, long start) { public LaunchTerminalSettingsDialog(Shell shell, long start) {
super(shell); super(shell);
this.start = start; this.start = start;
initializeDialogSettings(); initializeDialogSettings();
this.contextHelpId = IContextHelpIds.LAUNCH_TERMINAL_SETTINGS_DIALOG; this.contextHelpId = IContextHelpIds.LAUNCH_TERMINAL_SETTINGS_DIALOG;
setHelpAvailable(true); setHelpAvailable(true);
} }
/** /**
* Sets the parent selection. * Sets the parent selection.
* *
* @param selection The parent selection or <code>null</code>. * @param selection The parent selection or <code>null</code>.
*/ */
public void setSelection(ISelection selection) { public void setSelection(ISelection selection) {
this.selection = selection; this.selection = selection;
} }
/** /**
* Returns the parent selection. * Returns the parent selection.
* *
* @return The parent selection or <code>null</code>. * @return The parent selection or <code>null</code>.
*/ */
public ISelection getSelection() { public ISelection getSelection() {
return selection; return selection;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#close() * @see org.eclipse.jface.dialogs.Dialog#close()
*/ */
@Override @Override
public boolean close() { public boolean close() {
dispose(); dispose();
return super.close(); return super.close();
} }
/** /**
* Dispose the dialog resources. * Dispose the dialog resources.
*/ */
protected void dispose() { protected void dispose() {
if (settings != null) { settings.dispose(); settings = null; } if (settings != null) { settings.dispose(); settings = null; }
dialogSettings = null; dialogSettings = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#isResizable() * @see org.eclipse.jface.dialogs.Dialog#isResizable()
*/ */
@Override @Override
protected boolean isResizable() { protected boolean isResizable() {
return true; return true;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite) * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
*/ */
@Override @Override
protected Control createContents(Composite parent) { protected Control createContents(Composite parent) {
Control composite = super.createContents(parent); Control composite = super.createContents(parent);
// Validate the dialog after having created all the content // Validate the dialog after having created all the content
validate(); validate();
return composite; return composite;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
@ -277,83 +277,83 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
* *
* @param parent The parent composite. Must not be <code>null</code>. * @param parent The parent composite. Must not be <code>null</code>.
*/ */
protected void createDialogAreaContent(Composite parent) { protected void createDialogAreaContent(Composite parent) {
Assert.isNotNull(parent); Assert.isNotNull(parent);
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Creating dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Creating dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
setDialogTitle(Messages.LaunchTerminalSettingsDialog_title); setDialogTitle(Messages.LaunchTerminalSettingsDialog_title);
final List<String> items = getTerminals(); final List<String> items = getTerminals();
Composite panel = new Composite(parent, SWT.NONE); Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false); GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0; layout.marginWidth = 0; layout.marginHeight = 0; layout.marginWidth = 0;
panel.setLayout(layout); panel.setLayout(layout);
panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
if (items.size() != 1) { if (items.size() != 1) {
Label label = new Label(panel, SWT.HORIZONTAL); Label label = new Label(panel, SWT.HORIZONTAL);
label.setText(Messages.LaunchTerminalSettingsDialog_combo_label); label.setText(Messages.LaunchTerminalSettingsDialog_combo_label);
terminals = new Combo(panel, SWT.READ_ONLY); terminals = new Combo(panel, SWT.READ_ONLY);
terminals.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); terminals.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
terminals.addSelectionListener(new SelectionAdapter() { terminals.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
// Get the old panel // Get the old panel
IConfigurationPanel oldPanel = settings.getActiveConfigurationPanel(); IConfigurationPanel oldPanel = settings.getActiveConfigurationPanel();
// Extract the current settings in an special properties container // Extract the current settings in an special properties container
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
if (oldPanel != null) oldPanel.extractData(data); if (oldPanel != null) oldPanel.extractData(data);
// Clean out settings which are never passed between the panels // Clean out settings which are never passed between the panels
data.remove(ITerminalsConnectorConstants.PROP_IP_PORT); data.remove(ITerminalsConnectorConstants.PROP_IP_PORT);
data.remove(ITerminalsConnectorConstants.PROP_TIMEOUT); data.remove(ITerminalsConnectorConstants.PROP_TIMEOUT);
data.remove(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); data.remove(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
data.remove(ITerminalsConnectorConstants.PROP_ENCODING); data.remove(ITerminalsConnectorConstants.PROP_ENCODING);
// Switch to the new panel // Switch to the new panel
settings.showConfigurationPanel(terminals.getText()); settings.showConfigurationPanel(terminals.getText());
// Get the new panel // Get the new panel
IConfigurationPanel newPanel = settings.getActiveConfigurationPanel(); IConfigurationPanel newPanel = settings.getActiveConfigurationPanel();
// Re-setup the relevant data // Re-setup the relevant data
if (newPanel != null) newPanel.setupData(data); if (newPanel != null) newPanel.setupData(data);
// resize the dialog if needed to show the complete panel // resize the dialog if needed to show the complete panel
getShell().pack(); getShell().pack();
// validate the settings dialog // validate the settings dialog
validate(); validate();
} }
}); });
// fill the combo with content // fill the combo with content
fillCombo(terminals, items); fillCombo(terminals, items);
} else { } else {
Assert.isTrue(items.size() == 1); Assert.isTrue(items.size() == 1);
singleDelegateLabel = items.get(0); singleDelegateLabel = items.get(0);
} }
// Create the settings panel control // Create the settings panel control
settings = new SettingsPanelControl(); settings = new SettingsPanelControl();
// Create, initialize and add the first visible panel. All // Create, initialize and add the first visible panel. All
// other panels are created on demand only. // other panels are created on demand only.
String terminalLabel = terminals != null ? terminals.getItem(0) : singleDelegateLabel; String terminalLabel = terminals != null ? terminals.getItem(0) : singleDelegateLabel;
if (terminalLabel != null) { if (terminalLabel != null) {
// Get the corresponding delegate // Get the corresponding delegate
ILauncherDelegate delegate = label2delegate.get(terminalLabel); ILauncherDelegate delegate = label2delegate.get(terminalLabel);
Assert.isNotNull(delegate); Assert.isNotNull(delegate);
// Create the wizard configuration panel instance // Create the wizard configuration panel instance
IConfigurationPanel configPanel = delegate.getPanel(settings); IConfigurationPanel configPanel = delegate.getPanel(settings);
if (configPanel != null) { if (configPanel != null) {
// Add it to the settings panel control // Add it to the settings panel control
settings.addConfigurationPanel(terminalLabel, configPanel); settings.addConfigurationPanel(terminalLabel, configPanel);
// Push the selection to the configuration panel // Push the selection to the configuration panel
configPanel.setSelection(getSelection()); configPanel.setSelection(getSelection());
} }
} }
// Setup the panel control // Setup the panel control
settings.setupPanel(panel, terminals != null ? terminals.getItems() : new String[] { singleDelegateLabel }); settings.setupPanel(panel, terminals != null ? terminals.getItems() : new String[] { singleDelegateLabel });
@ -373,96 +373,96 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
restoreWidgetValues(); restoreWidgetValues();
applyDialogFont(panel); applyDialogFont(panel);
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Created dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Created dialog area after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
} }
/** /**
* Fill the given combo with the given list of terminal launcher delegate labels. * Fill the given combo with the given list of terminal launcher delegate labels.
* *
* @param combo The combo. Must not be <code>null</code>. * @param combo The combo. Must not be <code>null</code>.
* @param items The list of terminal launcher delegates. Must not be <code>null</code>. * @param items The list of terminal launcher delegates. Must not be <code>null</code>.
*/ */
protected void fillCombo(Combo combo, List<String> items) { protected void fillCombo(Combo combo, List<String> items) {
Assert.isNotNull(combo); Assert.isNotNull(combo);
Assert.isNotNull(items); Assert.isNotNull(items);
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Filling combo after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Filling combo after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
Collections.sort(items); Collections.sort(items);
combo.setItems(items.toArray(new String[items.size()])); combo.setItems(items.toArray(new String[items.size()]));
} }
/** /**
* Returns the list of terminal launcher delegate labels. The method queries the * Returns the list of terminal launcher delegate labels. The method queries the
* terminal launcher delegates and initialize the <code>label2delegate</code> map. * terminal launcher delegates and initialize the <code>label2delegate</code> map.
* *
* @return The list of terminal launcher delegate labels or an empty list. * @return The list of terminal launcher delegate labels or an empty list.
*/ */
protected List<String> getTerminals() { protected List<String> getTerminals() {
List<String> items = new ArrayList<String>(); List<String> items = new ArrayList<String>();
ILauncherDelegate localLauncher = null; ILauncherDelegate localLauncher = null;
if(selection==null || selection.isEmpty()){ if(selection==null || selection.isEmpty()){
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Getting launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Getting launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getLauncherDelegates(false); ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getLauncherDelegates(false);
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Got launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Got launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
for (ILauncherDelegate delegate : delegates) { for (ILauncherDelegate delegate : delegates) {
if (delegate.isHidden() || isFiltered(selection, delegate)) continue; if (delegate.isHidden() || isFiltered(selection, delegate)) continue;
String label = delegate.getLabel(); String label = delegate.getLabel();
if (label == null || "".equals(label.trim())) label = delegate.getId(); //$NON-NLS-1$ if (label == null || "".equals(label.trim()) || label2delegate.containsKey(label)) label = delegate.getId(); //$NON-NLS-1$
label2delegate.put(label, delegate); label2delegate.put(label, delegate);
items.add(label); items.add(label);
if ("org.eclipse.tm.terminal.connector.local.launcher.local".equals(delegate.getId())) { //$NON-NLS-1$ if ("org.eclipse.tm.terminal.connector.local.launcher.local".equals(delegate.getId())) { //$NON-NLS-1$
localLauncher = delegate; localLauncher = delegate;
} }
} }
} else { } else {
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Getting applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Getting applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection); ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection);
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Got applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Got applicable launcher delegates after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
for (ILauncherDelegate delegate : delegates) { for (ILauncherDelegate delegate : delegates) {
if (delegate.isHidden() || isFiltered(selection, delegate)) continue; if (delegate.isHidden() || isFiltered(selection, delegate)) continue;
String label = delegate.getLabel(); String label = delegate.getLabel();
if (label == null || "".equals(label.trim())) label = delegate.getId(); //$NON-NLS-1$ if (label == null || "".equals(label.trim())) label = delegate.getId(); //$NON-NLS-1$
label2delegate.put(label, delegate); label2delegate.put(label, delegate);
items.add(label); items.add(label);
if ("org.eclipse.tm.terminal.connector.local.launcher.local".equals(delegate.getId())) { //$NON-NLS-1$ if ("org.eclipse.tm.terminal.connector.local.launcher.local".equals(delegate.getId())) { //$NON-NLS-1$
localLauncher = delegate; localLauncher = delegate;
} }
} }
} }
// if the local launcher was found, check for configured external executables // if the local launcher was found, check for configured external executables
if (localLauncher != null) { if (localLauncher != null) {
List<Map<String, String>> l = ExternalExecutablesManager.load(); List<Map<String, String>> l = ExternalExecutablesManager.load();
if (l != null && !l.isEmpty()) { if (l != null && !l.isEmpty()) {
for (Map<String, String> executableData : l) { for (Map<String, String> executableData : l) {
@ -479,135 +479,135 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
if (selection != null && selection.isEmpty()) selection = null; if (selection != null && selection.isEmpty()) selection = null;
Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>();
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, path); properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, path);
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args); properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, args);
properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, Boolean.valueOf(translate)); properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, Boolean.valueOf(translate));
// store external executable and properties // store external executable and properties
label2delegate.put(name, localLauncher); label2delegate.put(name, localLauncher);
label2properties.put(name, properties); label2properties.put(name, properties);
items.add(name); items.add(name);
} }
} }
} }
} }
return items; return items;
} }
/** /**
* Hook to allow additional filtering of the applicable launcher delegates. * Hook to allow additional filtering of the applicable launcher delegates.
* <p> * <p>
* <b>Note:</b> The default implementation always returns <code>false</code>. * <b>Note:</b> The default implementation always returns <code>false</code>.
* *
* @param selection The selection or <code>null</code>. * @param selection The selection or <code>null</code>.
* @param delegate The launcher delegate. Must not be <code>null</code>. * @param delegate The launcher delegate. Must not be <code>null</code>.
* *
* @return <code>True</code> if the launcher delegate is filtered based on the given selection, <code>false</code> otherwise. * @return <code>True</code> if the launcher delegate is filtered based on the given selection, <code>false</code> otherwise.
*/ */
protected boolean isFiltered(ISelection selection, ILauncherDelegate delegate) { protected boolean isFiltered(ISelection selection, ILauncherDelegate delegate) {
return false; return false;
} }
/** /**
* Validate the dialog. * Validate the dialog.
*/ */
public void validate() { public void validate() {
IConfigurationPanel panel = this.settings.getActiveConfigurationPanel(); IConfigurationPanel panel = this.settings.getActiveConfigurationPanel();
Button okButton = getButton(IDialogConstants.OK_ID); Button okButton = getButton(IDialogConstants.OK_ID);
if (okButton != null) okButton.setEnabled(panel.isValid()); if (okButton != null) okButton.setEnabled(panel.isValid());
} }
/** /**
* Set the given message and message type. * Set the given message and message type.
* *
* @param message The message or <code>null</code>. * @param message The message or <code>null</code>.
* @param messageType The message type or <code>IMessageProvider.NONE</code>. * @param messageType The message type or <code>IMessageProvider.NONE</code>.
*/ */
public void setMessage(String message, int messageType) { public void setMessage(String message, int messageType) {
if (settings != null) { if (settings != null) {
settings.setMessage(message, messageType); settings.setMessage(message, messageType);
} }
} }
/** /**
* Save the dialog's widget values. * Save the dialog's widget values.
*/ */
protected void saveWidgetValues() { protected void saveWidgetValues() {
IDialogSettings settings = getDialogSettings(); IDialogSettings settings = getDialogSettings();
if (settings != null && terminals != null) { if (settings != null && terminals != null) {
settings.put("terminalLabel", terminals.getText()); //$NON-NLS-1$ settings.put("terminalLabel", terminals.getText()); //$NON-NLS-1$
this.settings.saveWidgetValues(settings, null); this.settings.saveWidgetValues(settings, null);
} }
} }
/** /**
* Restore the dialog's widget values. * Restore the dialog's widget values.
*/ */
protected void restoreWidgetValues() { protected void restoreWidgetValues() {
IDialogSettings settings = getDialogSettings(); IDialogSettings settings = getDialogSettings();
if (settings != null) { if (settings != null) {
String terminalLabel = settings.get("terminalLabel"); //$NON-NLS-1$ String terminalLabel = settings.get("terminalLabel"); //$NON-NLS-1$
int index = terminalLabel != null && terminals != null ? Arrays.asList(terminals.getItems()).indexOf(terminalLabel) : -1; int index = terminalLabel != null && terminals != null ? Arrays.asList(terminals.getItems()).indexOf(terminalLabel) : -1;
if (index != -1) { if (index != -1) {
terminals.select(index); terminals.select(index);
this.settings.showConfigurationPanel(terminals.getText()); this.settings.showConfigurationPanel(terminals.getText());
} }
this.settings.restoreWidgetValues(settings, null); this.settings.restoreWidgetValues(settings, null);
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#okPressed() * @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/ */
@Override @Override
protected void okPressed() { protected void okPressed() {
IConfigurationPanel panel = this.settings.getActiveConfigurationPanel(); IConfigurationPanel panel = this.settings.getActiveConfigurationPanel();
Assert.isNotNull(panel); Assert.isNotNull(panel);
if (!panel.isValid()) { if (!panel.isValid()) {
MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK); MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText(Messages.LaunchTerminalSettingsDialog_error_title); mb.setText(Messages.LaunchTerminalSettingsDialog_error_title);
mb.setMessage(NLS.bind(Messages.LaunchTerminalSettingsDialog_error_invalidSettings, panel.getMessage() != null ? panel.getMessage() : Messages.LaunchTerminalSettingsDialog_error_unknownReason)); mb.setMessage(NLS.bind(Messages.LaunchTerminalSettingsDialog_error_invalidSettings, panel.getMessage() != null ? panel.getMessage() : Messages.LaunchTerminalSettingsDialog_error_unknownReason));
mb.open(); mb.open();
return; return;
} }
data = new HashMap<String, Object>(); data = new HashMap<String, Object>();
// Store the id of the selected delegate // Store the id of the selected delegate
String terminalLabel = terminals != null ? terminals.getText() : singleDelegateLabel; String terminalLabel = terminals != null ? terminals.getText() : singleDelegateLabel;
String delegateId = terminalLabel != null ? label2delegate.get(terminalLabel).getId() : null; String delegateId = terminalLabel != null ? label2delegate.get(terminalLabel).getId() : null;
if (delegateId != null) data.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegateId); if (delegateId != null) data.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegateId);
// Store the selection // Store the selection
data.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); data.put(ITerminalsConnectorConstants.PROP_SELECTION, selection);
// Add the properties for external executables if there are any // Add the properties for external executables if there are any
if (label2properties.containsKey(terminalLabel)) { if (label2properties.containsKey(terminalLabel)) {
data.putAll(label2properties.get(terminalLabel)); data.putAll(label2properties.get(terminalLabel));
} }
// Store the delegate specific settings // Store the delegate specific settings
panel.extractData(data); panel.extractData(data);
// Save the current widget values // Save the current widget values
saveWidgetValues(); saveWidgetValues();
super.okPressed(); super.okPressed();
} }
/** /**
* Returns the configured terminal launcher settings. * Returns the configured terminal launcher settings.
* <p> * <p>
* The settings are extracted from the UI widgets once * The settings are extracted from the UI widgets once
* OK got pressed. * OK got pressed.
* *
* @return The configured terminal launcher settings or <code>null</code>. * @return The configured terminal launcher settings or <code>null</code>.
*/ */
public Map<String, Object> getSettings() { public Map<String, Object> getSettings() {
return data; return data;
} }
/** /**
* Initialize the dialog settings storage. * Initialize the dialog settings storage.