Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / fieldstree / FieldsTreeTable.java @ 34026

History | View | Annotate | Download (7.94 KB)

1
package org.gvsig.wfs.gui.panels.fieldstree;
2

    
3
import java.util.ArrayList;
4
import java.util.Vector;
5

    
6
import javax.swing.JToolTip;
7
import javax.swing.JTree;
8

    
9
import org.gvsig.gui.beans.controls.MultiLineToolTip;
10
import org.gvsig.gui.beans.swing.treeTable.TreeTableModelAdapter;
11
import org.gvsig.remoteclient.wfs.WFSFeatureField;
12
import org.gvsig.wfs.gui.panels.WFSSelectFieldsPanel;
13

    
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.4  2007-09-19 16:14:50  jaume
60
 * removed unnecessary imports
61
 *
62
 * Revision 1.3  2007/03/15 13:35:47  ppiqueras
63
 * Corregido bug: lanzaba una excepci?n en el m?todo de b?squeda de campo geometr?a cuando el nodo era null.
64
 *
65
 * Revision 1.2  2007/02/19 11:44:42  jorpiell
66
 * A?adidos los filtros por ?rea
67
 *
68
 * Revision 1.1  2006/12/26 09:12:48  ppiqueras
69
 * 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).
70
 *
71
 * Revision 1.5  2006/11/15 17:37:39  jorpiell
72
 * Se copia el padre
73
 *
74
 * Revision 1.4  2006/11/10 13:14:47  ppiqueras
75
 * Corregido un bug: caos que haya campos de una feature de una capa WFS, que no tengan tipo (tipo == null).
76
 *
77
 * Revision 1.3  2006/11/01 17:29:07  jorpiell
78
 * 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
79
 *
80
 * Revision 1.2  2006/10/31 09:39:44  jorpiell
81
 * Se devuelve el tipo de la entidad completo, y no sus hijos
82
 *
83
 * Revision 1.1  2006/10/27 11:33:19  jorpiell
84
 * A?adida la treetable con los check box para seleccionar los atributos
85
 *
86
 * Revision 1.3  2006/10/24 10:13:19  jorpiell
87
 * Se ha eliminado la pesta?a de filter
88
 *
89
 * Revision 1.2  2006/10/24 07:58:14  jorpiell
90
 * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
91
 *
92
 * Revision 1.1  2006/10/24 07:27:56  jorpiell
93
 * Algunos cambios en el modelo que usa la tabla
94
 *
95
 *
96
 */
97

    
98
/**
99
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
100
 */
101
public class FieldsTreeTable extends org.gvsig.gui.beans.swing.treeTable.TreeTable {
102
        WFSSelectFieldsPanel parent = null;
103
        
104
        public FieldsTreeTable(FieldsTreeTableModel treeTableModel) {
105
                super(treeTableModel);
106
                JTree tree = (JTree)getTree();
107
                tree.setCellRenderer(new CheckBoxTreeCellRenderer(this));
108
                tree.setCellEditor(new CheckBoxTreeCellEditor(this));
109
                tree.setEditable(true);                
110
        }
111

    
112
        public FieldsTreeTable(FieldsTreeTableModel treeTableModel,WFSSelectFieldsPanel parent) {
113
                super(treeTableModel);
114
                this.parent = parent;
115
                JTree tree = (JTree)getTree();
116
                tree.setCellRenderer(new CheckBoxTreeCellRenderer(this));
117
                tree.setCellEditor(new CheckBoxTreeCellEditor(this));
118
                tree.setEditable(true);
119
        }
120

    
121
        /**
122
         * Sets the fields
123
         * @param fields
124
         */
125
        public void setFields(Vector vFields){
126
                Object[] fields = new Object[vFields.size()];
127
                for (int i=0 ; i<vFields.size() ; i++){
128
                        fields[i] = vFields.get(i);
129
                }
130
                setModel(new FieldsTreeTableModel(fields));
131
                deleteIcons();
132
                setRootVisible(false);
133
        }
134

    
135
        /**
136
         * Gets the selected layer
137
         * @return
138
         */
139
        public Object[] getSelectedValues(){
140
                int[] selectedRows = getSelectedRows();
141
                TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
142
                Object[] objects = new Object[selectedRows.length];
143
                for (int i=0 ; i<selectedRows.length ; i++){
144
                        objects[i] = obj.nodeForRow(selectedRows[i]);
145
                }
146
                return objects;
147
        }
148

    
149
        /**
150
         * return the selected elements
151
         * @return
152
         */
153
        public WFSFeatureField[] getSelectedElements(){
154
                TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
155
                ArrayList elements = new ArrayList();
156
                for (int i=0 ; i< obj.getRowCount() ; i++){
157
                        if (obj.nodeForRow(i) instanceof CheckBoxNode){
158
                                CheckBoxNode node = (CheckBoxNode)obj.nodeForRow(i);
159
                                if (node.isSelected()){
160
                                    WFSFeatureField featureField = node.getFeatureField();
161
                                        CheckBoxNode parentNode = node.getParentNode();
162
//                                        if (parentNode != null){
163
//                                                element.setParentElement(parentNode.getElement());
164
//                                        }
165
                                        elements.add(featureField);
166
                                }                                        
167
                        }
168
                }
169
        
170
                WFSFeatureField[] selected = new WFSFeatureField[elements.size()];
171
                for (int i=0 ; i<elements.size() ; i++){
172
                        selected[i] = (WFSFeatureField)elements.get(i);
173
                }
174
                return selected;
175
        }
176
        
177
        
178
        public void setModel(FieldsTreeTableModel treeTableModel){
179
                super.setModel(treeTableModel);
180
                JTree tree = (JTree)getTree();
181
                tree.setCellRenderer(new CheckBoxTreeCellRenderer(this));
182
                tree.setCellEditor(new CheckBoxTreeCellEditor(this));
183
                tree.setEditable(true);                
184
        }
185
        
186
        /**
187
         * Gets the geometry field
188
         * @return
189
         */
190
        public String getGeometryField(){
191
                TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
192
                ArrayList elements = new ArrayList();
193
                for (int i=0 ; i< obj.getRowCount() ; i++){
194
                        if (obj.nodeForRow(i) instanceof CheckBoxNode){
195
                                CheckBoxNode node = (CheckBoxNode)obj.nodeForRow(i);
196
                                WFSFeatureField featureField = node.getFeatureField();
197
                                if (featureField.isGeometry()) {
198
                                        return featureField.getName();                                        
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
        
213
                for (int i = 0; i < tree.getRowCount(); i++) {
214
                        tree.expandRow(i);
215
                }        
216
                for (int i=0 ; i<obj.getRowCount() ; i++){
217
                        if (obj.nodeForRow(i) instanceof CheckBoxNode){
218
                            WFSFeatureField featureField = ((CheckBoxNode)obj.nodeForRow(i)).getFeatureField();
219
                                for (int j=0 ; j<selectedFields.size() ; j++){
220
                                        //If the name is equals
221
                                        if (((WFSFeatureField)selectedFields.get(j)).getName().equals(featureField.getName())){
222
                                                //If the type is equals                                        
223
                                                if ((featureField.getDataType() != null) && 
224
                                                    (((WFSFeatureField)selectedFields.get(j)).getDataType() != null) && 
225
                                                    (((WFSFeatureField)selectedFields.get(j)).getDataType().equals(featureField.getDataType())) ){
226
                                                        ((CheckBoxNode)obj.nodeForRow(i)).setSelected(true);
227
                                                }
228
                                        }
229
                                }
230
                        }                        
231
                }
232
                
233
        }
234
        
235
        /**
236
         * <p>Changes the status to applied.</p>
237
         * 
238
         * @param applicable a boolean value
239
         */
240
        public void setApplicable(boolean applicable) {
241
                if (parent != null){
242
                        parent.setApplicable(applicable);
243
                }
244
        }
245
        
246
        /*
247
         * (non-Javadoc)
248
         * @see javax.swing.JComponent#createToolTip()
249
         */
250
    public JToolTip createToolTip() {
251
            // Multiline support
252
            MultiLineToolTip tip = new MultiLineToolTip();
253
            tip.setComponent(this);
254
            return tip;
255
    }
256
}