I have a treeGrid, and initialize the tree in the client. And add hander of addSelectionUpdatedHandler. The tricky thing is: it can get selected record in the first time. Then whenever I select the record in the next time, The SelectionUpdatedEvent is triggered, but the selected record is always null.
public void afterScreenLoad() {
treeGrid = (TreeGrid) BaseWidget.getById(getApp().getScreenName() + "_ListGrid");
...
addTreeGridHandler();
addDataToGrids();
}
private void addDataToGrids() {
Criteria criteria = treeGrid.getCriteria();
tree = new Tree();
root = new TreeNode();
root.setIsFolder(true);
tree.setRoot(root);
jobs.forEach(job -> {
TreeNode jobNode = new TreeNode();
jobNode.setAttribute(ID, job.getId());
jobNode.setAttribute(NAME, job.getVin());
jobNode.setIsFolder(true);
tree.add(jobNode, root);
job.getProcessSteps().forEach(step -> {
TreeNode stepNode = new TreeNode();
stepNode.setAttribute(ID, step.getId());
stepNode.setAttribute(PARENT, job.getId());
stepNode.setAttribute(NAME, step.getName());
tree.add(stepNode, jobNode);
});
});
ListGridField[] fields = treeGrid.getAllFields();
assetsDataSourceIndex += 1;
ClientDataSource clientDataSource = new ClientDataSource(fields, assetsDataSourceIndex, true);
clientDataSource.setCacheData(tree.getAllNodes());
treeGrid.setDataSource(clientDataSource);
treeGrid.fetchData();
treeGrid.setFields(fields);
}
private void addTreeGridHandler() {
getActionUtil().addHandler(treeGrid.addDrawHandler(event -> treeGrid.getBody()
.setCanSelectText(true)));
treeGrid.addDataArrivedHandler((DataArrivedHandler) dataArrivedEvent -> {
SC.logWarn("Data arrived");
if (dataLoaded && !selectionChanged) {
selectPreviousSelectedAssetInTreeGrid();
}
});
getActionUtil().addHandler(treeGrid.addSelectionUpdatedHandler(this::selectionChanged));
}
private void selectionChanged(BrowserEvent selectEvent) {
SC.logWarn(selectEvent.getSource().toString());
TreeNode selectedRecord = treeGrid.getSelectedRecord();
boolean jobSelected = isJobSelected();
SC.logWarn("Selected record existed: " + (selectedRecord != null));
...
}
Could anybody help?