1 package de.loskutov.bco.views; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.eclipse.core.runtime.IStatus; 7 import org.eclipse.jface.viewers.IPostSelectionProvider; 8 import org.eclipse.jface.viewers.ISelection; 9 import org.eclipse.jface.viewers.ISelectionChangedListener; 10 11 import de.loskutov.bco.BytecodeOutlinePlugin; 12 13 24 class BCOViewSelectionProvider implements IPostSelectionProvider { 25 26 private IPostSelectionProvider realProvider; 27 private List selProviders; 28 private ISelection selection; 29 30 public BCOViewSelectionProvider(){ 31 super(); 32 selProviders = new ArrayList (); 33 } 34 35 public void setCurrentSelectionProvider(IPostSelectionProvider provider){ 36 if(!selProviders.contains(provider)){ 37 BytecodeOutlinePlugin.log( 38 new Exception ( 39 "Current selection provider is not registered yet"), 40 IStatus.WARNING); 41 return; 42 } 43 realProvider = provider; 44 if(selection != null) { 45 realProvider.setSelection(selection); 46 } 47 } 48 49 public void registerSelectionProvider(IPostSelectionProvider provider) { 50 if(!selProviders.contains(provider)){ 51 selProviders.add(provider); 52 } 53 } 54 55 58 public void addPostSelectionChangedListener(ISelectionChangedListener listener) { 59 for (int i = 0; i < selProviders.size(); i++) { 60 IPostSelectionProvider provider = (IPostSelectionProvider) selProviders.get(i); 61 provider.addPostSelectionChangedListener(listener); 62 } 63 } 64 65 68 public void removePostSelectionChangedListener(ISelectionChangedListener listener) { 69 for (int i = 0; i < selProviders.size(); i++) { 70 IPostSelectionProvider provider = (IPostSelectionProvider) selProviders.get(i); 71 provider.removePostSelectionChangedListener(listener); 72 } 73 } 74 75 78 public void addSelectionChangedListener(ISelectionChangedListener listener) { 79 for (int i = 0; i < selProviders.size(); i++) { 80 IPostSelectionProvider provider = (IPostSelectionProvider) selProviders.get(i); 81 provider.addSelectionChangedListener(listener); 82 } 83 } 84 85 88 public ISelection getSelection() { 89 return realProvider != null? realProvider.getSelection() : null; 90 } 91 92 95 public void removeSelectionChangedListener(ISelectionChangedListener listener) { 96 for (int i = 0; i < selProviders.size(); i++) { 97 IPostSelectionProvider provider = (IPostSelectionProvider) selProviders.get(i); 98 provider.removeSelectionChangedListener(listener); 99 } 100 } 101 102 105 public void setSelection(ISelection selection) { 106 this.selection = selection; 107 if(realProvider != null) { 108 realProvider.setSelection(selection); 109 } 110 } 111 112 } | Popular Tags |