Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / fieldstree / FieldsTreeTableModel.java @ 27077

History | View | Annotate | Download (7.85 KB)

1
package com.iver.cit.gvsig.gui.panels.fieldstree;
2

    
3
import java.util.Vector;
4

    
5
import org.gvsig.gui.beans.swing.treeTable.AbstractTreeTableModel;
6
import org.gvsig.gui.beans.swing.treeTable.TreeTableModel;
7
import org.gvsig.remoteClient.gml.schemas.XMLElement;
8
import org.gvsig.remoteClient.gml.types.IXMLType;
9
import org.gvsig.remoteClient.gml.types.XMLComplexType;
10

    
11
import com.iver.andami.PluginServices;
12
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSUtils;
13

    
14
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
15
 *
16
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
17
 *
18
 * This program is free software; you can redistribute it and/or
19
 * modify it under the terms of the GNU General Public License
20
 * as published by the Free Software Foundation; either version 2
21
 * of the License, or (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
31
 *
32
 * For more information, contact:
33
 *
34
 *  Generalitat Valenciana
35
 *   Conselleria d'Infraestructures i Transport
36
 *   Av. Blasco Ib??ez, 50
37
 *   46010 VALENCIA
38
 *   SPAIN
39
 *
40
 *      +34 963862235
41
 *   gvsig@gva.es
42
 *      www.gvsig.gva.es
43
 *
44
 *    or
45
 *
46
 *   IVER T.I. S.A
47
 *   Salamanca 50
48
 *   46005 Valencia
49
 *   Spain
50
 *
51
 *   +34 963163400
52
 *   dac@iver.es
53
 */
54
/* CVS MESSAGES:
55
 *
56
 * $Id$
57
 * $Log$
58
 * Revision 1.3  2007-01-23 13:11:04  ppiqueras
59
 * Cambios sin importancia.
60
 *
61
 * Revision 1.2  2006/12/26 10:25:37  ppiqueras
62
 * Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
63
 *
64
 * Revision 1.1  2006/12/26 09:12:48  ppiqueras
65
 * Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2). (En este caso se ha cambiado el nombre del paquete aparte de alguno otro nombre que puede haber cambiado).
66
 *
67
 * Revision 1.7  2006/12/14 12:29:58  ppiqueras
68
 * A?adido m?todo para obtener todas las hojas del ?rbol
69
 *
70
 * Revision 1.6  2006/11/10 13:14:47  ppiqueras
71
 * Corregido un bug: caos que haya campos de una feature de una capa WFS, que no tengan tipo (tipo == null).
72
 *
73
 * Revision 1.5  2006/11/10 09:04:33  ppiqueras
74
 * La geometr?a no se visualiza en el ?rbol del panel de filtro, pero s? en el de atributos
75
 *
76
 * Revision 1.4  2006/11/01 17:29:07  jorpiell
77
 * Se ha elimiado el nodo virtual de la raiz. Adem?s ya se cargan los valores de un campo complejo en la pesta?a del filtro
78
 *
79
 * Revision 1.3  2006/10/31 13:51:15  ppiqueras
80
 * Soporte parent Element
81
 *
82
 * Revision 1.2  2006/10/31 12:24:04  jorpiell
83
 * Comprobado el caso en el que los atributos no tienen tipo
84
 *
85
 * Revision 1.1  2006/10/27 11:33:19  jorpiell
86
 * A?adida la treetable con los check box para seleccionar los atributos
87
 *
88
 * Revision 1.2  2006/10/24 07:58:14  jorpiell
89
 * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
90
 *
91
 * Revision 1.1  2006/10/24 07:27:56  jorpiell
92
 * Algunos cambios en el modelo que usa la tabla
93
 *
94
 * Revision 1.2  2006/10/23 08:17:18  jorpiell
95
 * Algunos cambios realizados para tener un ?rbol com m?s de una ra?z
96
 *
97
 * Revision 1.1  2006/10/23 07:37:04  jorpiell
98
 * Ya funciona el filterEncoding
99
 *
100
 *
101
 */
102
/**
103
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
104
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
105
 */
106
public class FieldsTreeTableModel extends AbstractTreeTableModel {
107
        private boolean showGeometry;        
108
        private String[]  cNames = {PluginServices.getText(this,"attributeName"),
109
                        PluginServices.getText(this,"attributeType")};
110
        private Class[]  cTypes = {TreeTableModel.class,String.class};
111
                        
112
        public FieldsTreeTableModel(Object root) { 
113
                super(root);
114
                showGeometry = true;
115
        }
116
        
117
        public FieldsTreeTableModel(Object root, boolean show_Geometry) { 
118
                super(root);
119
                showGeometry = show_Geometry;
120
        }
121
        
122
        public FieldsTreeTableModel() { 
123
                super(null);
124
                showGeometry = true;
125
        }
126
        
127
        public boolean getShowGeometry() {
128
                return showGeometry;
129
        }
130
        
131
        //
132
        // The TreeModel interface
133
        //
134
        
135
        public int getChildCount(Object node) { 
136
                XMLElement element = (XMLElement)node;                        
137
                if (element.getEntityType().getType() == IXMLType.COMPLEX){
138

    
139
                        // It's supposed that geometry is on level 1
140
                        Vector fields = ((XMLComplexType)element.getEntityType()).getAttributes();
141
                        int size = fields.size();
142
                        
143
                        if (!showGeometry) {
144
                                for (int i = 0; i < fields.size(); i++) {
145
                                        if ((((XMLElement)fields.get(i)).getEntityType() == null) || (((XMLElement)fields.get(i)).getEntityType().getType() == IXMLType.GML_GEOMETRY))
146
                                                size --;
147
                                }
148
                        }
149
                        
150
                        return size;
151
                }else{
152
                        return 0;
153
                }
154
        }
155
        
156
        public Object getChild(Object node, int i) { 
157
                XMLElement element = (XMLElement)node;                        
158
                if (element.getEntityType().getType() == IXMLType.COMPLEX){
159
                        Vector fields = ((XMLComplexType)element.getEntityType()).getAttributes();
160
                        XMLElement child = null;
161
                        int k = -1;
162
                        
163
                        if (!showGeometry) {
164
                                for (int j = 0; j < fields.size(); j++) {
165
                                        child = (XMLElement) fields.get(j);
166

    
167
                                        if ((child.getEntityType() == null) || (child.getEntityType().getType() != IXMLType.GML_GEOMETRY))
168
                                                k++;                                        
169
                                        
170
                                        if (i == k)
171
                                                break;
172
                                }        
173
                        }
174
                        else {
175
                                child = (XMLElement) fields.get(i);
176
                        }
177
                        
178
                        child.setParentElement(element);
179
                        
180
                        return child;
181
                }
182
                return null;
183
        }
184
        
185
        // The superclass's implementation would work, but this is more efficient. 
186
        public boolean isLeaf(Object node) { 
187
                if (node == null){
188
                        return true;
189
                }
190
                XMLElement element = (XMLElement)node;        
191
                if (element.getEntityType() != null){
192
                        if (element.getEntityType().getType() == IXMLType.COMPLEX){
193
                                return false;
194
                        }
195
                }
196
                return true;
197
        }
198

    
199
        /*
200
         *  (non-Javadoc)
201
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnCount()
202
         */
203
        public int getColumnCount() {
204
                return cNames.length;
205
        }
206
        
207
        /*
208
         *  (non-Javadoc)
209
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnName(int)
210
         */
211
        public String getColumnName(int column) {
212
                return cNames[column];
213
        }
214
        
215
        /*
216
         *  (non-Javadoc)
217
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnClass(int)
218
         */
219
        public Class getColumnClass(int column) {
220
                return cTypes[column];
221
        }
222
        
223
        /*
224
         *  (non-Javadoc)
225
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getValueAt(java.lang.Object, int)
226
         */
227
        public Object getValueAt(Object node, int column) {
228
                XMLElement element = (XMLElement)node;        
229
                try {
230
                        switch(column) {
231
                        case 0:
232
                                return element.getName();
233
                        case 1:
234
                                return PluginServices.getText(this,WFSUtils.getFieldType(element.getEntityType()));
235
                        }
236
                }
237
                catch  (SecurityException se) { }
238
                
239
                return null; 
240
        }
241
        
242
        /**
243
         * Returns leafs from a node branch
244
         * 
245
         * @param node A node in this tree model
246
         * @return A vector with leafs
247
         */
248
        public Vector<Object> getLeafsFromNodeBranch(Object node) {
249
                Vector<Object> leafs = new Vector<Object>();
250
                Object parent;
251
                
252
                if (this.isLeaf(node))
253
                        leafs.add( ((XMLElement)node).getName() );
254
                else {
255
                        int childrenCount = this.getChildCount(node);
256
                        parent = node;
257
                        
258
                        for (int i = 0; i < childrenCount; i ++) {
259
                                node = this.getChild(parent, i);
260
                                
261
                                if ( (this.isLeaf(node)) && (! leafs.contains(node)) )
262
                                        leafs.add(node);
263
                                else
264
                                        leafs.addAll(getLeafsFromNodeBranch(node));
265
                        }
266
                }
267
                
268
                return leafs;
269
        }
270
}