]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
NPE while recalculating title for CompatibilityPart 72/2172/2
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 13 Sep 2018 12:27:43 +0000 (15:27 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Thu, 13 Sep 2018 12:28:09 +0000 (12:28 +0000)
gitlab #117

Change-Id: Ie293c21c66a273ceb0b2fe3908168b6aebf9f347

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

index 1cd72de635c2349fa3fec31241b25c76a55be0c7..ca06a5d7b5d538c9091fb8b71d7f45d26ad906d3 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.Simantics;
 import org.simantics.db.Resource;
@@ -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)