root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / fieldsTree / FieldsTreeTableModel.java @ 9461
History | View | Annotate | Download (7.43 KB)
1 | 9457 | ppiqueras | 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 | 9461 | ppiqueras | import org.gvsig.remoteClient.gml.types.IXMLType; |
9 | import org.gvsig.remoteClient.gml.types.XMLComplexType; |
||
10 | 9457 | ppiqueras | |
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 | 9461 | ppiqueras | * Revision 1.2 2006-12-26 10:25:37 ppiqueras
|
59 | * Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
|
||
60 | *
|
||
61 | * Revision 1.1 2006/12/26 09:12:48 ppiqueras
|
||
62 | 9457 | ppiqueras | * 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).
|
63 | *
|
||
64 | * Revision 1.7 2006/12/14 12:29:58 ppiqueras
|
||
65 | * A?adido m?todo para obtener todas las hojas del ?rbol
|
||
66 | *
|
||
67 | * Revision 1.6 2006/11/10 13:14:47 ppiqueras
|
||
68 | * Corregido un bug: caos que haya campos de una feature de una capa WFS, que no tengan tipo (tipo == null).
|
||
69 | *
|
||
70 | * Revision 1.5 2006/11/10 09:04:33 ppiqueras
|
||
71 | * La geometr?a no se visualiza en el ?rbol del panel de filtro, pero s? en el de atributos
|
||
72 | *
|
||
73 | * Revision 1.4 2006/11/01 17:29:07 jorpiell
|
||
74 | * 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
|
||
75 | *
|
||
76 | * Revision 1.3 2006/10/31 13:51:15 ppiqueras
|
||
77 | * Soporte parent Element
|
||
78 | *
|
||
79 | * Revision 1.2 2006/10/31 12:24:04 jorpiell
|
||
80 | * Comprobado el caso en el que los atributos no tienen tipo
|
||
81 | *
|
||
82 | * Revision 1.1 2006/10/27 11:33:19 jorpiell
|
||
83 | * A?adida la treetable con los check box para seleccionar los atributos
|
||
84 | *
|
||
85 | * Revision 1.2 2006/10/24 07:58:14 jorpiell
|
||
86 | * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
|
||
87 | *
|
||
88 | * Revision 1.1 2006/10/24 07:27:56 jorpiell
|
||
89 | * Algunos cambios en el modelo que usa la tabla
|
||
90 | *
|
||
91 | * Revision 1.2 2006/10/23 08:17:18 jorpiell
|
||
92 | * Algunos cambios realizados para tener un ?rbol com m?s de una ra?z
|
||
93 | *
|
||
94 | * Revision 1.1 2006/10/23 07:37:04 jorpiell
|
||
95 | * Ya funciona el filterEncoding
|
||
96 | *
|
||
97 | *
|
||
98 | */
|
||
99 | /**
|
||
100 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
101 | */
|
||
102 | public class FieldsTreeTableModel extends AbstractTreeTableModel { |
||
103 | private boolean showGeometry; |
||
104 | private String[] cNames = {PluginServices.getText(this,"attributeName"), |
||
105 | PluginServices.getText(this,"attributeType")}; |
||
106 | private Class[] cTypes = {TreeTableModel.class,String.class}; |
||
107 | |||
108 | public FieldsTreeTableModel(Object root) { |
||
109 | super(root);
|
||
110 | showGeometry = true;
|
||
111 | } |
||
112 | |||
113 | public FieldsTreeTableModel(Object root, boolean show_Geometry) { |
||
114 | super(root);
|
||
115 | showGeometry = show_Geometry; |
||
116 | } |
||
117 | |||
118 | public FieldsTreeTableModel() {
|
||
119 | super(null); |
||
120 | showGeometry = true;
|
||
121 | } |
||
122 | |||
123 | public boolean getShowGeometry() { |
||
124 | return showGeometry;
|
||
125 | } |
||
126 | |||
127 | //
|
||
128 | // The TreeModel interface
|
||
129 | //
|
||
130 | |||
131 | public int getChildCount(Object node) { |
||
132 | XMLElement element = (XMLElement)node; |
||
133 | if (element.getEntityType().getType() == IXMLType.COMPLEX){
|
||
134 | |||
135 | // It's supposed that geometry is on level 1
|
||
136 | Vector fields = ((XMLComplexType)element.getEntityType()).getAttributes();
|
||
137 | int size = fields.size();
|
||
138 | |||
139 | if (!showGeometry) {
|
||
140 | for (int i = 0; i < fields.size(); i++) { |
||
141 | if ((((XMLElement)fields.get(i)).getEntityType() == null) || (((XMLElement)fields.get(i)).getEntityType().getType() == IXMLType.GML_GEOMETRY)) |
||
142 | size --; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | return size;
|
||
147 | }else{
|
||
148 | return 0; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | public Object getChild(Object node, int i) { |
||
153 | XMLElement element = (XMLElement)node; |
||
154 | if (element.getEntityType().getType() == IXMLType.COMPLEX){
|
||
155 | Vector fields = ((XMLComplexType)element.getEntityType()).getAttributes();
|
||
156 | XMLElement child = null;
|
||
157 | int k = -1; |
||
158 | |||
159 | if (!showGeometry) {
|
||
160 | for (int j = 0; j < fields.size(); j++) { |
||
161 | child = (XMLElement) fields.get(j); |
||
162 | |||
163 | if ((child.getEntityType() == null) || (child.getEntityType().getType() != IXMLType.GML_GEOMETRY)) |
||
164 | k++; |
||
165 | |||
166 | if (i == k)
|
||
167 | break;
|
||
168 | } |
||
169 | } |
||
170 | else {
|
||
171 | child = (XMLElement) fields.get(i); |
||
172 | } |
||
173 | |||
174 | child.setParentElement(element); |
||
175 | |||
176 | return child;
|
||
177 | } |
||
178 | return null; |
||
179 | } |
||
180 | |||
181 | // The superclass's implementation would work, but this is more efficient.
|
||
182 | public boolean isLeaf(Object node) { |
||
183 | if (node == null){ |
||
184 | return true; |
||
185 | } |
||
186 | XMLElement element = (XMLElement)node; |
||
187 | if (element.getEntityType() != null){ |
||
188 | if (element.getEntityType().getType() == IXMLType.COMPLEX){
|
||
189 | return false; |
||
190 | } |
||
191 | } |
||
192 | return true; |
||
193 | } |
||
194 | |||
195 | /*
|
||
196 | * (non-Javadoc)
|
||
197 | * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnCount()
|
||
198 | */
|
||
199 | public int getColumnCount() { |
||
200 | return cNames.length;
|
||
201 | } |
||
202 | |||
203 | /*
|
||
204 | * (non-Javadoc)
|
||
205 | * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnName(int)
|
||
206 | */
|
||
207 | public String getColumnName(int column) { |
||
208 | return cNames[column];
|
||
209 | } |
||
210 | |||
211 | /*
|
||
212 | * (non-Javadoc)
|
||
213 | * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnClass(int)
|
||
214 | */
|
||
215 | public Class getColumnClass(int column) { |
||
216 | return cTypes[column];
|
||
217 | } |
||
218 | |||
219 | /*
|
||
220 | * (non-Javadoc)
|
||
221 | * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getValueAt(java.lang.Object, int)
|
||
222 | */
|
||
223 | public Object getValueAt(Object node, int column) { |
||
224 | XMLElement element = (XMLElement)node; |
||
225 | try {
|
||
226 | switch(column) {
|
||
227 | case 0: |
||
228 | return element.getName();
|
||
229 | case 1: |
||
230 | return PluginServices.getText(this,WFSUtils.getFieldType(element.getEntityType())); |
||
231 | } |
||
232 | } |
||
233 | catch (SecurityException se) { } |
||
234 | |||
235 | return null; |
||
236 | } |
||
237 | |||
238 | /**
|
||
239 | * Returns leafs from a node branch
|
||
240 | *
|
||
241 | * @param node A node in this tree model
|
||
242 | * @return A vector with leafs
|
||
243 | */
|
||
244 | public Vector getLeafsFromNodeBranch(Object node) { |
||
245 | Vector leafs = new Vector(); |
||
246 | Object parent;
|
||
247 | |||
248 | if (this.isLeaf(node)) |
||
249 | leafs.add( ((XMLElement)node).getName() ); |
||
250 | else {
|
||
251 | int childrenCount = this.getChildCount(node); |
||
252 | parent = node; |
||
253 | |||
254 | for (int i = 0; i < childrenCount; i ++) { |
||
255 | node = this.getChild(parent, i);
|
||
256 | |||
257 | if ( (this.isLeaf(node)) && (! leafs.contains(node)) ) |
||
258 | leafs.add(node); |
||
259 | else
|
||
260 | leafs.addAll(getLeafsFromNodeBranch(node)); |
||
261 | } |
||
262 | } |
||
263 | |||
264 | return leafs;
|
||
265 | } |
||
266 | } |
||
267 |