繁体   English   中英

如何将Swing TreeNode转换为Apache Tobago TreePath?

[英]How to convert Swing TreeNode to Apache Tobago TreePath?

我有一个Swing TreeNode(DefaultMutableTreeNode),并且必须为每个Swing TreeNode生成一个Apache Tobago TreePath:

秋千树:

Root
    Node1
        Child11
        Child12
        Child13
    Node2
        Child21
        Child22
        Child23
    Node3
        Child31
        Child32
        Child33

Apache Tobago TreePath:

[]
    [0]
        [0,0]
        [0,1]
        [0,2]
    [1]
        [1,0]
        [1,1]
        [1,2]
    [2]
        [2,0]
        [2,1]
        [2,2]

例:

  Input:  Child11
  Output: [0,1]

任何建议将不胜感激。

在此先感谢托马斯

例如这样的事情:

public static org.apache.myfaces.tobago.model.TreePath convertPath(TreeNode node) {
    List<Integer> list = new ArrayList<>();
    TreeNode current = node;
    while (current.getParent() != null) {
        list.add(0, current.getParent().getIndex(current));
        current = current.getParent();
    }
    return new org.apache.myfaces.tobago.model.TreePath(list);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM