1 11 package org.eclipse.debug.internal.ui.viewers.provisional; 12 13 import org.eclipse.core.runtime.ISafeRunnable; 14 import org.eclipse.core.runtime.ListenerList; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.core.runtime.SafeRunner; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener; 19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 22 import org.eclipse.jface.viewers.Viewer; 23 24 31 public abstract class AbstractModelProxy implements IModelProxy { 32 33 private IPresentationContext fContext; 34 private Viewer fViewer; 35 private boolean fDisposed = false; 36 37 private ListenerList fListeners = new ListenerList(); 38 39 public static boolean DEBUG_DELTAS = false; 41 42 static { 43 DEBUG_DELTAS = DebugUIPlugin.DEBUG && "true".equals( Platform.getDebugOption("org.eclipse.debug.ui/debug/viewers/deltas")); } 46 47 protected Object [] getListeners() { 48 synchronized (fListeners) { 49 return fListeners.getListeners(); 50 } 51 } 52 53 56 public void addModelChangedListener(IModelChangedListener listener) { 57 synchronized (fListeners) { 58 fListeners.add(listener); 59 } 60 } 61 62 65 public void removeModelChangedListener(IModelChangedListener listener) { 66 synchronized (fListeners) { 67 fListeners.remove(listener); 68 } 69 } 70 71 76 public void fireModelChanged(IModelDelta delta) { 77 final IModelDelta root = getRootDelta(delta); 78 Object [] listeners = getListeners(); 79 if (DEBUG_DELTAS) { 80 DebugUIPlugin.debug("FIRE DELTA: " + delta.toString()); } 82 for (int i = 0; i < listeners.length; i++) { 83 final IModelChangedListener listener = (IModelChangedListener) listeners[i]; 84 ISafeRunnable safeRunnable = new ISafeRunnable() { 85 public void handleException(Throwable exception) { 86 DebugUIPlugin.log(exception); 87 } 88 89 public void run() throws Exception { 90 listener.modelChanged(root, AbstractModelProxy.this); 91 } 92 93 }; 94 SafeRunner.run(safeRunnable); 95 } 96 } 97 98 104 protected IModelDelta getRootDelta(IModelDelta delta) { 105 IModelDelta parent = delta.getParentDelta(); 106 while (parent != null) { 107 delta = parent; 108 parent = delta.getParentDelta(); 109 } 110 return delta; 111 } 112 113 116 public synchronized void dispose() { 117 fDisposed = true; 118 fContext = null; 119 fViewer = null; 120 } 121 122 125 public void init(IPresentationContext context) { 126 fContext = context; 127 } 128 129 135 public IPresentationContext getPresentationContext() { 136 return fContext; 137 } 138 139 145 public void installed(Viewer viewer) { 146 fViewer = viewer; 147 } 148 149 154 protected Viewer getViewer() { 155 return fViewer; 156 } 157 158 161 public synchronized boolean isDisposed() { 162 return fDisposed; 163 } 164 165 } 166 | Popular Tags |