diff --git a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java index 4f187852965..b827af0e231 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.core.runtime.Assert; @@ -44,7 +45,6 @@ import org.eclipse.terminal.connector.local.controls.LocalWizardConfigurationPanel; import org.eclipse.terminal.connector.process.ProcessSettings; import org.eclipse.terminal.view.core.ILineSeparatorConstants; -import org.eclipse.terminal.view.core.ITerminalService; import org.eclipse.terminal.view.core.ITerminalServiceOutputStreamMonitorListener; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; import org.eclipse.terminal.view.ui.IMementoHandler; @@ -75,7 +75,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { } @Override - public void execute(Map properties, ITerminalService.Done done) { + public CompletableFuture execute(Map properties) { Assert.isNotNull(properties); // Set the terminal tab title @@ -221,12 +221,10 @@ public void execute(Map properties, ITerminalService.Done done) } } } - - // Get the terminal service - ITerminalService terminal = getTerminalService(); - // If not available, we cannot fulfill this request - if (terminal != null) { - terminal.openConsole(properties, done); + try { + return getTerminalService().openConsole(properties); + } catch (RuntimeException e) { + return CompletableFuture.failedFuture(e); } } diff --git a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java index 183a0339fef..4ddb1aac8de 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java +++ b/terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -37,9 +38,12 @@ public class LocalLauncherHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = selection(event); - UIPlugin.getLaunchDelegateManager().getApplicableLauncherDelegates(selection) - .filter(d -> "org.eclipse.terminal.connector.local.launcher.local".equals(d.getId())).findFirst() //$NON-NLS-1$ - .ifPresent(d -> executeDelegate(selection, d)); + Optional delegate = UIPlugin.getLaunchDelegateManager() + .getApplicableLauncherDelegates(selection) + .filter(d -> "org.eclipse.terminal.connector.local.launcher.local".equals(d.getId())).findFirst(); //$NON-NLS-1$ + if (delegate.isPresent()) { + executeDelegate(selection, delegate.get()); + } return null; } @@ -64,11 +68,15 @@ private ISelection selection(ExecutionEvent event) { return selection; } - private void executeDelegate(ISelection selection, ILauncherDelegate delegate) { + private void executeDelegate(ISelection selection, ILauncherDelegate delegate) throws ExecutionException { Map properties = new HashMap<>(); properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId()); properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); - delegate.execute(properties, null); + try { + delegate.execute(properties); + } catch (Exception e) { + throw new ExecutionException(e.getMessage(), e); + } } } diff --git a/terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java index dfc913dc8db..fb39e9a02f5 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java @@ -13,6 +13,7 @@ package org.eclipse.terminal.connector.process.internal; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.core.runtime.Assert; @@ -22,7 +23,6 @@ import org.eclipse.terminal.connector.InMemorySettingsStore; import org.eclipse.terminal.connector.TerminalConnectorExtension; import org.eclipse.terminal.connector.process.ProcessSettings; -import org.eclipse.terminal.view.core.ITerminalService; import org.eclipse.terminal.view.core.ITerminalServiceOutputStreamMonitorListener; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate; @@ -45,14 +45,12 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { } @Override - public void execute(Map properties, ITerminalService.Done done) { + public CompletableFuture execute(Map properties) { Assert.isNotNull(properties); - - // Get the terminal service - ITerminalService terminal = getTerminalService(); - // If not available, we cannot fulfill this request - if (terminal != null) { - terminal.openConsole(properties, done); + try { + return getTerminalService().openConsole(properties); + } catch (RuntimeException e) { + return CompletableFuture.failedFuture(e); } } diff --git a/terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java index 44a046511aa..b5956afc596 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java @@ -16,6 +16,7 @@ import java.text.DateFormat; import java.util.Date; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -28,7 +29,6 @@ import org.eclipse.terminal.connector.ssh.connector.SshSettings; import org.eclipse.terminal.connector.ssh.controls.SshWizardConfigurationPanel; import org.eclipse.terminal.connector.ssh.nls.Messages; -import org.eclipse.terminal.view.core.ITerminalService; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; import org.eclipse.terminal.view.ui.IMementoHandler; import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate; @@ -53,7 +53,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { } @Override - public void execute(Map properties, ITerminalService.Done done) { + public CompletableFuture execute(Map properties) { Assert.isNotNull(properties); // Set the terminal tab title @@ -67,12 +67,10 @@ public void execute(Map properties, ITerminalService.Done done) if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) { properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE); } - - // Get the terminal service - ITerminalService terminal = getTerminalService(); - // If not available, we cannot fulfill this request - if (terminal != null) { - terminal.openConsole(properties, done); + try { + return getTerminalService().openConsole(properties); + } catch (RuntimeException e) { + return CompletableFuture.failedFuture(e); } } diff --git a/terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java index c1730e79f01..c617d00c38e 100644 --- a/terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java @@ -16,6 +16,7 @@ import java.text.DateFormat; import java.util.Date; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -27,7 +28,6 @@ import org.eclipse.terminal.connector.telnet.connector.TelnetSettings; import org.eclipse.terminal.connector.telnet.controls.TelnetWizardConfigurationPanel; import org.eclipse.terminal.connector.telnet.nls.Messages; -import org.eclipse.terminal.view.core.ITerminalService; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; import org.eclipse.terminal.view.ui.IMementoHandler; import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate; @@ -52,7 +52,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { } @Override - public void execute(Map properties, ITerminalService.Done done) { + public CompletableFuture execute(Map properties) { Assert.isNotNull(properties); // Set the terminal tab title @@ -66,12 +66,10 @@ public void execute(Map properties, ITerminalService.Done done) if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) { properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE); } - - // Get the terminal service - ITerminalService terminal = getTerminalService(); - // If not available, we cannot fulfill this request - if (terminal != null) { - terminal.openConsole(properties, done); + try { + return getTerminalService().openConsole(properties); + } catch (RuntimeException e) { + return CompletableFuture.failedFuture(e); } } diff --git a/terminal/bundles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java b/terminal/bundles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java index 832f2709c72..d1ee6004154 100644 --- a/terminal/bundles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java +++ b/terminal/bundles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 - 2018 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011 - 2025 Wind River Systems, Inc. and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License 2.0 which accompanies this distribution, and is * available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,53 +8,41 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Alexander Fedorov (ArSysOp) - further evolution *******************************************************************************/ package org.eclipse.terminal.view.core; import java.util.Map; - -import org.eclipse.core.runtime.IStatus; +import java.util.concurrent.CompletableFuture; /** * Terminal service. */ public interface ITerminalService { - /** - * Client call back interface. - */ - public interface Done { - /** - * Called when the terminal service operation is done. - * - * @param status The status of the terminal service operation. - */ - public void done(IStatus status); - } - /** * Opens a terminal asynchronously and invokes the given callback if done. * * @param properties The terminal properties. Must not be null. - * @param done The callback to invoke if finished or null. + * @return the {@link CompletableFuture} */ - public void openConsole(Map properties, Done done); + public CompletableFuture openConsole(Map properties); /** - * Close the terminal asynchronously and invokes the given callback if done. + * Close the terminal asynchronously. * * @param properties The terminal properties. Must not be null. - * @param done The callback to invoke if finished or null. + * @return the {@link CompletableFuture} */ - public void closeConsole(Map properties, Done done); + public CompletableFuture closeConsole(Map properties); /** * Terminate (disconnect) the terminal asynchronously and invokes the given callback if done. * * @param properties The terminal properties. Must not be null. - * @param done The callback to invoke if finished or null. + * @return the {@link CompletableFuture} */ - public void terminateConsole(Map properties, Done done); + public CompletableFuture terminateConsole(Map properties); /** * Register the given listener to receive notifications about terminal events. diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.java index c533e5ece9a..6eac222ca93 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.java @@ -65,6 +65,7 @@ public static String getString(String key) { public static String AbstractConfigurationPanel_encoding_custom_title; public static String AbstractConfigurationPanel_encoding_custom_message; public static String AbstractConfigurationPanel_encoding_custom_error; + public static String AbstractLauncherDelegate_e_no_terminal_service; public static String ConsoleManager_e_cannot_create_console; public static String ConsoleManager_e_no_active_page; diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties index 97a9d10a921..d33fef3009e 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties @@ -27,6 +27,7 @@ AbstractConfigurationPanel_encoding_custom=Other... AbstractConfigurationPanel_encoding_custom_title=Other... AbstractConfigurationPanel_encoding_custom_message=Please enter the name of the encoding to use for the terminal. AbstractConfigurationPanel_encoding_custom_error=Unsupported encoding. Please enter the name of a supported encoding. +AbstractLauncherDelegate_e_no_terminal_service=Terminal service is not available ConsoleManager_e_cannot_create_console=Cannot create console ConsoleManager_e_no_active_page=No active workbench page diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java index 50d4d6ff2bb..57c50253d57 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java @@ -15,11 +15,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.CompletableFuture; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; @@ -34,7 +36,6 @@ import org.eclipse.terminal.view.ui.launcher.ILauncherDelegate; import org.eclipse.terminal.view.ui.launcher.ILauncherDelegateManager; import org.eclipse.terminal.view.ui.launcher.ITerminalConsoleViewManager; -import org.eclipse.ui.PlatformUI; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -77,10 +78,9 @@ protected static abstract class TerminalServiceRunnable { * @param title The terminal tab title. Must not be null. * @param connector The terminal connector. Must not be null. * @param data The custom terminal data node or null. - * @param done The callback to invoke if the operation finished or null. + * @return the result {@link IStatus} */ - public abstract void run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data, - Done done); + public abstract IStatus run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data); /** * Returns if or if not to execute the runnable asynchronously. @@ -159,10 +159,10 @@ public void run() throws Exception { * * @param properties The terminal properties. Must not be null. * @param runnable The terminal service runnable. Must not be null. - * @param done The callback to invoke if the operation has been finished or null. + * @return the {@link CompletableFuture} with result */ - protected final void executeServiceOperation(final Map properties, - final TerminalServiceRunnable runnable, final Done done) { + protected final CompletableFuture executeServiceOperation(final Map properties, + final TerminalServiceRunnable runnable) { Assert.isNotNull(properties); Assert.isNotNull(runnable); @@ -186,26 +186,19 @@ protected final void executeServiceOperation(final Map propertie connector = createTerminalConnector(properties); } catch (CoreException e) { // Properties contain invalid connector arguments - if (done != null) { - done.done(e.getStatus()); - } - return; + return CompletableFuture.failedFuture(e); } - executeServiceOperation(runnable, new TerminalViewId(id, secondaryId), title, connector, data, done); + return executeServiceOperation(runnable, new TerminalViewId(id, secondaryId), title, connector, data); } - private void executeServiceOperation(final TerminalServiceRunnable runnable, TerminalViewId tvid, - final String title, final ITerminalConnector connector, final Object data, final Done done) { + private CompletableFuture executeServiceOperation(final TerminalServiceRunnable runnable, TerminalViewId tvid, + final String title, final ITerminalConnector connector, final Object data) { // Execute the operation - if (!runnable.isExecuteAsync()) { - runnable.run(tvid, title, connector, data, done); + if (runnable.isExecuteAsync()) { + return CompletableFuture.supplyAsync(() -> runnable.run(tvid, title, connector, data), + Display.getDefault()); } else { - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(() -> runnable.run(tvid, title, connector, data, done)); - } catch (Exception e) { - // if display is disposed, silently ignore. - } + return CompletableFuture.completedFuture(runnable.run(tvid, title, connector, data)); } } @@ -258,16 +251,14 @@ protected ITerminalConnector createTerminalConnector(Map propert } @Override - public void openConsole(final Map properties, final Done done) { + public CompletableFuture openConsole(final Map properties) { Assert.isNotNull(properties); final boolean restoringView = fRestoringView; - - executeServiceOperation(properties, new TerminalServiceRunnable() { + return executeServiceOperation(properties, new TerminalServiceRunnable() { @Override - public void run(TerminalViewId tvid, final String title, final ITerminalConnector connector, - final Object data, final Done done) { + public IStatus run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data) { if (restoringView) { - doRun(tvid, title, connector, data, done); + return doRun(tvid, title, connector, data); } else { // First, restore the view. This opens consoles from the memento fRestoringView = true; @@ -277,18 +268,11 @@ public void run(TerminalViewId tvid, final String title, final ITerminalConnecto ILog.get().log(e.getStatus()); } fRestoringView = false; - - // After that schedule opening the requested console - try { - Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(() -> doRun(tvid, title, connector, data, done)); - } catch (Exception e) { - // if display is disposed, silently ignore. - } + return doRun(tvid, title, connector, data); } } - public void doRun(TerminalViewId tvid, String title, ITerminalConnector connector, Object data, Done done) { + private IStatus doRun(TerminalViewId tvid, String title, ITerminalConnector connector, Object data) { // Determine the terminal encoding String encoding = (String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING); // Create the flags to pass on to openConsole @@ -316,50 +300,36 @@ public void doRun(TerminalViewId tvid, String title, ITerminalConnector connecto if (!console.isDisposed()) { console.setData("properties", properties); //$NON-NLS-1$ } - // Invoke the callback - if (done != null) { - done.done(Status.OK_STATUS); - } + return Status.OK_STATUS; } catch (CoreException e) { - if (done != null) { - done.done(e.getStatus()); - } + return e.getStatus(); } } - }, done); + }); } @Override - public void closeConsole(final Map properties, final Done done) { + public CompletableFuture closeConsole(Map properties) { Assert.isNotNull(properties); - - executeServiceOperation(properties, new TerminalServiceRunnable() { + return executeServiceOperation(properties, new TerminalServiceRunnable() { @Override - public void run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data, Done done) { - // Close the console + public IStatus run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data) { consoleViewManager.closeConsole(tvid, title, connector, data); - // Invoke the callback - if (done != null) { - done.done(Status.OK_STATUS); - } + return Status.OK_STATUS; } - }, done); + }); } @Override - public void terminateConsole(Map properties, Done done) { + public CompletableFuture terminateConsole(Map properties) { Assert.isNotNull(properties); - executeServiceOperation(properties, new TerminalServiceRunnable() { + return executeServiceOperation(properties, new TerminalServiceRunnable() { @Override - public void run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data, Done done) { - // Close the console + public IStatus run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data) { consoleViewManager.terminateConsole(tvid, title, connector, data); - // Invoke the callback - if (done != null) { - done.done(Status.OK_STATUS); - } + return Status.OK_STATUS; } - }, done); + }); } } diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java index 22e7d9313e9..37a25a01835 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java @@ -20,8 +20,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.TrayDialog; @@ -41,7 +43,6 @@ import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.terminal.connector.ITerminalConnector; -import org.eclipse.terminal.view.core.ITerminalService.Done; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; import org.eclipse.terminal.view.ui.IExternalExecutablesProperties; import org.eclipse.terminal.view.ui.internal.IContextHelpIds; @@ -530,7 +531,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { } @Override - public void execute(Map properties, Done done) { + public CompletableFuture execute(Map properties) { throw new UnsupportedOperationException(); } diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java index 58d46c4e43d..492bc972098 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java @@ -84,7 +84,10 @@ public Object execute(ExecutionEvent event) throws ExecutionException { dialog.setSelection(selection); } if (dialog.open() == Window.OK) { - findDelegate(dialog).ifPresent(delegate -> delegate.execute(dialog.getSettings(), null)); + Optional delegate = findDelegate(dialog); + if (delegate.isPresent()) { + executeDelegate(dialog.getSettings(), delegate.get()); + } } } else { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { @@ -116,19 +119,14 @@ public Object execute(ExecutionEvent event) throws ExecutionException { dialog.setSelection(selection); } if (dialog.open() == Window.OK) { - findDelegate(dialog).ifPresent(delegate -> delegate.execute(dialog.getSettings(), null)); + Optional delegate = findDelegate(dialog); + if (delegate.isPresent()) { + executeDelegate(dialog.getSettings(), delegate.get()); + } } } else if (delegates.size() == 1) { ILauncherDelegate delegate = delegates.get(0); - Map properties = new HashMap<>(); - - // Store the id of the selected delegate - properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId()); - // Store the selection - properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); - - // Execute - delegate.execute(properties, null); + executeDelegate(selection, delegate); } } @@ -165,4 +163,20 @@ private boolean isValidSelection(ISelection selection) { return false; } + + private void executeDelegate(ISelection selection, ILauncherDelegate delegate) throws ExecutionException { + Map properties = new HashMap<>(); + properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId()); + properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); + executeDelegate(properties, delegate); + } + + private void executeDelegate(Map properties, ILauncherDelegate delegate) throws ExecutionException { + try { + delegate.execute(properties); + } catch (Exception e) { + throw new ExecutionException(e.getMessage(), e); + } + } + } diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/local/showin/DynamicContributionItems.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/local/showin/DynamicContributionItems.java index af2eeb40b32..70544d7838c 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/local/showin/DynamicContributionItems.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/local/showin/DynamicContributionItems.java @@ -18,6 +18,7 @@ import java.util.Map; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ILog; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; @@ -127,8 +128,11 @@ public void run() { } properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE, Boolean.valueOf(translate)); - - delegate.execute(properties, null); + try { + delegate.execute(properties); + } catch (Exception e) { + ILog.get().error(e.getMessage(), e); + } } }; diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/view/TerminalsViewMementoHandler.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/view/TerminalsViewMementoHandler.java index 47a0d3a980b..8fcc6fe5760 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/view/TerminalsViewMementoHandler.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/view/TerminalsViewMementoHandler.java @@ -19,6 +19,7 @@ import java.util.Optional; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ILog; import org.eclipse.swt.custom.CTabItem; import org.eclipse.terminal.control.ITerminalViewControl; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; @@ -186,7 +187,8 @@ protected void restoreState(final TerminalsView view, IMemento memento) { delegate.map(d -> d.getAdapter(IMementoHandler.class)) .ifPresent(mh -> mh.restoreState(connection, properties)); // Restore the terminal connection - delegate.ifPresent(d -> d.execute(properties, null)); + delegate.ifPresent(d -> executeDelegate(properties, d)); + } } } @@ -197,6 +199,14 @@ private Optional findDelegate(Map properties) .flatMap(id -> UIPlugin.getLaunchDelegateManager().findLauncherDelegate(id, false)); } + private void executeDelegate(Map properties, ILauncherDelegate delegate) { + try { + delegate.execute(properties); + } catch (Exception e) { + ILog.get().error(e.getMessage(), e); + } + } + private Optional mementoHandler(ILauncherDelegate delegate) { return Optional.ofNullable(delegate.getAdapter(IMementoHandler.class)); } diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/AbstractLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/AbstractLauncherDelegate.java index d057b391ad0..5dc6cd3d55c 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/AbstractLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/AbstractLauncherDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2025 Wind River Systems, Inc. and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License 2.0 which accompanies this distribution, and is * available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,6 +8,7 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Alexander Fedorov (ArSysOp) - further evolution *******************************************************************************/ package org.eclipse.terminal.view.ui.launcher; @@ -138,7 +139,15 @@ protected String getDefaultTerminalTitle(Map properties) { return title != null ? title : null; } - protected ITerminalService getTerminalService() { - return UIPlugin.getTerminalService(); + /** + * Get the terminal service + * + * @return an instance of {@link ITerminalService} + * + */ + protected final ITerminalService getTerminalService() { + ITerminalService service = UIPlugin.getTerminalService(); + Assert.isNotNull(service, Messages.AbstractLauncherDelegate_e_no_terminal_service); + return service; } } diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/ILauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/ILauncherDelegate.java index 26d434894e1..5644d426a7c 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/ILauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/ILauncherDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2025 Wind River Systems, Inc. and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License 2.0 which accompanies this distribution, and is * available at https://www.eclipse.org/legal/epl-2.0/ @@ -8,17 +8,18 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Alexander Fedorov (ArSysOp) - further evolution *******************************************************************************/ package org.eclipse.terminal.view.ui.launcher; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.core.expressions.Expression; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.terminal.connector.ITerminalConnector; -import org.eclipse.terminal.view.core.ITerminalService; /** * Terminal launcher delegate. @@ -84,9 +85,9 @@ public interface ILauncherDelegate extends IExecutableExtension, IAdaptable { * Execute the terminal launch. * * @param properties The properties. Must not be null. - * @param done The callback or null. + * @return the {@link CompletableFuture} */ - public void execute(Map properties, ITerminalService.Done done); + public CompletableFuture execute(Map properties); /** * Creates the terminal connector for this launcher delegate based on diff --git a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/streams/StreamsLauncherDelegate.java b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/streams/StreamsLauncherDelegate.java index d6850b33e4b..972a6014ee0 100644 --- a/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/streams/StreamsLauncherDelegate.java +++ b/terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/streams/StreamsLauncherDelegate.java @@ -15,6 +15,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Map; +import java.util.concurrent.CompletableFuture; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -22,10 +23,8 @@ import org.eclipse.terminal.connector.ITerminalConnector; import org.eclipse.terminal.connector.InMemorySettingsStore; import org.eclipse.terminal.connector.TerminalConnectorExtension; -import org.eclipse.terminal.view.core.ITerminalService; import org.eclipse.terminal.view.core.ITerminalServiceOutputStreamMonitorListener; import org.eclipse.terminal.view.core.ITerminalsConnectorConstants; -import org.eclipse.terminal.view.ui.internal.UIPlugin; import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate; import org.eclipse.terminal.view.ui.launcher.IConfigurationPanel; import org.eclipse.terminal.view.ui.launcher.IConfigurationPanelContainer; @@ -46,14 +45,12 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) { } @Override - public void execute(Map properties, ITerminalService.Done done) { + public CompletableFuture execute(Map properties) { Assert.isNotNull(properties); - - // Get the terminal service - ITerminalService terminal = UIPlugin.getTerminalService(); - // If not available, we cannot fulfill this request - if (terminal != null) { - terminal.openConsole(properties, done); + try { + return getTerminalService().openConsole(properties); + } catch (RuntimeException e) { + return CompletableFuture.failedFuture(e); } }