source: SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/sparam2/CorpusTreeModel2.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: 3.0 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.sparam2;
7
8import java.util.Arrays;
9import org.zkoss.zul.DefaultTreeModel;
10import org.zkoss.zul.DefaultTreeNode;
11
12/**
13 *
14 * @author Yana Panchenko <yana_panchenko at yahoo.com>
15 */
16public class CorpusTreeModel2 extends DefaultTreeModel<Corpus2> { 
17   
18    DefaultTreeNode<Corpus2> root;
19   
20    public CorpusTreeModel2(DefaultTreeNode<Corpus2> treeNode) {
21        super(treeNode);
22        root = treeNode;
23    }
24   
25    /**
26     * remove the nodes which parent is <code>parent</code> with indexes
27     * <code>indexes</code>
28     *
29     * @param parent
30     *            The parent of nodes are removed
31     * @param indexFrom
32     *            the lower index of the change range
33     * @param indexTo
34     *            the upper index of the change range
35     * @throws IndexOutOfBoundsException
36     *             - indexFrom < 0 or indexTo > number of parent's children
37     */
38    public void remove(DefaultTreeNode<Corpus2> parent, int indexFrom, int indexTo) {
39        for (int i = indexTo; i >= indexFrom; i--) {
40           parent.getChildren().remove(i);
41        }
42    }
43   
44    /**
45     * remove the nodes which parent is <code>parent</code> with indexes
46     * <code>indexes</code>
47     *
48     * @param parent
49     *            The parent of nodes are removed
50     * @param indexFrom
51     *            the lower index of the change range
52     * @param indexTo
53     *            the upper index of the change range
54     * @throws IndexOutOfBoundsException
55     *             - indexFrom < 0 or indexTo > number of parent's children
56     */
57    public void remove(DefaultTreeNode<Corpus2> parent, int index) {
58        parent.getChildren().remove(index);
59    }
60   
61    /**
62     * insert new nodes which parent is <code>parent</code> with indexes
63     * <code>indexes</code> by new nodes <code>newNodes</code>
64     *
65     * @param parent
66     *            The parent of nodes are inserted
67     * @param indexFrom
68     *            the lower index of the change range
69     * @param indexTo
70     *            the upper index of the change range
71     * @param newNodes
72     *            New nodes which are inserted
73     * @throws IndexOutOfBoundsException
74     *             - indexFrom < 0 or indexTo > number of parent's children
75     */
76    public void insert(DefaultTreeNode<Corpus2> parent, int indexFrom, int indexTo, DefaultTreeNode<Corpus2>[] newNodes) {
77        for (int i = indexFrom; i <= indexTo; i++) {
78           parent.getChildren().add(i, newNodes[i - indexFrom]);
79        }
80    }
81   
82    /**
83     * append new nodes which parent is <code>parent</code> by new nodes
84     * <code>newNodes</code>
85     *
86     * @param parent
87     *            The parent of nodes are appended
88     * @param newNodes
89     *            New nodes which are appended
90     */
91    public void add(DefaultTreeNode<Corpus2> parent, DefaultTreeNode<Corpus2>[] newNodes) {
92        parent.getChildren().addAll(Arrays.asList(newNodes));
93    }
94}
Note: See TracBrowser for help on using the repository browser.