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