]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java
Fixed IEditorPart reference (memory) leaks from ResourceEditorSupport
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / DefaultExplorerSelectionListener.java
index 407fbff3ba8fa750ae823c4148aa71c131d9b129..713b28297e67856ba0841f263aeb12a9f0028aa3 100644 (file)
@@ -15,9 +15,10 @@ import org.eclipse.jface.viewers.IPostSelectionProvider;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.services.IDisposable;
 import org.simantics.browsing.ui.GraphExplorer;
 
-public class DefaultExplorerSelectionListener implements ISelectionListener {
+public class DefaultExplorerSelectionListener implements ISelectionListener, IDisposable {
 
     private static final boolean DEBUG = false;
 
@@ -35,6 +36,13 @@ public class DefaultExplorerSelectionListener implements ISelectionListener {
         this.filter = filter;
     }
 
+    @Override
+    public void dispose() {
+        owner = null;
+        explorer = null;
+        filter = null;
+    }
+
     @Override
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
         // Always disregard own selections.
@@ -44,6 +52,7 @@ public class DefaultExplorerSelectionListener implements ISelectionListener {
         if (DEBUG)
             System.out.println("[" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
         ISelection s = selection;
+        WorkbenchSelectionFilter filter = this.filter;
         if (filter != null)
             s = filter.filterSelection(part, selection);
 
@@ -52,9 +61,12 @@ public class DefaultExplorerSelectionListener implements ISelectionListener {
                 System.out.println("** [" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
                 System.out.println("    SETTING NEW SELECTION");
             }
-            if(!explorer.isDisposed()) {
+            GraphExplorer explorer = this.explorer;
+            if(explorer != null && !explorer.isDisposed()) {
                 IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
-                selectionProvider.setSelection(selection);
+                if (selectionProvider != null) {
+                    selectionProvider.setSelection(selection);
+                }
             }
         } else {
             if (DEBUG)