1 11 package org.eclipse.debug.internal.ui.views.variables; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.debug.internal.ui.views.IDebugExceptionHandler; 19 import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; 20 import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; 21 import org.eclipse.jface.viewers.Viewer; 22 import org.eclipse.ui.IWorkbenchPartSite; 23 import org.eclipse.ui.model.BaseWorkbenchContentProvider; 24 25 28 public class RemoteVariablesContentProvider extends BaseWorkbenchContentProvider { 29 30 37 private HashMap fParentCache; 38 39 42 private IDebugExceptionHandler fExceptionHandler = null; 43 44 47 private boolean fUseObjectBrowsers; 48 49 52 private RemoteVariableContentManager fManager; 53 54 57 public RemoteVariablesContentProvider(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { 58 fManager = (RemoteVariableContentManager)createContentManager(viewer, site, view); 59 fParentCache = new HashMap (10); 60 } 61 62 protected RemoteTreeContentManager createContentManager(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { 63 return new RemoteVariableContentManager(this, viewer, site, view); 64 } 65 66 69 public Object [] getChildren(Object parent) { 70 Object [] children = fManager.getChildren(parent); 71 if (children == null) { 72 children = super.getChildren(parent); 73 } 74 if (children != null) { 75 cache(parent, children); 76 return children; 77 } 78 return new Object [0]; 79 } 80 81 88 protected void cache(Object parent, Object [] children) { 89 for (int i = 0; i < children.length; i++) { 90 Object child = children[i]; 91 if (!fParentCache.containsKey(child)) { 94 fParentCache.put(child, parent); 95 } 96 } 97 } 98 99 102 public Object getParent(Object item) { 103 return fParentCache.get(item); 104 } 105 106 110 public void dispose() { 111 fManager.clearHasChildrenCache(); 112 fManager.cancel(); 113 fParentCache= null; 114 setExceptionHandler(null); 115 } 116 117 protected void clearCache() { 118 if (fParentCache != null) { 119 fParentCache.clear(); 120 } 121 } 122 123 128 public void removeCache(Object [] children) { 129 if (fParentCache == null) { 130 return; 131 } 132 for (int i = 0; i < children.length; i++) { 133 fParentCache.remove(children[i]); 134 } 135 } 136 137 140 public boolean hasChildren(Object element) { 141 return fManager.mayHaveChildren(element); 142 } 143 144 147 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 148 clearCache(); 149 fManager.cancel(); 150 fManager.clearHasChildrenCache(); 151 } 152 153 160 public List getCachedDecendants(Object parent) { 161 Iterator children = fParentCache.keySet().iterator(); 162 List cachedChildren = new ArrayList (10); 163 while (children.hasNext()) { 164 Object child = children.next(); 165 if (isCachedDecendant(child, parent)) { 166 cachedChildren.add(child); 167 } 168 } 169 return cachedChildren; 170 } 171 172 179 protected boolean isCachedDecendant(Object child, Object parent) { 180 Object p = getParent(child); 181 while (p != null) { 182 if (p.equals(parent)) { 183 return true; 184 } 185 p = getParent(p); 186 } 187 return false; 188 } 189 190 195 protected void setExceptionHandler(IDebugExceptionHandler handler) { 196 fExceptionHandler = handler; 197 } 198 199 204 protected IDebugExceptionHandler getExceptionHandler() { 205 return fExceptionHandler; 206 } 207 208 211 public void setShowLogicalStructure(boolean flag) { 212 fUseObjectBrowsers = flag; 213 } 214 215 public boolean isShowLogicalStructure() { 216 return fUseObjectBrowsers; 217 } 218 219 public RemoteVariableContentManager getContentManager() { 220 return fManager; 221 } 222 223 } 224 225 | Popular Tags |