2016-11-10 6 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からのデータにしたいと思っています。私はそれを作る方法を知らない。どうやって教えてくれますか?またはそれと同様の例です。答えてくれてありがとう^ _ ^ –

答えて

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

再びこれを使用すると、階層の可変レベルを持っていた場合は、次のコードは、再帰的でなければならないであろう、階層のちょうど1つのレベルの単純な例です。

// 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コンポーネントに設定するだけで済みます。

これが役に立ちます。

関連する問題