diff --git a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF index b441a8c5d3a..2ea4c0a146f 100644 --- a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.e4.ui.workbench;singleton:=true -Bundle-Version: 1.16.0.qualifier +Bundle-Version: 1.16.100.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java index 6d15abbec0b..134a77c48b3 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java @@ -27,6 +27,7 @@ import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.workbench.UIEvents; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; @@ -35,7 +36,7 @@ public class ApplicationPartServiceImpl implements EPartService { private static final Supplier NO_VALID_PARTSERVICE = () -> new IllegalStateException( - "No valid PartService can be aquired from the current context"); //$NON-NLS-1$ + "No valid PartService can be acquired from the current context"); //$NON-NLS-1$ private MApplication application; @@ -50,15 +51,17 @@ public class ApplicationPartServiceImpl implements EPartService { private Optional getActiveWindowService() { IEclipseContext activeWindowContext = application.getContext().getActiveChild(); if (activeWindowContext == null) { - throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$ + // in this case the application has no focus so we can't determine the active + // child. + return Optional.empty(); } EPartService activeWindowPartService = activeWindowContext.get(EPartService.class); if (activeWindowPartService == null) { throw new IllegalStateException("Active window context is invalid"); //$NON-NLS-1$ } if (activeWindowPartService == this) { - // in this cas we would run into an infinite recursion, so from the current - // active window we can't aquire another part service + // in this case we would run into an infinite recursion, so from the current + // active window we can't acquire another part service return Optional.empty(); } return Optional.of(activeWindowPartService); @@ -68,10 +71,20 @@ private Optional getActiveWindowService(MPart part) { return getActiveWindowService().or(() -> { IEclipseContext context = part.getContext(); if (context != null) { + // First try the context of the part EPartService partService = context.get(EPartService.class); if (partService instanceof PartServiceImpl) { return Optional.of(partService); } + // Otherwise use the context of the contained window + MWindow window = modelService.getTopLevelWindowFor(part); + if (window != null) { + IEclipseContext windowContext = window.getContext(); + EPartService windowPartService = windowContext.get(EPartService.class); + if (windowPartService instanceof PartServiceImpl) { + return Optional.of(windowPartService); + } + } } return Optional.empty(); });