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