2016-11-10 14 views
0

我的问题很短。 “如何使用此方法中使用的抽象方法或示例?”如何在zk框架中使用抽象方法TreeModel?

这种方法是从org.zkoss.zul.TreeModel

tmtAtasan = new TreeModel<Map<String,Object>>() { 

     @Override 
     public void addTreeDataListener(TreeDataListener arg0) { 
      // TODO Auto-generated method stub 
     } 
     @Override 
     public Map<String, Object> getChild(int[] arg0) { 
      // TODO Auto-generated method stub 
      return null; 
     } 
     @Override 
     public Map<String, Object> getChild(Map<String, Object> arg0, 
       int arg1) { 
      // TODO Auto-generated method stub 
      return null; 
     } 
     @Override 
     public int getChildCount(Map<String, Object> arg0) { 
      // TODO Auto-generated method stub 
      return 0; 
     } 
     @Override 
     public int getIndexOfChild(Map<String, Object> arg0, 
       Map<String, Object> arg1) { 
      // TODO Auto-generated method stub 
      return 0; 
     } 
     @Override 
     public int[] getPath(Map<String, Object> arg0) { 
      // TODO Auto-generated method stub 
      return null; 
     } 
     @Override 
     public Map<String, Object> getRoot() { 
      // TODO Auto-generated method stub 
      return null; 
     } 
     @Override 
     public boolean isLeaf(Map<String, Object> arg0) { 
      // TODO Auto-generated method stub 
      return false; 
     } 
     @Override 
     public void removeTreeDataListener(TreeDataListener arg0) { 
      // TODO Auto-generated method stub 

     } 
    }; 

我非常坚持这个。任何帮助将非常感激。 在此先感谢!

+0

https://www.zkoss.org/wiki/ZK_Developer's_Reference/MVC/Model/Tree_Model – flo

+0

你想做什么?如果您只是想使用基本TreeModel调用DefaultTreeModel构造函数。 – TheBakker

+0

我想用Tree,ArrayList中的数据创建Hierarchy员工数据。我不知道该怎么做。你能告诉我如何?或者类似的例子。感谢您回答^ _ ^ –

回答

0

好吧,据我所知你只是想使用一个通用的TreeModel而不需要重新定义特定的行为。

因此,让我们想象一下你的模型是员工豆子一样的列表:

public class Employee { 
    private String name; 
    private List<Employee> listSubordinates = new ArrayList<Employee>(); 

    public Employee(String pName) { 
     name = pName; 
    } 

    public void setName(String pName) { 
     this.name = pName; 
    } 
    public String getName() { 
     return name; 
    } 

    public List<Employee> getListSubordinates() { 
     return listSubordinates; 
    } 
    public void setListSubordinates(List<Employee> pListSubordinates) { 
     this.listSubordinates = pListSubordinates; 
    } 
} 

在这个例子中,我们会想象您检索由层次已经排序(简化的例子员工名单)。

Employee boss1 = new Employee("Boss1"); 
Employee sub1 = new Employee("Sub1"); 
boss1.getListSubordinates().add(sub1); 
Employee sub2 = new Employee("Sub2"); 
boss1.getListSubordinates().add(sub2); 

Employee boss2 = new Employee("Boss2"); 
Employee sub3 = new Employee("Sub3"); 
boss2.getListSubordinates().add(sub3); 

List<Employee> listBosses = Arrays.asList(boss1, boss2); 

再次,这是一个简单的例子只有一个层次结构的,如果你有层级的变量级别下面的代码必须是递归的。

// Build the list of the nodes sorted by hierarchy 
List<DefaultTreeNode<Employee>> firstLevelNodes = new ArrayList<DefaultTreeNode<Employee>>(); 
// For each employee of the highest level 
for (Employee boss : listBosses) { 
    // Build the list of its sub employee 
    List<DefaultTreeNode<Employee>> listSubordinates = new ArrayList<DefaultTreeNode<Employee>>(); 
    for (Employee subordinate : boss.getListSubordinates()) { 
     listSubordinates.add(new DefaultTreeNode<Employee>(subordinate)); 
    } 
    // Then build the boss node with its data and its children nodes 
    DefaultTreeNode<Employee> bossNode = new DefaultTreeNode<Employee>(boss, listSubordinates); 
    // And add it to the list of first level nodes 
    firstLevelNodes.add(bossNode); 
} 

// Build the ROOT, a 'technical' node containing the nodes of the tree. 
DefaultTreeNode<Employee> root = new DefaultTreeNode<Employee>(null, firstLevelNodes); 
// Create the TreeModel 
TreeModel treeModel = new DefaultTreeModel<Employee>(root); 

现在,您只需将TreeModel设置为您的Tree组件。

希望这会有所帮助。