I\'m using Wicket\'s Tree component in a web app. But empty folders are shown in a file-way. Just like this:
You can override Folder.getStyleClass to return the desired Icon. I got something like this:
@Override
protected String getStyleClass() {
String styleClass;
if (isFolder(getModelObject()))
{
if (tree.getState(matter) == State.EXPANDED)
{
styleClass = getOpenStyleClass();
} else {
styleClass = getClosedStyleClass();
}
} else {
styleClass = getOtherStyleClass(matter);
}
if (isSelected()) {
styleClass += " " + getSelectedStyleClass();
}
return styleClass;
}
Your implementation of isFolder() may vary.
To be more helpful than in my comment, I found this code in the AbstractTreeClass which will control what image it assigns to the node:
/**
* Returns the resource reference for icon of specified tree node.
*
* @param node
* The node
* @return The package resource reference
*/
protected ResourceReference getNodeIcon(TreeNode node)
{
if (node.isLeaf() == true)
{
return getItem();
}
else
{
if (isNodeExpanded(node))
{
return getFolderOpen();
}
else
{
return getFolderClosed();
}
}
}
So, the whole thing comes to the question of what does the isLeaf() method return. I found this in the DefaultMutableTreeNode class:
public boolean isLeaf()
{
return children.size() == 0;
}
So, it seems that your combination would treat all elements without children as leafs and not as folders. Maybe you could overwrite the getNodeIcon method using the getAllowsChildren, making the necessary type adjustments...
Another idea is to overwrite the isLeaf() method of DefaultMutableTreeNode, but then you might get other unexpected issues if it is called somewhere you cannot control...
This is just some insight on how you could do it... Hope it is helpful...
Which Wicket version are you using? The old tree implementation is deprecated in 6.x and removed in 7.x, so you should use the new implementation in package org.apache.wicket.extensions.markup.html.repeater.tree - it is no longer based on the Swing classes.
The problem is with the line if(i < 4){
in the outer for
loop. You allow the node to have children but you don't create any children for this last node.
Edit: You are correct about the empty folder so my answer is incorrect. In Swing this works as expected. When the tree row is rendered the decision to draw a folder or file icon is based upon the flag setAsksAllowsChildren
. So the problem seems to be on Wicket's tree component