Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1009 / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / LayerTable.java @ 12649

History | View | Annotate | Download (6.42 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 com.iver.andami.PluginServices;
9
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSUtils;
10
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
11

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

    
251
                /**
252
                 * @return Returns the showLayerNames.
253
                 */
254
                public boolean isShowLayerNames() {
255
                        return showLayerNames;
256
                }
257

    
258
                /**
259
                 * @param showLayerNames The showLayerNames to set.
260
                 */
261
                public void setShowLayerNames(boolean showLayerNames) {
262
                        this.showLayerNames = showLayerNames;
263
                }
264
        }
265
}