root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / ui / search / SearchDialogPanel.java @ 15558
History | View | Annotate | Download (11.1 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 java.awt.BorderLayout; |
44 |
import java.awt.Cursor; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.util.Collection; |
48 |
|
49 |
import javax.swing.JFrame; |
50 |
import javax.swing.JOptionPane; |
51 |
import javax.swing.JPanel; |
52 |
|
53 |
import org.gvsig.i18n.Messages; |
54 |
|
55 |
import es.gva.cit.catalog.ui.search.SearchButtonPanel; |
56 |
import es.gva.cit.catalog.utils.CatalogConstants; |
57 |
import es.gva.cit.gazetteer.GazetteerClient; |
58 |
import es.gva.cit.gazetteer.querys.Feature; |
59 |
import es.gva.cit.gazetteer.querys.FeatureType; |
60 |
import es.gva.cit.gazetteer.querys.FeatureTypeAttribute; |
61 |
import es.gva.cit.gazetteer.querys.GazetteerQuery; |
62 |
import es.gva.cit.gazetteer.ui.showresults.ShowResultsDialog; |
63 |
|
64 |
/**
|
65 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
66 |
*/
|
67 |
public class SearchDialogPanel extends JPanel implements ActionListener { |
68 |
private JFrame parent; |
69 |
private GazetteerQuery query = null; |
70 |
protected Object serverConnectFrame; |
71 |
protected SearchUpperPanel upperPanel = null; |
72 |
protected SearchLowerPanel lowerPanel = null; |
73 |
protected SearchButtonPanel buttonsPanel = null; |
74 |
protected GazetteerClient client = null; |
75 |
protected boolean isMinimized = true; |
76 |
protected Feature[] features = null; |
77 |
private Collection searchThreads = null; |
78 |
private String currentServer = null; |
79 |
private String featureAttribute = null; |
80 |
|
81 |
/**
|
82 |
* This method initializes
|
83 |
*
|
84 |
*
|
85 |
* @param client
|
86 |
* @param translator
|
87 |
*/
|
88 |
public SearchDialogPanel(GazetteerClient client, Object serverConnectFrame) { |
89 |
super();
|
90 |
searchThreads = new java.util.ArrayList();
|
91 |
this.client = client;
|
92 |
this.isMinimized = true; |
93 |
this.serverConnectFrame = serverConnectFrame;
|
94 |
initialize(); |
95 |
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* This method initializes this
|
100 |
*/
|
101 |
private void initialize() { |
102 |
setLayout(new BorderLayout()); |
103 |
add(getUpperPanel(),BorderLayout.NORTH);
|
104 |
add(getLowerPanel(),BorderLayout.CENTER);
|
105 |
add(getButtonPanel(),BorderLayout.SOUTH);
|
106 |
getLowerPanel().setVisible(false);
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* It Gets the upperPanel
|
111 |
* @return
|
112 |
*/
|
113 |
public SearchUpperPanel getUpperPanel() {
|
114 |
if (upperPanel == null){ |
115 |
upperPanel = new SearchUpperPanel();
|
116 |
upperPanel.addActionListener(this);
|
117 |
} |
118 |
return upperPanel;
|
119 |
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* It Gets the lowePanel
|
124 |
* @return
|
125 |
*/
|
126 |
public SearchLowerPanel getLowerPanel() {
|
127 |
if (lowerPanel == null){ |
128 |
FeatureType[] types = null; |
129 |
try {
|
130 |
types = ((GazetteerClient)client).getFeatureTypes(); |
131 |
} catch (Exception e) { |
132 |
//The thesaurus will not loaded
|
133 |
} |
134 |
lowerPanel = new SearchLowerPanel(types,
|
135 |
client.getAditionalSearchPanel()); |
136 |
lowerPanel.addResultsByPageNumber(10);
|
137 |
lowerPanel.addResultsByPageNumber(25);
|
138 |
lowerPanel.addResultsByPageNumber(50);
|
139 |
lowerPanel.addCoordinatesRelationship( |
140 |
Messages.getText("coordinatesContains"));
|
141 |
lowerPanel.addCoordinatesRelationship( |
142 |
Messages.getText("coordinatesFullyOutsideOf"));
|
143 |
} |
144 |
return lowerPanel;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Set the gazetteer client
|
149 |
* @param
|
150 |
* Gazetteer client to set
|
151 |
*/
|
152 |
public void setGazetteerClient(GazetteerClient gazetteerClient) { |
153 |
this.client = gazetteerClient;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* @return the buttons panel
|
158 |
*/
|
159 |
public JPanel getButtonPanel() { |
160 |
if (buttonsPanel == null) { |
161 |
buttonsPanel = new SearchButtonPanel();
|
162 |
buttonsPanel.addActionListener(this);
|
163 |
} |
164 |
return buttonsPanel;
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* @return
|
169 |
*/
|
170 |
public FeatureType getFeatureSelected() {
|
171 |
return lowerPanel.getType();
|
172 |
} |
173 |
|
174 |
/*
|
175 |
* (non-Javadoc)
|
176 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
177 |
*/
|
178 |
public void actionPerformed(ActionEvent e) { |
179 |
if (e.getActionCommand().compareTo(CatalogConstants.SEARCH_BUTTON_ACTION_COMMAND)==0) { |
180 |
searchButtonActionPerformed(); |
181 |
}else if (e.getActionCommand().compareTo(CatalogConstants.CLOSE_BUTTON_ACTION_COMMAND)==0){ |
182 |
closeButtonActionPerformed(); |
183 |
}else if(e.getActionCommand().compareTo(CatalogConstants.RESIZE_BUTTON_ACTION_COMMAND)==0){ |
184 |
resizeButtonActionPerformed(); |
185 |
}else if (e.getActionCommand().compareTo(CatalogConstants.CANCEL_BUTTON_ACTION_COMMAND)==0){ |
186 |
cancelSearchesButtonActionPerformed(); |
187 |
}else if (e.getActionCommand().compareTo(CatalogConstants.LAST_BUTTON_ACTION_COMMAND)==0){ |
188 |
lastButtonActionPerformed(); |
189 |
} |
190 |
} |
191 |
|
192 |
/**
|
193 |
* thrown when the resize button is clicked
|
194 |
*/
|
195 |
protected void resizeButtonActionPerformed() { |
196 |
if (isMinimized){
|
197 |
parent.setSize(parent.getWidth(),450);
|
198 |
getLowerPanel().setVisible(true);
|
199 |
getUpperPanel().setUpIcon(); |
200 |
}else{
|
201 |
parent.setSize(parent.getWidth(),115);
|
202 |
getLowerPanel().setVisible(false);
|
203 |
getUpperPanel().setDownIcon(); |
204 |
} |
205 |
isMinimized = !isMinimized; |
206 |
} |
207 |
|
208 |
/**
|
209 |
* thrown when the search button is clicked
|
210 |
* @throws Exception
|
211 |
*/
|
212 |
protected void searchButtonActionPerformed() { |
213 |
FeatureType featureType = lowerPanel.getType(); |
214 |
if (client.isDescribeFeatureTypeNeeded()){
|
215 |
try {
|
216 |
FeatureTypeAttribute atribute = getAttribute(featureType); |
217 |
if (atribute == null){ |
218 |
return;
|
219 |
}else{
|
220 |
featureAttribute = atribute.getName(); |
221 |
} |
222 |
} catch (Exception e) { |
223 |
e.printStackTrace(); |
224 |
return;
|
225 |
} |
226 |
} |
227 |
searchThread st = new searchThread();
|
228 |
searchThreads.add(st); |
229 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
230 |
} |
231 |
|
232 |
/**
|
233 |
* This method open a Jdialog panel and shows a list of
|
234 |
* attributes to choose one of them.
|
235 |
* @param featureType
|
236 |
* Feature
|
237 |
* @return
|
238 |
* The selected attribute
|
239 |
* @throws Exception
|
240 |
*/
|
241 |
private FeatureTypeAttribute getAttribute(FeatureType featureType) throws Exception{ |
242 |
if ((featureType == null) || |
243 |
(lowerPanel.getType().getName().equals(Messages.getText("ThesaurusRoot")))){
|
244 |
JOptionPane.showMessageDialog(
|
245 |
this,
|
246 |
Messages.getText("errorNotThesaurusSelected"),
|
247 |
"WFS",
|
248 |
JOptionPane.ERROR_MESSAGE
|
249 |
); |
250 |
return null; |
251 |
} |
252 |
FeatureTypeAttribute[] atributes =
|
253 |
client.describeFeatureType(featureType.getName()); |
254 |
FeatureTypeAttribute attribute = (FeatureTypeAttribute)JOptionPane.showInputDialog(
|
255 |
this,
|
256 |
Messages.getText("chooseAttribute"),
|
257 |
null,
|
258 |
JOptionPane.PLAIN_MESSAGE,
|
259 |
null,
|
260 |
atributes, |
261 |
featureType.getName()); |
262 |
if (attribute == null) { |
263 |
JOptionPane.showMessageDialog(
|
264 |
this,
|
265 |
Messages.getText("chooseAttribute"),
|
266 |
"WFS",
|
267 |
JOptionPane.ERROR_MESSAGE
|
268 |
); |
269 |
} |
270 |
return attribute;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* thrown when the last button is clicked
|
275 |
*/
|
276 |
protected void lastButtonActionPerformed() { |
277 |
((JFrame)serverConnectFrame).setVisible(true); |
278 |
parent.setVisible(false);
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* thrown when the cancel button is clicked
|
283 |
*/
|
284 |
protected void cancelSearchesButtonActionPerformed() { |
285 |
for (int i=0 ; i<searchThreads.size() ; i++){ |
286 |
searchThread st = (searchThread)searchThreads.toArray()[i]; |
287 |
st.stop(); |
288 |
} |
289 |
searchThreads.clear(); |
290 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
291 |
} |
292 |
|
293 |
/**
|
294 |
* thrown when the close button is clicked
|
295 |
*/
|
296 |
protected void closeButtonActionPerformed() { |
297 |
parent.setVisible(false);
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* @return the selected query
|
302 |
*/
|
303 |
protected GazetteerQuery doQuery() {
|
304 |
query = client.createNewQuery(); |
305 |
query.setName(upperPanel.getName()); |
306 |
query.setNameFilter(lowerPanel.getConcordancia()); |
307 |
query.setFieldAttribute(featureAttribute); |
308 |
query.setFeatures(lowerPanel.getAllTypes()); |
309 |
query.setRecsByPage(lowerPanel.getResultsByPage()); |
310 |
query.setCoordinates(lowerPanel.getCoordinates()); |
311 |
query.setCoordinatesFilter(lowerPanel.getCoordinatesOption()); |
312 |
query.setCoordinatesClicked(upperPanel.isRestrictAreaClicked()); |
313 |
query.getOptions().getAspect().setGoTo(lowerPanel.isGoToClicked()); |
314 |
query.getOptions().getAspect().setKeepOld(lowerPanel.isKeepOldClicked()); |
315 |
query.getOptions().getAspect().setPaintCurrent(lowerPanel.isMarkedPlaceClicked()); |
316 |
query.getOptions().getSearch().setWithAccents(lowerPanel.isAccentsSearchEnabled()); |
317 |
query.setProperties(lowerPanel.getProperties()); |
318 |
return query;
|
319 |
} |
320 |
|
321 |
/**
|
322 |
* It returns the query that the user has selected
|
323 |
* @throws Exception
|
324 |
*
|
325 |
*/
|
326 |
private void doSearch() throws Exception { |
327 |
features = client.getFeature(doQuery()); |
328 |
if (features == null) { |
329 |
JOptionPane.showMessageDialog(this, |
330 |
Messages.getText("errorGetRecords"),
|
331 |
"Error",
|
332 |
JOptionPane.ERROR_MESSAGE);
|
333 |
} |
334 |
} |
335 |
|
336 |
/**
|
337 |
* Show the results
|
338 |
*/
|
339 |
private void showResults() { |
340 |
if (features.length == 0){ |
341 |
JOptionPane.showMessageDialog(this, |
342 |
Messages.getText("anyResult"),
|
343 |
Messages.getText("gazetteer_search"),
|
344 |
JOptionPane.INFORMATION_MESSAGE);
|
345 |
}else{
|
346 |
showResultsActionPerformed(features); |
347 |
} |
348 |
} |
349 |
|
350 |
/**
|
351 |
* @param features
|
352 |
*/
|
353 |
protected void showResultsActionPerformed(Feature[] features) { |
354 |
new ShowResultsDialog(client,
|
355 |
features, |
356 |
lowerPanel.getResultsByPage(), |
357 |
doQuery()); |
358 |
} |
359 |
|
360 |
/**
|
361 |
*
|
362 |
* @param parent The parent to set.
|
363 |
*/
|
364 |
public void setParent(JFrame parent) { |
365 |
this.parent = parent;
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* This class is used to manage the searches.
|
370 |
* It contains method to start and to stop a thread. It is
|
371 |
* necessary to create because "stop" method (for the Thread class)
|
372 |
* is deprecated.
|
373 |
*
|
374 |
*
|
375 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
376 |
*/
|
377 |
private class searchThread implements Runnable { |
378 |
volatile Thread myThread = null; |
379 |
|
380 |
public searchThread() {
|
381 |
myThread = new Thread(this); |
382 |
myThread.start(); |
383 |
} |
384 |
|
385 |
public void stop() { |
386 |
myThread.stop(); |
387 |
} |
388 |
|
389 |
/*
|
390 |
* (non-Javadoc)
|
391 |
* @see java.lang.Runnable#run()
|
392 |
*/
|
393 |
public void run() { |
394 |
try {
|
395 |
doSearch(); |
396 |
} catch (Exception e) { |
397 |
e.printStackTrace(); |
398 |
} |
399 |
if ((features != null) && (features.length >= 0)) { |
400 |
showResults(); |
401 |
} |
402 |
searchThreads.remove(this);
|
403 |
if (searchThreads.size() == 0){ |
404 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
405 |
} |
406 |
} |
407 |
} |
408 |
|
409 |
public GazetteerQuery getQuery() {
|
410 |
return query;
|
411 |
} |
412 |
|
413 |
public String getCurrentServer() { |
414 |
return currentServer;
|
415 |
} |
416 |
|
417 |
public void setCurrentServer(String currentServer) { |
418 |
this.currentServer = currentServer;
|
419 |
} |
420 |
} |