source: SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/sparam/CorpusTreeModel.java @ 2926

Last change on this file since 2926 was 2926, checked in by yana, 11 years ago

rebuilding the interface - initial version, still not functional!

File size: 1.4 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package eu.clarin.sru.fcs.aggregator.sparam;
7
8import eu.clarin.sru.fcs.aggregator.sparam.CorpusTreeNode;
9import org.zkoss.zul.AbstractTreeModel;
10import org.zkoss.zul.ext.TreeSelectableModel;
11
12/**
13 * TreeModel for CorpusTreeNode objects. Loads Institution and Endpoint nodes
14 * immediately. Loads Corpus child nodes only when the parent node (Endpoint or
15 * Corpus) is selected. I.e. if a user doesn't want to select a specific corpus,
16 * he doesn't have to wait till the whole tree is loaded.
17 *
18 * @author Yana Panchenko
19 */
20public class CorpusTreeModel extends AbstractTreeModel<CorpusTreeNode> implements TreeSelectableModel {
21 
22 
23    public CorpusTreeModel(CorpusTreeNode root) {
24        super(root);
25    }
26   
27    @Override
28    public CorpusTreeNode getChild(CorpusTreeNode parent, int index) {
29        if (!parent.hasChildrenLoaded()) {
30            parent.loadChildren();
31        }
32        if (index >= parent.getChildren().size()) {
33            return null;
34        } else {
35            return parent.getChildren().get(index);
36        }
37    }
38 
39    @Override
40    public int getChildCount(CorpusTreeNode parent) {
41        int count = 0;
42       
43        while (parent.getChild(count) != null) {
44            count++;
45        }
46        return count;
47    }
48 
49    @Override
50    public boolean isLeaf(CorpusTreeNode node) {
51        return (getChildCount(node) == 0);
52    }
53 
54}
Note: See TracBrowser for help on using the repository browser.