]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/ui/WorkbenchSelectionProvider.java
(refs #7568) Reinitialize diagram editor when element is switched
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / ui / WorkbenchSelectionProvider.java
index 6609ba24b155d1be1b508a566812274779432819..a93a0ab4106f8b563f780aa4a8474059742acf3a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2017 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - #7586
  *******************************************************************************/
 package org.simantics.diagram.ui;
 
@@ -75,40 +76,27 @@ public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implem
     @Override
     public void addedToContext(ICanvasContext ctx) {
         super.addedToContext(ctx);
-        if (site != null && site.getSelectionProvider() != this) {
-            swt.asyncExec(new Runnable() {
-                @Override
-                public void run() {
-                    if (site.getSelectionProvider() != WorkbenchSelectionProvider.this)
-                        site.setSelectionProvider(WorkbenchSelectionProvider.this);
-                }
-            });
-        }
+        swt.asyncExec(() -> {
+            if (site != null && site.getSelectionProvider() != WorkbenchSelectionProvider.this)
+                site.setSelectionProvider(WorkbenchSelectionProvider.this);
+        });
     }
 
     @Override
     public void removedFromContext(ICanvasContext ctx) {
-        if (site != null && site.getSelectionProvider() == this) {
-            swt.asyncExec(new Runnable() {
-                @Override
-                public void run() {
-                    if (site.getSelectionProvider() == WorkbenchSelectionProvider.this)
-                        site.setSelectionProvider(null);
-                }
-            });
-        }
+        swt.asyncExec(() -> {
+            if (site != null && site.getSelectionProvider() == WorkbenchSelectionProvider.this)
+                site.setSelectionProvider(null);
+        });
         super.removedFromContext(ctx);
     }
-    
+
     public void fireSelection(Iterable<?> selection) {
         final ISelection s = constructAdaptableSelection(selection);
-        swt.asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                currentSelection = s;
-                fireSelectionChanged(s);
-                schedulePostSelectionChanged(s);
-            }
+        swt.asyncExec(() -> {
+            currentSelection = s;
+            fireSelectionChanged(s);
+            schedulePostSelectionChanged(s);
         });
     }
 
@@ -117,7 +105,7 @@ public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implem
         Iterable<?> selection = (Iterable<?>) newValue;
         fireSelection(selection);
     }
-    
+
     @HintListener(Class = Selection.class, Field = "SELECTION0")
     public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {
         //System.out.println("selection removed: " + oldValue);
@@ -129,23 +117,16 @@ public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implem
 
     protected void schedulePostSelectionChanged(final ISelection s) {
         final int count = ++modCount;
-        ThreadUtils.getNonBlockingWorkExecutor().schedule(new Runnable() {
-            @Override
-            public void run() {
-                int newCount = modCount;
-                if (count != newCount)
-                    return;
-                if (isRemoved())
-                    return;
-                swt.asyncExec(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (isRemoved())
-                            return;
-                        firePostSelectionChanged(s);
-                    }
-                });
-            }
+        ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> {
+            int newCount = modCount;
+            if (count != newCount)
+                return;
+            if (isRemoved())
+                return;
+            swt.asyncExec(() -> {
+                if (!isRemoved())
+                    firePostSelectionChanged(s);
+            });
         }, POST_SELECTION_DELAY, TimeUnit.MILLISECONDS);
     }