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