1 11 package org.eclipse.ui.internal.part; 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 import org.eclipse.jface.viewers.StructuredSelection; 23 24 27 class SelectionProviderAdapter implements ISelectionProvider { 28 29 List listeners = new ArrayList (); 30 31 ISelection theSelection = StructuredSelection.EMPTY; 32 33 public void addSelectionChangedListener(ISelectionChangedListener listener) { 34 listeners.add(listener); 35 } 36 37 public ISelection getSelection() { 38 return theSelection; 39 } 40 41 public void removeSelectionChangedListener( 42 ISelectionChangedListener listener) { 43 listeners.remove(listener); 44 } 45 46 public void setSelection(ISelection selection) { 47 theSelection = selection; 48 final SelectionChangedEvent e = new SelectionChangedEvent(this, selection); 49 Object [] listenersArray = listeners.toArray(); 50 51 for (int i = 0; i < listenersArray.length; i++) { 52 final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[i]; 53 Platform.run(new SafeRunnable() { 54 public void run() { 55 l.selectionChanged(e); 56 } 57 }); 58 } 59 } 60 61 } 62 | Popular Tags |