I am developing a GWT app and I use Tree, TreeItem and CheckBoxes. I have treeItem with one rootcheckBox(allCheckBox) and when user clicks on that treeItem, that expands to child treeitems with checkBoxes(rootCheckBox) which also have child treeItems in them(childTreeItemCheckox). I have set that, when user clicks on allCheckBox all his child checkboxes(rootcheckboxes) are checked. But I notice bug: When I open Form Panel and immediately select allCheckBox not every rootCheckBox is checked, 2 or 3 last rootcheckboxes stay unchecked. I think that is because when user immediately click on allCheckBox not every rootCheckBox is retrieved from onSuccess method. This is my code:
GWT_DOMAIN_SERVICE.findAll(new AsyncCallback<List<GwtDomain>>() {
@Override
public void onFailure(Throwable caught) {
exitMessage = MSGS.dialogAddPermissionErrorDomains(caught.getLocalizedMessage());
exitStatus = false;
hide();
}
@Override
public void onSuccess(List<GwtDomain> result) {
for (final GwtDomain gwtDomain : result) {
GWT_DOMAIN_SERVICE.findActionsByDomainName(gwtDomain.name(), new AsyncCallback<List<GwtAction>>() {
@Override
public void onFailure(Throwable caught) {
exitMessage = MSGS.dialogAddPermissionErrorActions(caught.getLocalizedMessage());
exitStatus = false;
hide();
}
@Override
public void onSuccess(List<GwtAction> result) {
checkedItems = new GwtCheckedItems();
checkedItems.setName(gwtDomain);
rootCheckBox = new CheckBox();
rootCheckBox.setBoxLabel(gwtDomain.toString());
listCheckBoxes.add(rootCheckBox);
rootTreeItem = new TreeItem(rootCheckBox);
for (Map.Entry<GwtCheckedItems, CheckBox> map : listOfNewClass.entrySet()) {
boolean checking = true;
if (!map.getValue().getValue()) {
checking = false;
break;
}
checkingAllCheckBox = checking;
}
childCheckBoxMapList = new HashMap<GwtAction, CheckBox>();
checkedItems.setMap(childCheckBoxMapList);
for (GwtAccessPermission gwtAccessPermission : checkedPermissionsList) {
if (gwtAccessPermission.getPermissionDomain().toString().equals(checkedItems.getName().toString())) {
if (gwtAccessPermission.getPermissionAction().toString().equals(GwtAction.ALL.toString())) {
rootCheckBox.setValue(true);
}
}
}
for (final GwtAction gwtAction : result) {
final CheckBox childTreeItemCheckox = new CheckBox();
treeItem = new TreeItem(childTreeItemCheckox);
childTreeItemCheckox.setBoxLabel(gwtAction.toString());
rootTreeItem.addItem(treeItem);
childListOfNewClass.add(gwtAction);
allTreeItem.addItem(rootTreeItem);
childCheckBoxMapList.put(gwtAction, childTreeItemCheckox);
for (GwtAccessPermission gwtAccessPermission : checkedPermissionsList) {
if (gwtAccessPermission.getPermissionDomain().toString().equals(gwtDomain.toString())) {
if (gwtAccessPermission.getPermissionAction().toString().equals(gwtAction.toString())) {
childTreeItemCheckox.setValue(true);
}
}
}
}
listOfNewClass.put(checkedItems, rootCheckBox);
allCheckBox.setValue(checkingAllCheckBox);
rootCheckBox.addListener(Events.OnClick, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
boolean allSelected = true;
for (CheckBox child : listCheckBoxes) {
if (!child.getValue()) {
allSelected = false;
break;
}
}
allCheckBox.setValue(allSelected);
}
});
tree.addItem(allTreeItem);
}
});
}
allCheckBox.addListener(Events.OnClick, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if (allCheckBox.getValue()) {
for (CheckBox checkBox : listCheckBoxes) {
if (!checkBox.getValue()) {
checkBox.setValue(true);
}
}
} else {
for (CheckBox checkBox : listCheckBoxes) {
checkBox.setValue(false);
}
}
}
});
}
});
permissionFormPanel.add(tree);
Could someone help me to solve this bug? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire