X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2FResourceEditorPart.java;h=1cd72de635c2349fa3fec31241b25c76a55be0c7;hp=5689cfa4b7dee2b8a655ad59e6cbe2746f868c27;hb=e88be95edf1f80781646cfdf717ec1b663264179;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 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..1cd72de63 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; @@ -21,12 +22,11 @@ import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; +import org.simantics.Simantics; 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; /** * ResourceEditorPart is a base implementation for editors that support @@ -41,6 +41,7 @@ import org.simantics.ui.SimanticsUI; *

* * @author Tuukka Lehtonen + * @author Jani Simomaa */ public abstract class ResourceEditorPart extends EditorPart implements IResourceEditorPart { @@ -78,15 +79,39 @@ public abstract class ResourceEditorPart extends EditorPart implements IResource // Set initial part name according to the name given by IEditorInput setPartName(getEditorInput().getName()); - Session session = SimanticsUI.peekSession(); + Session session = Simantics.peekSession(); if (session != null) { 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); } }