Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Thoms2019-10-09 04:08:18 -0400
committerAlexander Kurtakov2019-10-14 15:07:04 -0400
commitc9a044f10e7d7189d2322068ee345c7db555b146 (patch)
tree20840eb5497617df5ab4afa5076d9c8f91c03596
parentb451fbc4440eb407a79e7be20836ffb1f0d118f7 (diff)
downloadrt.equinox.p2-c9a044f10e7d7189d2322068ee345c7db555b146.tar.gz
rt.equinox.p2-c9a044f10e7d7189d2322068ee345c7db555b146.tar.xz
rt.equinox.p2-c9a044f10e7d7189d2322068ee345c7db555b146.zip
Bug 457682 - Refactor getShellI20191014-1800
Refactored getModalShellExcluding() to getModalShell() since effectively no Shell was excluded in the call as getShell() is the only client of the method and always passed null. Refactored logic in getModalShell() to use a lambda expression. Refactored getModalShell()/getNonModalShell() to return Optional<Shell) to allow a fluent style in getShell(). Change-Id: Ie2246f83faab55924a0280e8ff3208d6d65cd3fc Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
-rw-r--r--bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/util/WorkbenchUtil.java37
1 files changed, 11 insertions, 26 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/util/WorkbenchUtil.java b/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/util/WorkbenchUtil.java
index b01bd8ddf..c045eab00 100644
--- a/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/util/WorkbenchUtil.java
+++ b/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/util/WorkbenchUtil.java
@@ -16,9 +16,12 @@
package org.eclipse.equinox.internal.p2.ui.discovery.util;
+import static java.util.Arrays.stream;
+
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
+import java.util.Optional;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
@@ -47,27 +50,13 @@ public class WorkbenchUtil {
* <p>
* <b>Note: Applied from patch on bug 99472.</b>
*
- * @param shell
- * A shell to exclude from the search. May be <code>null</code>.
- * @return Shell or <code>null</code>.
+ * @return Shell.
*/
- private static Shell getModalShellExcluding(Shell shell) {
+ private static Optional<Shell> getModalShell() {
IWorkbench workbench = PlatformUI.getWorkbench();
Shell[] shells = workbench.getDisplay().getShells();
int modal = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL | SWT.PRIMARY_MODAL;
- for (Shell shell2 : shells) {
- if (shell2.equals(shell)) {
- break;
- }
- // Do not worry about shells that will not block the user.
- if (shell2.isVisible()) {
- int style = shell2.getStyle();
- if ((style & modal) != 0) {
- return shell2;
- }
- }
- }
- return null;
+ return stream(shells).filter(shell -> shell.isVisible() && (shell.getStyle() & modal) != 0).findFirst();
}
/**
@@ -83,11 +72,7 @@ public class WorkbenchUtil {
if (!PlatformUI.isWorkbenchRunning() || PlatformUI.getWorkbench().isClosing()) {
return null;
}
- Shell modal = getModalShellExcluding(null);
- if (modal != null) {
- return modal;
- }
- return getNonModalShell();
+ return getModalShell().orElse(getNonModalShell().orElse(null));
}
/**
@@ -97,18 +82,18 @@ public class WorkbenchUtil {
*
* @return Shell
*/
- private static Shell getNonModalShell() {
+ private static Optional<Shell> getNonModalShell() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
if (windows.length > 0) {
- return windows[0].getShell();
+ return Optional.of(windows[0].getShell());
}
} else {
- return window.getShell();
+ return Optional.of(window.getShell());
}
- return null;
+ return Optional.empty();
}
/**

Back to the top