svn-gvsig-desktop / tags / v2_0_0_Build_2058 / extensions / extWFS2 / src / org / gvsig / wfs / gui / wizards / WFSWizard.java @ 39235
History | View | Annotate | Download (29.9 KB)
1 |
package org.gvsig.wfs.gui.wizards; |
---|---|
2 |
|
3 |
import java.awt.FlowLayout; |
4 |
import java.awt.event.KeyAdapter; |
5 |
import java.awt.event.KeyEvent; |
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.net.MalformedURLException; |
8 |
import java.net.URL; |
9 |
import java.util.ArrayList; |
10 |
import java.util.Iterator; |
11 |
import java.util.List; |
12 |
import java.util.prefs.Preferences; |
13 |
|
14 |
import javax.swing.DefaultComboBoxModel; |
15 |
import javax.swing.JCheckBox; |
16 |
import javax.swing.JComboBox; |
17 |
import javax.swing.JLabel; |
18 |
import javax.swing.JOptionPane; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JTabbedPane; |
21 |
import javax.swing.event.ChangeEvent; |
22 |
import javax.swing.event.ChangeListener; |
23 |
|
24 |
import org.gvsig.andami.PluginServices; |
25 |
import org.gvsig.andami.messages.NotificationManager; |
26 |
import org.gvsig.andami.persistence.serverData.ServerDataPersistence; |
27 |
import org.gvsig.app.gui.WizardPanel; |
28 |
import org.gvsig.app.panelGroup.loaders.PanelGroupLoaderFromExtensionPoint; |
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataManager; |
31 |
import org.gvsig.fmap.dal.DataStoreParameters; |
32 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
33 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters; |
34 |
import org.gvsig.gui.beans.Messages; |
35 |
import org.gvsig.gui.beans.panelGroup.PanelGroupManager; |
36 |
import org.gvsig.gui.beans.swing.JButton; |
37 |
import org.gvsig.tools.exception.BaseException; |
38 |
import org.gvsig.utils.NotExistInXMLEntity; |
39 |
import org.gvsig.utils.XMLEntity; |
40 |
import org.gvsig.utils.swing.jcomboServer.JComboServer; |
41 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
42 |
import org.gvsig.wfs.gui.panels.WFSParamsPanel; |
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
47 |
*
|
48 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
49 |
*
|
50 |
* This program is free software; you can redistribute it and/or
|
51 |
* modify it under the terms of the GNU General Public License
|
52 |
* as published by the Free Software Foundation; either version 2
|
53 |
* of the License, or (at your option) any later version.
|
54 |
*
|
55 |
* This program is distributed in the hope that it will be useful,
|
56 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
57 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
58 |
* GNU General Public License for more details.
|
59 |
*
|
60 |
* You should have received a copy of the GNU General Public License
|
61 |
* along with this program; if not, write to the Free Software
|
62 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
63 |
*
|
64 |
* For more information, contact:
|
65 |
*
|
66 |
* Generalitat Valenciana
|
67 |
* Conselleria d'Infraestructures i Transport
|
68 |
* Av. Blasco Ib??ez, 50
|
69 |
* 46010 VALENCIA
|
70 |
* SPAIN
|
71 |
*
|
72 |
* +34 963862235
|
73 |
* gvsig@gva.es
|
74 |
* www.gvsig.gva.es
|
75 |
*
|
76 |
* or
|
77 |
*
|
78 |
* IVER T.I. S.A
|
79 |
* Salamanca 50
|
80 |
* 46005 Valencia
|
81 |
* Spain
|
82 |
*
|
83 |
* +34 963163400
|
84 |
* dac@iver.es
|
85 |
*/
|
86 |
|
87 |
/**
|
88 |
* <p>
|
89 |
* Wizard that allows add a new WFS layer.
|
90 |
* </p>
|
91 |
*
|
92 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
93 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
94 |
*/
|
95 |
public class WFSWizard extends WizardPanel { |
96 |
|
97 |
private static Logger logger = LoggerFactory.getLogger(WFSWizard.class); |
98 |
private int page; |
99 |
private boolean connected = false; |
100 |
private JComboServer cmbHost = null; |
101 |
private JButton btnConnect = null; |
102 |
private javax.swing.JPanel jPanel = null; |
103 |
private javax.swing.JLabel jLabel1 = null; |
104 |
private javax.swing.JLabel lblTitle = null; |
105 |
private javax.swing.JScrollPane jScrollPane = null; |
106 |
private javax.swing.JTextArea txtAbstract = null; |
107 |
private javax.swing.JPanel panelPage1 = null; |
108 |
private javax.swing.JPanel pnlName = null; |
109 |
private JButton btnSiguiente = null; |
110 |
private JButton btnAnterior = null; |
111 |
private JComboBox cmbCache = null; |
112 |
private javax.swing.JPanel jPanel1 = null; |
113 |
private WFSParamsPanel wfsParamsPanel = null; |
114 |
private WFSWizard thisWFSPanel = null; |
115 |
private WFSServerExplorer serverExplorer = null; |
116 |
private JLabel lblServerType = null; |
117 |
private JLabel lblServerTypeValue = null; |
118 |
private JCheckBox chkCaching = null; |
119 |
private static Preferences fPrefs = Preferences.userRoot().node( |
120 |
"gvsig.wfs-wizard");
|
121 |
private boolean refreshing = fPrefs.getBoolean("refresh_capabilities", |
122 |
false);
|
123 |
private final String wfs_properties_extensionpoint_name = |
124 |
"WFSPropertiesDialog";
|
125 |
|
126 |
/**
|
127 |
* This is the default constructor
|
128 |
*/
|
129 |
public WFSWizard() {
|
130 |
super();
|
131 |
initialize(); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* This method initializes this
|
136 |
*/
|
137 |
private void initialize() { |
138 |
setTabName(PluginServices.getText(this, "WFS")); |
139 |
|
140 |
lblServerType = new JLabel(); |
141 |
lblServerType.setBounds(20, 444, 100, 20); |
142 |
lblServerType.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
143 |
lblServerType |
144 |
.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); |
145 |
lblServerType.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, |
146 |
11));
|
147 |
lblServerType |
148 |
.setText(PluginServices.getText(this, "server_type") + ":"); |
149 |
lblServerTypeValue = new JLabel(); |
150 |
lblServerTypeValue.setBounds(128, 444, 148, 20); |
151 |
lblServerTypeValue.setFont(new java.awt.Font("Arial", |
152 |
java.awt.Font.BOLD, 11));
|
153 |
lblServerTypeValue.setText("-");
|
154 |
|
155 |
cmbCache = new JComboBox(); |
156 |
|
157 |
cmbCache.addItem(PluginServices.getText(this, "none")); |
158 |
|
159 |
cmbCache.setEnabled(false);
|
160 |
cmbCache.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 11)); |
161 |
cmbCache.setBounds(40, 460, 180, 20); |
162 |
|
163 |
this.setLayout(null); |
164 |
this.setVisible(true); |
165 |
|
166 |
this.add(getPanelPage1(), null); |
167 |
page = 0;
|
168 |
this.add(getPanelPage2(), null); |
169 |
|
170 |
this.add(getBtnAnterior(), null); |
171 |
this.add(getBtnSiguiente(), null); |
172 |
|
173 |
this.add(lblServerType, null); |
174 |
this.add(lblServerTypeValue, null); |
175 |
this.add(cmbCache, null); |
176 |
|
177 |
uptateNavigatingButtons(); |
178 |
|
179 |
thisWFSPanel = this;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* Adds the host addres to a persistent data storage.
|
184 |
*
|
185 |
* @param host
|
186 |
* the host of the server
|
187 |
*/
|
188 |
private void addHost(String host) { |
189 |
host = host.trim(); |
190 |
ServerDataPersistence persistence = |
191 |
new ServerDataPersistence(this, ServerData.SERVER_TYPE_WFS); |
192 |
persistence.addServerData(new ServerData(host,
|
193 |
ServerData.SERVER_TYPE_WFS)); |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Fills up the initial WCSWizard controls.
|
198 |
*
|
199 |
* jaume
|
200 |
*/
|
201 |
private void rellenarControles() throws Exception { |
202 |
try {
|
203 |
String url = cmbHost.getModel().getSelectedItem().toString();
|
204 |
|
205 |
DataManager dataManager = DALLocator.getDataManager(); |
206 |
// Create the server explorer parameters
|
207 |
WFSServerExplorerParameters parameters = |
208 |
(WFSServerExplorerParameters) dataManager |
209 |
.createServerExplorerParameters(WFSServerExplorer.NAME); |
210 |
parameters.setUrl(url); |
211 |
addHost(url); |
212 |
// Create the server explorer
|
213 |
serverExplorer = |
214 |
(WFSServerExplorer) dataManager |
215 |
.createServerExplorer(parameters); |
216 |
|
217 |
// Update the forms
|
218 |
getLblTitle().setText(serverExplorer.getTitle()); |
219 |
getTxtAbstract().setText(serverExplorer.getAbstract()); |
220 |
lblServerTypeValue.setText(serverExplorer.getServerType()); |
221 |
|
222 |
List cacheProviders = dataManager.getFeatureCacheProviders();
|
223 |
Iterator<String> iter = cacheProviders.iterator(); |
224 |
|
225 |
while (iter.hasNext()) {
|
226 |
String featureCacheProvider = (String) iter.next(); |
227 |
cmbCache.addItem(featureCacheProvider); |
228 |
} |
229 |
|
230 |
if (!serverExplorer.getServerType().toLowerCase()
|
231 |
.startsWith("wfs 1.0")) {
|
232 |
cmbCache.setEnabled(true);
|
233 |
} else {
|
234 |
cmbCache.setEnabled(false);
|
235 |
} |
236 |
wfsParamsPanel.setServerExplorer(serverExplorer); |
237 |
connected = true;
|
238 |
} catch (Exception e) { |
239 |
throw e;
|
240 |
} |
241 |
} |
242 |
|
243 |
/**
|
244 |
* Enables or disables the Next and Previous buttons according with the
|
245 |
* current
|
246 |
* page and the enabled pages.
|
247 |
*/
|
248 |
private void uptateNavigatingButtons() { |
249 |
if (page == 0) { |
250 |
getBtnAnterior().setEnabled(false);
|
251 |
getBtnSiguiente().setVisible(true);
|
252 |
getBtnSiguiente().setEnabled(false);
|
253 |
} else {
|
254 |
short tabIndex = (short) wfsParamsPanel.getSelectedIndex(); |
255 |
|
256 |
getBtnAnterior().setEnabled(true);
|
257 |
if (wfsParamsPanel.nextPageEnabled() == -1) { |
258 |
getBtnSiguiente().setEnabled(false);
|
259 |
|
260 |
if (tabIndex == (wfsParamsPanel.getPanelInGUICount() - 1)) |
261 |
getBtnSiguiente().setVisible(false);
|
262 |
} else {
|
263 |
getBtnSiguiente().setVisible(true);
|
264 |
getBtnSiguiente().setEnabled(true);
|
265 |
} |
266 |
} |
267 |
} |
268 |
|
269 |
/**
|
270 |
* This method initializes txtHost from the persistent data storage
|
271 |
*
|
272 |
* @return javax.swing.JTextField
|
273 |
*/
|
274 |
private javax.swing.JComboBox getTxtHost() {
|
275 |
if (cmbHost == null) { |
276 |
cmbHost = new JComboServer();
|
277 |
cmbHost.setModel(new DefaultComboBoxModel()); |
278 |
cmbHost.setPreferredSize(new java.awt.Dimension(350, 20)); |
279 |
cmbHost.setBounds(11, 26, 454, 20); |
280 |
cmbHost.setEditable(true);
|
281 |
|
282 |
ServerDataPersistence persistence = |
283 |
new ServerDataPersistence(this, ServerData.SERVER_TYPE_WFS); |
284 |
ServerData[] servers = persistence.getArrayOfServerData();
|
285 |
|
286 |
if (servers.length == 0) { |
287 |
PluginServices ps = PluginServices.getPluginServices(this);
|
288 |
XMLEntity xml = ps.getPersistentXML(); |
289 |
try {
|
290 |
String[] oldServers = |
291 |
xml.getStringArrayProperty("wfs-servers");
|
292 |
servers = new ServerData[oldServers.length];
|
293 |
for (int i = 0; i < oldServers.length; i++) { |
294 |
servers[i] = |
295 |
new ServerData(oldServers[i],
|
296 |
ServerData.SERVER_TYPE_WMS); |
297 |
} |
298 |
xml.remove("wfs-servers");
|
299 |
ps.setPersistentXML(xml); |
300 |
} catch (NotExistInXMLEntity e) {
|
301 |
// Old servers doesn't exist
|
302 |
servers = new ServerData[2]; |
303 |
servers[0] =
|
304 |
new ServerData(
|
305 |
"http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap",
|
306 |
ServerData.SERVER_TYPE_WFS); |
307 |
servers[1] =
|
308 |
new ServerData(
|
309 |
"http://www.idee.es/IDEE-WFS/ogcwebservice",
|
310 |
ServerData.SERVER_TYPE_WFS); |
311 |
} |
312 |
|
313 |
for (int i = 0; i < servers.length; i++) { |
314 |
persistence.addServerData(servers[i]); |
315 |
} |
316 |
persistence.setPersistent(); |
317 |
} |
318 |
|
319 |
cmbHost.setServerList(servers); |
320 |
|
321 |
// Allows that user can start the connection to the written server
|
322 |
// pressing the 'Enter' key
|
323 |
cmbHost.getEditor().getEditorComponent() |
324 |
.addKeyListener(new KeyAdapter() { |
325 |
|
326 |
/*
|
327 |
* (non-Javadoc)
|
328 |
*
|
329 |
* @see
|
330 |
* java.awt.event.KeyAdapter#keyReleased(java.awt.event.
|
331 |
* KeyEvent)
|
332 |
*/
|
333 |
public void keyReleased(KeyEvent e) { |
334 |
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
335 |
getBtnConnect().doClick(); |
336 |
} |
337 |
} |
338 |
}); |
339 |
} |
340 |
return cmbHost;
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* This method initializes btnDetalles
|
345 |
*
|
346 |
* @return JButton
|
347 |
*/
|
348 |
private JButton getBtnConnect() { |
349 |
if (btnConnect == null) { |
350 |
btnConnect = new JButton(); |
351 |
btnConnect.setPreferredSize(new java.awt.Dimension(100, 20)); |
352 |
btnConnect.setBounds(366, 50, 100, 20); |
353 |
btnConnect.setText(PluginServices.getText(this, "connect")); |
354 |
btnConnect.addActionListener(new java.awt.event.ActionListener() {
|
355 |
|
356 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
357 |
|
358 |
/*
|
359 |
* Check if there is a suspicious parameter in URL
|
360 |
* The user should approve it
|
361 |
*/
|
362 |
if (!checkServerUrl()) {
|
363 |
return;
|
364 |
} |
365 |
|
366 |
btnConnect.setEnabled(false); // This avoids multiple |
367 |
// contiguous actions
|
368 |
|
369 |
try {
|
370 |
rellenarControles(); |
371 |
wfsParamsPanel.refreshCapabilitiesInfo(); |
372 |
wfsParamsPanel.refreshWFSSelectFeaturePanel(); |
373 |
wfsParamsPanel.enableDefaultTabs(false);
|
374 |
btnConnect.setEnabled(true); // This avoids multiple |
375 |
// contiguous actions
|
376 |
|
377 |
getBtnSiguiente().setEnabled(true);
|
378 |
getBtnSiguiente().requestFocus(); // Sets focus to the
|
379 |
// 'next' button
|
380 |
} catch (Exception e1) { |
381 |
NotificationManager.showMessageWarning( |
382 |
Messages.getText("invalid_url"), e1);
|
383 |
btnConnect.setEnabled(true);
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* Force panel not valid because connect button
|
388 |
* has been pressed
|
389 |
*/
|
390 |
thisWFSPanel.callStateChanged(false);
|
391 |
} |
392 |
|
393 |
|
394 |
}); |
395 |
|
396 |
// If user press the 'Enter' key -> advance
|
397 |
btnConnect.addKeyListener(new KeyAdapter() { |
398 |
|
399 |
/*
|
400 |
* (non-Javadoc)
|
401 |
*
|
402 |
* @see
|
403 |
* java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent
|
404 |
* )
|
405 |
*/
|
406 |
public void keyReleased(KeyEvent e) { |
407 |
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
408 |
btnConnect.doClick(); |
409 |
} |
410 |
} |
411 |
}); |
412 |
} |
413 |
|
414 |
return btnConnect;
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* This method initializes jPanel
|
419 |
*
|
420 |
* @return javax.swing.JPanel
|
421 |
*/
|
422 |
private javax.swing.JPanel getJPanel() {
|
423 |
if (jPanel == null) { |
424 |
jPanel = new javax.swing.JPanel();
|
425 |
jPanel.setLayout(null);
|
426 |
jPanel.setPreferredSize(new java.awt.Dimension(470, 130)); |
427 |
jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
428 |
PluginServices.getText(this, "descripcion"), |
429 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
430 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
431 |
jPanel.setBounds(2, 96, 477, 324); |
432 |
jPanel.add(getJScrollPane(), null);
|
433 |
jPanel.add(getPnlName(), null);
|
434 |
} |
435 |
|
436 |
return jPanel;
|
437 |
} |
438 |
|
439 |
/**
|
440 |
* This method initializes pnlName
|
441 |
*
|
442 |
* @return javax.swing.JPanel
|
443 |
*/
|
444 |
private JPanel getPnlName() { |
445 |
if (pnlName == null) { |
446 |
pnlName = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0)); |
447 |
pnlName.setBounds(new java.awt.Rectangle(9, 19, 452, 24)); |
448 |
pnlName.add(getJLabel1(), null);
|
449 |
pnlName.add(getLblTitle(), null);
|
450 |
} |
451 |
return pnlName;
|
452 |
} |
453 |
|
454 |
/**
|
455 |
* This method initializes jLabel1
|
456 |
*
|
457 |
* @return javax.swing.JLabel
|
458 |
*/
|
459 |
private javax.swing.JLabel getJLabel1() {
|
460 |
if (jLabel1 == null) { |
461 |
jLabel1 = new javax.swing.JLabel();
|
462 |
jLabel1.setText(PluginServices.getText(this, "nombre") + ":"); |
463 |
jLabel1.setBounds(15, 26, 65, 15); |
464 |
} |
465 |
|
466 |
return jLabel1;
|
467 |
} |
468 |
|
469 |
/**
|
470 |
* This method initializes lblTitle
|
471 |
*
|
472 |
* @return javax.swing.JLabel
|
473 |
*/
|
474 |
private javax.swing.JLabel getLblTitle() {
|
475 |
if (lblTitle == null) { |
476 |
lblTitle = new javax.swing.JLabel();
|
477 |
lblTitle.setText("-");
|
478 |
lblTitle.setPreferredSize(new java.awt.Dimension(350, 16)); |
479 |
lblTitle.setBounds(82, 26, 350, 16); |
480 |
} |
481 |
|
482 |
return lblTitle;
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* This method initializes jScrollPane
|
487 |
*
|
488 |
* @return javax.swing.JScrollPane
|
489 |
*/
|
490 |
private javax.swing.JScrollPane getJScrollPane() {
|
491 |
if (jScrollPane == null) { |
492 |
jScrollPane = new javax.swing.JScrollPane();
|
493 |
jScrollPane.setViewportView(getTxtAbstract()); |
494 |
jScrollPane.setPreferredSize(new java.awt.Dimension(450, 60)); |
495 |
jScrollPane.setBounds(10, 47, 457, 267); |
496 |
} |
497 |
|
498 |
return jScrollPane;
|
499 |
} |
500 |
|
501 |
/**
|
502 |
* This method initializes txtAbstract
|
503 |
*
|
504 |
* @return javax.swing.JTextArea
|
505 |
*/
|
506 |
private javax.swing.JTextArea getTxtAbstract() {
|
507 |
if (txtAbstract == null) { |
508 |
txtAbstract = new javax.swing.JTextArea();
|
509 |
txtAbstract.setWrapStyleWord(true);
|
510 |
txtAbstract.setColumns(30);
|
511 |
txtAbstract.setLineWrap(true);
|
512 |
} |
513 |
|
514 |
return txtAbstract;
|
515 |
} |
516 |
|
517 |
/**
|
518 |
* This method initializes panelPage1
|
519 |
*
|
520 |
* @return javax.swing.JPanel
|
521 |
*/
|
522 |
private javax.swing.JPanel getPanelPage1() {
|
523 |
if (panelPage1 == null) { |
524 |
panelPage1 = new javax.swing.JPanel();
|
525 |
panelPage1.setLayout(null);
|
526 |
panelPage1.setPreferredSize(new java.awt.Dimension(480, 220)); |
527 |
panelPage1.setVisible(true);
|
528 |
panelPage1.setBounds(15, 5, 480, 427); |
529 |
panelPage1.add(getJPanel1(), null);
|
530 |
panelPage1.add(getJPanel(), null);
|
531 |
} |
532 |
|
533 |
return panelPage1;
|
534 |
} |
535 |
|
536 |
/**
|
537 |
* This method initializes panelPage2
|
538 |
*
|
539 |
* @return javax.swing.JPanel
|
540 |
*/
|
541 |
private javax.swing.JPanel getPanelPage2() {
|
542 |
if (wfsParamsPanel == null) { |
543 |
|
544 |
try {
|
545 |
PanelGroupManager manager = PanelGroupManager.getManager(); |
546 |
manager.registerPanelGroup(WFSParamsPanel.class); |
547 |
manager.setDefaultType(WFSParamsPanel.class); |
548 |
|
549 |
// Initially there is no layer
|
550 |
wfsParamsPanel = (WFSParamsPanel) manager.getPanelGroup(null);
|
551 |
wfsParamsPanel.setBounds(4, 9, 502, 423); |
552 |
wfsParamsPanel |
553 |
.loadPanels(new PanelGroupLoaderFromExtensionPoint(
|
554 |
wfs_properties_extensionpoint_name)); |
555 |
wfsParamsPanel.addChangeListener(new ChangeListener() { |
556 |
|
557 |
// This method is called whenever the selected tab changes
|
558 |
public void stateChanged(ChangeEvent evt) { |
559 |
JTabbedPane pane = (JTabbedPane) evt.getSource(); |
560 |
|
561 |
// Update the navigation buttons
|
562 |
uptateNavigatingButtons(); |
563 |
} |
564 |
}); |
565 |
} catch (BaseException bE) {
|
566 |
NotificationManager.showMessageError( |
567 |
bE.getLocalizedMessageStack(), bE); |
568 |
} catch (Exception e) { |
569 |
NotificationManager |
570 |
.showMessageError(e.getLocalizedMessage(), e); |
571 |
} |
572 |
} |
573 |
|
574 |
return wfsParamsPanel;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* This method initializes btnSiguiente
|
579 |
*
|
580 |
* @return JButton
|
581 |
*/
|
582 |
private JButton getBtnSiguiente() { |
583 |
if (btnSiguiente == null) { |
584 |
btnSiguiente = new JButton(); |
585 |
btnSiguiente.setPreferredSize(new java.awt.Dimension(100, 30)); |
586 |
btnSiguiente.setBounds(395, 444, 100, 20); |
587 |
btnSiguiente.setText(PluginServices.getText(this, "siguiente")); |
588 |
btnSiguiente.addActionListener(new java.awt.event.ActionListener() {
|
589 |
|
590 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
591 |
if (page == 0) { |
592 |
page = 1;
|
593 |
getPanelPage1().setVisible(false);
|
594 |
getPanelPage2().setVisible(true);
|
595 |
} else {
|
596 |
wfsParamsPanel.goToNextTab(); |
597 |
} |
598 |
|
599 |
uptateNavigatingButtons(); |
600 |
} |
601 |
}); |
602 |
} |
603 |
return btnSiguiente;
|
604 |
} |
605 |
|
606 |
/**
|
607 |
* This method initializes btnAnterior
|
608 |
*
|
609 |
* @return JButton
|
610 |
*/
|
611 |
private JButton getBtnAnterior() { |
612 |
if (btnAnterior == null) { |
613 |
btnAnterior = new JButton(); |
614 |
btnAnterior.setBounds(292, 444, 100, 20); |
615 |
btnAnterior.setText(PluginServices.getText(this, "anterior")); |
616 |
btnAnterior.setPreferredSize(new java.awt.Dimension(100, 30)); |
617 |
btnAnterior.addActionListener(new java.awt.event.ActionListener() {
|
618 |
|
619 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
620 |
int tabIndex = wfsParamsPanel.getSelectedIndex();
|
621 |
|
622 |
if (page == 1) { |
623 |
if (tabIndex == 0) { |
624 |
page = 0;
|
625 |
connected = false;
|
626 |
|
627 |
wfsParamsPanel.enableDefaultTabs(false);
|
628 |
getLblTitle().setText("-");
|
629 |
getTxtAbstract().setText("");
|
630 |
|
631 |
getPanelPage2().setVisible(false);
|
632 |
getPanelPage1().setVisible(true);
|
633 |
} else {
|
634 |
wfsParamsPanel.goToPreviousTab(); |
635 |
} |
636 |
} else {
|
637 |
|
638 |
} |
639 |
|
640 |
uptateNavigatingButtons(); |
641 |
} |
642 |
}); |
643 |
} |
644 |
return btnAnterior;
|
645 |
} |
646 |
|
647 |
/**
|
648 |
* This method initializes jPanel1
|
649 |
*
|
650 |
* @return javax.swing.JPanel
|
651 |
*/
|
652 |
private javax.swing.JPanel getJPanel1() {
|
653 |
if (jPanel1 == null) { |
654 |
jPanel1 = new javax.swing.JPanel();
|
655 |
jPanel1.setLayout(null);
|
656 |
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder( |
657 |
null, PluginServices.getText(this, "server"), |
658 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
659 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
660 |
jPanel1.setBounds(2, 5, 477, 85); |
661 |
jPanel1.add(getTxtHost(), null);
|
662 |
jPanel1.add(getBtnConnect(), null);
|
663 |
jPanel1.add(getChkCaching(), null);
|
664 |
} |
665 |
|
666 |
return jPanel1;
|
667 |
} |
668 |
|
669 |
/**
|
670 |
* Returns the wizard's data source
|
671 |
*
|
672 |
* @return the wizard's data source
|
673 |
*/
|
674 |
public WFSServerExplorer getServerExplorer() {
|
675 |
return serverExplorer;
|
676 |
} |
677 |
|
678 |
|
679 |
|
680 |
/**
|
681 |
* Returns the rectangle that contains all the others
|
682 |
*
|
683 |
* @param rects
|
684 |
* [] rectangles with its positions and dimensions
|
685 |
*
|
686 |
* @return Rectangle2D the rectangle that contains all the others
|
687 |
*/
|
688 |
public static Rectangle2D getRectangle(Rectangle2D[] rects) { |
689 |
Rectangle2D ret = rects[0]; |
690 |
|
691 |
for (int i = 1; i < rects.length; i++) { |
692 |
ret.add(rects[i]); |
693 |
} |
694 |
|
695 |
return ret;
|
696 |
} |
697 |
|
698 |
/**
|
699 |
* Returns the host typed in the host text field or null if nothing is typed
|
700 |
* or it is not a valid URL.
|
701 |
*
|
702 |
* @return URL del host
|
703 |
*/
|
704 |
public URL getHost() { |
705 |
try {
|
706 |
return new URL(cmbHost.getModel().getSelectedItem().toString()); |
707 |
} catch (MalformedURLException e) { |
708 |
return null; |
709 |
} |
710 |
} |
711 |
|
712 |
/*
|
713 |
* (non-Javadoc)
|
714 |
*
|
715 |
* @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
|
716 |
*/
|
717 |
public void initWizard() { |
718 |
// setServerExplorer(new WFSWizardData());
|
719 |
} |
720 |
|
721 |
/*
|
722 |
* (non-Javadoc)
|
723 |
*
|
724 |
* @see com.iver.cit.gvsig.gui.WizardPanel#execute()
|
725 |
*/
|
726 |
public void execute() { |
727 |
wfsParamsPanel.setSelectedCache(cmbCache.getSelectedItem().toString()); |
728 |
String layerName = wfsParamsPanel.getFeaturesPanel().getLayerName();
|
729 |
DataStoreParameters parameters; |
730 |
try {
|
731 |
//
|
732 |
// TODO: La proyeccion deberia ir en los parametros ?? !!!!!!!!!
|
733 |
//
|
734 |
parameters = wfsParamsPanel.getDataStoreParameters(); |
735 |
} catch (Exception e) { |
736 |
logger.warn("Can't make the parameters of the wfs layer", e);
|
737 |
JOptionPane.showMessageDialog(null, |
738 |
PluginServices.getText(this, "_cant_create_wfslayer"), |
739 |
"addLayer", JOptionPane.WARNING_MESSAGE |
740 |
+ JOptionPane.OK_OPTION);
|
741 |
return;
|
742 |
} |
743 |
doAddLayer(getMapCtrl(), layerName, parameters); |
744 |
} |
745 |
|
746 |
/**
|
747 |
* This method initializes chkCaching
|
748 |
*
|
749 |
* @return javax.swing.JCheckBox
|
750 |
*/
|
751 |
private JCheckBox getChkCaching() { |
752 |
if (chkCaching == null) { |
753 |
chkCaching = new JCheckBox(); |
754 |
chkCaching.setBounds(7, 51, 349, 20); |
755 |
chkCaching.setText(PluginServices.getText(this,
|
756 |
"refresh_capabilities"));
|
757 |
chkCaching.setToolTipText(PluginServices.getText(this,
|
758 |
"refresh_capabilities_tooltip"));
|
759 |
chkCaching.setSelected(refreshing); |
760 |
chkCaching.addItemListener(new java.awt.event.ItemListener() {
|
761 |
|
762 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
763 |
refreshing = chkCaching.isSelected(); |
764 |
} |
765 |
}); |
766 |
chkCaching.addActionListener(new java.awt.event.ActionListener() {
|
767 |
|
768 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
769 |
chkCaching.setEnabled(false); // This avoids multiple |
770 |
// contiguous actions
|
771 |
fPrefs.putBoolean("refresh_capabilities",
|
772 |
chkCaching.isSelected()); |
773 |
chkCaching.setEnabled(true); // This avoids multiple |
774 |
// contiguous actions
|
775 |
} |
776 |
}); |
777 |
|
778 |
} |
779 |
return chkCaching;
|
780 |
} |
781 |
|
782 |
/**
|
783 |
* This method makes the 'btnSiguiente' to be clicked
|
784 |
*/
|
785 |
public void doClickOnNextButton() { |
786 |
getBtnSiguiente().doClick(); |
787 |
} |
788 |
|
789 |
/*
|
790 |
* (non-Javadoc)
|
791 |
*
|
792 |
* @see com.iver.cit.gvsig.gui.WizardPanel#getParameters()
|
793 |
*/
|
794 |
public DataStoreParameters[] getParameters() { |
795 |
// TODO Auto-generated method stub
|
796 |
return null; |
797 |
} |
798 |
|
799 |
@Override
|
800 |
public void close() { |
801 |
if (serverExplorer != null) { |
802 |
serverExplorer.dispose(); |
803 |
} |
804 |
} |
805 |
|
806 |
|
807 |
|
808 |
/**
|
809 |
* This method is called when user changes tab in add layer dialog
|
810 |
*/
|
811 |
public boolean areSettingsValid() { |
812 |
if (wfsParamsPanel != null) { |
813 |
return wfsParamsPanel.isCorretlyConfigured();
|
814 |
} else {
|
815 |
return false; |
816 |
} |
817 |
} |
818 |
|
819 |
|
820 |
|
821 |
/**
|
822 |
* This method suggests user to remove suspicious parameters
|
823 |
* such as "request=..."
|
824 |
*/
|
825 |
private boolean checkServerUrl() { |
826 |
|
827 |
Object sel_obj = cmbHost.getModel().getSelectedItem();
|
828 |
if (sel_obj != null) { |
829 |
|
830 |
String url = sel_obj.toString();
|
831 |
List<String> suspi = getSuspiciousParameters(url); |
832 |
if (suspi != null && suspi.size() > 0) { |
833 |
if (userWantsToContinue(suspi)) {
|
834 |
// user says url ok anyway
|
835 |
return true; |
836 |
} else {
|
837 |
// user wants to fix url by hand
|
838 |
return false; |
839 |
} |
840 |
} else {
|
841 |
// url is ok
|
842 |
return true; |
843 |
} |
844 |
} else {
|
845 |
// no selection in combo
|
846 |
return false; |
847 |
} |
848 |
} |
849 |
|
850 |
/**
|
851 |
* @param suspi
|
852 |
* @return
|
853 |
*/
|
854 |
private boolean userWantsToContinue(List<String> suspi) { |
855 |
|
856 |
String tit = PluginServices.getText(this, "server"); |
857 |
String msg = PluginServices.getText(this, "Dangerous_parameters_found_Continue_question"); |
858 |
int len = suspi.size();
|
859 |
msg = msg + " '";
|
860 |
for (int i=0; i<(len-1); i++) { |
861 |
msg = msg + suspi.get(i) + ", ";
|
862 |
} |
863 |
msg = msg + suspi.get(len-1) + "'"; |
864 |
|
865 |
int user_opt = JOptionPane.showConfirmDialog( |
866 |
thisWFSPanel, msg, tit, JOptionPane.YES_NO_OPTION);
|
867 |
|
868 |
return user_opt == JOptionPane.YES_OPTION; |
869 |
} |
870 |
|
871 |
/**
|
872 |
* @param url
|
873 |
* @return
|
874 |
*/
|
875 |
private List<String> getSuspiciousParameters(String _url) { |
876 |
|
877 |
String str_url = _url;
|
878 |
int len = SUSPICIOUS_PARAMS.length;
|
879 |
String item = null; |
880 |
ArrayList<String> resp = new ArrayList<String>(); |
881 |
for (int i=0; i<len; i++) { |
882 |
item = SUSPICIOUS_PARAMS[i]; |
883 |
item = "&" + item + "="; |
884 |
if (str_url.indexOf(item) != -1) { |
885 |
resp.add(SUSPICIOUS_PARAMS[i]); |
886 |
} |
887 |
} |
888 |
return resp;
|
889 |
} |
890 |
|
891 |
private static final String[] SUSPICIOUS_PARAMS = |
892 |
{ "request" }; // , ""}; |
893 |
} |