1 11 package org.eclipse.core.internal.watson; 12 13 import java.util.Vector ; 14 import org.eclipse.core.internal.dtree.*; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.Path; 17 18 50 public class ElementTreeDelta { 51 52 protected IElementComparator comparator; 53 protected DeltaDataTree deltaTree; 54 protected ElementTree elementTree; 55 protected ElementTree parent; 56 57 60 protected IPath rootPath; 61 62 65 ElementTreeDelta(ElementTree parent, ElementTree elementTree, IElementComparator comparator) { 66 initialize(parent, elementTree, comparator); 67 deltaTree = elementTree.getDataTree().compareWith(parent.getDataTree(), comparator).asReverseComparisonTree(comparator); 68 rootPath = Path.ROOT; 69 } 70 71 75 ElementTreeDelta(ElementTree parent, ElementTree elementTree, IElementComparator comparator, IPath path) { 76 initialize(parent, elementTree, comparator); 77 deltaTree = parent.getDataTree().compareWith(elementTree.getDataTree(), comparator, path); 78 rootPath = path; 79 } 80 81 84 public void destroy() { 85 comparator = null; 86 deltaTree = null; 87 elementTree = null; 88 parent = null; 89 rootPath = null; 90 } 91 92 97 protected ElementDelta[] getAffectedElements(IPath parentID, IDeltaFilter filter) { 98 IPath parentKey; 99 if (parentID == null) { 100 parentKey = deltaTree.rootKey(); 101 } else { 102 parentKey = parentID; 103 } 104 Vector v = new Vector (); 105 IPath[] childKeys = deltaTree.getChildren(parentKey); 106 107 for (int i = 0; i < childKeys.length; ++i) { 108 IPath key = childKeys[i]; 109 110 111 NodeComparison nodeComparison = (NodeComparison) deltaTree.getData(key); 112 int userComparison = nodeComparison.getUserComparison(); 113 if (filter.includeElement(userComparison)) { 114 v.addElement(new ElementDelta(this, rootPath.append(key), key, nodeComparison)); 115 } 116 } 117 118 ElementDelta[] result = new ElementDelta[v.size()]; 119 v.copyInto(result); 120 return result; 121 } 122 123 126 DeltaDataTree getDeltaTree() { 127 return deltaTree; 128 } 129 130 134 public ElementDelta getElementDelta(IPath key) { 135 136 if (key == null) { 137 throw new IllegalArgumentException (); 138 } 139 140 try { 141 NodeComparison nodeComparison = (NodeComparison) deltaTree.getData(key); 142 return new ElementDelta(this, rootPath.append(key), key, nodeComparison); 143 } catch (ObjectNotFoundException e) { 144 return null; 145 } 146 } 147 148 153 public ElementTree getElementTree() { 154 return elementTree; 155 } 156 157 161 public ElementTree getParent() { 162 return parent; 163 } 164 165 169 protected boolean hasAffectedElements(IPath parentID, IDeltaFilter filter) { 170 IPath parentKey = parentID == null ? deltaTree.rootKey() : parentID; 171 172 IPath[] childKeys = deltaTree.getChildren(parentKey); 173 for (int i = 0; i < childKeys.length; ++i) { 174 NodeComparison nodeComparison = (NodeComparison) deltaTree.getData(childKeys[i]); 175 if (filter.includeElement(nodeComparison.getUserComparison())) { 176 return true; 177 } 178 } 179 return false; 180 } 181 182 185 private void initialize(ElementTree parent, ElementTree elementTree, IElementComparator comparator) { 186 parent.immutable(); 187 elementTree.immutable(); 188 this.parent = parent; 189 this.elementTree = elementTree; 190 this.comparator = comparator; 191 } 192 } | Popular Tags |