ItEr49S04ValidacionEProbasFuncionaisItEr48S04: [Bug #357] Fixing bug.

The problem was that when children are added or removed, the parent
was not being redrawn at the tree. Stale date was being shown.
This commit is contained in:
Óscar González Fernández 2010-03-01 19:20:36 +01:00
parent bb75d900fa
commit b1b6c105dd
2 changed files with 16 additions and 0 deletions

View file

@ -278,6 +278,14 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
add(parent, children);
}
public void sendContentsChangedEventFor(T object) {
Node<T> node = find(object);
T parent = getParent(object);
Node<T> parentNode = find(parent);
int position = parentNode.getIndexOf(node);
fireEvent(parent, position, position, TreeDataEvent.CONTENTS_CHANGED);
}
public void add(T parent, int position, Collection<? extends T> children) {
add(find(parent), position, wrap(children));
}

View file

@ -147,6 +147,11 @@ public abstract class EntitiesTree<T extends ITreeNode<T>> {
ITreeParentNode<T> container = turnIntoContainerIfNeeded(destinationNode);
container.add(position, elementToAdd.getThis());
addToTree(container, position, elementToAdd);
if (!tree.isRoot(container.getThis())) {
// the destination node might have data that depends on its
// children, so it should be redrawn
tree.sendContentsChangedEventFor(container.getThis());
}
added(destinationNode, elementToAdd, container);
}
@ -204,6 +209,9 @@ public abstract class EntitiesTree<T extends ITreeNode<T>> {
T destination = tree.getParent(parent);
move(nodeToUnindent, destination, getChildren(destination).indexOf(
parent) + 1);
if (!tree.isRoot(parent)) {
tree.sendContentsChangedEventFor(parent);
}
}
private class WithPosition {