From: jsimomaa Date: Wed, 31 Jan 2018 10:29:40 +0000 (+0200) Subject: Safely set part name and tooltip in ResourceEditorPart X-Git-Tag: v1.43.0~136^2~612 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F1411%2F2;p=simantics%2Fplatform.git Safely set part name and tooltip in ResourceEditorPart refs #7737 Change-Id: I5704e9189d18baf449f419026a1876cca3c02870 --- 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 5689cfa4b..a81357532 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 @@ -9,6 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation * Semantum Oy - issue #4384 + * Semantum Oy - issue #7737 *******************************************************************************/ package org.simantics.ui.workbench; @@ -24,7 +25,6 @@ import org.eclipse.ui.part.EditorPart; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.common.request.ParametrizedRead; -import org.simantics.db.event.ChangeListener; import org.simantics.db.management.ISessionContext; import org.simantics.ui.SimanticsUI; @@ -41,6 +41,7 @@ import org.simantics.ui.SimanticsUI; *

* * @author Tuukka Lehtonen + * @author Jani Simomaa */ public abstract class ResourceEditorPart extends EditorPart implements IResourceEditorPart { @@ -83,10 +84,34 @@ public abstract class ResourceEditorPart extends EditorPart implements IResource Supplier disposedCallback = () -> disposed; session.asyncRequest( new TitleRequest(site.getId(), getResourceInput()), - new TitleUpdater(site.getShell().getDisplay(), this::setPartName, disposedCallback)); + new TitleUpdater(site.getShell().getDisplay(), this::safeSetPartName, disposedCallback)); session.asyncRequest( new ToolTipRequest(site.getId(), getResourceInput()), - new TitleUpdater(site.getShell().getDisplay(), this::setTitleToolTip, disposedCallback)); + new TitleUpdater(site.getShell().getDisplay(), this::safeSetTitleToolTip, disposedCallback)); + } + } + + /** + * Safely sets part name for parts whose IEditorInput is not yet disposed (e.g. + * removed from database) + * + * @param partName + */ + protected void safeSetPartName(String partName) { + if (!disposed) { + setPartName(partName); + } + } + + /** + * Safely sets title tooltip for parts whose IEditorInput is not yet disposed (e.g. + * removed from database) + * + * @param toolTip + */ + protected void safeSetTitleToolTip(String toolTip) { + if (!disposed) { + setTitleToolTip(toolTip); } }