1 19 20 package org.netbeans.modules.scripting.php.dbginterface; 21 22 import java.util.Collection ; 23 import java.util.Vector ; 24 import org.netbeans.spi.viewmodel.ModelEvent; 25 import org.netbeans.spi.viewmodel.ModelEvent.TreeChanged; 26 import org.netbeans.spi.viewmodel.ModelListener; 27 28 29 33 public abstract class ModelSupport { 34 35 private static final boolean DEBUG = false; 36 37 private Vector <ModelListener> listeners = new Vector <ModelListener>(); 38 39 protected ModelSupport() { 40 } 41 42 public void addModelListener(ModelListener l) { 46 listeners.add(l); 47 } 48 49 public void removeModelListener(ModelListener l) { 50 listeners.remove(l); 51 } 52 53 57 private volatile boolean needsRefresh = false; 58 59 public void setNeedsRefresh() { 60 needsRefresh = true; 61 } 62 63 public void refresh(boolean force) { 64 if (force || needsRefresh) { 65 needsRefresh = false; 66 fireChangeEvent(new TreeChanged(this)); 67 } 68 } 69 70 protected void fireChangeEvent(ModelEvent modelEvent) { 71 Vector <ModelListener> v; 72 73 synchronized (listeners) { 74 v = new Vector <ModelListener>(listeners); 75 } 76 77 int k = v.size(); 78 for (int i = 0; i < k; i++) { 79 v.get(i).modelChanged(modelEvent); 80 } 81 } 82 83 protected void fireChangeEvents(ModelEvent[] events) { 84 Vector <ModelListener> v; 85 86 synchronized (listeners) { 87 v = new Vector <ModelListener>(listeners); 88 } 89 90 int k = v.size(); 91 for(ModelEvent modelEvent : events) { 92 for (int i = 0; i < k; i++) { 93 v.get(i).modelChanged(modelEvent); 94 } 95 } 96 } 97 98 protected void fireChangeEvents(Collection <ModelEvent> events) { 99 Vector <ModelListener> v; 100 101 synchronized (listeners) { 102 v = new Vector <ModelListener>(listeners); 103 } 104 105 int k = v.size(); 106 for(ModelEvent modelEvent: events) { 107 for(int i = 0; i < k; i++) { 108 v.get(i).modelChanged(modelEvent); 109 } 110 } 111 } 112 } 113 | Popular Tags |