Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / fieldstree / FieldsTreeTableModel.java @ 34026

History | View | Annotate | Download (7.83 KB)

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

    
3
import java.util.Vector;
4

    
5
import org.gvsig.andami.PluginServices;
6
import org.gvsig.gui.beans.swing.treeTable.AbstractTreeTableModel;
7
import org.gvsig.gui.beans.swing.treeTable.TreeTableModel;
8
import org.gvsig.remoteclient.wfs.WFSFeatureField;
9

    
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id$
54
 * $Log$
55
 * Revision 1.3  2007-01-23 13:11:04  ppiqueras
56
 * Cambios sin importancia.
57
 *
58
 * 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
 * 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
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
102
 */
103
public class FieldsTreeTableModel extends AbstractTreeTableModel {
104
    private boolean showGeometry;        
105
    private String[]  cNames = {PluginServices.getText(this,"attributeName"),
106
        PluginServices.getText(this,"attributeType")};
107
    private Class[]  cTypes = {TreeTableModel.class,String.class};
108

    
109
    public FieldsTreeTableModel(Object root) { 
110
        super(root);
111
        showGeometry = true;
112
    }
113

    
114
    public FieldsTreeTableModel(Object root, boolean show_Geometry) { 
115
        super(root);
116
        showGeometry = show_Geometry;
117
    }
118

    
119
    public FieldsTreeTableModel() { 
120
        super(null);
121
        showGeometry = true;
122
    }
123

    
124
    public boolean getShowGeometry() {
125
        return showGeometry;
126
    }
127

    
128
    //
129
    // The TreeModel interface
130
    //
131

    
132
    public int getChildCount(Object node) { 
133
        WFSFeatureField featureField = (WFSFeatureField)node;                        
134
        if (featureField.isComplex()){
135
            return (featureField.getFieldSize());        
136
        }else{
137
            return 0;
138
        }
139
    }
140

    
141
    public Object getChild(Object node, int i) { 
142
        WFSFeatureField element = (WFSFeatureField)node;                        
143
        if (element.isComplex()){
144
            WFSFeatureField child = null;      
145
            int k = -1;
146
            if (!showGeometry) {
147
                for (int j=0 ; j<element.getFieldSize() ; j++){
148
                    child = element.getFieldAt(j);
149
                    if (!child.isGeometry()){
150
                        k++;
151
                    }
152
                    if (i == k){
153
                        break;  
154
                    }
155
                }
156
            }
157
            return child;              
158
        }
159
        return null;
160
    }
161

    
162
    // The superclass's implementation would work, but this is more efficient. 
163
    public boolean isLeaf(Object node) { 
164
        if (node == null){
165
            return true;
166
        }
167
        WFSFeatureField featureField = (WFSFeatureField)node;        
168
        if (featureField.isComplex()){
169
            return false;
170
        }
171
        return true;
172
    }
173

    
174
    /*
175
     *  (non-Javadoc)
176
     * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnCount()
177
     */
178
    public int getColumnCount() {
179
        return cNames.length;
180
    }
181

    
182
    /*
183
     *  (non-Javadoc)
184
     * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnName(int)
185
     */
186
    public String getColumnName(int column) {
187
        return cNames[column];
188
    }
189

    
190
    /*
191
     *  (non-Javadoc)
192
     * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnClass(int)
193
     */
194
    public Class getColumnClass(int column) {
195
        return cTypes[column];
196
    }
197

    
198
    /*
199
     *  (non-Javadoc)
200
     * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getValueAt(java.lang.Object, int)
201
     */
202
    public Object getValueAt(Object node, int column) {
203
        WFSFeatureField element = (WFSFeatureField)node;        
204
        if (element == null){
205
            return "";
206
        }
207
        try {
208
            switch(column) {
209
            case 0:
210
                return element.getName();
211
            case 1:
212
                if (element.getDataType() == null){
213
                    return "";
214
                }
215
                return PluginServices.getText(this, element.getDataType().getName());
216
            }
217
        }
218
        catch  (SecurityException se) { }
219

    
220
        return null; 
221
    }
222

    
223
    /**
224
     * Returns leafs from a node branch
225
     * 
226
     * @param node A node in this tree model
227
     * @return A vector with leafs
228
     */
229
    public Vector<Object> getLeafsFromNodeBranch(Object node) {
230
        Vector<Object> leafs = new Vector<Object>();
231
        WFSFeatureField parent = (WFSFeatureField)node;
232
        
233
        if (this.isLeaf(node))
234
            leafs.add(parent.getName());
235
        else {
236
           
237
            for (int i = 0; i < parent.getFieldSize() ; i ++) {
238
                WFSFeatureField child = parent.getFieldAt(i);
239

    
240
                if ((this.isLeaf(child)) && (! leafs.contains(node)) )
241
                    leafs.add(child);
242
                else
243
                    leafs.addAll(getLeafsFromNodeBranch(child));
244
            }
245
        }
246

    
247
        return leafs;
248
    }
249
}