Buttons for toggling "insert/overwrite" and "insert left/right" in toolbar replaced...
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / SimpleSelectionProvider.java
index 4af6db9b54fbf20ca5c15591f9544ea9a9fe2808..a1c38a7db597cc9d69136574534ffa9080e4f643 100644 (file)
@@ -9,9 +9,11 @@
 
 package eu.etaxonomy.taxeditor.editor;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.util.SafeRunnable;
@@ -32,7 +34,7 @@ import org.eclipse.swt.widgets.Display;
  */
 public class SimpleSelectionProvider implements ISelectionProvider {
 
-       private ListenerList selectionChangedListeners = new ListenerList();
+       private Set<ISelectionChangedListener> selectionChangedListeners = new HashSet<ISelectionChangedListener>();
        private ISelection selection;
        private Job job;
        
@@ -56,8 +58,9 @@ public class SimpleSelectionProvider implements ISelectionProvider {
         * @return a {@link org.eclipse.jface.viewers.ISelection} object.
         */
        public ISelection getSelection() {
-               if (selection != null)
+               if (selection != null){
                        return selection;
+               }
                // TODO we have to return an empty selection to avoid NPE
                // I don't really understand why this was not the case before
                return new StructuredSelection();
@@ -83,7 +86,9 @@ public class SimpleSelectionProvider implements ISelectionProvider {
                
                // cancel previous selection setting
                if(job != null){
-                       job.cancel();
+                       if(job.getState() != Job.NONE){
+                               job.cancel();
+                       }
                        job = null;
                }
                
@@ -100,7 +105,7 @@ public class SimpleSelectionProvider implements ISelectionProvider {
                                                display.asyncExec(new Runnable() {
                                         
                                                        public void run() {
-                                                               fireSelectionChanged(selectionChangedEvent);
+                                                               SimpleSelectionProvider.this.fireSelectionChanged(selectionChangedEvent);
                                                        }
                                                });
                                        }
@@ -118,12 +123,10 @@ public class SimpleSelectionProvider implements ISelectionProvider {
 
        private void fireSelectionChanged(final SelectionChangedEvent event) {
                
-               Object[] listeners = selectionChangedListeners.getListeners();
-               for (int i = 0; i < listeners.length; ++i) {
-                       final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
+               for (final ISelectionChangedListener listener : selectionChangedListeners) {
                        SafeRunnable.run(new SafeRunnable() {
                                public void run() {
-                                       l.selectionChanged(event);
+                                       listener.selectionChanged(event);
                                }
                        });
                }