root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / search / SearchDialogPanel.java @ 4334
History | View | Annotate | Download (14.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 |
protected Object serverConnectFrame; |
80 |
// Panels
|
81 |
/**
|
82 |
*
|
83 |
*
|
84 |
*/
|
85 |
protected JPanel ppalPanel = null; |
86 |
/**
|
87 |
*
|
88 |
*
|
89 |
*/
|
90 |
protected SearchUpperPanel upperPanel = null; |
91 |
/**
|
92 |
*
|
93 |
*
|
94 |
*/
|
95 |
protected SearchLowerPanel lowerPanel = null; |
96 |
/**
|
97 |
*
|
98 |
*
|
99 |
*/
|
100 |
protected JPanel buttonsPanel = null; |
101 |
// Buttons
|
102 |
/**
|
103 |
*
|
104 |
*
|
105 |
*/
|
106 |
private JButton searchButton = null; |
107 |
/**
|
108 |
*
|
109 |
*
|
110 |
*/
|
111 |
private JButton closeButton = null; |
112 |
/**
|
113 |
*
|
114 |
*
|
115 |
*/
|
116 |
private JButton cancelSearchesButton = null; |
117 |
/**
|
118 |
*
|
119 |
*
|
120 |
*/
|
121 |
private JButton returnButton = null; |
122 |
/**
|
123 |
*
|
124 |
*
|
125 |
*/
|
126 |
private JButton sizeButton = null; |
127 |
// Otros
|
128 |
/**
|
129 |
*
|
130 |
*
|
131 |
*/
|
132 |
protected GazetteerClient client = null; |
133 |
|
134 |
/**
|
135 |
*
|
136 |
*
|
137 |
*/
|
138 |
protected Collection nodesRecords = new java.util.ArrayList(); |
139 |
|
140 |
/**
|
141 |
*
|
142 |
*
|
143 |
*/
|
144 |
protected String attribute = null; |
145 |
|
146 |
/**
|
147 |
*
|
148 |
*
|
149 |
*/
|
150 |
protected boolean isMinimized = true; |
151 |
/**
|
152 |
*
|
153 |
*
|
154 |
*/
|
155 |
private ITranslator translator = null; |
156 |
/**
|
157 |
*
|
158 |
*
|
159 |
*/
|
160 |
private ThesaurusName currentThesaurus = null; |
161 |
|
162 |
/**
|
163 |
*
|
164 |
*
|
165 |
*/
|
166 |
private Collection searchThreads = null; |
167 |
|
168 |
/**
|
169 |
* This method initializes
|
170 |
*
|
171 |
*
|
172 |
* @param client
|
173 |
* @param translator
|
174 |
*/
|
175 |
public SearchDialogPanel(GazetteerClient client, Object serverConnectFrame, ITranslator translator) { |
176 |
super();
|
177 |
searchThreads = new java.util.ArrayList();
|
178 |
this.translator = translator;
|
179 |
this.client = client;
|
180 |
this.isMinimized = true; |
181 |
this.serverConnectFrame = serverConnectFrame;
|
182 |
initialize(); |
183 |
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* This method initializes this
|
188 |
*
|
189 |
*/
|
190 |
private void initialize() { |
191 |
ppalPanel = new JPanel(); |
192 |
ppalPanel.setBounds(0, 0,625,330); |
193 |
ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
194 |
ppalPanel.add(getUpperPanel(), null);
|
195 |
ppalPanel.add(getLowerPanel(), null);
|
196 |
ppalPanel.add(getButtonPanel(), null);
|
197 |
add(ppalPanel); |
198 |
|
199 |
getLowerPanel().setVisible(false);
|
200 |
setDefaultButtonListeners(); |
201 |
} |
202 |
|
203 |
/**
|
204 |
* It Gets the upperPanel
|
205 |
*
|
206 |
*
|
207 |
* @return
|
208 |
*/
|
209 |
public SearchUpperPanel getUpperPanel() {
|
210 |
if (upperPanel == null){ |
211 |
upperPanel = new SearchUpperPanel(translator,
|
212 |
client.getProtocol()); |
213 |
|
214 |
} |
215 |
return upperPanel;
|
216 |
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* It Gets the lowePanel
|
221 |
*
|
222 |
*
|
223 |
* @return
|
224 |
*/
|
225 |
public SearchLowerPanel getLowerPanel() {
|
226 |
if (lowerPanel == null){ |
227 |
lowerPanel = new SearchLowerPanel(client.getLnkIGazetteerDriver().getVectorFeatures(),
|
228 |
translator, |
229 |
client.getProtocol()); |
230 |
if (client.getProtocol().equals("IDEC")) |
231 |
lowerPanel.getJScrollThesaurus().setEnabled(false);
|
232 |
} |
233 |
return lowerPanel;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
*
|
238 |
*
|
239 |
*
|
240 |
* @param catCli
|
241 |
*/
|
242 |
public void setCatalogClient(GazetteerClient catCli) { |
243 |
this.client = catCli;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
*
|
248 |
*
|
249 |
*
|
250 |
* @return
|
251 |
*/
|
252 |
public JPanel getButtonPanel() { |
253 |
if (buttonsPanel == null) { |
254 |
buttonsPanel = new JPanel(new FlowLayout()); |
255 |
buttonsPanel.add(getSearchButton()); |
256 |
buttonsPanel.add(getCancelSearchesButton()); |
257 |
buttonsPanel.add(getReturnButton()); |
258 |
buttonsPanel.add(getCloseButton()); |
259 |
|
260 |
} |
261 |
return buttonsPanel;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* It gets the return button
|
266 |
*
|
267 |
*
|
268 |
* @return
|
269 |
*/
|
270 |
public JButton getReturnButton() { |
271 |
if (returnButton == null) { |
272 |
returnButton = new JButton(Translator.getText(translator,"return")); |
273 |
returnButton.setPreferredSize(new Dimension(90, 25)); |
274 |
returnButton.setActionCommand("return");
|
275 |
} |
276 |
return returnButton;
|
277 |
} |
278 |
|
279 |
|
280 |
/**
|
281 |
*
|
282 |
*
|
283 |
*
|
284 |
* @return
|
285 |
*/
|
286 |
public JButton getSearchButton() { |
287 |
if (searchButton == null) { |
288 |
searchButton = new JButton(Translator.getText(translator,"searchButton")); |
289 |
searchButton.setPreferredSize(new Dimension(90, 25)); |
290 |
searchButton.setActionCommand("search");
|
291 |
} |
292 |
return searchButton;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* It gets the cancel searches button
|
297 |
*
|
298 |
*
|
299 |
* @return
|
300 |
*/
|
301 |
public JButton getCancelSearchesButton() { |
302 |
if (cancelSearchesButton == null) { |
303 |
cancelSearchesButton = new JButton(Translator.getText(translator,"cancelSearchButton")); |
304 |
cancelSearchesButton.setPreferredSize(new Dimension(90, 25)); |
305 |
cancelSearchesButton.setActionCommand("cancel");
|
306 |
} |
307 |
return cancelSearchesButton;
|
308 |
} |
309 |
|
310 |
/**
|
311 |
*
|
312 |
*
|
313 |
*
|
314 |
* @return
|
315 |
*/
|
316 |
public JButton getCloseButton() { |
317 |
if (closeButton == null) { |
318 |
closeButton = new JButton(Translator.getText(translator,"close")); |
319 |
closeButton.setPreferredSize(new Dimension(90, 25)); |
320 |
closeButton.setActionCommand("close");
|
321 |
} |
322 |
return closeButton;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* It gets the change size button
|
327 |
*
|
328 |
*
|
329 |
* @return
|
330 |
*/
|
331 |
public JButton getSizeButton() { |
332 |
if (sizeButton == null) { |
333 |
sizeButton = upperPanel.getSizeButton(); |
334 |
sizeButton.setActionCommand("size");
|
335 |
} |
336 |
return sizeButton;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
*
|
341 |
*
|
342 |
*
|
343 |
* @return
|
344 |
*/
|
345 |
public ThesaurusName getFeatureSelected() {
|
346 |
//return (Feature) controlsPanel.getTipoList().getSelectedValue();
|
347 |
return lowerPanel.getType();
|
348 |
} |
349 |
|
350 |
/**
|
351 |
*
|
352 |
*
|
353 |
*/
|
354 |
public void setDefaultButtonListeners() { |
355 |
getSearchButton().addActionListener(this);
|
356 |
getCloseButton().addActionListener(this);
|
357 |
getSizeButton().addActionListener(this);
|
358 |
getReturnButton().addActionListener(this);
|
359 |
getCancelSearchesButton().addActionListener(this);
|
360 |
lowerPanel.getThesaurusList().addTreeSelectionListener(this);
|
361 |
} |
362 |
/* (non-Javadoc)
|
363 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
364 |
*/
|
365 |
|
366 |
/**
|
367 |
*
|
368 |
*
|
369 |
*
|
370 |
* @param e
|
371 |
*/
|
372 |
public void actionPerformed(ActionEvent e) { |
373 |
//Buscar
|
374 |
if (e.getActionCommand() == "search") { |
375 |
searchButtonActionPerformed(); |
376 |
} |
377 |
if (e.getActionCommand() == "close") { |
378 |
closeButtonActionPerformed(); |
379 |
} |
380 |
if (e.getActionCommand() == "size") { |
381 |
sizeButtonActionPerformed(); |
382 |
} |
383 |
if (e.getActionCommand() == "cancel") { |
384 |
cancelSearchesButtonActionPerformed(); |
385 |
} |
386 |
if (e.getActionCommand() == "return") { |
387 |
returnButtonActionPerformed(); |
388 |
} |
389 |
|
390 |
} |
391 |
|
392 |
/**
|
393 |
*
|
394 |
*
|
395 |
*/
|
396 |
protected void sizeButtonActionPerformed() { |
397 |
if (isMinimized){
|
398 |
parent.setSize(525,450); |
399 |
getLowerPanel().setVisible(true);
|
400 |
getLowerPanel().repaint(); |
401 |
getUpperPanel().setUpIcon(); |
402 |
parent.setVisible(true);
|
403 |
}else{
|
404 |
parent.setSize(525,115); |
405 |
getLowerPanel().setVisible(false);
|
406 |
getUpperPanel().setDownIcon(); |
407 |
} |
408 |
isMinimized = !isMinimized; |
409 |
} |
410 |
|
411 |
/**
|
412 |
*
|
413 |
*
|
414 |
*/
|
415 |
protected void searchButtonActionPerformed() { |
416 |
if (client.getProtocol().equals("WFS")){ |
417 |
if ((currentThesaurus == null) || |
418 |
(currentThesaurus.getName().equals("ThesaurusRoot"))){
|
419 |
JOptionPane.showMessageDialog(
|
420 |
this,
|
421 |
Translator.getText(translator,"errorNotThesaurusSelected"),
|
422 |
"WFS",
|
423 |
JOptionPane.ERROR_MESSAGE
|
424 |
); |
425 |
return;
|
426 |
} |
427 |
} |
428 |
searchThread st = new searchThread();
|
429 |
searchThreads.add(st); |
430 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
431 |
} |
432 |
|
433 |
/**
|
434 |
* Return button
|
435 |
*
|
436 |
*/
|
437 |
protected void returnButtonActionPerformed() { |
438 |
((JFrame)serverConnectFrame).setVisible(true); |
439 |
parent.setVisible(false);
|
440 |
} |
441 |
|
442 |
|
443 |
|
444 |
/**
|
445 |
*
|
446 |
*
|
447 |
*/
|
448 |
protected void cancelSearchesButtonActionPerformed() { |
449 |
for (int i=0 ; i<searchThreads.size() ; i++){ |
450 |
searchThread st = (searchThread)searchThreads.toArray()[i]; |
451 |
st.stop(); |
452 |
} |
453 |
searchThreads.clear(); |
454 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
455 |
} |
456 |
|
457 |
/**
|
458 |
*
|
459 |
*
|
460 |
*/
|
461 |
protected void closeButtonActionPerformed() { |
462 |
parent.setVisible(false);
|
463 |
} |
464 |
|
465 |
/**
|
466 |
*
|
467 |
*
|
468 |
*
|
469 |
* @return
|
470 |
*/
|
471 |
protected Query doQuery() { |
472 |
ThesaurusName[] thesaurus;
|
473 |
if (client.getProtocol().equals("WFS-G")){ |
474 |
thesaurus = lowerPanel.getAllTypes(); |
475 |
currentThesaurus = thesaurus[0];
|
476 |
}else{
|
477 |
if (lowerPanel.getType() == null){ |
478 |
thesaurus = null;
|
479 |
}else{
|
480 |
thesaurus = new ThesaurusName[1]; |
481 |
thesaurus[0] = lowerPanel.getType();
|
482 |
} |
483 |
} |
484 |
|
485 |
Query query = client.createNewQuery();
|
486 |
query.setName(upperPanel.getName()); |
487 |
query.setNameFilter(lowerPanel.getConcordancia()); |
488 |
query.setFeatures(thesaurus); |
489 |
query.setFieldAttribute(getFieldAttribute()); |
490 |
query.setRecsByPage(lowerPanel.getNPaginas()); |
491 |
query.setCoordinates(lowerPanel.getCoordenadas()); |
492 |
query.setCoordinatesFilter(lowerPanel.getCoordenadasOpcion()); |
493 |
query.setCoordinatesClicked(upperPanel.isRestrictAreaClicked()); |
494 |
query.getOptions().getAspect().setGoTo(lowerPanel.isGoToClicked()); |
495 |
query.getOptions().getAspect().setKeepOld(lowerPanel.isKeepOldClicked()); |
496 |
query.getOptions().getAspect().setPaintCurrent(lowerPanel.isMarkedPlaceClicked()); |
497 |
query.getOptions().getSearch().setWithAccents(lowerPanel.isAccentsSearchEnabled()); |
498 |
query.setTranslator(translator); |
499 |
return query;
|
500 |
} |
501 |
|
502 |
/**
|
503 |
* It opens a window with a combo and returns a field attribute name
|
504 |
*
|
505 |
*
|
506 |
* @return
|
507 |
*/
|
508 |
private String getFieldAttribute() { |
509 |
if (!(client.getProtocol().equals("WFS"))) |
510 |
return "geographicIdentifier"; |
511 |
|
512 |
Object[] possibilities = new Object[currentThesaurus.getFields().length]; |
513 |
for (int i=0 ; i< possibilities.length ; i++) |
514 |
possibilities[i] = currentThesaurus.getFields()[i].getName(); |
515 |
|
516 |
String s = (String)JOptionPane.showInputDialog( |
517 |
this,
|
518 |
Translator.getText(translator,"chooseAttribute"),
|
519 |
"WFS",
|
520 |
JOptionPane.PLAIN_MESSAGE,
|
521 |
null,
|
522 |
possibilities, |
523 |
currentThesaurus.getFields()[0].getName());
|
524 |
if ((s != null) && (s.length() > 0)) { |
525 |
attribute = s; |
526 |
return s;
|
527 |
} |
528 |
return null; |
529 |
} |
530 |
|
531 |
/**
|
532 |
* It returns the query that the user has selected
|
533 |
*
|
534 |
*/
|
535 |
private void doSearch() { |
536 |
nodesRecords = client.getFeature(client.getUrl(), |
537 |
doQuery()); |
538 |
if (nodesRecords == null) { |
539 |
JOptionPane.showMessageDialog(this, |
540 |
Translator.getText(translator,"errorGetRecords"),
|
541 |
"Error",
|
542 |
JOptionPane.ERROR_MESSAGE);
|
543 |
} |
544 |
|
545 |
} |
546 |
|
547 |
/**
|
548 |
*
|
549 |
*
|
550 |
*/
|
551 |
private void showResults() { |
552 |
Feature[] features = client.getLnkIGazetteerDriver().parseFeatures((XMLNode)nodesRecords.toArray()[0],currentThesaurus,attribute); |
553 |
|
554 |
if (features.length == 0){ |
555 |
JOptionPane.showMessageDialog(this, |
556 |
Translator.getText(translator,"anyResult"),
|
557 |
Translator.getText(translator,"gazetteer_search"),
|
558 |
JOptionPane.INFORMATION_MESSAGE);
|
559 |
}else{
|
560 |
ShowResultsActionPerformed(features); |
561 |
} |
562 |
} |
563 |
|
564 |
/**
|
565 |
*
|
566 |
*
|
567 |
*
|
568 |
* @param features
|
569 |
*/
|
570 |
protected void ShowResultsActionPerformed(Feature[] features) { |
571 |
new ShowResultsDialog(client,
|
572 |
features, |
573 |
lowerPanel.getNPaginas(), |
574 |
doQuery()); |
575 |
|
576 |
} |
577 |
|
578 |
/**
|
579 |
* It loads the fields for the feature
|
580 |
*
|
581 |
*/
|
582 |
private void loadCurrentFeature() { |
583 |
if (client.getProtocol().equals("WFS-G")) |
584 |
return;
|
585 |
|
586 |
Collection fields = client.getLnkIGazetteerDriver().describeFeatureType(client.getUrl(),
|
587 |
currentThesaurus.getName()); |
588 |
|
589 |
if (client.getProtocol().equals("WFS")){ |
590 |
new WfsgDescribeFeatureTypeParser().parse((XMLNode)fields.toArray()[0],currentThesaurus); |
591 |
} |
592 |
|
593 |
} |
594 |
|
595 |
/**
|
596 |
*
|
597 |
*
|
598 |
*
|
599 |
* @param e
|
600 |
*/
|
601 |
public void valueChanged(TreeSelectionEvent e) { |
602 |
if (currentThesaurus == null){ |
603 |
currentThesaurus = getFeatureSelected(); |
604 |
loadCurrentFeature(); |
605 |
}else{
|
606 |
ThesaurusName feature = getFeatureSelected(); |
607 |
if (!(currentThesaurus.equals(feature))){
|
608 |
if (feature != null){ |
609 |
currentThesaurus = feature; |
610 |
loadCurrentFeature(); |
611 |
} |
612 |
} |
613 |
} |
614 |
|
615 |
} |
616 |
|
617 |
/**
|
618 |
*
|
619 |
*
|
620 |
*
|
621 |
* @param parent The parent to set.
|
622 |
*/
|
623 |
public void setParent(JFrame parent) { |
624 |
this.parent = parent;
|
625 |
} |
626 |
/**
|
627 |
* This class is used to manage the searches.
|
628 |
* It contains method to start and to stop a thread. It is
|
629 |
* necessary to create because "stop" method (for the Thread class)
|
630 |
* is deprecated.
|
631 |
*
|
632 |
*
|
633 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
634 |
*/
|
635 |
private class searchThread implements Runnable { |
636 |
|
637 |
/**
|
638 |
*
|
639 |
*
|
640 |
*/
|
641 |
volatile Thread myThread = null; |
642 |
|
643 |
/**
|
644 |
*
|
645 |
*
|
646 |
*/
|
647 |
public searchThread() {
|
648 |
myThread = new Thread(this); |
649 |
myThread.start(); |
650 |
} |
651 |
|
652 |
/**
|
653 |
*
|
654 |
*
|
655 |
*/
|
656 |
public void stop() { |
657 |
myThread.stop(); |
658 |
} |
659 |
|
660 |
/**
|
661 |
*
|
662 |
*
|
663 |
*/
|
664 |
public void run() { |
665 |
doSearch(); |
666 |
if ((nodesRecords != null) && (nodesRecords.size() > 0)) { |
667 |
showResults(); |
668 |
} |
669 |
searchThreads.remove(this);
|
670 |
if (searchThreads.size() == 0){ |
671 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
672 |
} |
673 |
} |
674 |
} |
675 |
} |