Re: How to update GWT CellTree data model preserving the node open states?
The challenging thing about this is that the TreeNode class has no get child method, making it problematic to do a tree traversal. The only way to get a child of TreeNode is by calling:
TreeNode childNode = treeNode.setChildOpen(i, treeNode.isChildOpen(i));
Since you're making the call with the open status it's already set to, the call has absolutely no effect, except that it returns the child. Why the creators of this class didn't add a getChild method is beyond me. Despite it's MANY problems, it's one of the better options I've seen.
Here's my complete solution. These methods are inside a class that extends CellTree:
public void refresh() {
Map<Object,Boolean> openMap = new HashMap<Object,Boolean>();
TreeNode root = getRootTreeNode();
getNodeOpenMap(root, openMap);
openMap.put(root, true);
refresh(root, openMap);
}
private void getNodeOpenMap(TreeNode treeNode, Map<Object,Boolean> openMap) {
if (treeNode == null) {
return;
}
for (int i = 0, n = treeNode.getChildCount(); i < n; ++i) {
if (null == treeNode.getChildValue(i) || treeNode.isChildLeaf(i)) {
continue;
}
openMap.put(treeNode.getChildValue(i), treeNode.isChildOpen(i));
// This gets the child node, but doesn't change the open status (there's no other way to get the child).
TreeNode childNode = treeNode.setChildOpen(i, treeNode.isChildOpen(i));
getNodeOpenMap(childNode, openMap);
}
}
public void refresh(TreeNode treeNode, Map<Object,Boolean> openMap) {
if (treeNode == null) {
return;
}
for (int i = 0, n = treeNode.getChildCount(); i < n; ++i) {
if (null == treeNode.getChildValue(i) || treeNode.isChildLeaf(i)) {
continue;
}
treeNode.setChildOpen(i, false);
Boolean open = openMap.get(treeNode.getChildValue(i));
if (open != null && open) {
TreeNode childNode = treeNode.setChildOpen(i, true);
refresh(childNode, openMap);
}
}
}
-- TreeNode childNode = treeNode.setChildOpen(i, treeNode.isChildOpen(i));
Since you're making the call with the open status it's already set to, the call has absolutely no effect, except that it returns the child. Why the creators of this class didn't add a getChild method is beyond me. Despite it's MANY problems, it's one of the better options I've seen.
Here's my complete solution. These methods are inside a class that extends CellTree:
public void refresh() {
Map<Object,Boolean> openMap = new HashMap<Object,Boolean>();
TreeNode root = getRootTreeNode();
getNodeOpenMap(root, openMap);
openMap.put(root, true);
refresh(root, openMap);
}
private void getNodeOpenMap(TreeNode treeNode, Map<Object,Boolean> openMap) {
if (treeNode == null) {
return;
}
for (int i = 0, n = treeNode.getChildCount(); i < n; ++i) {
if (null == treeNode.getChildValue(i) || treeNode.isChildLeaf(i)) {
continue;
}
openMap.put(treeNode.getChildValue(i), treeNode.isChildOpen(i));
// This gets the child node, but doesn't change the open status (there's no other way to get the child).
TreeNode childNode = treeNode.setChildOpen(i, treeNode.isChildOpen(i));
getNodeOpenMap(childNode, openMap);
}
}
public void refresh(TreeNode treeNode, Map<Object,Boolean> openMap) {
if (treeNode == null) {
return;
}
for (int i = 0, n = treeNode.getChildCount(); i < n; ++i) {
if (null == treeNode.getChildValue(i) || treeNode.isChildLeaf(i)) {
continue;
}
treeNode.setChildOpen(i, false);
Boolean open = openMap.get(treeNode.getChildValue(i));
if (open != null && open) {
TreeNode childNode = treeNode.setChildOpen(i, true);
refresh(childNode, openMap);
}
}
}
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home