Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / attributesTree / AttributesTreeTable.java @ 8847

History | View | Annotate | Download (6.6 KB)

1
package com.iver.cit.gvsig.gui.panels.attributesTree;
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

    
12
import com.iver.cit.gvsig.gui.panels.WFSSelectAttributesPanel;
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: AttributesTreeTable.java 8847 2006-11-17 11:29:00Z ppiqueras $
57
 * $Log$
58
 * Revision 1.4.2.2  2006-11-17 11:28:45  ppiqueras
59
 * Corregidos bugs y a?adida nueva funcionalidad.
60
 *
61
 * Revision 1.5  2006/11/15 17:37:39  jorpiell
62
 * Se copia el padre
63
 *
64
 * Revision 1.4  2006/11/10 13:14:47  ppiqueras
65
 * Corregido un bug: caos que haya campos de una feature de una capa WFS, que no tengan tipo (tipo == null).
66
 *
67
 * Revision 1.3  2006/11/01 17:29:07  jorpiell
68
 * 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
69
 *
70
 * Revision 1.2  2006/10/31 09:39:44  jorpiell
71
 * Se devuelve el tipo de la entidad completo, y no sus hijos
72
 *
73
 * Revision 1.1  2006/10/27 11:33:19  jorpiell
74
 * A?adida la treetable con los check box para seleccionar los atributos
75
 *
76
 * Revision 1.3  2006/10/24 10:13:19  jorpiell
77
 * Se ha eliminado la pesta?a de filter
78
 *
79
 * Revision 1.2  2006/10/24 07:58:14  jorpiell
80
 * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
81
 *
82
 * Revision 1.1  2006/10/24 07:27:56  jorpiell
83
 * Algunos cambios en el modelo que usa la tabla
84
 *
85
 *
86
 */
87
/**
88
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
89
 */
90
public class AttributesTreeTable extends org.gvsig.gui.beans.swing.treeTable.TreeTable{
91
        Object[] attributes = null;
92
        WFSSelectAttributesPanel parent = null;
93
        
94
        public AttributesTreeTable(AttributesTreeTableModel treeTableModel) {
95
                super(treeTableModel);
96
                JTree tree = (JTree)getTree();
97
                tree.setCellRenderer(new CheckBoxTreeCellRenderer(this));
98
                tree.setCellEditor(new CheckBoxTreeCellEditor(this));
99
                tree.setEditable(true);                
100
        }
101
        
102
        public AttributesTreeTable(AttributesTreeTableModel treeTableModel,WFSSelectAttributesPanel parent) {
103
                super(treeTableModel);
104
                this.parent = parent;
105
                JTree tree = (JTree)getTree();
106
                tree.setCellRenderer(new CheckBoxTreeCellRenderer(this));
107
                tree.setCellEditor(new CheckBoxTreeCellEditor(this));
108
                tree.setEditable(true);
109
        }
110
        
111
        /**
112
         * Sets the attributes
113
         * @param attributes
114
         */
115
        public void setAttributes(Vector vAttributes){
116
                attributes = new Object[vAttributes.size()];
117
                for (int i=0 ; i<vAttributes.size() ; i++){
118
                        attributes[i] = vAttributes.get(i);
119
                }
120
                setModel(new AttributesTreeTableModel(attributes));
121
                deleteIcons();
122
                setRootVisible(false);
123
        }
124
        
125
        /**
126
         * Gets the selected layer
127
         * @return
128
         */
129
        public Object[] getSelectedValues(){
130
                int[] selectedRows = getSelectedRows();
131
                TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
132
                Object[] objects = new Object[selectedRows.length];
133
                for (int i=0 ; i<selectedRows.length ; i++){
134
                        objects[i] = obj.nodeForRow(selectedRows[i]);
135
                }
136
                return objects;
137
        }
138
        
139
        /**
140
         * return the selected elements
141
         * @return
142
         */
143
        public XMLElement[] getSelectedElements(){
144
                TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
145
                ArrayList elements = new ArrayList();
146
                for (int i=0 ; i< obj.getRowCount() ; i++){
147
                        if (obj.nodeForRow(i) instanceof CheckBoxNode){
148
                                CheckBoxNode node = (CheckBoxNode)obj.nodeForRow(i);
149
                                if (node.isSelected()){
150
                                        XMLElement element = node.getElement();
151
                                        CheckBoxNode parentNode = node.getParentNode();
152
                                        if (parentNode != null){
153
                                                element.setParentElement(parentNode.getElement());
154
                                        }
155
                                        elements.add(element);
156
                                }                                        
157
                        }
158
                }
159
        
160
        XMLElement[] selected = new XMLElement[elements.size()];
161
        for (int i=0 ; i<elements.size() ; i++){
162
                selected[i] = (XMLElement)elements.get(i);
163
        }
164
        return selected;
165
}
166

    
167
/**
168
 * Return all the attributes
169
 * @return
170
 */
171
public Object[] getAllValues() {
172
        return attributes;
173
}
174

    
175
/**
176
 * Return true if the node is queryable
177
 * @param node
178
 * @return
179
 */
180
public boolean isQueryable(Object node){
181
        for (int i=0 ; i<attributes.length ; i++){
182
                if (node.equals(attributes[i])){
183
                        return true;
184
                }
185
        }
186
        return false;
187
}
188

    
189
public void setModel(AttributesTreeTableModel treeTableModel){
190
        super.setModel(treeTableModel);
191
        JTree tree = (JTree)getTree();
192
        tree.setCellRenderer(new CheckBoxTreeCellRenderer(this));
193
        tree.setCellEditor(new CheckBoxTreeCellEditor(this));
194
        tree.setEditable(true);                
195
}
196

    
197
/**
198
 * Set the selected fields
199
 * @param selectedFields
200
 */
201
public void setSelectedFields(Vector selectedFields) {
202
        TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
203
        JTree tree = (JTree)getTree();
204
        for (int i = 0; i < tree.getRowCount(); i++) {
205
                tree.expandRow(i);
206
        }        
207
        for (int i=0 ; i<obj.getRowCount() ; i++){
208
                if (obj.nodeForRow(i) instanceof CheckBoxNode){
209
                        XMLElement element = ((CheckBoxNode)obj.nodeForRow(i)).getElement();
210
                        for (int j=0 ; j<selectedFields.size() ; j++){
211
                                //If the name is equals
212
                                if (((XMLElement)selectedFields.get(j)).getName().equals(element.getName())){
213
                                        //If the type is equals                                        
214
                                        if ( (element.getEntityType() != null) && (((XMLElement)selectedFields.get(j)).getEntityType() != null) && (((XMLElement)selectedFields.get(j)).getEntityType().getName().equals(element.getEntityType().getName())) ){
215
                                                ((CheckBoxNode)obj.nodeForRow(i)).setSelected(true);
216
                                        }
217
                                }
218
                        }
219
                }                        
220
        }
221
        
222
}
223

    
224
/**
225
 * @param updated The updated to set.
226
 */
227
public void setUpdated(boolean updated) {
228
        if (parent != null){
229
                parent.setUpdated(updated);
230
        }
231
}
232

    
233

    
234
}