Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / addResource / ProjectInfoTreeModel.java @ 22616

History | View | Annotate | Download (3.69 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.gui.addResource;
42

    
43

    
44
import javax.swing.event.TreeModelListener;
45
import javax.swing.tree.TreeModel;
46
import javax.swing.tree.TreePath;
47

    
48
import org.gvsig.publish.PublishLogger;
49
import org.gvsig.publish.infoproject.ILayerInfo;
50
import org.gvsig.publish.infoproject.IProjectInfo;
51
import org.gvsig.publish.infoproject.IViewInfo;
52

    
53
/**
54
 * Class to represent the information about the project with a tree
55
 * 
56
 * @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
57
 *
58
 */
59
public class ProjectInfoTreeModel implements TreeModel {
60
        IProjectInfo project = null;
61
        
62
        public ProjectInfoTreeModel(IProjectInfo p){
63
                project = p;
64
        }
65
        
66
        public void addTreeModelListener(TreeModelListener l) {
67
                // TODO Auto-generated method stub
68

    
69
        }
70
        /**
71
         * Gets the childs count, if the parent is a projectinfo, at
72
         * the moment, it only has a child (viewinfo) 
73
         */
74
        public int getChildCount(Object parent) {
75
                if(parent instanceof IProjectInfo){
76
                        IProjectInfo project = (IProjectInfo)parent;
77
                        return project.getViewsInfo().length;
78
                }
79
                if (parent instanceof IViewInfo){
80
                        IViewInfo view = (IViewInfo) parent;
81
                        if (view.getLayers() == null){
82
                                return 0;
83
                        }else{
84
                                return view.getLayers().length;
85
                        }                        
86
                }
87
                if (parent instanceof ILayerInfo){
88
                        ILayerInfo layer =(ILayerInfo) parent;
89
                        if (layer.getChilds() == null){
90
                                return 0;
91
                        }else{
92
                                return layer.getChilds().length;
93
                        }
94
                }
95
                return 0;
96
        }
97

    
98
        public int getIndexOfChild(Object parent, Object child) {
99
                // TODO Auto-generated method stub
100
                return 0;
101
        }
102

    
103
        public Object getRoot() {
104
                return project;                
105
        }
106

    
107
        public boolean isLeaf(Object node) {
108
                if (node instanceof ILayerInfo){
109
                        ILayerInfo layer = (ILayerInfo)node;
110
                        if(layer.getChilds() == null){
111
                                return true;                
112
                        }
113
                }
114
                return false;
115
        }
116

    
117
        public void removeTreeModelListener(TreeModelListener l) {
118
                // TODO Auto-generated method stub
119

    
120
        }
121

    
122
        public void valueForPathChanged(TreePath path, Object newValue) {
123
                // TODO Auto-generated method stub
124

    
125
        }
126
        /**
127
         * Get the child of a projectinfo, viewinfo or layerinfo
128
         */
129
        public Object getChild(Object parent, int index) {
130
                if (parent instanceof IProjectInfo){
131
                        IProjectInfo p = (IProjectInfo)parent;
132
                        return p.getViewsInfo()[index];
133
                }
134
                if (parent instanceof IViewInfo){
135
                        IViewInfo v = (IViewInfo)parent;
136
                        return v.getLayers()[index];
137
                }
138
                if (parent instanceof ILayerInfo){
139
                        ILayerInfo l = (ILayerInfo)parent;
140
                        return l.getChilds()[index];
141
                }
142
                PublishLogger.getLog().error("ERROR ProjectInfoTreeModel: I'm going to return a null!!");
143
                return null;
144
        }
145

    
146
}