Skip to content

Commit 8e520e1

Browse files
committed
Replace Done callback with CompletableFuture result
Currently `null` is tolerated as a callback for a number of terminal-related operations. Moreover, it seems that callers prefer to avoid any callback. Replace rarely used callback with completable future result.
1 parent cbe2947 commit 8e520e1

File tree

16 files changed

+151
-155
lines changed

16 files changed

+151
-155
lines changed

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Iterator;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.concurrent.CompletableFuture;
2627

2728
import org.eclipse.cdt.utils.pty.PTY;
2829
import org.eclipse.core.runtime.Assert;
@@ -44,7 +45,6 @@
4445
import org.eclipse.terminal.connector.local.controls.LocalWizardConfigurationPanel;
4546
import org.eclipse.terminal.connector.process.ProcessSettings;
4647
import org.eclipse.terminal.view.core.ILineSeparatorConstants;
47-
import org.eclipse.terminal.view.core.ITerminalService;
4848
import org.eclipse.terminal.view.core.ITerminalServiceOutputStreamMonitorListener;
4949
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
5050
import org.eclipse.terminal.view.ui.IMementoHandler;
@@ -75,7 +75,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
7575
}
7676

7777
@Override
78-
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
78+
public CompletableFuture<?> execute(Map<String, Object> properties) {
7979
Assert.isNotNull(properties);
8080

8181
// Set the terminal tab title
@@ -221,12 +221,10 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
221221
}
222222
}
223223
}
224-
225-
// Get the terminal service
226-
ITerminalService terminal = getTerminalService();
227-
// If not available, we cannot fulfill this request
228-
if (terminal != null) {
229-
terminal.openConsole(properties, done);
224+
try {
225+
return getTerminalService().openConsole(properties);
226+
} catch (RuntimeException e) {
227+
return CompletableFuture.failedFuture(e);
230228
}
231229
}
232230

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.util.HashMap;
1616
import java.util.Map;
17+
import java.util.Optional;
1718

1819
import org.eclipse.core.commands.AbstractHandler;
1920
import org.eclipse.core.commands.ExecutionEvent;
@@ -37,9 +38,12 @@ public class LocalLauncherHandler extends AbstractHandler {
3738
@Override
3839
public Object execute(ExecutionEvent event) throws ExecutionException {
3940
ISelection selection = selection(event);
40-
UIPlugin.getLaunchDelegateManager().getApplicableLauncherDelegates(selection)
41-
.filter(d -> "org.eclipse.terminal.connector.local.launcher.local".equals(d.getId())).findFirst() //$NON-NLS-1$
42-
.ifPresent(d -> executeDelegate(selection, d));
41+
Optional<ILauncherDelegate> delegate = UIPlugin.getLaunchDelegateManager()
42+
.getApplicableLauncherDelegates(selection)
43+
.filter(d -> "org.eclipse.terminal.connector.local.launcher.local".equals(d.getId())).findFirst(); //$NON-NLS-1$
44+
if (delegate.isPresent()) {
45+
executeDelegate(selection, delegate.get());
46+
}
4347
return null;
4448
}
4549

@@ -64,11 +68,15 @@ private ISelection selection(ExecutionEvent event) {
6468
return selection;
6569
}
6670

67-
private void executeDelegate(ISelection selection, ILauncherDelegate delegate) {
71+
private void executeDelegate(ISelection selection, ILauncherDelegate delegate) throws ExecutionException {
6872
Map<String, Object> properties = new HashMap<>();
6973
properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId());
7074
properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection);
71-
delegate.execute(properties, null);
75+
try {
76+
delegate.execute(properties);
77+
} catch (Exception e) {
78+
throw new ExecutionException(e.getMessage(), e);
79+
}
7280
}
7381

7482
}

terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.eclipse.terminal.connector.process.internal;
1414

1515
import java.util.Map;
16+
import java.util.concurrent.CompletableFuture;
1617

1718
import org.eclipse.cdt.utils.pty.PTY;
1819
import org.eclipse.core.runtime.Assert;
@@ -22,7 +23,6 @@
2223
import org.eclipse.terminal.connector.InMemorySettingsStore;
2324
import org.eclipse.terminal.connector.TerminalConnectorExtension;
2425
import org.eclipse.terminal.connector.process.ProcessSettings;
25-
import org.eclipse.terminal.view.core.ITerminalService;
2626
import org.eclipse.terminal.view.core.ITerminalServiceOutputStreamMonitorListener;
2727
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
2828
import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate;
@@ -45,14 +45,12 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
4545
}
4646

4747
@Override
48-
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
48+
public CompletableFuture<?> execute(Map<String, Object> properties) {
4949
Assert.isNotNull(properties);
50-
51-
// Get the terminal service
52-
ITerminalService terminal = getTerminalService();
53-
// If not available, we cannot fulfill this request
54-
if (terminal != null) {
55-
terminal.openConsole(properties, done);
50+
try {
51+
return getTerminalService().openConsole(properties);
52+
} catch (RuntimeException e) {
53+
return CompletableFuture.failedFuture(e);
5654
}
5755
}
5856

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.text.DateFormat;
1717
import java.util.Date;
1818
import java.util.Map;
19+
import java.util.concurrent.CompletableFuture;
1920

2021
import org.eclipse.core.runtime.Assert;
2122
import org.eclipse.core.runtime.CoreException;
@@ -28,7 +29,6 @@
2829
import org.eclipse.terminal.connector.ssh.connector.SshSettings;
2930
import org.eclipse.terminal.connector.ssh.controls.SshWizardConfigurationPanel;
3031
import org.eclipse.terminal.connector.ssh.nls.Messages;
31-
import org.eclipse.terminal.view.core.ITerminalService;
3232
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
3333
import org.eclipse.terminal.view.ui.IMementoHandler;
3434
import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate;
@@ -53,7 +53,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
5353
}
5454

5555
@Override
56-
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
56+
public CompletableFuture<?> execute(Map<String, Object> properties) {
5757
Assert.isNotNull(properties);
5858

5959
// Set the terminal tab title
@@ -67,12 +67,10 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
6767
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) {
6868
properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE);
6969
}
70-
71-
// Get the terminal service
72-
ITerminalService terminal = getTerminalService();
73-
// If not available, we cannot fulfill this request
74-
if (terminal != null) {
75-
terminal.openConsole(properties, done);
70+
try {
71+
return getTerminalService().openConsole(properties);
72+
} catch (RuntimeException e) {
73+
return CompletableFuture.failedFuture(e);
7674
}
7775
}
7876

terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.text.DateFormat;
1717
import java.util.Date;
1818
import java.util.Map;
19+
import java.util.concurrent.CompletableFuture;
1920

2021
import org.eclipse.core.runtime.Assert;
2122
import org.eclipse.core.runtime.CoreException;
@@ -27,7 +28,6 @@
2728
import org.eclipse.terminal.connector.telnet.connector.TelnetSettings;
2829
import org.eclipse.terminal.connector.telnet.controls.TelnetWizardConfigurationPanel;
2930
import org.eclipse.terminal.connector.telnet.nls.Messages;
30-
import org.eclipse.terminal.view.core.ITerminalService;
3131
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
3232
import org.eclipse.terminal.view.ui.IMementoHandler;
3333
import org.eclipse.terminal.view.ui.launcher.AbstractLauncherDelegate;
@@ -52,7 +52,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
5252
}
5353

5454
@Override
55-
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
55+
public CompletableFuture<?> execute(Map<String, Object> properties) {
5656
Assert.isNotNull(properties);
5757

5858
// Set the terminal tab title
@@ -66,12 +66,10 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
6666
if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) {
6767
properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE);
6868
}
69-
70-
// Get the terminal service
71-
ITerminalService terminal = getTerminalService();
72-
// If not available, we cannot fulfill this request
73-
if (terminal != null) {
74-
terminal.openConsole(properties, done);
69+
try {
70+
return getTerminalService().openConsole(properties);
71+
} catch (RuntimeException e) {
72+
return CompletableFuture.failedFuture(e);
7573
}
7674
}
7775

terminal/bundles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 - 2018 Wind River Systems, Inc. and others. All rights reserved.
2+
* Copyright (c) 2011 - 2025 Wind River Systems, Inc. and others. All rights reserved.
33
* This program and the accompanying materials are made available under the terms
44
* of the Eclipse Public License 2.0 which accompanies this distribution, and is
55
* available at https://www.eclipse.org/legal/epl-2.0/
@@ -8,53 +8,41 @@
88
*
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
11+
* Alexander Fedorov (ArSysOp) - further evolution
1112
*******************************************************************************/
1213
package org.eclipse.terminal.view.core;
1314

1415
import java.util.Map;
15-
16-
import org.eclipse.core.runtime.IStatus;
16+
import java.util.concurrent.CompletableFuture;
1717

1818
/**
1919
* Terminal service.
2020
*/
2121
public interface ITerminalService {
2222

23-
/**
24-
* Client call back interface.
25-
*/
26-
public interface Done {
27-
/**
28-
* Called when the terminal service operation is done.
29-
*
30-
* @param status The status of the terminal service operation.
31-
*/
32-
public void done(IStatus status);
33-
}
34-
3523
/**
3624
* Opens a terminal asynchronously and invokes the given callback if done.
3725
*
3826
* @param properties The terminal properties. Must not be <code>null</code>.
39-
* @param done The callback to invoke if finished or <code>null</code>.
27+
* @return the {@link CompletableFuture}
4028
*/
41-
public void openConsole(Map<String, Object> properties, Done done);
29+
public CompletableFuture<?> openConsole(Map<String, Object> properties);
4230

4331
/**
44-
* Close the terminal asynchronously and invokes the given callback if done.
32+
* Close the terminal asynchronously.
4533
*
4634
* @param properties The terminal properties. Must not be <code>null</code>.
47-
* @param done The callback to invoke if finished or <code>null</code>.
35+
* @return the {@link CompletableFuture}
4836
*/
49-
public void closeConsole(Map<String, Object> properties, Done done);
37+
public CompletableFuture<?> closeConsole(Map<String, Object> properties);
5038

5139
/**
5240
* Terminate (disconnect) the terminal asynchronously and invokes the given callback if done.
5341
*
5442
* @param properties The terminal properties. Must not be <code>null</code>.
55-
* @param done The callback to invoke if finished or <code>null</code>.
43+
* @return the {@link CompletableFuture}
5644
*/
57-
public void terminateConsole(Map<String, Object> properties, Done done);
45+
public CompletableFuture<?> terminateConsole(Map<String, Object> properties);
5846

5947
/**
6048
* Register the given listener to receive notifications about terminal events.

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static String getString(String key) {
6565
public static String AbstractConfigurationPanel_encoding_custom_title;
6666
public static String AbstractConfigurationPanel_encoding_custom_message;
6767
public static String AbstractConfigurationPanel_encoding_custom_error;
68+
public static String AbstractLauncherDelegate_e_no_terminal_service;
6869

6970
public static String ConsoleManager_e_cannot_create_console;
7071
public static String ConsoleManager_e_no_active_page;

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ AbstractConfigurationPanel_encoding_custom=Other...
2727
AbstractConfigurationPanel_encoding_custom_title=Other...
2828
AbstractConfigurationPanel_encoding_custom_message=Please enter the name of the encoding to use for the terminal.
2929
AbstractConfigurationPanel_encoding_custom_error=Unsupported encoding. Please enter the name of a supported encoding.
30+
AbstractLauncherDelegate_e_no_terminal_service=Terminal service is not available
3031
ConsoleManager_e_cannot_create_console=Cannot create console
3132
ConsoleManager_e_no_active_page=No active workbench page
3233

0 commit comments

Comments
 (0)