svn-gvsig-desktop / branches / v10 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / search / SearchDialogPanel.java @ 8604
History | View | Annotate | Download (12.6 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.catalogClient.ui.search; |
43 |
import es.gva.cit.catalogClient.CatalogClient; |
44 |
import es.gva.cit.catalogClient.querys.Query; |
45 |
import es.gva.cit.catalogClient.ui.showResults.ShowResultsDialog; |
46 |
import java.awt.Cursor; |
47 |
import java.awt.Dimension; |
48 |
import java.awt.FlowLayout; |
49 |
import java.awt.event.ActionEvent; |
50 |
import java.awt.event.ActionListener; |
51 |
import java.awt.event.ItemEvent; |
52 |
import java.awt.event.ItemListener; |
53 |
import java.util.Collection; |
54 |
import javax.swing.BoxLayout; |
55 |
import javax.swing.JButton; |
56 |
import javax.swing.JCheckBox; |
57 |
import javax.swing.JFrame; |
58 |
import javax.swing.JLabel; |
59 |
import javax.swing.JOptionPane; |
60 |
import javax.swing.JPanel; |
61 |
|
62 |
import org.gvsig.i18n.Messages; |
63 |
|
64 |
/**
|
65 |
*
|
66 |
*
|
67 |
*
|
68 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
69 |
*/
|
70 |
public class SearchDialogPanel extends JPanel implements ItemListener, ActionListener { |
71 |
// This component its used to resize the frame
|
72 |
/**
|
73 |
*
|
74 |
*
|
75 |
*/
|
76 |
private JFrame parent; |
77 |
protected Object serverConnectFrame; |
78 |
// Panels
|
79 |
/**
|
80 |
*
|
81 |
*
|
82 |
*/
|
83 |
protected JPanel ppalPanel = null; |
84 |
/**
|
85 |
*
|
86 |
*
|
87 |
*/
|
88 |
protected SearchUpperPanel upperPanel = null; |
89 |
/**
|
90 |
*
|
91 |
*
|
92 |
*/
|
93 |
protected SearchLowerPanel lowerPanel = null; |
94 |
/**
|
95 |
*
|
96 |
*
|
97 |
*/
|
98 |
protected JPanel checkBoxPanel = null; |
99 |
/**
|
100 |
*
|
101 |
*
|
102 |
*/
|
103 |
protected JPanel buttonsPanel = null; |
104 |
// Buttons
|
105 |
/**
|
106 |
*
|
107 |
*
|
108 |
*/
|
109 |
private JButton searchButton = null; |
110 |
/**
|
111 |
* <p></p>
|
112 |
*
|
113 |
*
|
114 |
*
|
115 |
* @poseidon-type es.gva.cit.catalogClient.metadataXML.XMLNode
|
116 |
*/
|
117 |
protected java.util.Collection nodes = new java.util.ArrayList(); |
118 |
/**
|
119 |
*
|
120 |
*
|
121 |
*/
|
122 |
private JButton closeButton = null; |
123 |
/**
|
124 |
*
|
125 |
*
|
126 |
*/
|
127 |
private JButton cancelSearchesButton = null; |
128 |
/**
|
129 |
*
|
130 |
*
|
131 |
*/
|
132 |
private JButton returnButton = null; |
133 |
/**
|
134 |
*
|
135 |
*
|
136 |
*/
|
137 |
private JButton sizeButton = null; |
138 |
/**
|
139 |
*
|
140 |
*
|
141 |
*/
|
142 |
private JCheckBox areaCheckBox = null; |
143 |
// Otros
|
144 |
/**
|
145 |
*
|
146 |
*
|
147 |
*/
|
148 |
protected CatalogClient client = null; |
149 |
|
150 |
/**
|
151 |
*
|
152 |
*
|
153 |
*/
|
154 |
protected boolean isMinimized = true; |
155 |
|
156 |
/**
|
157 |
*
|
158 |
*
|
159 |
*/
|
160 |
protected String currentServer = null; |
161 |
|
162 |
/**
|
163 |
*
|
164 |
*
|
165 |
*/
|
166 |
private Collection searchThreads = null; |
167 |
|
168 |
/**
|
169 |
* This method initializes
|
170 |
*
|
171 |
*
|
172 |
* @param parent
|
173 |
* @param translator
|
174 |
* @param client
|
175 |
*/
|
176 |
public SearchDialogPanel(JFrame parent, Object serverConnectFrame, CatalogClient client) { |
177 |
super();
|
178 |
searchThreads = new java.util.ArrayList();
|
179 |
this.isMinimized = true; |
180 |
this.parent = parent;
|
181 |
this.client = client;
|
182 |
this.serverConnectFrame = serverConnectFrame;
|
183 |
initialize(); |
184 |
} |
185 |
|
186 |
/**
|
187 |
* This method initializes this
|
188 |
*
|
189 |
*/
|
190 |
protected void initialize() { |
191 |
ppalPanel = null;
|
192 |
ppalPanel = new JPanel(); |
193 |
ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
194 |
ppalPanel.setPreferredSize(new Dimension(514,150)); |
195 |
ppalPanel.add(getUpperPanel()); |
196 |
ppalPanel.add(getLowerPanel()); |
197 |
ppalPanel.add(getButtonsPanel()); |
198 |
add(ppalPanel); |
199 |
setDefaultButtonListeners(); |
200 |
|
201 |
getLowerPanel().setVisible(false);
|
202 |
setVisible(true);
|
203 |
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* It Gets the upperPanel
|
208 |
*
|
209 |
*
|
210 |
* @return
|
211 |
*/
|
212 |
public SearchUpperPanel getUpperPanel() {
|
213 |
if (upperPanel == null){ |
214 |
upperPanel = new SearchUpperPanel(client.getProtocol(),
|
215 |
client.getLnkICatalogServerDriver().getQueryProfile()); |
216 |
} |
217 |
return upperPanel;
|
218 |
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* It Gets the lowePanel
|
223 |
*
|
224 |
*
|
225 |
* @return
|
226 |
*/
|
227 |
public SearchLowerPanel getLowerPanel() {
|
228 |
if (lowerPanel == null){ |
229 |
lowerPanel = new SearchLowerPanel(client.getProtocol(),
|
230 |
client.getLnkICatalogServerDriver().getQueryProfile()); |
231 |
|
232 |
} |
233 |
return lowerPanel;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* It gets the buttons panel
|
238 |
*
|
239 |
*
|
240 |
* @return
|
241 |
*/
|
242 |
public JPanel getButtonsPanel() { |
243 |
if (buttonsPanel == null) { |
244 |
FlowLayout flowLayout = new FlowLayout(); |
245 |
flowLayout.setAlignment(FlowLayout.RIGHT);
|
246 |
buttonsPanel = new JPanel(flowLayout); |
247 |
buttonsPanel.add(getSearchButton(), null);
|
248 |
buttonsPanel.add(getCancelSearchesButton(), null);
|
249 |
JLabel label = new JLabel(); |
250 |
label.setPreferredSize(new Dimension(6,0)); |
251 |
buttonsPanel.add(label, null);
|
252 |
buttonsPanel.add(getReturnButton(), null);
|
253 |
buttonsPanel.add(getCloseButton(), null);
|
254 |
} |
255 |
return buttonsPanel;
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* It gets the search button
|
260 |
*
|
261 |
*
|
262 |
* @return
|
263 |
*/
|
264 |
public JButton getSearchButton() { |
265 |
if (searchButton == null) { |
266 |
searchButton = new JButton(Messages.getText("searchButton")); |
267 |
searchButton.setPreferredSize(new Dimension(80, 23)); |
268 |
searchButton.setActionCommand("search");
|
269 |
} |
270 |
return searchButton;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* It gets the cancel searches button
|
275 |
*
|
276 |
*
|
277 |
* @return
|
278 |
*/
|
279 |
public JButton getCancelSearchesButton() { |
280 |
if (cancelSearchesButton == null) { |
281 |
cancelSearchesButton = new JButton(Messages.getText("cancelSearchButton")); |
282 |
cancelSearchesButton.setPreferredSize(new Dimension(90, 23)); |
283 |
cancelSearchesButton.setActionCommand("cancel");
|
284 |
} |
285 |
return cancelSearchesButton;
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* It gets the close button
|
290 |
*
|
291 |
*
|
292 |
* @return
|
293 |
*/
|
294 |
public JButton getCloseButton() { |
295 |
if (closeButton == null) { |
296 |
closeButton = new JButton(Messages.getText("close")); |
297 |
closeButton.setPreferredSize(new Dimension(80, 23)); |
298 |
closeButton.setActionCommand("close");
|
299 |
} |
300 |
return closeButton;
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* It gets the return button
|
305 |
*
|
306 |
*
|
307 |
* @return
|
308 |
*/
|
309 |
public JButton getReturnButton() { |
310 |
if (returnButton == null) { |
311 |
returnButton = new JButton(Messages.getText("last")); |
312 |
returnButton.setPreferredSize(new Dimension(80, 23)); |
313 |
returnButton.setActionCommand("return");
|
314 |
} |
315 |
return returnButton;
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* It gets the change size button
|
320 |
*
|
321 |
*
|
322 |
* @return
|
323 |
*/
|
324 |
public JButton getSizeButton() { |
325 |
if (sizeButton == null) { |
326 |
sizeButton = upperPanel.getSizeButton(); |
327 |
sizeButton.setActionCommand("size");
|
328 |
} |
329 |
return sizeButton;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* It gets the checkBox area component
|
334 |
*
|
335 |
*
|
336 |
* @return
|
337 |
*/
|
338 |
public JCheckBox getAreaCheckBox() { |
339 |
if (areaCheckBox == null){ |
340 |
areaCheckBox = upperPanel.getCoordinatesCheckBox(); |
341 |
areaCheckBox.setActionCommand("areaCheckButton");
|
342 |
} |
343 |
return areaCheckBox;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* It sets the listeners
|
348 |
*
|
349 |
*/
|
350 |
public void setDefaultButtonListeners() { |
351 |
getSearchButton().addActionListener(this);
|
352 |
getCloseButton().addActionListener(this);
|
353 |
getSizeButton().addActionListener(this);
|
354 |
getAreaCheckBox().addItemListener(this);
|
355 |
getReturnButton().addActionListener(this);
|
356 |
getCancelSearchesButton().addActionListener(this);
|
357 |
} |
358 |
|
359 |
/**
|
360 |
*
|
361 |
*
|
362 |
*
|
363 |
* @param e
|
364 |
*/
|
365 |
public void actionPerformed(ActionEvent e) { |
366 |
//Buscar
|
367 |
if (e.getActionCommand() == "search") { |
368 |
searchButtonActionPerformed(); |
369 |
} |
370 |
if (e.getActionCommand() == "close") { |
371 |
closeButtonActionPerformed(); |
372 |
} |
373 |
if (e.getActionCommand() == "size") { |
374 |
sizeButtonActionPerformed(); |
375 |
} |
376 |
if (e.getActionCommand() == "cancel") { |
377 |
cancelSearchesButtonActionPerformed(); |
378 |
} |
379 |
if (e.getActionCommand() == "return") { |
380 |
returnButtonActionPerformed(); |
381 |
} |
382 |
} |
383 |
|
384 |
/**
|
385 |
*
|
386 |
*
|
387 |
*/
|
388 |
protected void sizeButtonActionPerformed() { |
389 |
if (isMinimized){
|
390 |
parent.resize(525,540); |
391 |
ppalPanel.setPreferredSize(new Dimension(514,550)); |
392 |
getLowerPanel().setVisible(true);
|
393 |
parent.setVisible(true);
|
394 |
getUpperPanel().setUpIcon(); |
395 |
}else{
|
396 |
parent.setSize(525,160); |
397 |
ppalPanel.setPreferredSize(new Dimension(514,150)); |
398 |
getLowerPanel().setVisible(false);
|
399 |
ppalPanel.setVisible(true);
|
400 |
getUpperPanel().setDownIcon(); |
401 |
} |
402 |
isMinimized = !isMinimized; |
403 |
} |
404 |
|
405 |
/**
|
406 |
* Return button
|
407 |
*
|
408 |
*/
|
409 |
protected void returnButtonActionPerformed() { |
410 |
((JFrame)serverConnectFrame).setVisible(true); |
411 |
parent.setVisible(false);
|
412 |
} |
413 |
|
414 |
|
415 |
/**
|
416 |
*
|
417 |
*
|
418 |
*/
|
419 |
protected void searchButtonActionPerformed() { |
420 |
searchThread st = new searchThread();
|
421 |
searchThreads.add(st); |
422 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
423 |
} |
424 |
|
425 |
/**
|
426 |
*
|
427 |
*
|
428 |
*/
|
429 |
protected void cancelSearchesButtonActionPerformed() { |
430 |
for (int i=0 ; i<searchThreads.size() ; i++){ |
431 |
searchThread st = (searchThread)searchThreads.toArray()[i]; |
432 |
st.stop(); |
433 |
} |
434 |
searchThreads.clear(); |
435 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
436 |
} |
437 |
|
438 |
/**
|
439 |
*
|
440 |
*
|
441 |
*/
|
442 |
protected void closeButtonActionPerformed() { |
443 |
parent.setVisible(false);
|
444 |
} |
445 |
|
446 |
/**
|
447 |
* It returns the query that the user has selected
|
448 |
*
|
449 |
*
|
450 |
* @return
|
451 |
*/
|
452 |
private Query doQuery() { |
453 |
Query query = client.createNewQuery();
|
454 |
query.setSearchType(upperPanel.getService()); |
455 |
query.setTitle(upperPanel.getTitle()); |
456 |
query.setTitleFilter(lowerPanel.getTitleOption()); |
457 |
query.setAbstract(lowerPanel.getAbstract()); |
458 |
query.setThemeKey(lowerPanel.getKeys()); |
459 |
query.setTopic(lowerPanel.getCathegory()); |
460 |
query.setScale(lowerPanel.getScale()); |
461 |
query.setProvider(lowerPanel.getProvider()); |
462 |
query.setDateFrom(lowerPanel.getDateFrom()); |
463 |
query.setDateTo(lowerPanel.getDateTo()); |
464 |
query.setCoordenates(lowerPanel.getCoordinates()); |
465 |
query.setCoordenatesFilter(lowerPanel.getCoordinatesOption()); |
466 |
query.setMinimized(isMinimized); |
467 |
query.setCoordinatesClicked(upperPanel.getRestrictAreaClicked()); |
468 |
|
469 |
if (isMinimized){
|
470 |
query.setTitleFilter("E");
|
471 |
} |
472 |
return query;
|
473 |
} |
474 |
|
475 |
/**
|
476 |
* This method realizes the search
|
477 |
*
|
478 |
*/
|
479 |
private void doSearch() { |
480 |
nodes = client.getRecords(client.getUrl(), |
481 |
doQuery(), 1);
|
482 |
if (nodes == null) { |
483 |
JOptionPane.showMessageDialog(this, |
484 |
Messages.getText("errorGetRecords"),
|
485 |
"Error",
|
486 |
JOptionPane.ERROR_MESSAGE);
|
487 |
} else if (nodes.size() == 1) { |
488 |
JOptionPane.showMessageDialog(this, |
489 |
Messages.getText("anyResult"),
|
490 |
Messages.getText("catalog_search"),
|
491 |
JOptionPane.INFORMATION_MESSAGE);
|
492 |
} |
493 |
} |
494 |
|
495 |
/**
|
496 |
* This methos calls to present results form
|
497 |
*
|
498 |
*
|
499 |
* @param nodes
|
500 |
*/
|
501 |
protected void showResults(Collection nodes) { |
502 |
new ShowResultsDialog(client, nodes, 1); |
503 |
} |
504 |
/* (non-Javadoc)
|
505 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
506 |
* This methodhave to be implemented in gvSIG to load the bbox to o the search
|
507 |
*/
|
508 |
|
509 |
/**
|
510 |
*
|
511 |
*
|
512 |
*
|
513 |
* @param e
|
514 |
*/
|
515 |
public void itemStateChanged(ItemEvent e) { |
516 |
|
517 |
|
518 |
} |
519 |
|
520 |
/**
|
521 |
*
|
522 |
*
|
523 |
*
|
524 |
* @param isMinimized The isMinimized to set.
|
525 |
*/
|
526 |
public void setMinimized(boolean isMinimized) { |
527 |
this.isMinimized = isMinimized;
|
528 |
} |
529 |
|
530 |
/**
|
531 |
*
|
532 |
*
|
533 |
*
|
534 |
* @return Returns the currentServer.
|
535 |
*/
|
536 |
public String getCurrentServer() { |
537 |
return currentServer;
|
538 |
} |
539 |
|
540 |
/**
|
541 |
*
|
542 |
*
|
543 |
*
|
544 |
* @param currentServer The currentServer to set.
|
545 |
*/
|
546 |
public void setCurrentServer(String currentServer) { |
547 |
this.currentServer = currentServer;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
*
|
552 |
*
|
553 |
*
|
554 |
* @param parent The parent to set.
|
555 |
*/
|
556 |
public void setParent(JFrame parent) { |
557 |
this.parent = parent;
|
558 |
} |
559 |
/**
|
560 |
* This class is used to manage the searches.
|
561 |
* It contains method to start and to stop a thread. It is
|
562 |
* necessary to create because "stop" method (for the Thread class)
|
563 |
* is deprecated.
|
564 |
*
|
565 |
*
|
566 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
567 |
*/
|
568 |
private class searchThread implements Runnable { |
569 |
|
570 |
/**
|
571 |
*
|
572 |
*
|
573 |
*/
|
574 |
volatile Thread myThread = null; |
575 |
|
576 |
/**
|
577 |
*
|
578 |
*
|
579 |
*/
|
580 |
public searchThread() {
|
581 |
myThread = new Thread(this); |
582 |
myThread.start(); |
583 |
} |
584 |
|
585 |
/**
|
586 |
*
|
587 |
*
|
588 |
*/
|
589 |
public void stop() { |
590 |
myThread.stop(); |
591 |
} |
592 |
|
593 |
/**
|
594 |
*
|
595 |
*
|
596 |
*/
|
597 |
public void run() { |
598 |
doSearch(); |
599 |
if ((nodes != null) && (nodes.size() > 1)) { |
600 |
showResults(nodes); |
601 |
} |
602 |
searchThreads.remove(this);
|
603 |
if (searchThreads.size() == 0){ |
604 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
605 |
} |
606 |
} |
607 |
} |
608 |
} |