boolean isPlatform = treeGrid.getTree().isRoot(parentNode);
boolean isCheckboxMarked = treeGrid.isSelected(selectedNode);
if (isPlatform) {
if (isCheckboxMarked) {
SC.ask(MSG.view_autoDiscoveryQ_confirmSelect(), new BooleanCallback() {
public void execute(Boolean confirmed) {
if (confirmed && !treeGrid.getTree().hasChildren(selectedNode)) {
selectedNode.setAttribute("selectChildOnArrival", "true");
treeGrid.getTree().loadChildren(selectedNode);
} else {
if (confirmed) {
selectAllPlatformChildren(selectedNode);
}
updateButtonEnablement(selectAllButton, deselectAllButton, importButton,
ignoreButton, unignoreButton);
selectionChangedHandlerDisabled = false;
}
}
});
} else {
selectedNode.setAttribute("autoSelectChildren", "false");
treeGrid.deselectRecords(treeGrid.getTree().getChildren(selectedNode));
// the immediate redraw below should not be necessary, but without it the deselected
// platform checkbox remained checked.
// treeGrid.redraw();
updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
unignoreButton);
selectionChangedHandlerDisabled = false;
}
} else {
if (isCheckboxMarked) {
if (!treeGrid.isSelected(parentNode)) {
treeGrid.selectRecord(parentNode);
}
}
updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
unignoreButton);
selectionChangedHandlerDisabled = false;
}
}
});
treeGrid.addDataArrivedHandler(new DataArrivedHandler() {
public void onDataArrived(DataArrivedEvent dataArrivedEvent) {
if (treeGrid != null) {
TreeNode parent = dataArrivedEvent.getParentNode();
if (!treeGrid.getTree().isRoot(parent)) {
// This flag can be set when we select a platform or as part of selectAll button handling. It
// means that we want to immediately select the child server nodes.
boolean selectChildOnArrival = Boolean.valueOf(parent.getAttribute("selectChildOnArrival"));
if (selectChildOnArrival) {
// data includes the platform, just get the descendant servers
treeGrid.selectRecords(treeGrid.getData().getDescendantLeaves());
}
}
// This logic is relevant to what we do in the selectAll button
boolean endDisable = true;
if (loadAllPlatforms) {
TreeNode rootNode = treeGrid.getTree().getRoot();
TreeNode[] platformNodes = treeGrid.getTree().getChildren(rootNode);
for (TreeNode platformNode : platformNodes) {
if (!treeGrid.getTree().isLoaded(platformNode)) {
endDisable = false;
break;
}
}
}
if (endDisable) {
updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
unignoreButton);
selectionChangedHandlerDisabled = false;
}
// NOTE: Due to a SmartGWT bug, the TreeGrid is not automatically redrawn upon data arrival, and
// calling treeGrid.markForRedraw() doesn't redraw it either. The user can mouse over the grid
// to cause it to redraw, but it is obviously not reasonable to expect that. So we must
// explicitly call redraw() here.
treeGrid.redraw();
}
}
});
dataSource.addFailedFetchListener(new AsyncCallback() {
// just in case we have a failure while fetching, try to make sure we don't lock up the view.
public void onFailure(Throwable caught) {
loadAllPlatforms = false;
updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton, unignoreButton);
selectionChangedHandlerDisabled = false;
}
public void onSuccess(Object result) {
// never called
}
});
selectAllButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
SC.ask(MSG.view_autoDiscoveryQ_confirmSelectAll(), new BooleanCallback() {
public void execute(Boolean selectChildServers) {
selectionChangedHandlerDisabled = true;
TreeNode rootNode = treeGrid.getTree().getRoot();
TreeNode[] platformNodes = treeGrid.getTree().getChildren(rootNode);