Hi,
The use case:
A tree can be recreated, sometimes with new data, sometimes with other data. Whenever this happens, it seems the TreeGrid is giving me 'unselect' events on the current data's selected records.
I don't expect those events, since I just try to overwrite the data.
Am I creating the new data wrong? Is there a better way to discard the previous data to not receive the 'unselect state' events when data is overwritten?
Illustration:
1) click Recreate Tree
2) open the folders and click one
=> the cascading comes in action and throws onChangedEvents (OK)
3) click Recreate Tree again
=> I receive onChangedEvents for the unselected state (OK?)
thanks,
using SNAPSHOT_v8.3d_2012-08-31/Pro Deployment (built 2012-08-31)
The use case:
A tree can be recreated, sometimes with new data, sometimes with other data. Whenever this happens, it seems the TreeGrid is giving me 'unselect' events on the current data's selected records.
I don't expect those events, since I just try to overwrite the data.
Am I creating the new data wrong? Is there a better way to discard the previous data to not receive the 'unselect state' events when data is overwritten?
Illustration:
Code:
private static final String fieldName1 = "id"; private static final String fieldName2 = "name"; private static final String parentField = "parent"; public Canvas getViewPanel() { final HTMLPane logger = new HTMLPane(); logger.setContents(""); logger.setWidth(300); logger.setHeight(300); final TreeGrid grid = new TreeGrid(); grid.setWidth(300); grid.setHeight(300); grid.setShowPartialSelection(true); grid.setCascadeSelection(true); grid.setSelectionAppearance(SelectionAppearance.CHECKBOX); grid.setShowSelectedStyle(false); ListGridField field1 = new ListGridField(fieldName1); ListGridField field2 = new ListGridField(fieldName2); ListGridField field3 = new ListGridField(parentField); grid.setFields(field2, field1, field3); IButton addData = new IButton("Recreate tree"); addData.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { logger.setContents(logger.getContents()+ "recreating tree<br/>"); TreeNode rootNode = new TreeNode(); int rootNodeID = 0; rootNode.setAttribute(fieldName1, rootNodeID); rootNode.setAttribute(fieldName2, "root"); TreeNode [] records = new TreeNode[5]; for (int i=0; i<records.length; i++) { records[i] = new TreeNode(); records[i].setAttribute(fieldName1, (i+1)); records[i].setAttribute(fieldName2, "oho" + (i+1)); records[i].setAttribute(parentField, i); } Tree dataTree = new Tree(); dataTree.setModelType(TreeModelType.PARENT); dataTree.setIdField(fieldName1); dataTree.setParentIdField(parentField); dataTree.setNameProperty(fieldName2); dataTree.setAutoOpenRoot(true); dataTree.setReportCollisions(false); dataTree.setShowRoot(false); dataTree.setAutoOpenRoot(true); dataTree.setRoot(rootNode); dataTree.setData(records); grid.setData(dataTree); } }); grid.addSelectionChangedHandler(new SelectionChangedHandler() { public void onSelectionChanged(SelectionEvent event) { String logLine = ""; Record r = event.getRecord(); if (event.getState()) { logLine = "selected " + r.getAttribute(fieldName1)+"<br/>"; } else { logLine = "unselected " + r.getAttribute(fieldName1)+"<br/>"; } logger.setContents(logger.getContents() + logLine); } }); VLayout layout = new VLayout(); layout.setWidth100(); layout.setMembers(grid, addData, logger); return layout; }
2) open the folders and click one
=> the cascading comes in action and throws onChangedEvents (OK)
3) click Recreate Tree again
=> I receive onChangedEvents for the unselected state (OK?)
thanks,
using SNAPSHOT_v8.3d_2012-08-31/Pro Deployment (built 2012-08-31)
Comment