visibleChildComponents.add(childComponent);
}
if (visibleChildComponents.size() == node.getChildCount()) {
boolean changed = false; // Same number of children - but have any changed or moved?
for (int index = 0; index < visibleChildComponents.size(); index++) {
MCTMutableTreeNode treeNode = (MCTMutableTreeNode) node.getChildAt(index);
AbstractComponent nodeComponent = ((View) treeNode.getUserObject()).getManifestedComponent();
if (!nodeComponent.getComponentId().equals(visibleChildComponents.get(index).getComponentId())) {
changed = true;
break;
}
}
if (!changed) return; // Don't continue with refresh if children are unchanged.
}
// Note currently expanded nodes to restore state after re-ordering
Set<String> expanded = new HashSet<String>();
for (int index = 0; index < node.getChildCount(); index++) {
MCTMutableTreeNode childNode = (MCTMutableTreeNode) node.getChildAt(index);
View childView = (View) childNode.getUserObject();
if (parentTree.isExpanded(childNode.getTreePath()))
expanded.add(childView.getManifestedComponent().getComponentId());
}
// Insert nodes at the bottom which reflect current structure...
for (AbstractComponent childComponent : visibleChildComponents) {
Set<ViewInfo> viewInfos = childComponent.getViewInfos(ViewType.NODE);
if (!node.isProxy()) {
MCTMutableTreeNode childNode = GUIUtil.cloneTreeNode(childComponent,viewInfos.iterator()
.next());
node.addChild(node.getChildCount(), childNode, objectStaleListener);
}
}
// ...and then remove the old nodes from the top. (Removing first would cause node to collapse.)
while (node.getChildCount() > visibleChildComponents.size()) {
node.removeChild((MCTMutableTreeNode) node.getChildAt(0), objectStaleListener);
}
// Finally, restore selection paths.
for (int index = 0; index < node.getChildCount(); index++) {
MCTMutableTreeNode childNode = (MCTMutableTreeNode) node.getChildAt(index);
View childView = (View) childNode.getUserObject();
if (expanded.contains(childView.getManifestedComponent().getComponentId())) {
parentTree.expandPath(childNode.getTreePath());
childNode.setProxy(false); // If expanded node is mislabeled as proxy, it will lose updates
}
}
treeModel.nodeChanged(node);
}