Skip to content

Commit 8b89a9d

Browse files
committed
Access services via IWorkbench
We may avoid additional service trackers that nobody closes and access services via IWorkbench for this UI bundle
1 parent b47f9cd commit 8b89a9d

File tree

3 files changed

+10
-35
lines changed

3 files changed

+10
-35
lines changed

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/activator/UIPlugin.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012 - 2018 Wind River Systems, Inc. and others. All rights reserved.
2+
* Copyright (c) 2012 - 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,19 +8,17 @@
88
*
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
11+
* Alexander Fedorov (ArSysOp) - further evolution
1112
*******************************************************************************/
1213
package org.eclipse.terminal.connector.local.activator;
1314

1415
import org.eclipse.jface.resource.ImageDescriptor;
1516
import org.eclipse.jface.resource.ImageRegistry;
1617
import org.eclipse.swt.graphics.Image;
17-
import org.eclipse.terminal.view.core.ITerminalService;
1818
import org.eclipse.terminal.view.core.utils.ScopedEclipsePreferences;
1919
import org.eclipse.terminal.view.core.utils.TraceHandler;
20-
import org.eclipse.terminal.view.ui.launcher.ILaunchDelegateManager;
2120
import org.eclipse.ui.plugin.AbstractUIPlugin;
2221
import org.osgi.framework.BundleContext;
23-
import org.osgi.util.tracker.ServiceTracker;
2422

2523
/**
2624
* The activator class controls the plug-in life cycle
@@ -121,25 +119,4 @@ public static ImageDescriptor getImageDescriptor(String key) {
121119
return getDefault().getImageRegistry().getDescriptor(key);
122120
}
123121

124-
private static ServiceTracker<ITerminalService, ITerminalService> terminalServiceTracker;
125-
126-
public static synchronized ITerminalService getTerminalService() {
127-
if (terminalServiceTracker == null) {
128-
terminalServiceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(),
129-
ITerminalService.class, null);
130-
terminalServiceTracker.open();
131-
}
132-
return terminalServiceTracker.getService();
133-
}
134-
135-
private static ServiceTracker<ILaunchDelegateManager, ILaunchDelegateManager> launchDelegateServiceTracker;
136-
137-
public static synchronized ILaunchDelegateManager getLaunchDelegateManager() {
138-
if (launchDelegateServiceTracker == null) {
139-
launchDelegateServiceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(),
140-
ILaunchDelegateManager.class, null);
141-
launchDelegateServiceTracker.open();
142-
}
143-
return launchDelegateServiceTracker.getService();
144-
}
145122
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2018 Wind River Systems, Inc. and others. All rights reserved.
2+
* Copyright (c) 2012, 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/
@@ -9,6 +9,7 @@
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
1111
* Dirk Fauth <[email protected]> - Bug 460496
12+
* Alexander Fedorov (ArSysOp) - further evolution
1213
*******************************************************************************/
1314
package org.eclipse.terminal.connector.local.launcher;
1415

@@ -22,6 +23,7 @@
2223
import java.util.Iterator;
2324
import java.util.List;
2425
import java.util.Map;
26+
import java.util.Optional;
2527

2628
import org.eclipse.cdt.utils.pty.PTY;
2729
import org.eclipse.core.runtime.Assert;
@@ -220,13 +222,8 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
220222
}
221223
}
222224
}
223-
224-
// Get the terminal service
225-
ITerminalService terminal = UIPlugin.getTerminalService();
226-
// If not available, we cannot fulfill this request
227-
if (terminal != null) {
228-
terminal.openConsole(properties, done);
229-
}
225+
Optional.ofNullable(PlatformUI.getWorkbench().getService(ITerminalService.class))
226+
.ifPresent(s -> s.openConsole(properties, done));
230227
}
231228

232229
/**

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
import org.eclipse.jface.viewers.ISelection;
2424
import org.eclipse.jface.viewers.IStructuredSelection;
2525
import org.eclipse.jface.viewers.StructuredSelection;
26-
import org.eclipse.terminal.connector.local.activator.UIPlugin;
2726
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
27+
import org.eclipse.terminal.view.ui.launcher.ILaunchDelegateManager;
2828
import org.eclipse.terminal.view.ui.launcher.ILauncherDelegate;
2929
import org.eclipse.ui.IEditorInput;
3030
import org.eclipse.ui.IPathEditorInput;
31+
import org.eclipse.ui.PlatformUI;
3132
import org.eclipse.ui.handlers.HandlerUtil;
3233

3334
/**
@@ -58,7 +59,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
5859
}
5960

6061
// Get all applicable launcher delegates for the current selection
61-
List<ILauncherDelegate> delegates = UIPlugin.getLaunchDelegateManager()
62+
List<ILauncherDelegate> delegates = PlatformUI.getWorkbench().getService(ILaunchDelegateManager.class)
6263
.getApplicableLauncherDelegates(selection);
6364
// Find the local terminal launcher delegate
6465
ILauncherDelegate delegate = null;

0 commit comments

Comments
 (0)