1 11 package org.eclipse.ui.views.markers.internal; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.Platform; 17 import org.eclipse.jface.util.SafeRunnable; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.jface.viewers.ISelectionChangedListener; 20 import org.eclipse.jface.viewers.ISelectionProvider; 21 import org.eclipse.jface.viewers.SelectionChangedEvent; 22 23 26 class SelectionProviderAdapter implements ISelectionProvider { 27 28 List listeners = new ArrayList (); 29 30 ISelection theSelection = null; 31 32 public void addSelectionChangedListener(ISelectionChangedListener listener) { 33 listeners.add(listener); 34 } 35 36 public ISelection getSelection() { 37 return theSelection; 38 } 39 40 public void removeSelectionChangedListener( 41 ISelectionChangedListener listener) { 42 listeners.remove(listener); 43 } 44 45 public void setSelection(ISelection selection) { 46 theSelection = selection; 47 final SelectionChangedEvent e = new SelectionChangedEvent(this, selection); 48 Object [] listenersArray = listeners.toArray(); 49 50 for (int i = 0; i < listenersArray.length; i++) { 51 final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[i]; 52 Platform.run(new SafeRunnable() { 53 public void run() { 54 l.selectionChanged(e); 55 } 56 }); 57 } 58 } 59 60 } 61 | Popular Tags |