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.IChildrenCountUpdate; 17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; 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 ChildrenCountUpdate extends ViewerUpdateMonitor implements IChildrenCountUpdate { 26 27 private int fCount = 0; 28 29 private List fBatchedRequests = null; 30 31 34 public ChildrenCountUpdate(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 int viewCount = fCount; 43 TreePath elementPath = getElementPath(); 44 if (viewCount == 0) { 45 getContentProvider().clearFilters(elementPath); 46 } else { 47 getContentProvider().setModelChildCount(elementPath, fCount); 48 viewCount = getContentProvider().modelToViewChildCount(elementPath, fCount); 49 } 50 if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { 51 System.out.println("setChildCount(" + getElement() + ", modelCount: " + fCount + " viewCount: " + viewCount + ")"); } 53 ((TreeViewer)(getContentProvider().getViewer())).setChildCount(elementPath, viewCount); 54 } 55 56 public void setChildCount(int numChildren) { 57 fCount = numChildren; 58 } 59 60 public String toString() { 61 StringBuffer buf = new StringBuffer (); 62 buf.append("IChildrenCountUpdate: "); buf.append(getElement()); 64 return buf.toString(); 65 } 66 67 70 boolean coalesce(ViewerUpdateMonitor request) { 71 if (request instanceof ChildrenCountUpdate) { 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 IChildrenCountUpdate[]{this}); 93 } else { 94 IChildrenCountUpdate[] updates = (IChildrenCountUpdate[]) fBatchedRequests.toArray(new IChildrenCountUpdate[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 2; 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 |