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