Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / attributesTree / AttributesTreeTableModel.java @ 8447

History | View | Annotate | Download (5.59 KB)

1
package com.iver.cit.gvsig.gui.panels.attributesTree;
2

    
3
import java.util.Vector;
4

    
5
import org.gvsig.gui.beans.swing.treeTable.AbstractTreeTableModel;
6
import org.gvsig.gui.beans.swing.treeTable.TreeTableModel;
7
import org.gvsig.remoteClient.gml.schemas.IXMLType;
8
import org.gvsig.remoteClient.gml.schemas.XMLComplexType;
9
import org.gvsig.remoteClient.gml.schemas.XMLElement;
10

    
11
import com.iver.andami.PluginServices;
12
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSUtils;
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: AttributesTreeTableModel.java 8447 2006-10-31 12:24:04Z jorpiell $
57
 * $Log$
58
 * Revision 1.2  2006-10-31 12:24:04  jorpiell
59
 * Comprobado el caso en el que los atributos no tienen tipo
60
 *
61
 * Revision 1.1  2006/10/27 11:33:19  jorpiell
62
 * A?adida la treetable con los check box para seleccionar los atributos
63
 *
64
 * Revision 1.2  2006/10/24 07:58:14  jorpiell
65
 * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
66
 *
67
 * Revision 1.1  2006/10/24 07:27:56  jorpiell
68
 * Algunos cambios en el modelo que usa la tabla
69
 *
70
 * Revision 1.2  2006/10/23 08:17:18  jorpiell
71
 * Algunos cambios realizados para tener un ?rbol com m?s de una ra?z
72
 *
73
 * Revision 1.1  2006/10/23 07:37:04  jorpiell
74
 * Ya funciona el filterEncoding
75
 *
76
 *
77
 */
78
/**
79
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
80
 */
81
public class AttributesTreeTableModel extends AbstractTreeTableModel {
82
        private String[]  cNames = {PluginServices.getText(this,"attributeName"),
83
                        PluginServices.getText(this,"attributeType")};
84
        private Class[]  cTypes = {TreeTableModel.class,String.class};
85
        private Object[] attributes = null;
86
                
87
        public AttributesTreeTableModel(Object[] attributes) { 
88
                super(attributes);                
89
                this.attributes = attributes;
90
        }                
91
        
92
        public AttributesTreeTableModel() { 
93
                super(null); 
94
                this.attributes = null;
95
        }
96
        
97
        public void setNodes(Object[] attributes){
98
                this.attributes = attributes;                
99
        }
100
        
101
        protected Object[] getChildren(Object node) {
102
                XMLElement element = (XMLElement)node;                        
103
                if (element.getEntityType().getType() == IXMLType.COMPLEX){
104
                        Vector vector = ((XMLComplexType)element.getEntityType()).getAttributes();
105
                        Object[] objs = new Object[vector.size()];
106
                        for (int i=0 ; i<vector.size() ; i++){
107
                                objs[i] = vector.get(i);
108
                        }
109
                }
110
                return null;        
111
        }
112
        
113
        //
114
        // The TreeModel interface
115
        //
116
        
117
        public int getChildCount(Object node) { 
118
                if (node instanceof AbstractTreeTableModel.Root){
119
                        return ((AbstractTreeTableModel.Root)node).getChildCount();
120
                }
121
                XMLElement element = (XMLElement)node;                        
122
                if (element.getEntityType().getType() == IXMLType.COMPLEX){
123
                        return ((XMLComplexType)element.getEntityType()).getAttributes().size();
124
                }else{
125
                        return 0;
126
                }
127
        }
128
        
129
        public Object getChild(Object node, int i) { 
130
                if (node instanceof AbstractTreeTableModel.Root){
131
                        return ((AbstractTreeTableModel.Root)node).getChildren()[i];
132
                }
133
                XMLElement element = (XMLElement)node;                        
134
                if (element.getEntityType().getType() == IXMLType.COMPLEX){
135
                        Vector vector = ((XMLComplexType)element.getEntityType()).getAttributes();
136
                        return vector.get(i);
137
                }
138
                return null;
139
        }
140
        
141
        // The superclass's implementation would work, but this is more efficient. 
142
        public boolean isLeaf(Object node) { 
143
                if (node == null){
144
                        return true;
145
                }
146
                if (node instanceof AbstractTreeTableModel.Root){
147
                        return false;
148
                }
149
                XMLElement element = (XMLElement)node;        
150
                if (element.getEntityType() != null){
151
                        if (element.getEntityType().getType() == IXMLType.COMPLEX){
152
                                return false;
153
                        }
154
                }
155
                return true;
156
        }
157

    
158
        /*
159
         *  (non-Javadoc)
160
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnCount()
161
         */
162
        public int getColumnCount() {
163
                return cNames.length;
164
        }
165
        
166
        /*
167
         *  (non-Javadoc)
168
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnName(int)
169
         */
170
        public String getColumnName(int column) {
171
                return cNames[column];
172
        }
173
        
174
        /*
175
         *  (non-Javadoc)
176
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getColumnClass(int)
177
         */
178
        public Class getColumnClass(int column) {
179
                return cTypes[column];
180
        }
181
        
182
        /*
183
         *  (non-Javadoc)
184
         * @see org.gvsig.gui.beans.swing.treeTable.TreeTableModel#getValueAt(java.lang.Object, int)
185
         */
186
        public Object getValueAt(Object node, int column) {
187
                if (node instanceof AbstractTreeTableModel.Root){
188
                        return "";
189
                }
190
                XMLElement element = (XMLElement)node;        
191
                try {
192
                        switch(column) {
193
                        case 0:
194
                                return element.getName();
195
                        case 1:
196
                                return PluginServices.getText(this,WFSUtils.getAttributeType(element.getEntityType()));
197
                        }
198
                }
199
                catch  (SecurityException se) { }
200
                
201
                return null; 
202
        }
203
}
204

    
205