]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/jface/BaseSelectionProvider.java
Usability fixes for GraphExplorerImpl -related WB selection propagation
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / jface / BaseSelectionProvider.java
index b2e6d921548618c790aa910bb3ee43713c2bda37..55ec0241b151540a9005b0f9ae842f7d685a3392 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 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
@@ -20,6 +20,7 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.simantics.utils.ObjectUtils;
 
 /**
  * BaseSelectionProvider is a base implementation ISelectionProvider -interface.
@@ -39,7 +40,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
  */
 public class BaseSelectionProvider implements ISelectionProvider {
 
-    protected ListenerList selectionListeners = new ListenerList();
+    protected ListenerList<ISelectionChangedListener> selectionListeners = new ListenerList<>();
 
     protected ISelection selection = StructuredSelection.EMPTY;
 
@@ -59,6 +60,14 @@ public class BaseSelectionProvider implements ISelectionProvider {
         return selection;
     }
 
+    public void clearListeners() {
+        clearSelectionChangedListeners();
+    }
+
+    public void clearSelectionChangedListeners() {
+        selectionListeners.clear();
+    }
+
     public void removeSelectionChangedListener(ISelectionChangedListener listener) {
         selectionListeners.remove(listener);
     }
@@ -106,14 +115,15 @@ public class BaseSelectionProvider implements ISelectionProvider {
      * 
      * @param selection the new selection
      */
-    public void setAndFireNonEqualSelection(ISelection selection) {
+    public boolean setAndFireNonEqualSelection(ISelection selection) {
         ISelection old = getSelection();
-        if (selection == old)
-            return;
+        if (ObjectUtils.objectEquals(old, selection))
+            return false;
 
         this.selection = selection;
-        if (selection != null && !selection.equals(old))
+        if (selection != null)
             fireSelection(selection);
+        return true;
     }
 
     public boolean selectionEquals(ISelection s) {