From f35d6f2d9a9ee9d09e02d2785caefb43aa2967cb Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 19 Jan 2017 13:17:33 +0200 Subject: [PATCH] Add getActiveIEditorPart to E4WorkbenchUtils Change-Id: Ie800b8da7a219e5c361620a1005a2a7428d760a5 --- .../ui/workbench/e4/E4WorkbenchUtils.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java index a7db1e2aa..5299b8981 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java @@ -14,9 +14,12 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor; import org.simantics.db.Resource; import org.simantics.utils.datastructures.ArrayMap; +import org.simantics.utils.ui.workbench.WorkbenchUtils; /** * @author Tuukka Lehtonen @@ -164,4 +167,20 @@ public class E4WorkbenchUtils { return partService.findPart(partId); } + @SuppressWarnings("restriction") + public static IEditorPart getActiveIEditorPart(MPart mActiveEditorPart) { + // TODO: Fix this when we get rid of CompatibilityEditors + IEditorPart activeEditor = null; + if (mActiveEditorPart != null) { + Object editor = mActiveEditorPart.getObject(); + if (editor instanceof CompatibilityEditor) { + CompatibilityEditor compEditor = (CompatibilityEditor) editor; + activeEditor = compEditor.getEditor(); + } else { + // TODO: This is not good practice with E4 but an OK fallback for now + activeEditor = WorkbenchUtils.getActiveEditor(); + } + } + return activeEditor; + } } -- 2.47.1