Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / AttributesTable.java @ 7721

History | View | Annotate | Download (5.59 KB)

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

    
3
import java.util.Vector;
4

    
5
import javax.swing.JTable;
6
import javax.swing.table.AbstractTableModel;
7

    
8
import org.gvsig.remoteClient.wfs.WFSAttribute;
9

    
10
import com.iver.andami.PluginServices;
11
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSUtils;
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: AttributesTable.java 7721 2006-10-02 09:09:45Z jorpiell $
56
 * $Log$
57
 * Revision 1.5  2006-10-02 09:09:45  jorpiell
58
 * Cambios del 10 copiados al head
59
 *
60
 * Revision 1.3.2.1  2006/09/19 12:28:11  jorpiell
61
 * Ya no se depende de geotools
62
 *
63
 * Revision 1.4  2006/09/18 12:07:31  jorpiell
64
 * Se ha sustituido geotools por el driver de remoteservices
65
 *
66
 * Revision 1.3  2006/07/24 07:30:33  jorpiell
67
 * Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
68
 *
69
 * Revision 1.2  2006/05/25 16:01:43  jorpiell
70
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
71
 *
72
 * Revision 1.1  2006/05/25 10:29:28  jorpiell
73
 * A?adida la clase
74
 *
75
 *
76
 */
77
/**
78
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
79
 */
80
public class AttributesTable extends JTable {
81
        
82
        public AttributesTable() {
83
                super();
84
                setModel(new AttributesTableModel());
85
        }
86
        
87
        /**
88
         * Returns all the attributes
89
         * @return
90
         */
91
        public Object[] getAllValues(){
92
                AttributesTableModel model = (AttributesTableModel)getModel();
93
                return model.getAllValues();
94
        }
95
        
96
        /**
97
         * Gets the selected layer
98
         * @return
99
         */
100
        public Object[] getSelectedValues(){
101
                AttributesTableModel model = (AttributesTableModel)getModel();
102
                int[] selectedRows = getSelectedRows();
103
                Object[] attributes = new Object[selectedRows.length];
104
                for (int i=0 ; i<attributes.length ; i++){
105
                        attributes[i] = model.getAttributeAt(selectedRows[i]);
106
                }
107
                return attributes;
108
        }
109
        
110
        /**
111
         * Adds a vector of features
112
         * @param features
113
         */
114
        public void addAttributes(Object[] attributes){
115
                AttributesTableModel model = (AttributesTableModel)getModel();
116
                model.deleteAllRows();
117
                for (int i=0 ; i<attributes.length ; i++){
118
                        model.addRow((WFSAttribute)attributes[i]);                        
119
                }                
120
        }        
121
        
122
        
123
        /**
124
         * Table model
125
         * @author Jorge Piera Llodr? (piera_jor@gva.es)
126
         *
127
         */
128
        public class AttributesTableModel extends AbstractTableModel{  
129
                private Vector attributes = new Vector();
130
                        
131
                /**
132
                 Constructs an investment table model.
133
                 */
134
                public AttributesTableModel(){  
135
                        super();
136
                }
137
                
138
                /*
139
                 *  (non-Javadoc)
140
                 * @see javax.swing.table.TableModel#getRowCount()
141
                 */
142
                public int getRowCount(){  
143
                        return attributes.size();                
144
                }
145
                
146
                /*
147
                 *  (non-Javadoc)
148
                 * @see javax.swing.table.TableModel#getColumnCount()
149
                 */
150
                public int getColumnCount(){  
151
                        return 2;
152
                }
153
                
154
                /*
155
                 *  (non-Javadoc)
156
                 * @see javax.swing.table.TableModel#getValueAt(int, int)
157
                 */
158
                public Object getValueAt(int rowNumber, int columnNumber){  
159
                        if (rowNumber < attributes.size()){
160
                                WFSAttribute attribute = (WFSAttribute)attributes.get(rowNumber);
161
                                if (columnNumber == 0){
162
                                        return attribute.getName();
163
                                }else{
164
                                        return PluginServices.getText(this,WFSUtils.getAttributeType(attribute)); 
165
                                }
166
                        }else{
167
                                return "";
168
                        }
169
                }
170
                
171
                /**
172
                 * Returns all the attributes
173
                 * @return
174
                 */
175
                public Object[] getAllValues(){
176
                        return attributes.toArray();
177
                }
178
                
179
                /**
180
                 * Return the attribute at the specified position
181
                 * @param rowNumber
182
                 * Row position
183
                 * @return
184
                 */
185
                public WFSAttribute getAttributeAt(int rowNumber){  
186
                        try{
187
                                return (WFSAttribute)attributes.get(rowNumber);
188
                        }catch (ArrayIndexOutOfBoundsException e){
189
                                return null;
190
                        }
191
                }        
192
                
193
                /**
194
                 * It adds a new attribute
195
                 * @param values
196
                 * Array of column values
197
                 */
198
                public void addRow(WFSAttribute attribute){
199
                        attributes.add(attribute);                
200
                        fireTableRowsInserted(getRowCount(),getRowCount());
201
                        fireTableRowsUpdated(0,getRowCount());
202
                }
203
                
204
                /**
205
                 * Delete all the table rows
206
                 */
207
                public void deleteAllRows(){
208
                        attributes.clear();
209
                        int rows = getRowCount();
210
                        if (rows >= 1){
211
                                fireTableRowsDeleted(0, rows - 1);
212
                        }                
213
                }        
214
                
215
                /**
216
                 * Delete all the table rows
217
                 */
218
                public void deleteRow(int rowPosition){
219
                        attributes.remove(rowPosition);
220
                        fireTableRowsDeleted(rowPosition, rowPosition);
221
                        fireTableRowsUpdated(0,getRowCount());                
222
                }        
223
                
224
                /*
225
                 *  (non-Javadoc)
226
                 * @see javax.swing.table.TableModel#getColumnName(int)
227
                 */
228
                public String getColumnName(int columnIndex){
229
                        if (columnIndex == 0){
230
                                return PluginServices.getText(this,"attributeName");
231
                        }else{
232
                                return PluginServices.getText(this,"attributeType");
233
                        }
234
                }                
235
        }
236

    
237
}