root / branches / v05 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / search / SearchDialogPanel.java @ 3928
History | View | Annotate | Download (15.3 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package es.gva.cit.gazetteer.ui.search; |
43 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
44 |
import es.gva.cit.catalogClient.traductor.ITranslator; |
45 |
import es.gva.cit.catalogClient.traductor.Translator; |
46 |
import es.gva.cit.gazetteer.GazetteerClient; |
47 |
import es.gva.cit.gazetteer.querys.Feature; |
48 |
import es.gva.cit.gazetteer.querys.Query; |
49 |
import es.gva.cit.gazetteer.querys.ThesaurusName; |
50 |
import es.gva.cit.gazetteer.ui.showResults.ShowResultsDialog; |
51 |
import es.gva.cit.gazetteer.wfsg.parsers.WfsgDescribeFeatureTypeParser; |
52 |
import java.awt.Cursor; |
53 |
import java.awt.Dimension; |
54 |
import java.awt.FlowLayout; |
55 |
import java.awt.event.ActionEvent; |
56 |
import java.awt.event.ActionListener; |
57 |
import java.util.Collection; |
58 |
import javax.swing.BoxLayout; |
59 |
import javax.swing.JButton; |
60 |
import javax.swing.JFrame; |
61 |
import javax.swing.JOptionPane; |
62 |
import javax.swing.JPanel; |
63 |
import javax.swing.event.TreeSelectionEvent; |
64 |
import javax.swing.event.TreeSelectionListener; |
65 |
|
66 |
/**
|
67 |
*
|
68 |
*
|
69 |
*
|
70 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
71 |
*/
|
72 |
public class SearchDialogPanel extends JPanel implements ActionListener, TreeSelectionListener { |
73 |
// It is needed to close the frame
|
74 |
/**
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
private JFrame parent; |
79 |
//Panels
|
80 |
/**
|
81 |
*
|
82 |
*
|
83 |
*/
|
84 |
protected JPanel ppalPanel = null; |
85 |
/**
|
86 |
*
|
87 |
*
|
88 |
*/
|
89 |
protected SearchUpperPanel upperPanel = null; |
90 |
/**
|
91 |
*
|
92 |
*
|
93 |
*/
|
94 |
protected SearchLowerPanel lowerPanel = null; |
95 |
/**
|
96 |
*
|
97 |
*
|
98 |
*/
|
99 |
protected JPanel buttonsPanel = null; |
100 |
//Buttons
|
101 |
/**
|
102 |
*
|
103 |
*
|
104 |
*/
|
105 |
private JButton searchButton = null; |
106 |
/**
|
107 |
*
|
108 |
*
|
109 |
*/
|
110 |
private JButton closeButton = null; |
111 |
/**
|
112 |
*
|
113 |
*
|
114 |
*/
|
115 |
private JButton cancelSearchesButton = null; |
116 |
/**
|
117 |
*
|
118 |
*
|
119 |
*/
|
120 |
private JButton sizeButton = null; |
121 |
//Otros
|
122 |
/**
|
123 |
*
|
124 |
*
|
125 |
*/
|
126 |
protected GazetteerClient client = null; |
127 |
|
128 |
/**
|
129 |
*
|
130 |
*
|
131 |
*/
|
132 |
protected Collection nodesRecords = new java.util.ArrayList(); |
133 |
|
134 |
/**
|
135 |
*
|
136 |
*
|
137 |
*/
|
138 |
protected String attribute = null; |
139 |
|
140 |
/**
|
141 |
*
|
142 |
*
|
143 |
*/
|
144 |
protected boolean isMinimized = true; |
145 |
/**
|
146 |
*
|
147 |
*
|
148 |
*/
|
149 |
private ITranslator translator = null; |
150 |
/**
|
151 |
*
|
152 |
*
|
153 |
*/
|
154 |
private ThesaurusName currentThesaurus = null; |
155 |
|
156 |
/**
|
157 |
*
|
158 |
*
|
159 |
*/
|
160 |
private Collection searchThreads = null; |
161 |
|
162 |
/**
|
163 |
* This method initializes
|
164 |
*
|
165 |
*
|
166 |
* @param client
|
167 |
* @param translator
|
168 |
*/
|
169 |
public SearchDialogPanel(GazetteerClient client, ITranslator translator) {
|
170 |
super();
|
171 |
searchThreads = new java.util.ArrayList();
|
172 |
this.translator = translator;
|
173 |
this.client = client;
|
174 |
this.isMinimized = true; |
175 |
initialize(); |
176 |
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* This method initializes this
|
181 |
*
|
182 |
*/
|
183 |
private void initialize() { |
184 |
ppalPanel = new JPanel(); |
185 |
ppalPanel.setBounds(0, 0,625,330); |
186 |
ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
187 |
ppalPanel.add(getUpperPanel(), null);
|
188 |
ppalPanel.add(getLowerPanel(), null);
|
189 |
ppalPanel.add(getButtonPanel(), null);
|
190 |
add(ppalPanel); |
191 |
|
192 |
getLowerPanel().setVisible(false);
|
193 |
setDefaultButtonListeners(); |
194 |
} |
195 |
|
196 |
/**
|
197 |
* It Gets the upperPanel
|
198 |
*
|
199 |
*
|
200 |
* @return
|
201 |
*/
|
202 |
public SearchUpperPanel getUpperPanel() {
|
203 |
if (upperPanel == null){ |
204 |
upperPanel = new SearchUpperPanel(translator,
|
205 |
client.getProtocol()); |
206 |
|
207 |
} |
208 |
return upperPanel;
|
209 |
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* It Gets the lowePanel
|
214 |
*
|
215 |
*
|
216 |
* @return
|
217 |
*/
|
218 |
public SearchLowerPanel getLowerPanel() {
|
219 |
if (lowerPanel == null){ |
220 |
lowerPanel = new SearchLowerPanel(client.getLnkIGazetteerDriver().getVectorFeatures(),
|
221 |
translator, |
222 |
client.getProtocol()); |
223 |
if (client.getProtocol().equals("IDEC")) |
224 |
lowerPanel.getJScrollThesaurus().setEnabled(false);
|
225 |
} |
226 |
return lowerPanel;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
*
|
231 |
*
|
232 |
*
|
233 |
* @param catCli
|
234 |
*/
|
235 |
public void setCatalogClient(GazetteerClient catCli) { |
236 |
this.client = catCli;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
*
|
241 |
*
|
242 |
*
|
243 |
* @return
|
244 |
*/
|
245 |
public JPanel getButtonPanel() { |
246 |
if (buttonsPanel == null) { |
247 |
buttonsPanel = new JPanel(new FlowLayout()); |
248 |
buttonsPanel.add(getSearchButton()); |
249 |
buttonsPanel.add(getCancelSearchesButton()); |
250 |
buttonsPanel.add(getCloseButton()); |
251 |
} |
252 |
return buttonsPanel;
|
253 |
} |
254 |
|
255 |
/**
|
256 |
*
|
257 |
*
|
258 |
*
|
259 |
* @return
|
260 |
*/
|
261 |
public JButton getSearchButton() { |
262 |
if (searchButton == null) { |
263 |
searchButton = new JButton(Translator.getText(translator,"searchButton")); |
264 |
searchButton.setPreferredSize(new Dimension(90, 25)); |
265 |
searchButton.setActionCommand("search");
|
266 |
} |
267 |
return searchButton;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* It gets the cancel searches button
|
272 |
*
|
273 |
*
|
274 |
* @return
|
275 |
*/
|
276 |
public JButton getCancelSearchesButton() { |
277 |
if (cancelSearchesButton == null) { |
278 |
cancelSearchesButton = new JButton(Translator.getText(translator,"cancelSearchButton")); |
279 |
cancelSearchesButton.setPreferredSize(new Dimension(90, 25)); |
280 |
cancelSearchesButton.setActionCommand("cancel");
|
281 |
} |
282 |
return cancelSearchesButton;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
*
|
287 |
*
|
288 |
*
|
289 |
* @return
|
290 |
*/
|
291 |
public JButton getCloseButton() { |
292 |
if (closeButton == null) { |
293 |
closeButton = new JButton(Translator.getText(translator,"close")); |
294 |
closeButton.setPreferredSize(new Dimension(90, 25)); |
295 |
closeButton.setActionCommand("close");
|
296 |
} |
297 |
return closeButton;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* It gets the change size button
|
302 |
*
|
303 |
*
|
304 |
* @return
|
305 |
*/
|
306 |
public JButton getSizeButton() { |
307 |
if (sizeButton == null) { |
308 |
sizeButton = upperPanel.getSizeButton(); |
309 |
sizeButton.setActionCommand("size");
|
310 |
} |
311 |
return sizeButton;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
*
|
316 |
*
|
317 |
*
|
318 |
* @return
|
319 |
*/
|
320 |
public ThesaurusName getFeatureSelected() {
|
321 |
//return (Feature) controlsPanel.getTipoList().getSelectedValue();
|
322 |
return lowerPanel.getType();
|
323 |
} |
324 |
|
325 |
/**
|
326 |
*
|
327 |
*
|
328 |
*/
|
329 |
public void setDefaultButtonListeners() { |
330 |
getSearchButton().addActionListener(this);
|
331 |
getCloseButton().addActionListener(this);
|
332 |
getSizeButton().addActionListener(this);
|
333 |
getCancelSearchesButton().addActionListener(this);
|
334 |
lowerPanel.getThesaurusList().addTreeSelectionListener(this);
|
335 |
} |
336 |
/* (non-Javadoc)
|
337 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
338 |
*/
|
339 |
|
340 |
/**
|
341 |
*
|
342 |
*
|
343 |
*
|
344 |
* @param e
|
345 |
*/
|
346 |
public void actionPerformed(ActionEvent e) { |
347 |
//Buscar
|
348 |
if (e.getActionCommand() == "search") { |
349 |
searchButtonActionPerformed(); |
350 |
} |
351 |
if (e.getActionCommand() == "close") { |
352 |
closeButtonActionPerformed(); |
353 |
} |
354 |
if (e.getActionCommand() == "size") { |
355 |
sizeButtonActionPerformed(); |
356 |
} |
357 |
if (e.getActionCommand() == "cancel") { |
358 |
cancelSearchesButtonActionPerformed(); |
359 |
} |
360 |
|
361 |
} |
362 |
|
363 |
/**
|
364 |
*
|
365 |
*
|
366 |
*/
|
367 |
protected void sizeButtonActionPerformed() { |
368 |
if (isMinimized){
|
369 |
parent.setSize(525,450); |
370 |
getLowerPanel().setVisible(true);
|
371 |
getLowerPanel().repaint(); |
372 |
getUpperPanel().setUpIcon(); |
373 |
parent.setVisible(true);
|
374 |
}else{
|
375 |
parent.setSize(525,115); |
376 |
getLowerPanel().setVisible(false);
|
377 |
getUpperPanel().setDownIcon(); |
378 |
} |
379 |
isMinimized = !isMinimized; |
380 |
} |
381 |
|
382 |
/**
|
383 |
*
|
384 |
*
|
385 |
*/
|
386 |
protected void searchButtonActionPerformed() { |
387 |
if (client.getProtocol().equals("WFS")){ |
388 |
if ((currentThesaurus == null) || |
389 |
(currentThesaurus.getName().equals("ThesaurusRoot"))){
|
390 |
JOptionPane.showMessageDialog(
|
391 |
this,
|
392 |
Translator.getText(translator,"errorNotThesaurusSelected"),
|
393 |
"WFS",
|
394 |
JOptionPane.ERROR_MESSAGE
|
395 |
); |
396 |
return;
|
397 |
} |
398 |
} |
399 |
searchThread st = new searchThread();
|
400 |
searchThreads.add(st); |
401 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
402 |
} |
403 |
|
404 |
/**
|
405 |
*
|
406 |
*
|
407 |
*/
|
408 |
protected void cancelSearchesButtonActionPerformed() { |
409 |
for (int i=0 ; i<searchThreads.size() ; i++){ |
410 |
searchThread st = (searchThread)searchThreads.toArray()[i]; |
411 |
st.stop(); |
412 |
} |
413 |
searchThreads.clear(); |
414 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
415 |
} |
416 |
|
417 |
/**
|
418 |
*
|
419 |
*
|
420 |
*/
|
421 |
protected void closeButtonActionPerformed() { |
422 |
parent.setVisible(false);
|
423 |
} |
424 |
|
425 |
/**
|
426 |
*
|
427 |
*
|
428 |
*
|
429 |
* @return
|
430 |
*/
|
431 |
private Query doQuery() { |
432 |
ThesaurusName[] thesaurus;
|
433 |
if (client.getProtocol().equals("WFS-G")){ |
434 |
thesaurus = lowerPanel.getAllTypes(); |
435 |
currentThesaurus = thesaurus[0];
|
436 |
}else{
|
437 |
if (lowerPanel.getType() == null){ |
438 |
thesaurus = null;
|
439 |
}else{
|
440 |
thesaurus = new ThesaurusName[1]; |
441 |
thesaurus[0] = lowerPanel.getType();
|
442 |
} |
443 |
} |
444 |
|
445 |
Query query = client.createNewQuery();
|
446 |
query.setName(upperPanel.getName()); |
447 |
query.setNameFilter(lowerPanel.getConcordancia()); |
448 |
query.setFeatures(thesaurus); |
449 |
query.setFieldAttribute(getFieldAttribute()); |
450 |
query.setRecsByPage(lowerPanel.getNPaginas()); |
451 |
query.setCoordinates(lowerPanel.getCoordenadas()); |
452 |
query.setCoordinatesFilter(lowerPanel.getCoordenadasOpcion()); |
453 |
query.setCoordinatesClicked(upperPanel.isRestrictAreaClicked()); |
454 |
query.setGotoclicked(lowerPanel.isGoToClicked()); |
455 |
query.setKeepOldClicked(lowerPanel.isKeepOldClicked()); |
456 |
query.setMarkedPlaceClicked(lowerPanel.isMarkedPlaceClicked()); |
457 |
query.setTranslator(translator); |
458 |
return query;
|
459 |
} |
460 |
|
461 |
/**
|
462 |
* It opens a window with a combo and returns a field attribute name
|
463 |
*
|
464 |
*
|
465 |
* @return
|
466 |
*/
|
467 |
private String getFieldAttribute() { |
468 |
if (!(client.getProtocol().equals("WFS"))) |
469 |
return "geographicIdentifier"; |
470 |
|
471 |
Object[] possibilities = new Object[currentThesaurus.getFields().length]; |
472 |
for (int i=0 ; i< possibilities.length ; i++) |
473 |
possibilities[i] = currentThesaurus.getFields()[i].getName(); |
474 |
|
475 |
String s = (String)JOptionPane.showInputDialog( |
476 |
this,
|
477 |
Translator.getText(translator,"chooseAttribute"),
|
478 |
"WFS",
|
479 |
JOptionPane.PLAIN_MESSAGE,
|
480 |
null,
|
481 |
possibilities, |
482 |
currentThesaurus.getFields()[0].getName());
|
483 |
if ((s != null) && (s.length() > 0)) { |
484 |
attribute = s; |
485 |
return s;
|
486 |
} |
487 |
return null; |
488 |
} |
489 |
|
490 |
/**
|
491 |
* It returns the query that the user has selected
|
492 |
*
|
493 |
*/
|
494 |
private void doSearch() { |
495 |
nodesRecords = client.getFeature(client.getUrl(), |
496 |
doQuery()); |
497 |
if (nodesRecords == null) { |
498 |
JOptionPane.showMessageDialog(this, |
499 |
Translator.getText(translator,"errorGetRecords"),
|
500 |
"Error",
|
501 |
JOptionPane.ERROR_MESSAGE);
|
502 |
} |
503 |
|
504 |
} |
505 |
|
506 |
/**
|
507 |
*
|
508 |
*
|
509 |
*/
|
510 |
private void showResults() { |
511 |
Feature[] features = client.getLnkIGazetteerDriver().parseFeatures((XMLNode)nodesRecords.toArray()[0],currentThesaurus,attribute); |
512 |
|
513 |
if (features.length == 0){ |
514 |
JOptionPane.showMessageDialog(this, |
515 |
Translator.getText(translator,"anyResult"),
|
516 |
Translator.getText(translator,"gazetteer_search"),
|
517 |
JOptionPane.INFORMATION_MESSAGE);
|
518 |
}else{
|
519 |
ShowResultsActionPerformed(features); |
520 |
} |
521 |
} |
522 |
|
523 |
/**
|
524 |
*
|
525 |
*
|
526 |
*
|
527 |
* @param features
|
528 |
*/
|
529 |
protected void ShowResultsActionPerformed(Feature[] features) { |
530 |
new ShowResultsDialog(client,
|
531 |
features, |
532 |
lowerPanel.getNPaginas(), |
533 |
lowerPanel.isGoToClicked(), |
534 |
lowerPanel.isKeepOldClicked(), |
535 |
lowerPanel.isMarkedPlaceClicked()); |
536 |
} |
537 |
|
538 |
/**
|
539 |
* It loads the fields for the feature
|
540 |
*
|
541 |
*/
|
542 |
private void loadCurrentFeature() { |
543 |
if (client.getProtocol().equals("WFS-G")) |
544 |
return;
|
545 |
|
546 |
Collection fields = client.getLnkIGazetteerDriver().describeFeatureType(client.getUrl(),
|
547 |
currentThesaurus.getName()); |
548 |
|
549 |
if (client.getProtocol().equals("WFS")){ |
550 |
new WfsgDescribeFeatureTypeParser().parse((XMLNode)fields.toArray()[0],currentThesaurus); |
551 |
} |
552 |
|
553 |
} |
554 |
|
555 |
/**
|
556 |
*
|
557 |
*
|
558 |
*
|
559 |
* @param e
|
560 |
*/
|
561 |
public void valueChanged(TreeSelectionEvent e) { |
562 |
if (currentThesaurus == null){ |
563 |
currentThesaurus = getFeatureSelected(); |
564 |
loadCurrentFeature(); |
565 |
}else{
|
566 |
ThesaurusName feature = getFeatureSelected(); |
567 |
if (!(currentThesaurus.equals(feature))){
|
568 |
if (feature != null){ |
569 |
currentThesaurus = feature; |
570 |
loadCurrentFeature(); |
571 |
} |
572 |
} |
573 |
} |
574 |
|
575 |
} |
576 |
|
577 |
/**
|
578 |
*
|
579 |
*
|
580 |
*
|
581 |
* @param parent The parent to set.
|
582 |
*/
|
583 |
public void setParent(JFrame parent) { |
584 |
this.parent = parent;
|
585 |
} |
586 |
/**
|
587 |
* This class is used to manage the searches.
|
588 |
* It contains method to start and to stop a thread. It is
|
589 |
* necessary to create because "stop" method (for the Thread class)
|
590 |
* is deprecated.
|
591 |
*
|
592 |
*
|
593 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
594 |
*/
|
595 |
private class searchThread implements Runnable { |
596 |
|
597 |
/**
|
598 |
*
|
599 |
*
|
600 |
*/
|
601 |
volatile Thread myThread = null; |
602 |
|
603 |
/**
|
604 |
*
|
605 |
*
|
606 |
*/
|
607 |
public searchThread() {
|
608 |
myThread = new Thread(this); |
609 |
myThread.start(); |
610 |
} |
611 |
|
612 |
/**
|
613 |
*
|
614 |
*
|
615 |
*/
|
616 |
public void stop() { |
617 |
myThread.stop(); |
618 |
} |
619 |
|
620 |
/**
|
621 |
*
|
622 |
*
|
623 |
*/
|
624 |
public void run() { |
625 |
doSearch(); |
626 |
if ((nodesRecords != null) && (nodesRecords.size() > 0)) { |
627 |
showResults(); |
628 |
} |
629 |
searchThreads.remove(this);
|
630 |
if (searchThreads.size() == 0){ |
631 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
632 |
} |
633 |
} |
634 |
} |
635 |
} |