Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / attributesTree / AttributesTreeTableModel.java @ 8388

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

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

    
200