From: jsimomaa Date: Thu, 13 Sep 2018 12:27:43 +0000 (+0300) Subject: NPE while recalculating title for CompatibilityPart X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F92%2F2692%2F1;p=simantics%2Fplatform.git NPE while recalculating title for CompatibilityPart gitlab #117 Change-Id: Ie293c21c66a273ceb0b2fe3908168b6aebf9f347 (cherry picked from commit 20c2fa2629081d808fe313e387951f69111236b6) --- diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorPart.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorPart.java index a81357532..517ddf39e 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorPart.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorPart.java @@ -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)