Safely set part name and tooltip in ResourceEditorPart 11/1411/2
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 31 Jan 2018 10:29:40 +0000 (12:29 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 31 Jan 2018 10:30:45 +0000 (12:30 +0200)
refs #7737

Change-Id: I5704e9189d18baf449f419026a1876cca3c02870

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

index 5689cfa4b7dee2b8a655ad59e6cbe2746f868c27..a81357532e4d4ae02c42f61bc9813efb1fe57270 100644 (file)
@@ -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;
  * </p>
  * 
  * @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<Boolean> 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);
         }
     }