DefaultTreeModel和Wicket树:setAsksAllowsChildren不起作用 [英] DefaultTreeModel and Wicket Tree: setAsksAllowsChildren doesn't work

查看:72
本文介绍了DefaultTreeModel和Wicket树:setAsksAllowsChildren不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Web应用程序中使用Wicket的Tree组件.但是空文件夹以文件方式显示. 像这样:

I'm using Wicket's Tree component in a web app. But empty folders are shown in a file-way. Just like this:

下面是我使用DefaultTreeModel和Tree的地方:

Bellow is where I use the DefaultTreeModel and Tree:

PDMinterface pdmI = new PDMinterface(); 
DefaultMutabletreeNode rootTreeNode = pdmI.getDocTree();            //文档树根结点,由PDM接口提供
DefaultTreeModel treeModel = new DefaultTreeModel(rootTreeNode);
treeModel.setAsksAllowsChildren(true);

并且我确定folder5设置为允许子级:

and I'm sure that folder5 is set to allow children:

public DefaultMutableTreeNode getDocTree(){  
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    root.setAllowsChildren(true);
    FolderNode rootFolder = new FolderNode(0, "root", "Jiajun", true);
    root.setUserObject(rootFolder);

    for(int i=0; i < 5; i++){
        DefaultMutableTreeNode newnode = new DefaultMutableTreeNode();
        newnode.setAllowsChildren(true);
        FolderNode newFolder = new FolderNode(i+1, "Folder" + Integer.toString(i+1), "Jiajun", false);
        newnode.setUserObject(newFolder);
        root.add(newnode);
        if(i < 4){
            for(int j=0; j < 5; j++){
                DefaultMutableTreeNode newdocNode = new DefaultMutableTreeNode();
                newdocNode.setAllowsChildren(false);
                DocNode newDoc = new DocNode(10*(i+1) + j, "Document" + Integer.toString(10*(i+1)+j), "Jiajun");
                newdocNode.setUserObject(newDoc);
                newnode.add(newdocNode);
            }
        }
    }

推荐答案

要在我的评论中提供更多帮助,我在AbstractTreeClass中找到了以下代码,该代码将控制将其分配给节点的图像:

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();
        }
    }
}

因此,整个问题涉及isLeaf()方法返回什么的问题.我在DefaultMutableTreeNode类中找到了它:

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;
}

因此,似乎您的组合会将没有子级的所有元素都视为叶子而不是文件夹.也许您可以使用getAllowsChildren覆盖getNodeIcon方法,并进行必要的类型调整...

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...

另一个想法是覆盖DefaultMutableTreeNode的isLeaf()方法,但是如果在无法控制的地方调用它,则可能会遇到其他意外问题.

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...

这篇关于DefaultTreeModel和Wicket树:setAsksAllowsChildren不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆