Bug 489181 - Reduce usage of AbstractUIPlugin.getWorkbench in PDE
Replaced with PlatformUI.getWorkbench()
Change-Id: I104e58d3aa1baa3ff922d7f6a02a990c43110978
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
diff --git a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/ApiUIPlugin.java b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/ApiUIPlugin.java
index bdb3a5e..136a898 100644
--- a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/ApiUIPlugin.java
+++ b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/ApiUIPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2018 IBM Corporation and others.
+ * Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 489181
*******************************************************************************/
package org.eclipse.pde.api.tools.ui.internal;
@@ -31,6 +32,7 @@
import org.eclipse.pde.api.tools.internal.provisional.ISessionListener;
import org.eclipse.pde.api.tools.ui.internal.views.APIToolingView;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
@@ -240,7 +242,7 @@
private ISessionListener sessionListener = new ISessionListener() {
@Override
public void sessionAdded(ISession addedSession) {
- getWorkbench().getDisplay().asyncExec(() -> showAPIToolingView());
+ Display.getDefault().asyncExec(() -> showAPIToolingView());
}
@Override
@@ -324,7 +326,7 @@
}
private void showView(String id) {
- IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
diff --git a/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/Activator.java b/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/Activator.java
index 6027379..d8f12be 100644
--- a/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/Activator.java
+++ b/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/Activator.java
@@ -11,7 +11,7 @@
* Contributors:
* Code 9 Corporation - initial API and implementation
* Rafael Oliveira Nobrega <rafael.oliveira@gmail.com> - bug 242028
- * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 549441
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 549441, Bug 489181
*******************************************************************************/
package org.eclipse.pde.internal.ds.ui;
@@ -27,6 +27,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -102,7 +103,7 @@
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
- return getDefault().getWorkbench().getActiveWorkbenchWindow();
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
public static void logException(Throwable e, final String title,
diff --git a/ua/org.eclipse.pde.ua.ui/src/org/eclipse/pde/internal/ua/ui/PDEUserAssistanceUIPlugin.java b/ua/org.eclipse.pde.ua.ui/src/org/eclipse/pde/internal/ua/ui/PDEUserAssistanceUIPlugin.java
index 7263881..35ed90d 100644
--- a/ua/org.eclipse.pde.ua.ui/src/org/eclipse/pde/internal/ua/ui/PDEUserAssistanceUIPlugin.java
+++ b/ua/org.eclipse.pde.ua.ui/src/org/eclipse/pde/internal/ua/ui/PDEUserAssistanceUIPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2017 IBM Corporation and others.
+ * Copyright (c) 2008, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* Chris Aniszczyk <zx@code9.com> - initial API and implementation
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 489181
*******************************************************************************/
package org.eclipse.pde.internal.ua.ui;
@@ -24,6 +25,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -76,7 +78,7 @@
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
- return getDefault().getWorkbench().getActiveWorkbenchWindow();
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
public static void logException(Throwable e, final String title,
diff --git a/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/PDERuntimePlugin.java b/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/PDERuntimePlugin.java
index fb6eb30..082e921 100644
--- a/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/PDERuntimePlugin.java
+++ b/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/PDERuntimePlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 489181
*******************************************************************************/
package org.eclipse.pde.internal.runtime;
@@ -18,8 +19,7 @@
import org.eclipse.osgi.service.resolver.PlatformAdmin;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.*;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -60,15 +60,23 @@
}
public static IWorkbenchPage getActivePage() {
- return getDefault().internalGetActivePage();
+ IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (activeWindow != null) {
+ return activeWindow.getActivePage();
+ }
+ return null;
}
public static Shell getActiveWorkbenchShell() {
- return getActiveWorkbenchWindow().getShell();
+ IWorkbenchWindow activeWindow = getActiveWorkbenchWindow();
+ if (activeWindow != null) {
+ return activeWindow.getShell();
+ }
+ return null;
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
- return getDefault().getWorkbench().getActiveWorkbenchWindow();
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
public PackageAdmin getPackageAdmin() {
@@ -93,10 +101,6 @@
return getDefault().getBundle().getSymbolicName();
}
- private IWorkbenchPage internalGetActivePage() {
- return getWorkbench().getActiveWorkbenchWindow().getActivePage();
- }
-
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java
index de734d8..26cf638 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 489181
*******************************************************************************/
package org.eclipse.pde.internal.ui;
@@ -28,8 +29,7 @@
import org.eclipse.pde.internal.ui.util.SWTUtil;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.*;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.internal.views.log.ILogFileProvider;
@@ -99,7 +99,7 @@
* no active workbench window or if called from a non-UI thread
*/
public static IWorkbenchWindow getActiveWorkbenchWindow() {
- return getDefault().getWorkbench().getActiveWorkbenchWindow();
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
public static PDEPlugin getDefault() {
@@ -124,7 +124,7 @@
* @return The active workbench page or <code>null</code> if the workbench is shutting down
*/
private IWorkbenchPage internalGetActivePage() {
- IWorkbenchWindow workbenchWin = getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchWindow workbenchWin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
return workbenchWin != null ? workbenchWin.getActivePage() : null;
}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java
index 59d6dd5..9979070 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java
@@ -13,6 +13,7 @@
* Achim Demelt, eXXcellent solutions gmbh - initial API and implementation
* EclipseSource - initial API and implementation, ongoing enhancements
* IBM Corporation - ongoing enhancements
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 489181
*******************************************************************************/
package org.eclipse.pde.internal.ui.launcher;
@@ -31,14 +32,13 @@
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
import org.eclipse.pde.internal.launching.PDEMessages;
import org.eclipse.pde.internal.launching.launcher.LauncherUtils;
-import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsProcessor;
import org.eclipse.pde.launching.IPDELauncherConstants;
import org.eclipse.pde.ui.launcher.MainTab;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.*;
public class LauncherUtilsStatusHandler implements IStatusHandler {
@@ -137,13 +137,16 @@
}
public final static Shell getActiveShell() {
- IWorkbenchWindow window = PDEPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window == null) {
- IWorkbenchWindow[] windows = PDEPlugin.getDefault().getWorkbench().getWorkbenchWindows();
- if (windows.length > 0)
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
+ if (windows.length > 0) {
return windows[0].getShell();
- } else
+ }
+ } else {
return window.getShell();
+ }
return getDisplay().getActiveShell();
}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java
index cb724dc..4177552 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,7 @@
* Gary Duprex <Gary.Duprex@aspectstools.com> - bug 179213
* Benjamin Cabe <benjamin.cabe@anyware-tech.com> - bug 247553
* Johannes Ahlers <Johannes.Ahlers@gmx.de> - bug 477677
+ * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 489181
*******************************************************************************/
package org.eclipse.pde.internal.ui.wizards.plugin;
@@ -41,6 +42,7 @@
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
import org.eclipse.pde.ui.*;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.ide.IDE;
@@ -460,11 +462,12 @@
* @param file file to open the editor on
*/
private void openFile(final IFile file) {
- PDEPlugin.getDefault().getWorkbench().getDisplay().asyncExec(() -> {
+ Display.getDefault().asyncExec(() -> {
final IWorkbenchWindow ww = PDEPlugin.getActiveWorkbenchWindow();
final IWorkbenchPage page = ww.getActivePage();
- if (page == null)
+ if (page == null) {
return;
+ }
IWorkbenchPart focusPart = page.getActivePart();
if (focusPart instanceof ISetSelectionTarget) {
ISelection selection = new StructuredSelection(file);