root / branches / v10 / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / dialogs / WFSPropsDialog.java @ 9020
History | View | Annotate | Download (13.6 KB)
1 |
package com.iver.cit.gvsig.gui.dialogs; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.net.MalformedURLException; |
7 |
import java.net.URL; |
8 |
import java.util.HashMap; |
9 |
|
10 |
import javax.swing.JButton; |
11 |
import javax.swing.JOptionPane; |
12 |
import javax.swing.JPanel; |
13 |
|
14 |
import org.gvsig.remoteClient.wfs.WFSStatus; |
15 |
|
16 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
17 |
import com.iver.andami.PluginServices; |
18 |
import com.iver.andami.ui.mdiManager.IWindow; |
19 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
20 |
import com.iver.cit.gvsig.fmap.DriverException; |
21 |
import com.iver.cit.gvsig.fmap.MapControl; |
22 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrWFS; |
27 |
import com.iver.cit.gvsig.fmap.layers.FLyrWFSFactory; |
28 |
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode; |
29 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
30 |
import com.iver.cit.gvsig.gui.layout.Layout; |
31 |
import com.iver.cit.gvsig.gui.panels.WFSParamsPanel; |
32 |
import com.iver.cit.gvsig.gui.wizards.WFSWizardData; |
33 |
import com.iver.cit.gvsig.gui.wizards.WizardListener; |
34 |
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport; |
35 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
36 |
|
37 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
38 |
*
|
39 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
40 |
*
|
41 |
* This program is free software; you can redistribute it and/or
|
42 |
* modify it under the terms of the GNU General Public License
|
43 |
* as published by the Free Software Foundation; either version 2
|
44 |
* of the License, or (at your option) any later version.
|
45 |
*
|
46 |
* This program is distributed in the hope that it will be useful,
|
47 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
48 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
49 |
* GNU General Public License for more details.
|
50 |
*
|
51 |
* You should have received a copy of the GNU General Public License
|
52 |
* along with this program; if not, write to the Free Software
|
53 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
54 |
*
|
55 |
* For more information, contact:
|
56 |
*
|
57 |
* Generalitat Valenciana
|
58 |
* Conselleria d'Infraestructures i Transport
|
59 |
* Av. Blasco Ib??ez, 50
|
60 |
* 46010 VALENCIA
|
61 |
* SPAIN
|
62 |
*
|
63 |
* +34 963862235
|
64 |
* gvsig@gva.es
|
65 |
* www.gvsig.gva.es
|
66 |
*
|
67 |
* or
|
68 |
*
|
69 |
* IVER T.I. S.A
|
70 |
* Salamanca 50
|
71 |
* 46005 Valencia
|
72 |
* Spain
|
73 |
*
|
74 |
* +34 963163400
|
75 |
* dac@iver.es
|
76 |
*/
|
77 |
/* CVS MESSAGES:
|
78 |
*
|
79 |
* $Id: WFSPropsDialog.java 9020 2006-11-28 08:04:12Z jorpiell $
|
80 |
* $Log$
|
81 |
* Revision 1.4.2.7 2006-11-28 08:04:12 jorpiell
|
82 |
* Se refercan los mapas despu?s de modificar una capa WFS
|
83 |
*
|
84 |
* Revision 1.4.2.6 2006/11/17 11:28:45 ppiqueras
|
85 |
* Corregidos bugs y a?adida nueva funcionalidad.
|
86 |
*
|
87 |
* Revision 1.13 2006/11/16 16:57:49 jorpiell
|
88 |
* Se copia la laeyenda de la capa anterior antes de eliminarla
|
89 |
*
|
90 |
* Revision 1.12 2006/11/14 13:45:49 ppiqueras
|
91 |
* A?adida peque?a funcionalidad:
|
92 |
* Cuando se pulsa el bot?n "Aplicar", (al seleccionar un nuevo filtro), si el ?rbol de campos posee alguno seleccionado, actualiza los valores (con los nuevos), asociados a ?ste campo seleccionado.
|
93 |
*
|
94 |
* Revision 1.11 2006/10/31 09:40:49 jorpiell
|
95 |
* Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
|
96 |
*
|
97 |
* Revision 1.9 2006/10/23 08:47:12 jorpiell
|
98 |
* Refactorizado un m?todo
|
99 |
*
|
100 |
* Revision 1.8 2006/10/23 08:29:06 ppiqueras
|
101 |
* Algunos cambios
|
102 |
*
|
103 |
* Revision 1.6 2006/10/02 09:09:45 jorpiell
|
104 |
* Cambios del 10 copiados al head
|
105 |
*
|
106 |
* Revision 1.4.2.3 2006/09/27 11:12:15 jorpiell
|
107 |
* Hay que comprobar que se han devuelto un n?mero de features menor que el n?mero m?ximo permitido
|
108 |
*
|
109 |
* Revision 1.4.2.2 2006/09/27 09:15:01 jorpiell
|
110 |
* Ya no se hace otra petici?n al pulsar sobre el bot?n aceptar.
|
111 |
*
|
112 |
* Revision 1.4.2.1 2006/09/19 12:28:11 jorpiell
|
113 |
* Ya no se depende de geotools
|
114 |
*
|
115 |
*
|
116 |
* Revision 1.4 2006/08/30 07:42:29 jorpiell
|
117 |
* Se le asigna a la capa creada una proyecci?n concreta. Si esto no se hace, al exportar a postigis se produce un error.
|
118 |
*
|
119 |
* Revision 1.3 2006/08/29 07:56:12 cesar
|
120 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
121 |
*
|
122 |
* Revision 1.2 2006/08/29 07:13:40 cesar
|
123 |
* Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
124 |
*
|
125 |
* Revision 1.1 2006/06/21 12:35:45 jorpiell
|
126 |
* 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
|
127 |
*
|
128 |
*
|
129 |
*/
|
130 |
/**
|
131 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
132 |
*/
|
133 |
public class WFSPropsDialog extends JPanel implements IWindow{ |
134 |
private WFSParamsPanel wfsParamsTabbedPane = null; |
135 |
private WindowInfo m_ViewInfo = null; |
136 |
private FLayer fLayer = null; |
137 |
private JButton btnApply = null; |
138 |
private JButton btnOk = null; |
139 |
private JButton btnCancel = null; |
140 |
private CommandListener m_actionListener = null; |
141 |
private JPanel buttonsPanel = null; |
142 |
boolean applied = false; |
143 |
|
144 |
|
145 |
public WFSPropsDialog(FLayer layer) {
|
146 |
super();
|
147 |
initialize(layer); |
148 |
} |
149 |
|
150 |
private void initialize(FLayer layer) { |
151 |
setLayout(null);
|
152 |
setFLayer(layer); |
153 |
wfsParamsTabbedPane = getParamsPanel(((FLyrWFS) layer).getProperties()); |
154 |
wfsParamsTabbedPane.addWizardListener(new WizardListener(){
|
155 |
public void wizardStateChanged(boolean finishable) { |
156 |
getBtnOk().setEnabled(finishable); |
157 |
getBtnApply().setEnabled(finishable); |
158 |
} |
159 |
|
160 |
public void error(Exception e) { |
161 |
} |
162 |
|
163 |
}) ; |
164 |
//wfsParamsTabbedPane.disableDisagregatedLayers();
|
165 |
this.add(wfsParamsTabbedPane);
|
166 |
this.add(getButtonsPanel(), null); |
167 |
} |
168 |
|
169 |
public JPanel getButtonsPanel() { |
170 |
if (buttonsPanel == null) { |
171 |
m_actionListener = new CommandListener(this); |
172 |
buttonsPanel = new JPanel(); |
173 |
buttonsPanel.setBounds(5, wfsParamsTabbedPane.getHeight(), 471, 40); |
174 |
buttonsPanel.setLayout(null);
|
175 |
buttonsPanel.setName("buttonPanel");
|
176 |
|
177 |
buttonsPanel.add(getBtnOk(), null);
|
178 |
buttonsPanel.add(getBtnApply(), null);
|
179 |
buttonsPanel.add(getBtnCancel(), null);
|
180 |
} |
181 |
return buttonsPanel;
|
182 |
} |
183 |
|
184 |
|
185 |
/**
|
186 |
* With getParamsPanel we have access to the map config TabbedPane.
|
187 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
188 |
* recovered) it is been automatically constructed by connecting to the server,
|
189 |
* reloading the necessary data, filling up the content and setting the selected
|
190 |
* values that were selected when the projet was saved.
|
191 |
*
|
192 |
*
|
193 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
194 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
195 |
* no path to the server.
|
196 |
*
|
197 |
*
|
198 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
199 |
* del mapa. Si este panel todav?a no existe (como puede ser cuando
|
200 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
201 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
202 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
203 |
* guard? el proyecto.
|
204 |
*
|
205 |
*
|
206 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
207 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
208 |
* hay conexi?n hasta el servidor.
|
209 |
*
|
210 |
*
|
211 |
* @return WMSParamsPanel
|
212 |
*/
|
213 |
public WFSParamsPanel getParamsPanel(HashMap info) { |
214 |
if (info!=null){ |
215 |
try {
|
216 |
URL host = (URL) info.get("host"); |
217 |
WFSWizardData dataSource = new WFSWizardData();
|
218 |
dataSource.setHost(host, false);
|
219 |
|
220 |
WFSParamsPanel toc = new WFSParamsPanel();
|
221 |
toc.setWizardData(dataSource); |
222 |
toc.setListenerSupport(new WizardListenerSupport());
|
223 |
toc.setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
|
224 |
toc.setLayerName(fLayer.getName()); |
225 |
toc.refreshInfo((WFSLayerNode)info.get("wfsLayerNode"));
|
226 |
toc.setStatus((WFSStatus)info.get("status"));
|
227 |
toc.setVisible(true);
|
228 |
applied = false;
|
229 |
return toc;
|
230 |
} catch (DriverException e) {
|
231 |
// TODO Auto-generated catch block
|
232 |
e.printStackTrace(); |
233 |
} |
234 |
} |
235 |
return null; |
236 |
} |
237 |
|
238 |
|
239 |
public WindowInfo getWindowInfo() {
|
240 |
if (m_ViewInfo == null){ |
241 |
m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
242 |
m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WFS_layer")); |
243 |
m_ViewInfo.setWidth(wfsParamsTabbedPane.getWidth()+ 10);
|
244 |
m_ViewInfo.setHeight(wfsParamsTabbedPane.getHeight() + 40);
|
245 |
} |
246 |
return m_ViewInfo;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* @return Returns the fLayer.
|
251 |
*/
|
252 |
public FLayer getFLayer() {
|
253 |
return fLayer;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* @param layer The fLayer to set.
|
258 |
*/
|
259 |
public void setFLayer(FLayer layer) { |
260 |
fLayer = layer; |
261 |
} |
262 |
|
263 |
public JButton getBtnOk() { |
264 |
if (btnOk == null) { |
265 |
btnOk = new JButton("ok"); |
266 |
btnOk.setText(PluginServices.getText(this,"ok")); |
267 |
btnOk.setActionCommand("OK");
|
268 |
btnOk.addActionListener(m_actionListener); |
269 |
btnOk.setBounds(367, 9, 90, 25); |
270 |
} |
271 |
return btnOk;
|
272 |
} |
273 |
|
274 |
public JButton getBtnApply() { |
275 |
if (btnApply == null) { |
276 |
btnApply = new JButton("apply"); |
277 |
btnApply.setText(PluginServices.getText(this,"apply")); |
278 |
btnApply.setEnabled(false);
|
279 |
btnApply.setActionCommand("APPLY");
|
280 |
btnApply.addActionListener(m_actionListener); |
281 |
btnApply.setBounds(267, 9, 90, 25); |
282 |
} |
283 |
return btnApply;
|
284 |
} |
285 |
|
286 |
public JButton getBtnCancel() { |
287 |
if (btnCancel == null) { |
288 |
btnCancel = new JButton("cancel"); |
289 |
btnCancel.setText(PluginServices.getText(this,"cancel")); |
290 |
btnCancel.setActionCommand("CANCEL");
|
291 |
btnCancel.addActionListener(m_actionListener); |
292 |
btnCancel.setBounds(137, 9, 90, 25); |
293 |
} |
294 |
return btnCancel;
|
295 |
} |
296 |
|
297 |
public void close() { |
298 |
PluginServices.getMDIManager().closeWindow(this);
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* Merge two FLayers in one
|
303 |
* @param group1
|
304 |
* @param group2
|
305 |
* @return
|
306 |
*/
|
307 |
private FLayers mergeFLayers(FLayers group1, FLayers group2)
|
308 |
{ |
309 |
FLayer layer; |
310 |
for(int i = 0; i < group2.getLayersCount(); i++) |
311 |
{ |
312 |
layer = group2.getLayer( i ); |
313 |
if(group1.getLayer( layer.getName()) == null ){ |
314 |
group1.addLayer( layer ); |
315 |
} |
316 |
} |
317 |
|
318 |
return group1;
|
319 |
} |
320 |
|
321 |
private class CommandListener implements ActionListener { |
322 |
public CommandListener(WFSPropsDialog tp) {
|
323 |
//m_tp = tp;
|
324 |
} |
325 |
|
326 |
/* (non-Javadoc)
|
327 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
328 |
*/
|
329 |
public void actionPerformed(ActionEvent e) { |
330 |
if (e.getActionCommand() == "CANCEL"){ |
331 |
close(); |
332 |
}else{
|
333 |
String layerName = fLayer.getName();
|
334 |
View activeView = (View) PluginServices.getMDIManager().getActiveWindow(); |
335 |
VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend(); |
336 |
FMapWFSDriver driver = ((FLyrWFS)fLayer).getWfsDriver(); |
337 |
try {
|
338 |
fLayer = wfsParamsTabbedPane.getLayer(); |
339 |
URL host = new URL(wfsParamsTabbedPane.getData().getHost()); |
340 |
String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
|
341 |
fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,false); |
342 |
((FLyrWFS)fLayer).setLegend(legend); |
343 |
} catch (MalformedURLException e1) { |
344 |
// TODO Auto-generated catch block
|
345 |
e1.printStackTrace(); |
346 |
} catch (FieldNotFoundException e1) {
|
347 |
// TODO Auto-generated catch block
|
348 |
e1.printStackTrace(); |
349 |
} catch (DriverException e1) {
|
350 |
// TODO Auto-generated catch block
|
351 |
e1.printStackTrace(); |
352 |
} |
353 |
if (e.getActionCommand() == "APPLY"){ |
354 |
if (loadLayer(fLayer)){
|
355 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
356 |
MapControl mapCtrl = vista.getMapControl(); |
357 |
|
358 |
mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer); |
359 |
wfsParamsTabbedPane.updateWFSFilterFieldValues(); |
360 |
mapCtrl.getMapContext().invalidate(); |
361 |
applied = true;
|
362 |
getBtnApply().setEnabled(!applied); |
363 |
refreshLayouts(); |
364 |
} |
365 |
} |
366 |
if (e.getActionCommand() == "OK") { |
367 |
if (!applied) {
|
368 |
if (getBtnApply().isEnabled()){
|
369 |
if (loadLayer(fLayer)){
|
370 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
371 |
MapControl mapCtrl = vista.getMapControl(); |
372 |
mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer); |
373 |
mapCtrl.getMapContext().invalidate(); |
374 |
refreshLayouts(); |
375 |
} |
376 |
} |
377 |
} |
378 |
close(); |
379 |
} |
380 |
} |
381 |
} |
382 |
private boolean loadLayer(FLayer flayer){ |
383 |
try {
|
384 |
((FLyrWFS)fLayer).load(); |
385 |
|
386 |
if (((FLyrWFS)fLayer).getNumfeatures() == ((FLyrWFS)fLayer).getWfsDriver().getRowCount()) {
|
387 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
388 |
PluginServices.getText(this,"maxFeatures_aviso")); |
389 |
} |
390 |
} catch (Exception e1) { |
391 |
// TODO Auto-generated catch block
|
392 |
e1.printStackTrace(); |
393 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
394 |
PluginServices.getText(this,"cantLoad")); |
395 |
return false; |
396 |
} |
397 |
return true; |
398 |
} |
399 |
|
400 |
} |
401 |
|
402 |
/**
|
403 |
* @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
|
404 |
*/
|
405 |
public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) { |
406 |
this.wfsParamsTabbedPane.setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* Refresh the layouts
|
411 |
*
|
412 |
*/
|
413 |
private void refreshLayouts(){ |
414 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
415 |
for (int i=0 ; i<windows.length ; i++){ |
416 |
if (windows[i] instanceof Layout){ |
417 |
((Layout)windows[i]).fullRefresh(); |
418 |
} |
419 |
} |
420 |
} |
421 |
} |
422 |
|