1 11 package org.eclipse.debug.internal.ui.viewers.model; 12 13 import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; 14 import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; 15 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 16 import org.eclipse.jface.viewers.TreePath; 17 18 23 public class ChildrenUpdate extends ViewerUpdateMonitor implements IChildrenUpdate { 24 25 private Object [] fElements; 26 private int fIndex; 27 private int fLength; 28 29 35 public ChildrenUpdate(ModelContentProvider provider, TreePath elementPath, Object element, int index, IElementContentProvider elementContentProvider, IPresentationContext context) { 36 super(provider, elementPath, element, elementContentProvider, context); 37 fIndex = index; 38 fLength = 1; 39 } 40 41 46 protected void performUpdate() { 47 TreeModelContentProvider provider = (TreeModelContentProvider) getContentProvider(); 48 TreePath elementPath = getElementPath(); 49 if (fElements != null) { 50 InternalTreeModelViewer viewer = (InternalTreeModelViewer) provider.getViewer(); 51 for (int i = 0; i < fElements.length; i++) { 52 int modelIndex = fIndex + i; 53 Object element = fElements[i]; 54 if (element != null) { 55 int viewIndex = provider.modelToViewIndex(elementPath, modelIndex); 56 if (provider.shouldFilter(elementPath, element)) { 57 if (provider.addFilteredIndex(elementPath, modelIndex, element)) { 58 if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { 59 System.out.println("REMOVE(" + getElement() + ", modelIndex: " + modelIndex + " viewIndex: " + viewIndex + ", " + element + ")"); } 61 viewer.remove(elementPath, viewIndex); 62 } 63 } else { 64 if (provider.isFiltered(elementPath, modelIndex)) { 65 provider.clearFilteredChild(elementPath, modelIndex); 66 int insertIndex = provider.modelToViewIndex(elementPath, modelIndex); 67 if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { 68 System.out.println("insert(" + getElement() + ", modelIndex: " + modelIndex + " insertIndex: " + insertIndex + ", " + element + ")"); } 70 viewer.insert(elementPath, element, insertIndex); 71 } else { 72 if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { 73 System.out.println("replace(" + getElement() + ", modelIndex: " + modelIndex + " viewIndex: " + viewIndex + ", " + element + ")"); } 75 viewer.replace(elementPath, viewIndex, element); 76 } 77 TreePath childPath = elementPath.createChildPath(element); 78 provider.updateHasChildren(childPath); 79 } 80 } 81 } 82 } else { 83 provider.updateHasChildren(elementPath); 84 } 85 } 86 87 90 public void setChild(Object child, int index) { 91 if (fElements == null) { 92 fElements = new Object [fLength]; 93 } 94 fElements[index - fIndex] = child; 95 } 96 97 103 public synchronized boolean coalesce(ViewerUpdateMonitor request) { 104 if (request instanceof ChildrenUpdate) { 105 ChildrenUpdate cu = (ChildrenUpdate) request; 106 if (getElement().equals(cu.getElement()) && getElementPath().equals(cu.getElementPath())) { 107 int end = fIndex + fLength; 108 int otherStart = cu.getOffset(); 109 int otherEnd = otherStart + cu.getLength(); 110 if ((otherStart >= fIndex && otherStart <= end) || (otherEnd >= fIndex && otherEnd <= end)) { 111 fIndex = Math.min(fIndex, otherStart); 113 end = Math.max(end, otherEnd); 114 fLength = end - fIndex; 115 if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { 116 System.out.println("coalesced: " + this.toString()); } 118 return true; 119 } 120 } 121 } 122 return false; 123 } 124 125 128 public int getLength() { 129 return fLength; 130 } 131 132 135 public int getOffset() { 136 return fIndex; 137 } 138 139 142 void startRequest() { 143 getElementContentProvider().update(new IChildrenUpdate[]{this}); 144 } 145 146 public String toString() { 147 StringBuffer buf = new StringBuffer (); 148 buf.append("IChildrenUpdate: "); buf.append(getElement()); 150 buf.append(" {"); buf.append(getOffset()); 152 buf.append(','); 153 buf.append(getLength()); 154 buf.append("}"); return buf.toString(); 156 } 157 158 161 int getPriority() { 162 return 3; 163 } 164 165 168 TreePath getSchedulingPath() { 169 return getElementPath(); 170 } 171 172 178 void setOffset(int offset) { 179 fIndex = offset; 180 } 181 } 182 183 | Popular Tags |