1 11 12 package org.eclipse.jface.internal.databinding.provisional.observable.mapping; 13 14 import java.util.Iterator ; 15 16 import org.eclipse.jface.internal.databinding.provisional.observable.set.IObservableSet; 17 import org.eclipse.jface.internal.databinding.provisional.observable.set.ISetChangeListener; 18 import org.eclipse.jface.internal.databinding.provisional.observable.set.SetDiff; 19 20 24 abstract public class ObservableMappingWithDomain extends AbstractObservableMapping implements IObservableMappingWithDomain { 25 26 private ISetChangeListener listener = new ISetChangeListener() { 27 public void handleSetChange(IObservableSet source, SetDiff diff) { 28 for (Iterator it = diff.getAdditions().iterator(); it.hasNext();) { 29 addListenerTo(it.next()); 30 } 31 for (Iterator it = diff.getRemovals().iterator(); it.hasNext();) { 32 removeListenerFrom(it.next()); 33 } 34 } 35 }; 36 37 private IObservableSet domain; 38 39 42 public ObservableMappingWithDomain() { 43 } 44 45 48 protected void initDomain(IObservableSet domain) { 49 this.domain = domain; 50 domain.addSetChangeListener(listener); 51 for (Iterator it = domain.iterator(); it.hasNext();) { 52 addListenerTo(it.next()); 53 } 54 } 55 56 59 public IObservableSet getDomain() { 60 return domain; 61 } 62 63 66 protected abstract void addListenerTo(Object domainElement); 67 68 71 protected abstract void removeListenerFrom(Object domainElement); 72 73 public void dispose() { 74 for (Iterator iter = domain.iterator(); iter.hasNext();) { 75 removeListenerFrom(iter.next()); 76 } 77 domain.removeSetChangeListener(listener); 78 super.dispose(); 79 } 80 81 } 82 | Popular Tags |