Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appCatalog / src / org / gvsig / catalog / ui / search / SearchDialogPanel.java @ 28434

History | View | Annotate | Download (11.2 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 org.gvsig.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.Icon;
50
import javax.swing.ImageIcon;
51
import javax.swing.JFrame;
52
import javax.swing.JOptionPane;
53
import javax.swing.JPanel;
54

    
55
import org.gvsig.catalog.CatalogClient;
56
import org.gvsig.catalog.drivers.GetRecordsReply;
57
import org.gvsig.catalog.querys.CatalogQuery;
58
import org.gvsig.catalog.querys.MetadataSearch;
59
import org.gvsig.catalog.ui.showresults.ShowResultsDialog;
60
import org.gvsig.catalog.utils.CatalogConstants;
61
import org.gvsig.i18n.Messages;
62

    
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
                getUpperPanel().setIcon(getDownIcon());
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().setIcon(getUpIcon());
221
                }else{
222
                        parent.setSize(parent.getWidth(),165);
223
                        getLowerPanel().setVisible(false);                        
224
                        getUpperPanel().setIcon(getDownIcon());
225
                }
226
                isMinimized = !isMinimized;
227
        } 
228
        
229
        protected Icon getUpIcon(){
230
                return new ImageIcon("./gvSIG/extensiones/org.gvsig.catalog/images/up.png");
231
        }
232
        
233
        protected Icon getDownIcon(){
234
                return new ImageIcon("./gvSIG/extensiones/org.gvsig.catalog/images/down.png");
235
        }
236

    
237
        /**
238
         * thrown when the search button is clicked
239
         * @throws Exception 
240
         */
241
        protected void searchButtonActionPerformed() {        
242
                SearchThread st =  new SearchThread();
243
                searchThreads.add(st);   
244
                setCursor(new Cursor(Cursor.WAIT_CURSOR));       
245
        } 
246
        
247

    
248
        /**
249
         * thrown when the last button is clicked
250
         */
251
        protected void lastButtonActionPerformed() {        
252
                ((JFrame)serverConnectFrame).setVisible(true);
253
                parent.setVisible(false);
254
        }         
255

    
256
        /**
257
         * thrown when the cancel button is clicked
258
         */
259
        protected void cancelSearchesButtonActionPerformed() {        
260
                for (int i=0 ; i<searchThreads.size() ; i++){
261
                        SearchThread st = (SearchThread)searchThreads.toArray()[i];
262
                        st.stop();            
263
                }     
264
                searchThreads.clear();
265
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));        
266
        } 
267

    
268
        /**
269
         * thrown when the close button is clicked
270
         */
271
        protected void closeButtonActionPerformed() {        
272
                parent.setVisible(false);
273
        } 
274

    
275
        /**
276
         * @return the selected query
277
         */
278
        protected CatalogQuery doQuery() {        
279
                CatalogQuery query = client.createNewQuery();
280
                query.setService(upperPanel.getService());
281
                query.setTitle(upperPanel.getTitle());
282
                query.setTitleFilter(lowerPanel.getTitleOption());
283
                query.setAbstract(lowerPanel.getAbstract());
284
                query.setThemeKey(lowerPanel.getKeys());
285
                query.setTopic(lowerPanel.getCathegory());
286
                query.setScale(lowerPanel.getScale());
287
                query.setProvider(lowerPanel.getProvider());
288
                query.setDateFrom(lowerPanel.getDateFrom());
289
                query.setDateTo(lowerPanel.getDateTo());
290
                query.setCoordenates(lowerPanel.getCoordinates());
291
                query.setCoordenatesFilter(lowerPanel.getCoordinatesOption());
292
                query.setMinimized(isMinimized);
293
                query.setCoordinatesClicked(upperPanel.getRestrictAreaClicked());
294
                return query;
295
        } 
296

    
297
        /**
298
         * It returns the query that the user has selected
299
         * @throws Exception 
300
         * 
301
         */
302
        private void doSearch() throws Exception {        
303
                recordsReply = client.getRecords(doQuery(), 1);
304
                if (recordsReply == null) {
305
                        JOptionPane.showMessageDialog(this,
306
                                        Messages.getText("errorGetRecords"),
307
                                        "Error",
308
                                        JOptionPane.ERROR_MESSAGE);
309
                } else if (recordsReply.getRecordsNumber() == 0) {
310
                        JOptionPane.showMessageDialog(this,
311
                                        Messages.getText("anyResult"),
312
                                        Messages.getText("catalog_search"),
313
                                        JOptionPane.INFORMATION_MESSAGE);
314
                }
315
        } 
316

    
317
        /**
318
         * @param features 
319
         */
320
        protected void showResultsActionPerformed(GetRecordsReply recordsReply) {        
321
                new ShowResultsDialog(client, recordsReply, 1);                        
322
        } 
323

    
324
        /**
325
         * 
326
         * @param parent The parent to set.
327
         */
328
        public void setParent(JFrame parent) {        
329
                this.parent = parent;
330
        } 
331

    
332
        /**
333
         * This class is used to manage the searches.
334
         * It contains method to start and to stop a thread. It is
335
         * necessary to create because "stop" method (for the Thread class)
336
         * is deprecated.
337
         * 
338
         * 
339
         * @author Jorge Piera Llodra (piera_jor@gva.es)
340
         */
341
        private class SearchThread implements Runnable {
342
                volatile Thread myThread = null;
343

    
344
                public  SearchThread() {        
345
                        myThread = new Thread(this);
346
                        myThread.start();
347
                } 
348

    
349
                public void stop() {        
350
                        myThread.stop();
351
                } 
352

    
353
                /*
354
                 * (non-Javadoc)
355
                 * @see java.lang.Runnable#run()
356
                 */
357
                public void run() {        
358
                        try {
359
                                doSearch();
360
                        } catch (Exception e) {
361
                                e.printStackTrace();
362
                        }
363
                        if ((recordsReply != null) && (recordsReply.getRecordsNumber() > 0)) {
364
                                showResultsActionPerformed(recordsReply);
365
                        }
366
                        searchThreads.remove(this);
367
                        if (searchThreads.size() == 0){
368
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));       
369
                        }
370
                } 
371
        }
372

    
373
        public CatalogQuery getQuery() {
374
                return query;
375
        }
376

    
377
        public String getCurrentServer() {
378
                return currentServer;
379
        }
380

    
381
        public void setCurrentServer(String currentServer) {
382
                this.currentServer = currentServer;
383
        }
384
}