Hi
I've tried both solutions offered here do the same thing however to force
the nodes to be redrawn you need to call treeNodesChanged() - which in turn
adds the right components to the ajax target.
Unfortunately the api is a bit awkward and uses Enumerations. Here's my
solution which seems to work:
@Override
protected void onJunctionLinkClicked(AjaxRequestTarget target, TreeNode
node) {
// keep current list of children to mark changes
Set<TreeNode> nodeChanges = new HashSet<TreeNode>();
for (TreeNode treeNode :
CollectionUtils.makeIterable((Enumeration<TreeNode>)node.children())) {
nodeChanges.add(treeNode);
}
// expand the next level of the model
modelChanging();
if (isNodeExpanded(node)) { // node has already been (un)expanded
for this cycle
m_dataProvider.expand((DefaultMutableTreeNode)node, 1);
} else {
// otherwise delete the children and replace with our marker
node to save memory
m_dataProvider.expand((DefaultMutableTreeNode)node, 0);
}
// compile list of added and removed nodes
Enumeration<TreeNode> children = node.children();
while (children.hasMoreElements()) {
TreeNode treeNode = children.nextElement();
if (nodeChanges.contains(treeNode)) {
nodeChanges.remove(treeNode);
} else {
nodeChanges.add(treeNode);
}
}
modelChanged();
// need array of ints to match changed node list
int nchanges = nodeChanges.size();
int[] indices = new int[nchanges];
for (int i = 0; i < nchanges; ++i) {
indices[i] = i;
}
// trigger redraw of clicked node's changed children
treeNodesChanged(new TreeModelEvent(this, new TreePath(node),
indices, nodeChanges.toArray() ));
super.onJunctionLinkClicked(target, node);
}
(m_dataProvider.expand(node, depth) adds children or replaces them with a
marker node as appropriate.)
Hope that helps :-)
MikeG
--
View this message in context:
http://www.nabble.com/LinkTree-lazy-loading-possible--tf4493231.html#a12921685
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]