I am building GWT app where I have Tree and TreeItems with CheckBoxes. I have one rootCheckBox called allCheckBox and his child elements rootCheckBox(this checkBoxes also have theirs children but that is not matter for this). I want that, when user opens dialog with checkBoxes, this checkBox is selected if every childCheckBox is selected. I have done that when tihs root checkBox is selected that child checkBoxes also are selected.
This is my piece of code:
enter cod 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);
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);
}
}
}
if (listOfNewClass.size() == checkedPermissionsList.size()) {
allCheckBox.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.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);
}
}
}
});
How to set that when all rootCheckBoxes are checked then allCheckBox become also checked?
EDIT: This checkedPermissionsList is List of rootCheckBox which are checked.
Aucun commentaire:
Enregistrer un commentaire