Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.wmts / org.gvsig.wmts.provider / src / main / java / org / gvsig / wmts / provider / tree / DefaultWMTSRootNode.java @ 8700

History | View | Annotate | Download (3.62 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2018 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.wmts.provider.tree;
24

    
25
import java.net.URL;
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.Enumeration;
29
import java.util.Iterator;
30
import java.util.List;
31

    
32
import javax.swing.tree.TreeNode;
33

    
34
import org.gvsig.fmap.dal.OpenDataStoreParameters;
35
import org.gvsig.raster.wmts.ogc.WMTSClient;
36
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer;
37
import org.gvsig.raster.wmts.ogc.struct.WMTSTheme;
38
import org.gvsig.raster.wmts.ogc.struct.WMTSThemes;
39
import org.gvsig.tools.ToolsLocator;
40

    
41

    
42
/**
43
 * @author fdiaz
44
 *
45
 */
46
public class DefaultWMTSRootNode extends AbstractWMTSNode implements WMTSRootNode {
47

    
48
    private List<WMTSNode> children;
49
    private WMTSThemes source;
50
    private URL service;
51

    
52
    /**
53
     * @param source
54
     * @param service
55
     * @param parent
56
     */
57
    public DefaultWMTSRootNode(WMTSThemes source, URL service) {
58
        super(null);
59
        this.source = source;
60
        this.service = service;
61
        children = new ArrayList<WMTSNode>();
62
        List<WMTSLayer> wmtsLayers = new ArrayList<WMTSLayer>();
63
        for (int i = 0; i < source.getChildCount(); i++) {
64
            WMTSTheme theme = source.getChildren(i);
65
            wmtsLayers.addAll(getLayers(theme));
66
        }
67
        for (Iterator iterator = wmtsLayers.iterator(); iterator.hasNext();) {
68
            WMTSLayer wmtsLayer = (WMTSLayer) iterator.next();
69
            children.add(new DefaultWMTSLayerNode(wmtsLayer, this, service));
70
        }
71
        this.title = ToolsLocator.getI18nManager().getTranslation("_base");
72
    }
73

    
74
    private List<WMTSLayer> getLayers(WMTSTheme theme){
75
        List<WMTSLayer> wmtsLayers = new ArrayList<WMTSLayer>();
76
        if(theme.getLayer()!=null){
77
            wmtsLayers.add(theme.getLayer());
78
        }
79
        for (int i = 0; i < theme.getChildCount(); i++) {
80
            wmtsLayers.addAll(getLayers(theme.getChildren(i)));
81
        }
82
        return wmtsLayers;
83
    }
84

    
85

    
86
    @Override
87
    public TreeNode getChildAt(int childIndex) {
88
        return children.get(childIndex);
89
    }
90

    
91
    @Override
92
    public int getChildCount() {
93
        return children.size();
94
    }
95

    
96
    @Override
97
    public int getIndex(TreeNode node) {
98
        return this.children.indexOf(node);
99
    }
100

    
101
    @Override
102
    public boolean getAllowsChildren() {
103
        return true;
104
    }
105

    
106
    @Override
107
    public boolean isLeaf() {
108
        return (this.children.size()<=0);
109
    }
110

    
111
    @Override
112
    public Enumeration children() {
113
        return Collections.enumeration(getChildren());
114
    }
115

    
116
    /**
117
     * @return the children
118
     */
119
    public List<WMTSNode> getChildren() {
120
        if (this.children == null) {
121
            this.children = new ArrayList<WMTSNode>();
122
        }
123
        return this.children;
124
    }
125
}