svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / LayerTable.java @ 32051
History | View | Annotate | Download (6.53 KB)
1 | 29645 | jpiera | package org.gvsig.wfs.gui.panels; |
---|---|---|---|
2 | 27885 | jpiera | |
3 | import java.util.Vector; |
||
4 | |||
5 | import javax.swing.JTable; |
||
6 | import javax.swing.table.AbstractTableModel; |
||
7 | |||
8 | 29645 | jpiera | import org.gvsig.andami.PluginServices; |
9 | import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature; |
||
10 | import org.gvsig.wfs.gui.panels.model.WFSUtils; |
||
11 | 27885 | jpiera | |
12 | 29645 | jpiera | |
13 | 27885 | jpiera | /* 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: LayerTable.java 8847 2006-11-17 11:29:00Z ppiqueras $
|
||
56 | * $Log$
|
||
57 | * Revision 1.4.2.3 2006-11-17 11:28:45 ppiqueras
|
||
58 | * Corregidos bugs y a?adida nueva funcionalidad.
|
||
59 | *
|
||
60 | * Revision 1.6 2006/10/02 09:09:45 jorpiell
|
||
61 | * Cambios del 10 copiados al head
|
||
62 | *
|
||
63 | * Revision 1.4.2.1 2006/09/19 12:28:11 jorpiell
|
||
64 | * Ya no se depende de geotools
|
||
65 | *
|
||
66 | * Revision 1.5 2006/09/18 12:07:31 jorpiell
|
||
67 | * Se ha sustituido geotools por el driver de remoteservices
|
||
68 | *
|
||
69 | * Revision 1.4 2006/07/24 07:30:33 jorpiell
|
||
70 | * Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
|
||
71 | *
|
||
72 | * Revision 1.3 2006/06/21 12:35:45 jorpiell
|
||
73 | * 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
|
||
74 | *
|
||
75 | * Revision 1.2 2006/05/25 16:01:43 jorpiell
|
||
76 | * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
|
||
77 | *
|
||
78 | * Revision 1.1 2006/05/25 10:29:50 jorpiell
|
||
79 | * A?adida la clase
|
||
80 | *
|
||
81 | *
|
||
82 | */
|
||
83 | /**
|
||
84 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
85 | */
|
||
86 | public class LayerTable extends JTable{ |
||
87 | public LayerTable() {
|
||
88 | super();
|
||
89 | setModel(new LayerTableModel());
|
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * Gets the selected layer
|
||
94 | * @return
|
||
95 | */
|
||
96 | public WFSSelectedFeature getSelectedValue(){
|
||
97 | int selectedRow = getSelectedRow();
|
||
98 | LayerTableModel model = (LayerTableModel)getModel(); |
||
99 | return model.getLayerAt(selectedRow);
|
||
100 | } |
||
101 | |||
102 | public WFSSelectedFeature getValueAt(int position){ |
||
103 | if (position<this.getRowCount()){ |
||
104 | LayerTableModel model = (LayerTableModel)getModel(); |
||
105 | return model.getLayerAt(position);
|
||
106 | } |
||
107 | return null; |
||
108 | } |
||
109 | |||
110 | /**
|
||
111 | * Adds a vector of features
|
||
112 | * @param features
|
||
113 | */
|
||
114 | public void addFeatures(Object[] features){ |
||
115 | LayerTableModel model = (LayerTableModel)getModel(); |
||
116 | model.deleteAllRows(); |
||
117 | for (int i=0 ; i<features.length ; i++){ |
||
118 | model.addRow((WFSSelectedFeature)features[i]); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | /**
|
||
123 | * @param showLayerNames The showLayerNames to set.
|
||
124 | */
|
||
125 | public void setShowLayerNames(boolean showLayerNames) { |
||
126 | LayerTableModel model = (LayerTableModel)getModel(); |
||
127 | model.setShowLayerNames(showLayerNames); |
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * Table model
|
||
132 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
133 | *
|
||
134 | */
|
||
135 | public class LayerTableModel extends AbstractTableModel{ |
||
136 | private Vector layers = new Vector(); |
||
137 | private boolean showLayerNames = false; |
||
138 | |||
139 | /**
|
||
140 | Constructs an investment table model.
|
||
141 | */
|
||
142 | public LayerTableModel(){
|
||
143 | super();
|
||
144 | } |
||
145 | |||
146 | /*
|
||
147 | * (non-Javadoc)
|
||
148 | * @see javax.swing.table.TableModel#getRowCount()
|
||
149 | */
|
||
150 | public int getRowCount(){ |
||
151 | return layers.size();
|
||
152 | } |
||
153 | |||
154 | /*
|
||
155 | * (non-Javadoc)
|
||
156 | * @see javax.swing.table.TableModel#getColumnCount()
|
||
157 | */
|
||
158 | public int getColumnCount(){ |
||
159 | return 2; |
||
160 | } |
||
161 | |||
162 | /*
|
||
163 | * (non-Javadoc)
|
||
164 | * @see javax.swing.table.TableModel#getValueAt(int, int)
|
||
165 | */
|
||
166 | public Object getValueAt(int rowNumber, int columnNumber){ |
||
167 | if (rowNumber < layers.size()){
|
||
168 | WFSSelectedFeature layer = (WFSSelectedFeature)layers.get(rowNumber); |
||
169 | if (columnNumber == 0){ |
||
170 | return getLayerName(layer);
|
||
171 | }else{
|
||
172 | return PluginServices.getText(this,WFSUtils.getGeometry(layer)); |
||
173 | } |
||
174 | }else{
|
||
175 | return ""; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * Returns the layer name (depending of the "show layer names"
|
||
181 | * check cob is clicked)
|
||
182 | * @param layer
|
||
183 | * @return
|
||
184 | */
|
||
185 | private String getLayerName(WFSSelectedFeature layer){ |
||
186 | if (showLayerNames){
|
||
187 | return "[" + layer.getName() + "] " + layer.getTitle(); |
||
188 | } else {
|
||
189 | return layer.getTitle();
|
||
190 | } |
||
191 | } |
||
192 | |||
193 | /**
|
||
194 | * Return the layer at the specified position
|
||
195 | * @param rowNumber
|
||
196 | * Row position
|
||
197 | * @return
|
||
198 | */
|
||
199 | public WFSSelectedFeature getLayerAt(int rowNumber){ |
||
200 | try{
|
||
201 | return (WFSSelectedFeature)layers.get(rowNumber);
|
||
202 | }catch (ArrayIndexOutOfBoundsException e){ |
||
203 | return null; |
||
204 | } |
||
205 | } |
||
206 | |||
207 | /**
|
||
208 | * It adds a new
|
||
209 | * @param values
|
||
210 | * Array of column values
|
||
211 | */
|
||
212 | public void addRow(WFSSelectedFeature layer){ |
||
213 | layers.add(layer); |
||
214 | fireTableRowsInserted(getRowCount(),getRowCount()); |
||
215 | fireTableRowsUpdated(0,getRowCount());
|
||
216 | } |
||
217 | |||
218 | /**
|
||
219 | * Delete all the table rows
|
||
220 | */
|
||
221 | public void deleteAllRows(){ |
||
222 | layers.clear(); |
||
223 | int rows = getRowCount();
|
||
224 | if (rows >= 1){ |
||
225 | fireTableRowsDeleted(0, rows - 1); |
||
226 | } |
||
227 | } |
||
228 | |||
229 | /**
|
||
230 | * Delete all the table rows
|
||
231 | */
|
||
232 | public void deleteRow(int rowPosition){ |
||
233 | layers.remove(rowPosition); |
||
234 | fireTableRowsDeleted(rowPosition, rowPosition); |
||
235 | fireTableRowsUpdated(0,getRowCount());
|
||
236 | } |
||
237 | |||
238 | |||
239 | |||
240 | /*
|
||
241 | * (non-Javadoc)
|
||
242 | * @see javax.swing.table.TableModel#getColumnName(int)
|
||
243 | */
|
||
244 | public String getColumnName(int columnIndex){ |
||
245 | if (columnIndex == 0){ |
||
246 | return PluginServices.getText(this,"layerName"); |
||
247 | }else{
|
||
248 | return PluginServices.getText(this,"layerType"); |
||
249 | } |
||
250 | } |
||
251 | |||
252 | /**
|
||
253 | * @return Returns the showLayerNames.
|
||
254 | */
|
||
255 | public boolean isShowLayerNames() { |
||
256 | return showLayerNames;
|
||
257 | } |
||
258 | |||
259 | /**
|
||
260 | * @param showLayerNames The showLayerNames to set.
|
||
261 | */
|
||
262 | public void setShowLayerNames(boolean showLayerNames) { |
||
263 | this.showLayerNames = showLayerNames;
|
||
264 | } |
||
265 | } |
||
266 | } |