From cef25079ebdc75a73dc5477426dbd3e47a865dca Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Wed, 31 Jan 2018 12:29:40 +0200 Subject: [PATCH] Safely set part name and tooltip in ResourceEditorPart refs #7737 Change-Id: I5704e9189d18baf449f419026a1876cca3c02870 --- .../ui/workbench/ResourceEditorPart.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) 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); } } -- 2.47.1