Statistics
| Revision:

root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / wfs / gui / panels / fieldstree / FieldsTreeTable.java @ 10

History | View | Annotate | Download (7.61 KB)

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

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

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

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

    
15

    
16
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
17
 *
18
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
19
 *
20
 * This program is free software; you can redistribute it and/or
21
 * modify it under the terms of the GNU General Public License
22
 * as published by the Free Software Foundation; either version 2
23
 * of the License, or (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
33
 *
34
 * For more information, contact:
35
 *
36
 *  Generalitat Valenciana
37
 *   Conselleria d'Infraestructures i Transport
38
 *   Av. Blasco Ib??ez, 50
39
 *   46010 VALENCIA
40
 *   SPAIN
41
 *
42
 *      +34 963862235
43
 *   gvsig@gva.es
44
 *      www.gvsig.gva.es
45
 *
46
 *    or
47
 *
48
 *   IVER T.I. S.A
49
 *   Salamanca 50
50
 *   46005 Valencia
51
 *   Spain
52
 *
53
 *   +34 963163400
54
 *   dac@iver.es
55
 */
56
/* CVS MESSAGES:
57
 *
58
 * $Id$
59
 * $Log$
60
 * Revision 1.4  2007-09-19 16:14:50  jaume
61
 * removed unnecessary imports
62
 *
63
 * Revision 1.3  2007/03/15 13:35:47  ppiqueras
64
 * Corregido bug: lanzaba una excepci?n en el m?todo de b?squeda de campo geometr?a cuando el nodo era null.
65
 *
66
 * Revision 1.2  2007/02/19 11:44:42  jorpiell
67
 * A?adidos los filtros por ?rea
68
 *
69
 * Revision 1.1  2006/12/26 09:12:48  ppiqueras
70
 * 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).
71
 *
72
 * Revision 1.5  2006/11/15 17:37:39  jorpiell
73
 * Se copia el padre
74
 *
75
 * Revision 1.4  2006/11/10 13:14:47  ppiqueras
76
 * Corregido un bug: caos que haya campos de una feature de una capa WFS, que no tengan tipo (tipo == null).
77
 *
78
 * Revision 1.3  2006/11/01 17:29:07  jorpiell
79
 * 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
80
 *
81
 * Revision 1.2  2006/10/31 09:39:44  jorpiell
82
 * Se devuelve el tipo de la entidad completo, y no sus hijos
83
 *
84
 * Revision 1.1  2006/10/27 11:33:19  jorpiell
85
 * A?adida la treetable con los check box para seleccionar los atributos
86
 *
87
 * Revision 1.3  2006/10/24 10:13:19  jorpiell
88
 * Se ha eliminado la pesta?a de filter
89
 *
90
 * Revision 1.2  2006/10/24 07:58:14  jorpiell
91
 * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
92
 *
93
 * Revision 1.1  2006/10/24 07:27:56  jorpiell
94
 * Algunos cambios en el modelo que usa la tabla
95
 *
96
 *
97
 */
98

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

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

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

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

    
150
        /**
151
         * return the selected elements
152
         * @return
153
         */
154
        public WFSFeatureField[] getSelectedElements(){
155
                TreeTableModelAdapter obj = (TreeTableModelAdapter)getModel();
156
                ArrayList elements = new ArrayList();
157
                for (int i=0 ; i< obj.getRowCount() ; i++){
158
                        if (obj.nodeForRow(i) instanceof CheckBoxNode){
159
                                CheckBoxNode node = (CheckBoxNode)obj.nodeForRow(i);
160
                                if (node.isSelected()){
161
                                    WFSFeatureField featureField = node.getFeatureField();
162
                                        CheckBoxNode parentNode = node.getParentNode();
163
                                        if (parentNode != null){
164
                                            elements.add(featureField);
165
                                        }                                
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(List 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 ((selectedFields.get(j)).equals(featureField.getName())){                                                
222
                                            ((CheckBoxNode)obj.nodeForRow(i)).setSelected(true);
223
                                        }
224
                                }
225
                        }                        
226
                }                
227
        }
228
        
229
        /**
230
         * <p>Changes the status to applied.</p>
231
         * 
232
         * @param applicable a boolean value
233
         */
234
        public void setApplicable(boolean applicable) {
235
                if (parent != null){
236
                        parent.setApplicable(applicable);
237
                }
238
        }
239
        
240
        /*
241
         * (non-Javadoc)
242
         * @see javax.swing.JComponent#createToolTip()
243
         */
244
    public JToolTip createToolTip() {
245
            // Multiline support
246
            MultiLineToolTip tip = new MultiLineToolTip();
247
            tip.setComponent(this);
248
            return tip;
249
    }
250
}