I am developing a GWT app. I have some TreeItems with checkbox(rootCheckBox) which store GwtDomain objects and inside of TreeItems more items with checkBoxes(childTreeItemCheckBox) which are GwtActions. But I don't know how to get values from each TreeItem specifically. I write some code with tho HashMaps:rootCheckBoxMapList which collects values from rootCheckBox and childCheckBoxMapList which collects values from childTreeItemCheckBoxes. But this childCheckBoxMapList gives me the list of all selected childTreeItemCheckBoxes, but I want to sort that for every selected rootCheckBox I have list of selected childTreeItemCheckobex from that TreeItem specifically ,not from all TreeItems. 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) {
rootCheckBox = new CheckBox();
rootCheckBox.setBoxLabel(gwtDomain.toString());
rootTreeItem = new TreeItem(rootCheckBox);
for (final GwtAction gwtAction : result) {
final CheckBox childTreeItemCheckox = new CheckBox();
treeItem = new TreeItem(childTreeItemCheckox);
childTreeItemCheckox.setBoxLabel(gwtAction.toString());
rootTreeItem.addItem(treeItem);
tree.addItem(rootTreeItem);
childTreeItemCheckox.addListener(Events.OnClick, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
childTreeItemCheckox.setValue(true);
if (childTreeItemCheckox.getValue()) {
childCheckBoxMapList.put(gwtAction, childTreeItemCheckox);
}
}
});
}
rootCheckBoxMapList.put(gwtDomain, rootCheckBox);
}
});
}
}
});
And this is my code when I should collect checked values:
List<GwtDomain> rootCheckBoxChecked = new ArrayList<GwtDomain>();
List<GwtAction> childCheckBoxChecked = new ArrayList<GwtAction>();
for (Map.Entry<GwtDomain, CheckBox> e : rootCheckBoxMapList.entrySet()) {
if (e.getValue().getValue()) {
rootCheckBoxChecked.add(e.getKey());
for (Map.Entry<GwtAction, CheckBox> childCheckBox : childCheckBoxMapList.entrySet()) {
if (childCheckBox.getValue().getValue())
childCheckBoxChecked.add(childCheckBox.getKey());
}
}
}
What I am doing wrong? How to set that every treeItem has list with values just from itself?
Aucun commentaire:
Enregistrer un commentaire