public void onSuccess(final List <TreeNode> kids) {
DeferredCommand.addCommand(new IncrementalCommand() {
private int index = 0;
public boolean execute() {
if (index >= kids.size()) {
LoadEvent le = new LoadEvent(null, parentNode);
tree.loaded(le);
((Workbench)Registry.get(Workbench.ID)).hideWaitCursor();
return false;
}
XObject xObj = kids.get(index).getXObject();
String name;
String image = "";
if (xObj instanceof XElementNode) {
image = "<img paddingTop=\"2px\" width=\"16\" height=\"14\" src=\"icons/element_";
XElementType xElemType =
((XElementNode) xObj).getElement().getElementType();
if (XElementType.CONSOLIDATED.equals(xElemType)) {
image += "con2.png\"> ";
} else if (XElementType.NUMERIC.equals(xElemType)) {
image += "num2.png\"> ";
} else if (XElementType.STRING.equals(xElemType)) {
image += "str2.png\"> ";
} else {
image = "";
}
int count = ((XElementNode) xObj).getChildCount();
name = count == 0 ? xObj.getName() : xObj.getName() + " <i><font color=\"gray\">(" + count + ")</i></font>";
((XElementNode) xObj).setAxisHierarchyId(hierarchyId, viewId);
} else {
name = xObj.getName();
}
FastMSTreeItem item = new FastMSTreeItem(image + name) {
public void ensureChildren() {
loadChildren(this, getModel());
}
};
if (kids.get(index).hasChildren()) {
item.becomeInteriorNode();
}
item.setModel(kids.get(index));
parentItem.addItem(item);
if (item.getParentItem() != null &&
item.getParentItem().getModel() != null) {
item.getParentItem().getModel().addChild(kids.get(index));
}
index++;
if (item.getParentItem() != null) {
if (item.getParentItem().getFinishHandler() != null && index >= kids.size()) {
item.getParentItem().getFinishHandler().onSuccess(null);
}
}
if (index >= kids.size()) {
LoadEvent le = new LoadEvent(null, parentNode);
tree.loaded(le);
((Workbench)Registry.get(Workbench.ID)).hideWaitCursor();
}
return index < kids.size();
}