svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSSelectAttributesPanel.java @ 5472
History | View | Annotate | Download (10.1 KB)
1 |
package com.iver.cit.gvsig.gui.panels; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Hashtable; |
5 |
import java.util.Vector; |
6 |
|
7 |
import javax.swing.JButton; |
8 |
import javax.swing.JList; |
9 |
import javax.swing.JPanel; |
10 |
import javax.swing.JScrollPane; |
11 |
|
12 |
import org.gvsig.remoteClient.wfs.WFSAttribute; |
13 |
|
14 |
import com.iver.andami.PluginServices; |
15 |
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSFilter; |
16 |
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode; |
17 |
|
18 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
19 |
*
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
21 |
*
|
22 |
* This program is free software; you can redistribute it and/or
|
23 |
* modify it under the terms of the GNU General Public License
|
24 |
* as published by the Free Software Foundation; either version 2
|
25 |
* of the License, or (at your option) any later version.
|
26 |
*
|
27 |
* This program is distributed in the hope that it will be useful,
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
* GNU General Public License for more details.
|
31 |
*
|
32 |
* You should have received a copy of the GNU General Public License
|
33 |
* along with this program; if not, write to the Free Software
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
35 |
*
|
36 |
* For more information, contact:
|
37 |
*
|
38 |
* Generalitat Valenciana
|
39 |
* Conselleria d'Infraestructures i Transport
|
40 |
* Av. Blasco Ib??ez, 50
|
41 |
* 46010 VALENCIA
|
42 |
* SPAIN
|
43 |
*
|
44 |
* +34 963862235
|
45 |
* gvsig@gva.es
|
46 |
* www.gvsig.gva.es
|
47 |
*
|
48 |
* or
|
49 |
*
|
50 |
* IVER T.I. S.A
|
51 |
* Salamanca 50
|
52 |
* 46005 Valencia
|
53 |
* Spain
|
54 |
*
|
55 |
* +34 963163400
|
56 |
* dac@iver.es
|
57 |
*/
|
58 |
/* CVS MESSAGES:
|
59 |
*
|
60 |
* $Id: WFSSelectAttributesPanel.java 5472 2006-05-26 06:29:42Z jorpiell $
|
61 |
* $Log$
|
62 |
* Revision 1.2 2006-05-26 06:29:42 jorpiell
|
63 |
* Se ha cambiado el tama?o de los botones. Adem?s, al seleccionar todos los atributos se seleccionan en orden.
|
64 |
*
|
65 |
* Revision 1.1 2006/05/25 10:30:13 jorpiell
|
66 |
* Esta clase se ha renombrado. WFSFields era algo confusa
|
67 |
*
|
68 |
* Revision 1.3 2006/05/23 08:09:39 jorpiell
|
69 |
* Se ha cambiado la forma en la que se leian los valores seleccionados en los paneles y se ha cambiado el comportamiento de los botones
|
70 |
*
|
71 |
* Revision 1.2 2006/05/19 12:57:08 jorpiell
|
72 |
* Modificados algunos paneles
|
73 |
*
|
74 |
* Revision 1.1 2006/04/20 16:38:24 jorpiell
|
75 |
* Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
|
76 |
*
|
77 |
*
|
78 |
*/
|
79 |
/**
|
80 |
* This panel shows the feature fields list
|
81 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
82 |
*/
|
83 |
public class WFSSelectAttributesPanel extends JPanel { |
84 |
private static final long serialVersionUID = 3073243334672620143L; |
85 |
private JButton addButton = null; |
86 |
private JButton delButton = null; |
87 |
private JScrollPane jScrollPane3 = null; |
88 |
private JScrollPane jScrollPane4 = null; |
89 |
private AttributesTable attributesList = null; |
90 |
private JList selectedAttributesList = null; |
91 |
private JButton addAllButton = null; |
92 |
private JButton delAllButton = null; |
93 |
|
94 |
public WFSSelectAttributesPanel(){
|
95 |
super();
|
96 |
initialize(); |
97 |
} |
98 |
|
99 |
public void initialize(){ |
100 |
this.setLayout(null); |
101 |
this.setBounds(5, 17, 464, 374); |
102 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(
|
103 |
null, PluginServices.getText(this, "select_fields"), |
104 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
105 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
106 |
this.add(getAddButton(), null); |
107 |
this.add(getDelButton(), null); |
108 |
this.add(getJScrollPane3(), null); |
109 |
this.add(getJScrollPane4(), null); |
110 |
this.add(getAddAllButton(), null); |
111 |
this.add(getDelAllButton(), null); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* This method initializes jButton2
|
116 |
*
|
117 |
* @return javax.swing.JButton
|
118 |
*/
|
119 |
private JButton getAddButton() { |
120 |
if (addButton == null) { |
121 |
addButton = new JButton(); |
122 |
addButton.setBounds(245, 160, 50, 50); |
123 |
addButton.setText(">");
|
124 |
addButton.addActionListener( |
125 |
new java.awt.event.ActionListener() {
|
126 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
127 |
addAttribute(); |
128 |
} |
129 |
}); |
130 |
} |
131 |
return addButton;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* This method initializes btnDelTemps
|
136 |
*
|
137 |
* @return javax.swing.JButton
|
138 |
*/
|
139 |
private JButton getDelButton() { |
140 |
if (delButton == null) { |
141 |
delButton = new JButton(); |
142 |
delButton.setText("<");
|
143 |
delButton.setBounds(245, 220, 50, 50); |
144 |
delButton.addActionListener( |
145 |
new java.awt.event.ActionListener() {
|
146 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
147 |
delAttribute(); |
148 |
} |
149 |
}); |
150 |
} |
151 |
return delButton;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* This method initializes jButton
|
156 |
*
|
157 |
* @return javax.swing.JButton
|
158 |
*/
|
159 |
private JButton getAddAllButton() { |
160 |
if (addAllButton == null) { |
161 |
addAllButton = new JButton(); |
162 |
addAllButton.setBounds(new java.awt.Rectangle(245,100,50, 50)); |
163 |
addAllButton.setText(">>");
|
164 |
addAllButton.addActionListener( |
165 |
new java.awt.event.ActionListener() {
|
166 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
167 |
addAllAttributes(); |
168 |
} |
169 |
}); |
170 |
} |
171 |
return addAllButton;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* This method initializes jButton1
|
176 |
*
|
177 |
* @return javax.swing.JButton
|
178 |
*/
|
179 |
private JButton getDelAllButton() { |
180 |
if (delAllButton == null) { |
181 |
delAllButton = new JButton(); |
182 |
delAllButton.setBounds(new java.awt.Rectangle(245,280,50,50)); |
183 |
delAllButton.setText("<<");
|
184 |
delAllButton.addActionListener( |
185 |
new java.awt.event.ActionListener() {
|
186 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
187 |
delAllAttributes(); |
188 |
} |
189 |
}); |
190 |
} |
191 |
return delAllButton;
|
192 |
} |
193 |
|
194 |
|
195 |
/**
|
196 |
* This method initializes jScrollPane3
|
197 |
*
|
198 |
* @return javax.swing.JScrollPane
|
199 |
*/
|
200 |
private JScrollPane getJScrollPane3() { |
201 |
if (jScrollPane3 == null) { |
202 |
jScrollPane3 = new JScrollPane(); |
203 |
jScrollPane3.setBounds(10, 30, 226, 334); |
204 |
jScrollPane3.setViewportView(getAttributesList()); |
205 |
} |
206 |
return jScrollPane3;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* This method initializes jScrollPane4
|
211 |
*
|
212 |
* @return javax.swing.JScrollPane
|
213 |
*/
|
214 |
private JScrollPane getJScrollPane4() { |
215 |
if (jScrollPane4 == null) { |
216 |
jScrollPane4 = new JScrollPane(); |
217 |
jScrollPane4.setBounds(304, 30, 158, 334); |
218 |
jScrollPane4.setViewportView(getSelectedAttributesList()); |
219 |
} |
220 |
return jScrollPane4;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* This method initializes lstTemps
|
225 |
*
|
226 |
* @return javax.swing.JList
|
227 |
*/
|
228 |
public AttributesTable getAttributesList() {
|
229 |
if (attributesList == null) { |
230 |
attributesList = new AttributesTable();
|
231 |
} |
232 |
return attributesList;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* This method initializes selectedAttributesList
|
237 |
*
|
238 |
* @return javax.swing.JList
|
239 |
*/
|
240 |
public JList getSelectedAttributesList() { |
241 |
if (selectedAttributesList == null) { |
242 |
selectedAttributesList = new JList(); |
243 |
selectedAttributesList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
244 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
245 |
// selectedAttributesList.callStateChanged(isCorretlyConfigured());
|
246 |
} |
247 |
}); |
248 |
} |
249 |
return selectedAttributesList;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
*
|
254 |
* @param feature
|
255 |
*/
|
256 |
public void setFields(WFSLayerNode feature){ |
257 |
getSelectedAttributesList().setListData(new Object[0]); |
258 |
Vector fields = feature.getFields();
|
259 |
getAttributesList().addAttributes(fields.toArray()); |
260 |
for (int i=0 ; i<fields.size() ;i++){ |
261 |
WFSAttribute field = (WFSAttribute)fields.get(i); |
262 |
if (WFSFilter.isGeometry(field.getType())){
|
263 |
Vector geometry = new Vector(); |
264 |
geometry.add(field); |
265 |
getSelectedAttributesList().setListData(geometry.toArray()); |
266 |
} |
267 |
} |
268 |
} |
269 |
|
270 |
/**
|
271 |
* Adds the selected items from the time list to the selected
|
272 |
* features list.
|
273 |
*/
|
274 |
private void addAttribute(){ |
275 |
ArrayList times = new ArrayList(); |
276 |
for (int i = 0; i < getSelectedAttributesList() |
277 |
.getModel().getSize(); i++) { |
278 |
times.add(getSelectedAttributesList().getModel() |
279 |
.getElementAt(i)); |
280 |
} |
281 |
|
282 |
Object[] obj = getAttributesList().getSelectedValues(); |
283 |
for (int i = 0; i < obj.length; i++) { |
284 |
if (!times.contains(obj[i]))
|
285 |
times.add(obj[i]); |
286 |
} |
287 |
getSelectedAttributesList() |
288 |
.setListData(times.toArray()); |
289 |
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* Removes the selected items from the selected features list.
|
294 |
*/
|
295 |
private void delAttribute(){ |
296 |
ArrayList features = new ArrayList(); |
297 |
Object[] obj = getSelectedAttributesList() |
298 |
.getSelectedValues(); |
299 |
for (int i = 0; i < getSelectedAttributesList() |
300 |
.getModel().getSize(); i++) |
301 |
features.add(getSelectedAttributesList().getModel() |
302 |
.getElementAt(i)); |
303 |
|
304 |
for (int j = 0; j < obj.length; j++){ |
305 |
if (features.contains(obj[j])){
|
306 |
WFSAttribute field = (WFSAttribute)obj[j]; |
307 |
if (!(WFSFilter.isGeometry(field.getType()))){
|
308 |
features.remove(obj[j]); |
309 |
} |
310 |
} |
311 |
} |
312 |
obj = new Object[features.size()]; |
313 |
for (int i = 0; i < obj.length; i++) { |
314 |
obj[i] = features.get(i); |
315 |
} |
316 |
getSelectedAttributesList() |
317 |
.setListData(features.toArray()); |
318 |
} |
319 |
|
320 |
/**
|
321 |
* Removes all the selected attributes
|
322 |
*/
|
323 |
private void delAllAttributes() { |
324 |
getSelectedAttributesList().setListData(new Object[0]); |
325 |
Object[] obj = getAttributesList().getAllValues(); |
326 |
for (int i = 0; i < obj.length; i++) { |
327 |
WFSAttribute field = (WFSAttribute)obj[i]; |
328 |
if (WFSFilter.isGeometry(field.getType())){
|
329 |
Vector geometry = new Vector(); |
330 |
geometry.add(field); |
331 |
getSelectedAttributesList().setListData(geometry.toArray()); |
332 |
} |
333 |
} |
334 |
} |
335 |
|
336 |
/**
|
337 |
* Adds all the selectable attributes
|
338 |
*
|
339 |
*/
|
340 |
private void addAllAttributes() { |
341 |
ArrayList attributes = new ArrayList(); |
342 |
for (int i = 0; i < getSelectedAttributesList() |
343 |
.getModel().getSize(); i++) { |
344 |
attributes.add(getSelectedAttributesList().getModel() |
345 |
.getElementAt(i)); |
346 |
} |
347 |
|
348 |
Object[] obj = getAttributesList().getAllValues(); |
349 |
for (int i = 0; i < obj.length; i++) { |
350 |
if (!attributes.contains(obj[i]))
|
351 |
attributes.add(obj[i]); |
352 |
} |
353 |
getSelectedAttributesList() |
354 |
.setListData(attributes.toArray()); |
355 |
|
356 |
} |
357 |
|
358 |
/**
|
359 |
*
|
360 |
* @return the selected fields.
|
361 |
*/
|
362 |
public WFSAttribute[] getSelectedFields(){ |
363 |
int numSelected = getSelectedAttributesList().getModel().getSize();
|
364 |
WFSAttribute[] fields = new WFSAttribute[numSelected]; |
365 |
for (int i=0 ; i<fields.length ; i++){ |
366 |
fields[i] = ((WFSAttribute)getSelectedAttributesList().getModel().getElementAt(i)); |
367 |
} |
368 |
return fields;
|
369 |
} |
370 |
} // @jve:decl-index=0:visual-constraint="10,22"
|