]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
NPE while recalculating title for CompatibilityPart 92/2692/1
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 13 Sep 2018 12:27:43 +0000 (15:27 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 25 Feb 2019 11:29:24 +0000 (11:29 +0000)
gitlab #117

Change-Id: Ie293c21c66a273ceb0b2fe3908168b6aebf9f347
(cherry picked from commit 20c2fa2629081d808fe313e387951f69111236b6)

bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorPart.java

index a81357532e4d4ae02c42f61bc9813efb1fe57270..517ddf39e850a904d949da0c98b6dc36222ad3f6 100644 (file)
@@ -20,7 +20,10 @@ import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IWorkbenchPartSite;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.internal.PartSite;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
 import org.eclipse.ui.part.EditorPart;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
@@ -98,11 +101,25 @@ public abstract class ResourceEditorPart extends EditorPart implements IResource
      * @param partName
      */
     protected void safeSetPartName(String partName) {
-        if (!disposed) {
+        if (!disposed && checkCompatibilityPartNotBeingDisposed()) { // this is to fix bug https://gitlab.simantics.org/simantics/platform/issues/117
             setPartName(partName);
         }
     }
 
+    @SuppressWarnings("restriction")
+    private boolean checkCompatibilityPartNotBeingDisposed() {
+        IWorkbenchPartSite site = getSite();
+        if (site instanceof PartSite) {
+            PartSite partSite = (PartSite) getSite();
+            Object object = partSite.getModel().getObject();
+            if (object instanceof CompatibilityEditor) {
+                CompatibilityEditor editor = (CompatibilityEditor) object;
+                return !editor.isBeingDisposed();
+            }
+        }
+        return true;
+    }
+
     /**
      * Safely sets title tooltip for parts whose IEditorInput is not yet disposed (e.g.
      * removed from database)