root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / fieldsTree / FieldsTreeTable.java @ 10778
History | View | Annotate | Download (7.23 KB)
1 |
package com.iver.cit.gvsig.gui.panels.fieldsTree; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Vector; |
5 |
|
6 |
import javax.swing.JTree; |
7 |
import javax.swing.tree.TreePath; |
8 |
|
9 |
import org.gvsig.gui.beans.swing.treeTable.TreeTableModelAdapter; |
10 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
11 |
import org.gvsig.remoteClient.gml.types.IXMLType; |
12 |
|
13 |
import com.iver.cit.gvsig.gui.panels.WFSSelectFieldsPanel; |
14 |
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
16 |
*
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
21 |
* as published by the Free Software Foundation; either version 2
|
22 |
* of the License, or (at your option) any later version.
|
23 |
*
|
24 |
* This program is distributed in the hope that it will be useful,
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27 |
* GNU General Public License for more details.
|
28 |
*
|
29 |
* You should have received a copy of the GNU General Public License
|
30 |
* along with this program; if not, write to the Free Software
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
32 |
*
|
33 |
* For more information, contact:
|
34 |
*
|
35 |
* Generalitat Valenciana
|
36 |
* Conselleria d'Infraestructures i Transport
|
37 |
* Av. Blasco Ib??ez, 50
|
38 |
* 46010 VALENCIA
|
39 |
* SPAIN
|
40 |
*
|
41 |
* +34 963862235
|
42 |
* gvsig@gva.es
|
43 |
* www.gvsig.gva.es
|
44 |
*
|
45 |
* or
|
46 |
*
|
47 |
* IVER T.I. S.A
|
48 |
* Salamanca 50
|
49 |
* 46005 Valencia
|
50 |
* Spain
|
51 |
*
|
52 |
* +34 963163400
|
53 |
* dac@iver.es
|
54 |
*/
|
55 |
/* CVS MESSAGES:
|
56 |
*
|
57 |
* $Id$
|
58 |
* $Log$
|
59 |
* Revision 1.3 2007-03-15 13:35:47 ppiqueras
|
60 |
* Corregido bug: lanzaba una excepci?n en el m?todo de b?squeda de campo geometr?a cuando el nodo era null.
|
61 |
*
|
62 |
* Revision 1.2 2007/02/19 11:44:42 jorpiell
|
63 |
* A?adidos los filtros por ?rea
|
64 |
*
|
65 |
* Revision 1.1 2006/12/26 09:12:48 ppiqueras
|
66 |
* 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).
|
67 |
*
|
68 |
* Revision 1.5 2006/11/15 17:37:39 jorpiell
|
69 |
* Se copia el padre
|
70 |
*
|
71 |
* Revision 1.4 2006/11/10 13:14:47 ppiqueras
|
72 |
* Corregido un bug: caos que haya campos de una feature de una capa WFS, que no tengan tipo (tipo == null).
|
73 |
*
|
74 |
* Revision 1.3 2006/11/01 17:29:07 jorpiell
|
75 |
* 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
|
76 |
*
|
77 |
* Revision 1.2 2006/10/31 09:39:44 jorpiell
|
78 |
* Se devuelve el tipo de la entidad completo, y no sus hijos
|
79 |
*
|
80 |
* Revision 1.1 2006/10/27 11:33:19 jorpiell
|
81 |
* A?adida la treetable con los check box para seleccionar los atributos
|
82 |
*
|
83 |
* Revision 1.3 2006/10/24 10:13:19 jorpiell
|
84 |
* Se ha eliminado la pesta?a de filter
|
85 |
*
|
86 |
* Revision 1.2 2006/10/24 07:58:14 jorpiell
|
87 |
* Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
|
88 |
*
|
89 |
* Revision 1.1 2006/10/24 07:27:56 jorpiell
|
90 |
* Algunos cambios en el modelo que usa la tabla
|
91 |
*
|
92 |
*
|
93 |
*/
|
94 |
/**
|
95 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
96 |
*/
|
97 |
public class FieldsTreeTable extends org.gvsig.gui.beans.swing.treeTable.TreeTable{ |
98 |
WFSSelectFieldsPanel parent = null;
|
99 |
|
100 |
public FieldsTreeTable(FieldsTreeTableModel treeTableModel) {
|
101 |
super(treeTableModel);
|
102 |
JTree tree = (JTree)getTree(); |
103 |
tree.setCellRenderer(new CheckBoxTreeCellRenderer(this)); |
104 |
tree.setCellEditor(new CheckBoxTreeCellEditor(this)); |
105 |
tree.setEditable(true);
|
106 |
} |
107 |
|
108 |
public FieldsTreeTable(FieldsTreeTableModel treeTableModel,WFSSelectFieldsPanel parent) {
|
109 |
super(treeTableModel);
|
110 |
this.parent = parent;
|
111 |
JTree tree = (JTree)getTree(); |
112 |
tree.setCellRenderer(new CheckBoxTreeCellRenderer(this)); |
113 |
tree.setCellEditor(new CheckBoxTreeCellEditor(this)); |
114 |
tree.setEditable(true);
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Sets the fields
|
119 |
* @param fields
|
120 |
*/
|
121 |
public void setFields(Vector vFields){ |
122 |
Object[] fields = new Object[vFields.size()]; |
123 |
for (int i=0 ; i<vFields.size() ; i++){ |
124 |
fields[i] = vFields.get(i); |
125 |
} |
126 |
setModel(new FieldsTreeTableModel(fields));
|
127 |
deleteIcons(); |
128 |
setRootVisible(false);
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Gets the selected layer
|
133 |
* @return
|
134 |
*/
|
135 |
public Object[] getSelectedValues(){ |
136 |
int[] selectedRows = getSelectedRows(); |
137 |
TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel(); |
138 |
Object[] objects = new Object[selectedRows.length]; |
139 |
for (int i=0 ; i<selectedRows.length ; i++){ |
140 |
objects[i] = obj.nodeForRow(selectedRows[i]); |
141 |
} |
142 |
return objects;
|
143 |
} |
144 |
|
145 |
|
146 |
|
147 |
/**
|
148 |
* return the selected elements
|
149 |
* @return
|
150 |
*/
|
151 |
public XMLElement[] getSelectedElements(){ |
152 |
TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel(); |
153 |
ArrayList elements = new ArrayList(); |
154 |
for (int i=0 ; i< obj.getRowCount() ; i++){ |
155 |
if (obj.nodeForRow(i) instanceof CheckBoxNode){ |
156 |
CheckBoxNode node = (CheckBoxNode)obj.nodeForRow(i); |
157 |
if (node.isSelected()){
|
158 |
XMLElement element = node.getElement(); |
159 |
CheckBoxNode parentNode = node.getParentNode(); |
160 |
if (parentNode != null){ |
161 |
element.setParentElement(parentNode.getElement()); |
162 |
} |
163 |
elements.add(element); |
164 |
} |
165 |
} |
166 |
} |
167 |
|
168 |
XMLElement[] selected = new XMLElement[elements.size()]; |
169 |
for (int i=0 ; i<elements.size() ; i++){ |
170 |
selected[i] = (XMLElement)elements.get(i); |
171 |
} |
172 |
return selected;
|
173 |
} |
174 |
|
175 |
|
176 |
public void setModel(FieldsTreeTableModel treeTableModel){ |
177 |
super.setModel(treeTableModel);
|
178 |
JTree tree = (JTree)getTree(); |
179 |
tree.setCellRenderer(new CheckBoxTreeCellRenderer(this)); |
180 |
tree.setCellEditor(new CheckBoxTreeCellEditor(this)); |
181 |
tree.setEditable(true);
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Gets the geometry field
|
186 |
* @return
|
187 |
*/
|
188 |
public String getGeometryField(){ |
189 |
TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel(); |
190 |
ArrayList elements = new ArrayList(); |
191 |
for (int i=0 ; i< obj.getRowCount() ; i++){ |
192 |
if (obj.nodeForRow(i) instanceof CheckBoxNode){ |
193 |
CheckBoxNode node = (CheckBoxNode)obj.nodeForRow(i); |
194 |
XMLElement element = node.getElement(); |
195 |
if (element.getEntityType() != null) { |
196 |
if (element.getEntityType().getType() == IXMLType.GML_GEOMETRY){
|
197 |
return element.getName();
|
198 |
} |
199 |
} |
200 |
} |
201 |
} |
202 |
return null; |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Set the selected fields
|
207 |
* @param selectedFields
|
208 |
*/
|
209 |
public void setSelectedFields(Vector selectedFields) { |
210 |
TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel(); |
211 |
JTree tree = (JTree)getTree(); |
212 |
for (int i = 0; i < tree.getRowCount(); i++) { |
213 |
tree.expandRow(i); |
214 |
} |
215 |
for (int i=0 ; i<obj.getRowCount() ; i++){ |
216 |
if (obj.nodeForRow(i) instanceof CheckBoxNode){ |
217 |
XMLElement element = ((CheckBoxNode)obj.nodeForRow(i)).getElement(); |
218 |
for (int j=0 ; j<selectedFields.size() ; j++){ |
219 |
//If the name is equals
|
220 |
if (((XMLElement)selectedFields.get(j)).getName().equals(element.getName())){
|
221 |
//If the type is equals
|
222 |
if ( (element.getEntityType() != null) && (((XMLElement)selectedFields.get(j)).getEntityType() != null) && (((XMLElement)selectedFields.get(j)).getEntityType().getName().equals(element.getEntityType().getName())) ){ |
223 |
((CheckBoxNode)obj.nodeForRow(i)).setSelected(true);
|
224 |
} |
225 |
} |
226 |
} |
227 |
} |
228 |
} |
229 |
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* @param updated The updated to set.
|
234 |
*/
|
235 |
public void setUpdated(boolean updated) { |
236 |
if (parent != null){ |
237 |
parent.setUpdated(updated); |
238 |
} |
239 |
} |
240 |
|
241 |
|
242 |
} |