Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.app / org.gvsig.raster.wcs.app.wcsclient / src / main / java / org / gvsig / raster / wcs / app / wcsclient / gui / wizard / LayerTreeModel.java @ 418

History | View | Annotate | Download (4.22 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wcs.app.wcsclient.gui.wizard;
24

    
25
import java.util.ArrayList;
26
import java.util.Vector;
27

    
28
import javax.swing.event.TreeModelListener;
29
import javax.swing.tree.TreeModel;
30
import javax.swing.tree.TreePath;
31

    
32
import org.gvsig.fmap.dal.coverage.store.remote.RemoteWMSLayerNode;
33

    
34

    
35

    
36
public class LayerTreeModel implements TreeModel {
37

    
38
        RemoteWMSLayerNode root;
39

    
40
        public LayerTreeModel(RemoteWMSLayerNode root){
41
                this.root = root;
42
        }
43

    
44
        public Object getRoot() {
45
                return root;
46
        }
47

    
48
        public int getChildCount(Object parent) {
49
                return ((RemoteWMSLayerNode)parent).getChildren().size();
50
        }
51

    
52
    public boolean isLeaf(Object node) {
53
                return ((RemoteWMSLayerNode)node).getChildren().size() == 0;
54
        }
55

    
56
        public void addTreeModelListener(TreeModelListener l) {
57
        }
58

    
59
        public void removeTreeModelListener(TreeModelListener l) {
60
        }
61

    
62
        public Object getChild(Object parent, int index) {
63
                return (RemoteWMSLayerNode)((RemoteWMSLayerNode)parent).getChildren().get(index);
64
        }
65

    
66
        public int getIndexOfChild(Object parent, Object child) {
67
        RemoteWMSLayerNode pare = (RemoteWMSLayerNode) parent;
68
                for (int i = 0; i < pare.getChildren().size(); i++)
69
                        if (child == pare.getChildren().get(i)) return i;
70
                return -1;
71
        }
72

    
73
        public void valueForPathChanged(TreePath path, Object newValue) {
74
        }
75

    
76
    /**
77
     * @param node, the tree's desired node.
78
     * @return Returns the name of the node.
79
     */
80
    public String getName(Object node) {
81
        return ((RemoteWMSLayerNode) node).getName();
82
    }
83
    
84
    /**
85
     * @param node, the tree's desired node.
86
     * @return Returns the namedStyles.
87
     */
88
    public ArrayList getStyles(Object node) {
89
        return ((RemoteWMSLayerNode) node).getStyles();
90
    }
91
    /**
92
     * @param node, the tree's desired node.
93
     * @return Returns the queryable.
94
     */
95
    public boolean isQueryable(Object node) {
96
        return ((RemoteWMSLayerNode) node).isQueryable();
97
    }
98
    
99
    /**
100
     * @param node, the tree's desired node.
101
     * @return Returns the srs.
102
     */
103
    public Vector getSrs(Object node) {
104
        return ((RemoteWMSLayerNode) node).getAllSrs();
105
    }
106
    /**
107
     * @param node, the tree's desired node.
108
     * @return Returns the title.
109
     */
110
    public String getTitle(Object node) {
111
        return ((RemoteWMSLayerNode) node).getTitle();
112
    }
113
    /**
114
     * @param node, the tree's desired node.
115
     * @return Returns the transparency.
116
     */
117
    public boolean hasTransparency(Object node) {
118
        return ((RemoteWMSLayerNode) node).isTransparent();
119
    }
120
    
121
    public String toString(){
122
        return getTitle(this);
123
    }
124
    
125
    /**
126
     * Searches in the tree for the first (and must be the unique) RemoteLayerNode with
127
     * the name specified by name.
128
     * @param name
129
     * @return
130
     */
131
    public Object getNodeByName(String name) {
132
            return getNodeByName(root, name);
133
    }
134
    
135
    /**
136
     * Service method.
137
     * @param node
138
     * @param name
139
     * @return
140
     */
141
    private Object getNodeByName(RemoteWMSLayerNode node, String name) {
142
            RemoteWMSLayerNode n = node;
143
            if (n.getName()!= null && n.getName().equals(name)) {
144
                    return n;
145
            } else {
146
                    for (int i = 0; i < getChildCount(n); i++) {
147
                            RemoteWMSLayerNode n1 = (RemoteWMSLayerNode) n.getChildren().get(i);
148
                            Object obj = getNodeByName(n1, name);
149
                            if (obj!= null)
150
                                    return obj;
151
                        }
152
            }
153
            return null;
154
    }
155
}