|
Lines 31-36
Link Here
|
| 31 |
* @param <T> the actual value type that is stored by the tree |
31 |
* @param <T> the actual value type that is stored by the tree |
| 32 |
* |
32 |
* |
| 33 |
* @author emueller |
33 |
* @author emueller |
|
|
34 |
* @author Tobias Verhoeven |
| 34 |
*/ |
35 |
*/ |
| 35 |
public abstract class AbstractCachedTree<T> { |
36 |
public abstract class AbstractCachedTree<T> { |
| 36 |
|
37 |
|
|
Lines 85-100
Link Here
|
| 85 |
updateNode(eObject, value); |
86 |
updateNode(eObject, value); |
| 86 |
rootValue.putIntoCache(eObject, value); |
87 |
rootValue.putIntoCache(eObject, value); |
| 87 |
|
88 |
|
| 88 |
Set<EObject> affectedElements = new HashSet<EObject>(); |
89 |
Set<EObject> affectedElements = removeOutdatedParentCacheIfNeeded(eObject); |
| 89 |
// propagate upwards |
90 |
// propagate upwards |
| 90 |
EObject parent = eObject.eContainer(); |
91 |
EObject parent = eObject.eContainer(); |
| 91 |
|
92 |
|
| 92 |
while (parent != null && !excludedCallback.isExcluded(parent)) {// !isExcludedType(excludedTypes, |
93 |
while (parent != null && !excludedCallback.isExcluded(parent)) {// !isExcludedType(excludedTypes, |
| 93 |
// parent.getClass()) |
94 |
// parent.getClass()) |
| 94 |
updateParentNode(parent, eObject, value); |
95 |
updateParentNode(parent, eObject, nodes.get(eObject).getDisplayValue()); |
| 95 |
eObject = parent; |
96 |
eObject = parent; |
| 96 |
parent = parent.eContainer(); |
97 |
parent = parent.eContainer(); |
| 97 |
affectedElements.add(eObject); |
98 |
affectedElements.add(eObject); |
|
|
99 |
} |
| 100 |
return affectedElements; |
| 101 |
} |
| 102 |
|
| 103 |
// If an object has been moved the cached entries must be removed from old parents. |
| 104 |
private Set<EObject> removeOutdatedParentCacheIfNeeded(EObject eObject) { |
| 105 |
|
| 106 |
Set<EObject> affectedElements = new HashSet<EObject>(); |
| 107 |
CachedTreeNode<T> node = nodes.get(eObject); |
| 108 |
|
| 109 |
if (node.getParent() != null && node.getParent() != eObject.eContainer()) { |
| 110 |
EObject oldParent = (EObject) node.getParent(); |
| 111 |
while (oldParent != null && !excludedCallback.isExcluded(oldParent)) { |
| 112 |
affectedElements.add(oldParent); |
| 113 |
node = nodes.get(oldParent); |
| 114 |
node.removeFromCache(eObject); |
| 115 |
oldParent = oldParent.eContainer(); |
| 116 |
eObject = oldParent; |
| 117 |
} |
| 98 |
} |
118 |
} |
| 99 |
return affectedElements; |
119 |
return affectedElements; |
| 100 |
} |
120 |
} |
|
Lines 106-112
Link Here
|
| 106 |
* @return the node |
126 |
* @return the node |
| 107 |
*/ |
127 |
*/ |
| 108 |
public T getRootValue() { |
128 |
public T getRootValue() { |
| 109 |
return rootValue.getValue(); |
129 |
return rootValue.getDisplayValue(); |
| 110 |
} |
130 |
} |
| 111 |
|
131 |
|
| 112 |
/** |
132 |
/** |
|
Lines 122-128
Link Here
|
| 122 |
CachedTreeNode<T> nodeEntry = nodes.get(eObject); |
142 |
CachedTreeNode<T> nodeEntry = nodes.get(eObject); |
| 123 |
|
143 |
|
| 124 |
if (nodeEntry != null) { |
144 |
if (nodeEntry != null) { |
| 125 |
return nodes.get(eObject).getValue(); |
145 |
return nodes.get(eObject).getDisplayValue(); |
| 126 |
} |
146 |
} |
| 127 |
|
147 |
|
| 128 |
return getDefaultValue(); |
148 |
return getDefaultValue(); |
|
Lines 137-143
Link Here
|
| 137 |
public void remove(EObject eObject) { |
157 |
public void remove(EObject eObject) { |
| 138 |
|
158 |
|
| 139 |
CachedTreeNode<T> node = nodes.get(eObject); |
159 |
CachedTreeNode<T> node = nodes.get(eObject); |
| 140 |
CachedTreeNode<T> parentNode = nodes.get(node.parent); |
160 |
CachedTreeNode<T> parentNode = nodes.get(node.getParent()); |
| 141 |
|
161 |
|
| 142 |
nodes.remove(eObject); |
162 |
nodes.remove(eObject); |
| 143 |
rootValue.removeFromCache(eObject); |
163 |
rootValue.removeFromCache(eObject); |
|
Lines 167-173
Link Here
|
| 167 |
node = createNodeEntry(object, t); |
187 |
node = createNodeEntry(object, t); |
| 168 |
} |
188 |
} |
| 169 |
|
189 |
|
| 170 |
node.setValue(t); |
190 |
node.setOwnValue(t); |
| 171 |
} |
191 |
} |
| 172 |
|
192 |
|
| 173 |
private CachedTreeNode<T> createNodeEntry(Object object, T t) { |
193 |
private CachedTreeNode<T> createNodeEntry(Object object, T t) { |
|
Lines 176-192
Link Here
|
| 176 |
return node; |
196 |
return node; |
| 177 |
} |
197 |
} |
| 178 |
|
198 |
|
|
|
199 |
/** |
| 200 |
* Updates the passed parent nodes cached value. |
| 201 |
* |
| 202 |
* @param parent the parent object to be updated |
| 203 |
* @param object the object for which the cached value should be changed. |
| 204 |
* @param value the the cached value for the object |
| 205 |
*/ |
| 179 |
protected void updateParentNode(Object parent, Object object, T value) { |
206 |
protected void updateParentNode(Object parent, Object object, T value) { |
| 180 |
CachedTreeNode<T> node = nodes.get(object); |
207 |
CachedTreeNode<T> node = nodes.get(object); |
| 181 |
CachedTreeNode<T> parentNode = nodes.get(parent); |
208 |
CachedTreeNode<T> parentNode = nodes.get(parent); |
| 182 |
node.parent = parent; |
209 |
node.setParent(parent); |
| 183 |
|
210 |
|
| 184 |
if (parentNode == null) { |
211 |
if (parentNode == null) { |
| 185 |
parentNode = createNodeEntry(parent, value); |
212 |
parentNode = createNodeEntry(parent, value); |
| 186 |
} |
213 |
} |
| 187 |
|
214 |
|
| 188 |
parentNode.putIntoCache(object, value); |
215 |
parentNode.putIntoCache(object, value); |
| 189 |
rootValue.putIntoCache(parent, value); |
216 |
rootValue.putIntoCache(parent, parentNode.getDisplayValue()); |
| 190 |
} |
217 |
} |
| 191 |
|
218 |
|
| 192 |
/** |
219 |
/** |