1 12 13 package org.eclipse.core.databinding; 14 15 import java.util.HashMap ; 16 import java.util.HashSet ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 import java.util.Set ; 20 21 import org.eclipse.core.databinding.observable.IObservable; 22 import org.eclipse.core.internal.databinding.Pair; 23 24 33 public class ObservablesManager { 34 35 private Set managedObservables = new HashSet (); 36 private Set excludedObservables = new HashSet (); 37 private Map contexts = new HashMap (); 38 39 42 public ObservablesManager() { 43 } 44 45 51 public void addObservable(IObservable observable) { 52 managedObservables.add(observable); 53 } 54 55 62 public void excludeObservable(IObservable observable) { 63 excludedObservables.add(observable); 64 } 65 66 79 public void addObservablesFromContext(DataBindingContext context, 80 boolean trackTargets, boolean trackModels) { 81 if (trackTargets || trackModels) { 82 contexts.put(context, new Pair(new Boolean (trackTargets), 83 new Boolean (trackModels))); 84 } 85 } 86 87 90 public void dispose() { 91 Set observables = new HashSet (); 92 observables.addAll(managedObservables); 93 for (Iterator it = contexts.keySet().iterator(); it.hasNext();) { 94 DataBindingContext context = (DataBindingContext) it.next(); 95 Pair trackModelsOrTargets = (Pair) contexts.get(context); 96 boolean disposeTargets = ((Boolean ) trackModelsOrTargets.a) 97 .booleanValue(); 98 boolean disposeModels = ((Boolean ) trackModelsOrTargets.b) 99 .booleanValue(); 100 for (Iterator it2 = context.getBindings().iterator(); it2.hasNext();) { 101 Binding binding = (Binding) it2.next(); 102 if (disposeTargets) { 103 observables.add(binding.getTarget()); 104 } 105 if (disposeModels) { 106 observables.add(binding.getModel()); 107 } 108 } 109 } 110 observables.removeAll(excludedObservables); 111 for (Iterator it = observables.iterator(); it.hasNext();) { 112 IObservable observable = (IObservable) it.next(); 113 observable.dispose(); 114 } 115 } 116 } 117 | Popular Tags |