root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / catalog / ui / search / SearchDialogPanel.java @ 15558
History | View | Annotate | Download (11 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.catalog.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.CatalogClient; |
56 |
import es.gva.cit.catalog.drivers.GetRecordsReply; |
57 |
import es.gva.cit.catalog.querys.CatalogQuery; |
58 |
import es.gva.cit.catalog.querys.MetadataSearch; |
59 |
import es.gva.cit.catalog.querys.ServicesSearch; |
60 |
import es.gva.cit.catalog.ui.showresults.ShowResultsDialog; |
61 |
import es.gva.cit.catalog.utils.CatalogConstants; |
62 |
import es.gva.cit.gazetteer.querys.Feature; |
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 CatalogQuery query = null; |
70 |
protected Object serverConnectFrame; |
71 |
protected SearchUpperPanel upperPanel = null; |
72 |
protected SearchLowerPanel lowerPanel = null; |
73 |
protected SearchButtonPanel buttonsPanel = null; |
74 |
protected CatalogClient client = null; |
75 |
protected boolean isMinimized = true; |
76 |
private Collection searchThreads = null; |
77 |
private String currentServer = null; |
78 |
private GetRecordsReply recordsReply = null; |
79 |
|
80 |
/**
|
81 |
* This method initializes
|
82 |
* @param client
|
83 |
* @param translator
|
84 |
*/
|
85 |
public SearchDialogPanel(CatalogClient client, Object serverConnectFrame) { |
86 |
super();
|
87 |
searchThreads = new java.util.ArrayList();
|
88 |
this.client = client;
|
89 |
this.isMinimized = true; |
90 |
this.serverConnectFrame = serverConnectFrame;
|
91 |
initialize(); |
92 |
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* This method initializes this
|
97 |
*/
|
98 |
private void initialize() { |
99 |
setLayout(new BorderLayout()); |
100 |
add(getUpperPanel(),BorderLayout.NORTH);
|
101 |
add(getLowerPanel(),BorderLayout.CENTER);
|
102 |
add(getButtonPanel(),BorderLayout.SOUTH);
|
103 |
getLowerPanel().setVisible(false);
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* It Gets the upperPanel
|
108 |
* @return
|
109 |
*/
|
110 |
public SearchUpperPanel getUpperPanel() {
|
111 |
if (upperPanel == null){ |
112 |
upperPanel = new SearchUpperPanel();
|
113 |
upperPanel.addActionListener(this);
|
114 |
} |
115 |
return upperPanel;
|
116 |
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* It Gets the lowePanel
|
121 |
* @return
|
122 |
*/
|
123 |
public SearchLowerPanel getLowerPanel() {
|
124 |
if (lowerPanel == null){ |
125 |
lowerPanel = new SearchLowerPanel(client.getAditionalSearchPanel());
|
126 |
lowerPanel.addCoordinatesRelationship( |
127 |
Messages.getText("coordinatesContains"));
|
128 |
lowerPanel.addCoordinatesRelationship( |
129 |
Messages.getText("coordinatesFullyOutsideOf"));
|
130 |
addServices(); |
131 |
addCathegories(); |
132 |
addScales(); |
133 |
} |
134 |
return lowerPanel;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Add the services
|
139 |
*/
|
140 |
private void addServices(){ |
141 |
upperPanel.addService(new MetadataSearch(Messages.getText("data"))); |
142 |
//upperPanel.addService(new ServicesSearch(Messages.getText("services")));
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Adds the default cathegories
|
147 |
*/
|
148 |
private void addCathegories(){ |
149 |
lowerPanel.addCathegory(Messages.getText("cathegoryAny"));
|
150 |
lowerPanel.addCathegory(Messages.getText("cathegoryBiota"));
|
151 |
lowerPanel.addCathegory(Messages.getText("cathegoryBoundaries"));
|
152 |
lowerPanel.addCathegory(Messages.getText("cathegoryClimatologyMeteorologyAtmosphere"));
|
153 |
lowerPanel.addCathegory(Messages.getText("cathegoryEconomy"));
|
154 |
lowerPanel.addCathegory(Messages.getText("cathegoryElevation"));
|
155 |
lowerPanel.addCathegory(Messages.getText("cathegoryEnvironment"));
|
156 |
lowerPanel.addCathegory(Messages.getText("cathegoryFarming"));
|
157 |
lowerPanel.addCathegory(Messages.getText("cathegoryGeoscientificInformation"));
|
158 |
lowerPanel.addCathegory(Messages.getText("cathegoryHealth"));
|
159 |
lowerPanel.addCathegory(Messages.getText("cathegoryImageryBaseMapsEarthCover"));
|
160 |
lowerPanel.addCathegory(Messages.getText("cathegoryInlandWaters"));
|
161 |
lowerPanel.addCathegory(Messages.getText("cathegoryIntelligenceMilitary"));
|
162 |
lowerPanel.addCathegory(Messages.getText("cathegoryLocation"));
|
163 |
lowerPanel.addCathegory(Messages.getText("cathegoryOceans"));
|
164 |
lowerPanel.addCathegory(Messages.getText("cathegoryPlanningCadastre"));
|
165 |
lowerPanel.addCathegory(Messages.getText("cathegorySociety"));
|
166 |
lowerPanel.addCathegory(Messages.getText("cathegoryStructure"));
|
167 |
lowerPanel.addCathegory(Messages.getText("cathegoryTransportation"));
|
168 |
lowerPanel.addCathegory(Messages.getText("cathegoryUtilitiesCommunication"));
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Adds the default scales
|
173 |
*/
|
174 |
private void addScales(){ |
175 |
lowerPanel.addScale(Messages.getText("scaleAny"));
|
176 |
lowerPanel.addScale(Messages.getText("scaleI"));
|
177 |
lowerPanel.addScale(Messages.getText("scaleII"));
|
178 |
lowerPanel.addScale(Messages.getText("scaleIII"));
|
179 |
lowerPanel.addScale(Messages.getText("scaleIV"));
|
180 |
lowerPanel.addScale(Messages.getText("scaleV"));
|
181 |
lowerPanel.addScale(Messages.getText("scaleVI"));
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* @return the buttons panel
|
186 |
*/
|
187 |
public JPanel getButtonPanel() { |
188 |
if (buttonsPanel == null) { |
189 |
buttonsPanel = new SearchButtonPanel();
|
190 |
buttonsPanel.addActionListener(this);
|
191 |
} |
192 |
return buttonsPanel;
|
193 |
} |
194 |
|
195 |
/*
|
196 |
* (non-Javadoc)
|
197 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
198 |
*/
|
199 |
public void actionPerformed(ActionEvent e) { |
200 |
if (e.getActionCommand().compareTo(CatalogConstants.SEARCH_BUTTON_ACTION_COMMAND)==0) { |
201 |
searchButtonActionPerformed(); |
202 |
}else if (e.getActionCommand().compareTo(CatalogConstants.CLOSE_BUTTON_ACTION_COMMAND)==0){ |
203 |
closeButtonActionPerformed(); |
204 |
}else if(e.getActionCommand().compareTo(CatalogConstants.RESIZE_BUTTON_ACTION_COMMAND)==0){ |
205 |
resizeButtonActionPerformed(); |
206 |
}else if (e.getActionCommand().compareTo(CatalogConstants.CANCEL_BUTTON_ACTION_COMMAND)==0){ |
207 |
cancelSearchesButtonActionPerformed(); |
208 |
}else if (e.getActionCommand().compareTo(CatalogConstants.LAST_BUTTON_ACTION_COMMAND)==0){ |
209 |
lastButtonActionPerformed(); |
210 |
} |
211 |
} |
212 |
|
213 |
/**
|
214 |
* thrown when the resize button is clicked
|
215 |
*/
|
216 |
protected void resizeButtonActionPerformed() { |
217 |
if (isMinimized){
|
218 |
parent.setSize(parent.getWidth(),487);
|
219 |
getLowerPanel().setVisible(true);
|
220 |
getUpperPanel().setUpIcon(); |
221 |
}else{
|
222 |
parent.setSize(parent.getWidth(),165);
|
223 |
getLowerPanel().setVisible(false);
|
224 |
getUpperPanel().setDownIcon(); |
225 |
} |
226 |
isMinimized = !isMinimized; |
227 |
} |
228 |
|
229 |
/**
|
230 |
* thrown when the search button is clicked
|
231 |
* @throws Exception
|
232 |
*/
|
233 |
protected void searchButtonActionPerformed() { |
234 |
SearchThread st = new SearchThread();
|
235 |
searchThreads.add(st); |
236 |
setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
237 |
} |
238 |
|
239 |
|
240 |
/**
|
241 |
* thrown when the last button is clicked
|
242 |
*/
|
243 |
protected void lastButtonActionPerformed() { |
244 |
((JFrame)serverConnectFrame).setVisible(true); |
245 |
parent.setVisible(false);
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* thrown when the cancel button is clicked
|
250 |
*/
|
251 |
protected void cancelSearchesButtonActionPerformed() { |
252 |
for (int i=0 ; i<searchThreads.size() ; i++){ |
253 |
SearchThread st = (SearchThread)searchThreads.toArray()[i]; |
254 |
st.stop(); |
255 |
} |
256 |
searchThreads.clear(); |
257 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
258 |
} |
259 |
|
260 |
/**
|
261 |
* thrown when the close button is clicked
|
262 |
*/
|
263 |
protected void closeButtonActionPerformed() { |
264 |
parent.setVisible(false);
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* @return the selected query
|
269 |
*/
|
270 |
protected CatalogQuery doQuery() {
|
271 |
CatalogQuery query = client.createNewQuery(); |
272 |
query.setService(upperPanel.getService()); |
273 |
query.setTitle(upperPanel.getTitle()); |
274 |
query.setTitleFilter(lowerPanel.getTitleOption()); |
275 |
query.setAbstract(lowerPanel.getAbstract()); |
276 |
query.setThemeKey(lowerPanel.getKeys()); |
277 |
query.setTopic(lowerPanel.getCathegory()); |
278 |
query.setScale(lowerPanel.getScale()); |
279 |
query.setProvider(lowerPanel.getProvider()); |
280 |
query.setDateFrom(lowerPanel.getDateFrom()); |
281 |
query.setDateTo(lowerPanel.getDateTo()); |
282 |
query.setCoordenates(lowerPanel.getCoordinates()); |
283 |
query.setCoordenatesFilter(lowerPanel.getCoordinatesOption()); |
284 |
query.setMinimized(isMinimized); |
285 |
query.setCoordinatesClicked(upperPanel.getRestrictAreaClicked()); |
286 |
return query;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* It returns the query that the user has selected
|
291 |
* @throws Exception
|
292 |
*
|
293 |
*/
|
294 |
private void doSearch() throws Exception { |
295 |
recordsReply = client.getRecords(doQuery(), 1);
|
296 |
if (recordsReply == null) { |
297 |
JOptionPane.showMessageDialog(this, |
298 |
Messages.getText("errorGetRecords"),
|
299 |
"Error",
|
300 |
JOptionPane.ERROR_MESSAGE);
|
301 |
} else if (recordsReply.getRecordsNumber() == 0) { |
302 |
JOptionPane.showMessageDialog(this, |
303 |
Messages.getText("anyResult"),
|
304 |
Messages.getText("catalog_search"),
|
305 |
JOptionPane.INFORMATION_MESSAGE);
|
306 |
} |
307 |
} |
308 |
|
309 |
/**
|
310 |
* @param features
|
311 |
*/
|
312 |
protected void showResultsActionPerformed(GetRecordsReply recordsReply) { |
313 |
new ShowResultsDialog(client, recordsReply, 1); |
314 |
} |
315 |
|
316 |
/**
|
317 |
*
|
318 |
* @param parent The parent to set.
|
319 |
*/
|
320 |
public void setParent(JFrame parent) { |
321 |
this.parent = parent;
|
322 |
} |
323 |
|
324 |
/**
|
325 |
* This class is used to manage the searches.
|
326 |
* It contains method to start and to stop a thread. It is
|
327 |
* necessary to create because "stop" method (for the Thread class)
|
328 |
* is deprecated.
|
329 |
*
|
330 |
*
|
331 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
332 |
*/
|
333 |
private class SearchThread implements Runnable { |
334 |
volatile Thread myThread = null; |
335 |
|
336 |
public SearchThread() {
|
337 |
myThread = new Thread(this); |
338 |
myThread.start(); |
339 |
} |
340 |
|
341 |
public void stop() { |
342 |
myThread.stop(); |
343 |
} |
344 |
|
345 |
/*
|
346 |
* (non-Javadoc)
|
347 |
* @see java.lang.Runnable#run()
|
348 |
*/
|
349 |
public void run() { |
350 |
try {
|
351 |
doSearch(); |
352 |
} catch (Exception e) { |
353 |
e.printStackTrace(); |
354 |
} |
355 |
if ((recordsReply != null) && (recordsReply.getRecordsNumber() > 0)) { |
356 |
showResultsActionPerformed(recordsReply); |
357 |
} |
358 |
searchThreads.remove(this);
|
359 |
if (searchThreads.size() == 0){ |
360 |
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
361 |
} |
362 |
} |
363 |
} |
364 |
|
365 |
public CatalogQuery getQuery() {
|
366 |
return query;
|
367 |
} |
368 |
|
369 |
public String getCurrentServer() { |
370 |
return currentServer;
|
371 |
} |
372 |
|
373 |
public void setCurrentServer(String currentServer) { |
374 |
this.currentServer = currentServer;
|
375 |
} |
376 |
} |