1 11 package org.eclipse.debug.internal.ui.viewers.model; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; 17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; 18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 19 import org.eclipse.jface.viewers.TreePath; 20 import org.eclipse.jface.viewers.TreeViewer; 21 22 25 class HasChildrenUpdate extends ViewerUpdateMonitor implements IHasChildrenUpdate { 26 27 private boolean fHasChildren = false; 28 29 private List fBatchedRequests = null; 30 31 34 public HasChildrenUpdate(ModelContentProvider contentProvider, TreePath elementPath, Object element, IElementContentProvider elementContentProvider, IPresentationContext context) { 35 super(contentProvider, elementPath, element, elementContentProvider, context); 36 } 37 38 41 protected void performUpdate() { 42 ModelContentProvider contentProvider = getContentProvider(); 43 TreePath elementPath = getElementPath(); 44 if (!fHasChildren) { 45 contentProvider.clearFilters(elementPath); 46 } 47 if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { 48 System.out.println("setHasChildren(" + getElement() + " >> " + fHasChildren); } 50 ((TreeViewer)(contentProvider.getViewer())).setHasChildren(elementPath, fHasChildren); 51 if (elementPath.getSegmentCount() > 0) { 52 contentProvider.doRestore(elementPath); 53 } 54 } 55 56 public void setHasChilren(boolean hasChildren) { 57 fHasChildren = hasChildren; 58 } 59 60 public String toString() { 61 StringBuffer buf = new StringBuffer (); 62 buf.append("IHasChildrenUpdate: "); buf.append(getElement()); 64 return buf.toString(); 65 } 66 67 70 boolean coalesce(ViewerUpdateMonitor request) { 71 if (request instanceof HasChildrenUpdate) { 72 if (getElementPath().equals(request.getElementPath())) { 73 return true; 75 } else if (getElementContentProvider().equals(request.getElementContentProvider())) { 76 if (fBatchedRequests == null) { 77 fBatchedRequests = new ArrayList (); 78 fBatchedRequests.add(this); 79 } 80 fBatchedRequests.add(request); 81 return true; 82 } 83 } 84 return false; 85 } 86 87 90 void startRequest() { 91 if (fBatchedRequests == null) { 92 getElementContentProvider().update(new IHasChildrenUpdate[]{this}); 93 } else { 94 IHasChildrenUpdate[] updates = (IHasChildrenUpdate[]) fBatchedRequests.toArray(new IHasChildrenUpdate[fBatchedRequests.size()]); 95 for (int i = 1; i < updates.length; i++) { 99 getContentProvider().updateStarted((ViewerUpdateMonitor) updates[i]); 100 } 101 getElementContentProvider().update(updates); 102 } 103 } 104 105 108 int getPriority() { 109 return 1; 110 } 111 112 115 TreePath getSchedulingPath() { 116 TreePath path = getElementPath(); 117 if (path.getSegmentCount() > 0) { 118 return path.getParentPath(); 119 } 120 return path; 121 } 122 } 123 | Popular Tags |