}
});
}
private void getAutoGroupBackingGroup(final AutoGroupTreeNode agNode, final AsyncCallback<ResourceGroup> callback) {
final ResourceGroupGWTServiceAsync resourceGroupService = GWTServiceLookup.getResourceGroupService();
// get the children tree nodes and build a child resourceId array
TreeNode[] children = treeGrid.getTree().getChildren(agNode);
final int[] childIds = new int[children.length];
for (int i = 0, size = children.length; (i < size); ++i) {
childIds[i] = ((ResourceTreeNode) children[i]).getResource().getId();
}
// get the backing group if it exists, otherwise create the group
ResourceGroupCriteria criteria = new ResourceGroupCriteria();
criteria.addFilterPrivate(true);
criteria.addFilterResourceTypeId(agNode.getResourceType().getId());
criteria.addFilterAutoGroupParentResourceId(agNode.getParentResource().getId());
criteria.addFilterVisible(false);
CoreGUI.showBusy(true);;
resourceGroupService.findResourceGroupsByCriteria(criteria, new AsyncCallback<PageList<ResourceGroup>>() {
public void onFailure(Throwable caught) {
CoreGUI.showBusy(false);;
callback.onFailure(new RuntimeException(MSG.view_tree_common_loadFailed_node(), caught));
}
public void onSuccess(PageList<ResourceGroup> result) {
if (result.isEmpty()) {
// Not found, create new backing group
// the backing group name is a display name using a unique parentResource-resourceType combo
final String backingGroupName = agNode.getBackingGroupName();
ResourceGroup backingGroup = new ResourceGroup(backingGroupName);
backingGroup.setAutoGroupParentResource(agNode.getParentResource());
backingGroup.setResourceType(agNode.getResourceType());
backingGroup.setVisible(false);
resourceGroupService.createPrivateResourceGroup(backingGroup, childIds,
new AsyncCallback<ResourceGroup>() {
public void onFailure(Throwable caught) {
CoreGUI.showBusy(false);;
callback.onFailure(new RuntimeException(MSG.view_tree_common_loadFailed_create(),
caught));
}
public void onSuccess(ResourceGroup result) {
CoreGUI.showBusy(false);;
// store a map entry from backingGroupId to AGTreeNode so we can easily
// get back to this node given the id of the backing group (from the viewpath)
autoGroupNodeMap.put(result.getId(), agNode);
// now that we know that backing group id, hold onto it in the node in case we need it
agNode.setResourceGroupId(result.getId());
callback.onSuccess(result);
}
});
} else {
// backing group found
final ResourceGroup backingGroup = result.get(0);
// store a map entry from backingGroupId to AGTreeNode so we can easily
// get back to this node given the id of the backing group (from the viewpath)
autoGroupNodeMap.put(backingGroup.getId(), agNode);
// now that we know that backing group id, hold onto it in the node in case we need it
agNode.setResourceGroupId(backingGroup.getId());
// make sure the members are correct before rendering
resourceGroupService.setAssignedResources(backingGroup.getId(), childIds, false,
new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
CoreGUI.showBusy(false);;
callback.onFailure(new RuntimeException(MSG.view_tree_common_loadFailed_update(),
caught));