Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / SearchDialogPanel.java @ 3108

History | View | Annotate | Download (9.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.catalogClient.ui;
42

    
43
import es.gva.cit.catalogClient.CatalogClient;
44
import es.gva.cit.catalogClient.metadataXML.XMLNode;
45
import es.gva.cit.catalogClient.querys.Query;
46

    
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

    
54
import javax.swing.BoxLayout;
55
import javax.swing.JButton;
56
import javax.swing.JCheckBox;
57
import javax.swing.JDialog;
58
import javax.swing.JFrame;
59
import javax.swing.JOptionPane;
60
import javax.swing.JPanel;
61

    
62

    
63
/**
64
 * @author Jorge Piera Llodra (piera_jor@gva.es)
65
 */
66
public class SearchDialogPanel extends JPanel implements ActionListener,ItemListener {
67
    //This component its used to resize the frame
68
    private JFrame parent;
69
    
70
    //Panels
71
    protected JPanel ppalPanel = null;
72
    protected SearchUpperPanel upperPanel = null;
73
    protected SearchLowerPanel lowerPanel = null;
74
    protected JPanel checkBoxPanel = null;
75
    protected JPanel buttonsPanel = null;
76

    
77
    //Buttons
78
    private JButton searchButton = null;
79
    private JButton closeButton = null;
80
    private JButton sizeButton = null;
81
    private JCheckBox areaCheckBox = null;
82

    
83
    //Otros
84
    protected CatalogClient client = null;
85
    protected XMLNode[] nodesRecords = null;
86
    protected boolean isMinimized = true;
87
    protected String currentServer = null;
88
   
89
    /**
90
     * This method initializes
91
     *
92
     */
93
    public SearchDialogPanel(boolean isMinimized,String title, JFrame parent) {
94
        super();
95
        this.isMinimized = isMinimized;
96
        this.parent = parent;
97
        initialize(title);
98
    }
99

    
100
    /**
101
     * This method initializes this
102
     *
103
     * @return void
104
     */
105
    protected void initialize(String title) {
106
        ppalPanel = null;
107
        ppalPanel = new JPanel();
108
        ppalPanel.setLocation(0, 0);
109
        ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS));
110

    
111
        ppalPanel.add(getUpperPanel());
112
        
113
        if (!(isMinimized))
114
            ppalPanel.add(getLowerPanel());
115
        
116
        ppalPanel.add(getButtonsPanel());
117

    
118
        add(ppalPanel);
119

    
120
        setDefaultButtonListeners();
121
        
122
        setTitle(title);
123
    }    
124
    /**
125
     * It Gets the upperPanel 
126
     * @return
127
     */
128
    
129
   public SearchUpperPanel getUpperPanel() {
130
       if (upperPanel == null){
131
            upperPanel = new SearchUpperPanel();  
132
          
133
        }
134
        return upperPanel;
135
       
136
    }
137
   /**
138
    * It Gets the lowePanel 
139
    * @return
140
    */
141
   
142
  public SearchLowerPanel getLowerPanel() {
143
      if (!(isMinimized)){
144
          parent.setSize(525,450);
145
          if (lowerPanel == null){
146
              lowerPanel = new SearchLowerPanel();  
147
              upperPanel.setUpIcon();
148
          }
149
      }
150
      return lowerPanel;
151
   }
152
   
153
    /**
154
    * It gets the buttons panel
155
    * @return
156
    */
157
    public JPanel getButtonsPanel() {
158
        if (buttonsPanel == null) {
159
            buttonsPanel = new JPanel(new FlowLayout());
160
            buttonsPanel.add(getSearchButton());
161
            buttonsPanel.add(getCloseButton());
162
        }
163
        return buttonsPanel;
164
    }
165
    
166
    /**
167
     * It gets the search button
168
     * @return
169
     */
170
    public JButton getSearchButton() {
171
        if (searchButton == null) {
172
            searchButton = new JButton("Buscar");
173
            searchButton.setSize(new Dimension(30, 20));
174
            searchButton.setActionCommand("Search");
175
        }
176

    
177
        return searchButton;
178
    }
179
    
180
    /**
181
     * It gets the close button
182
     * @return
183
     */
184
    public JButton getCloseButton() {
185
        if (closeButton == null) {
186
            closeButton = new JButton("Cerrar");
187
            closeButton.setSize(new Dimension(30, 20));
188
            closeButton.setActionCommand("Close");
189
        }
190

    
191
        return closeButton;
192
    }
193
    
194
    /**
195
     * It  gets the change size button
196
     * @return
197
     */
198
    public JButton getSizeButton() {
199
        if (sizeButton == null) {
200
            sizeButton = upperPanel.getSizeButton();
201
            sizeButton.setActionCommand("Size");
202
        }
203
        return sizeButton;
204
    }    
205
    
206
    /**
207
     * It gets the checkBox area component
208
     * @return
209
     */
210
    public JCheckBox getAreaCheckBox(){
211
        if (areaCheckBox == null){
212
            areaCheckBox = upperPanel.getCoordinatesCheckBox();
213
            areaCheckBox.setActionCommand("areaCheckButton");
214
        }
215
        return areaCheckBox;
216
    }
217
    
218
    /**
219
     * It sets the listeners
220
     *
221
     */
222
    public void setDefaultButtonListeners() {
223
        getSearchButton().addActionListener(this);
224
        getCloseButton().addActionListener(this);
225
        getSizeButton().addActionListener(this);
226
        getAreaCheckBox().addItemListener(this);
227
     }
228
    
229
     /* (non-Javadoc)
230
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
231
     */
232
    public void actionPerformed(ActionEvent e) {
233
        //Buscar
234
        if (e.getActionCommand() == "Search") {
235
            searchButtonActionPerformed();
236
        } 
237
        if (e.getActionCommand() == "Close") {
238
            closeButtonActionPerformed();
239
        }
240
        if (e.getActionCommand() == "Size") {
241
            sizeButtonActionPerformed();
242
        }     
243
        
244
    }    
245
       
246
    protected void sizeButtonActionPerformed(){
247
        parent.setVisible(false);
248
        new SearchDialog(client,!(isMinimized),upperPanel.getTitle());
249
    }
250
    
251
    protected void searchButtonActionPerformed(){
252
        Query currentQuery = doQuery();
253
        doSearch();
254

    
255
        if ((nodesRecords != null) && (nodesRecords.length > 1)) {
256
            showResults(nodesRecords);
257
        }
258
    }
259
    
260
    protected void closeButtonActionPerformed(){
261
        parent.setVisible(false);
262
    }
263

    
264
    /**
265
     * It returns the query that the user has selected
266
     * @return
267
     */
268
    public Query doQuery() {
269
        Query query = null;
270
        if (isMinimized){
271
            query = new Query(upperPanel.getTitle(),
272
                    "E", null,
273
                    null , null,
274
                    null , null,
275
                    null , null,
276
                    null , null);
277
            
278
        }else{
279
            query = new Query(upperPanel.getTitle(),
280
                    lowerPanel.getTitleOption(), lowerPanel.getAbstract(),
281
                    lowerPanel.getKeys(), lowerPanel.getCathegory(),
282
                    lowerPanel.getScale(), lowerPanel.getProvider(),
283
                    lowerPanel.getDateFrom(), lowerPanel.getDateTo(),
284
                    lowerPanel.getCoordinates(), lowerPanel.getCoordinatesOption());
285
        }
286
        query.setMinimized(isMinimized);
287
        return query;
288
    }
289
    
290
    /**
291
     * This method realizes the search
292
     *
293
     */
294
    public void doSearch() {
295
        nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(),
296
                doQuery(), 1);
297

    
298
        if (nodesRecords == null) {
299
            JOptionPane.showMessageDialog(this,
300
                "Se ha producido un error al hacer el get records", "Error",
301
                JOptionPane.ERROR_MESSAGE);
302
        } else if (nodesRecords.length == 1) {
303
            JOptionPane.showMessageDialog(this,
304
                "La b?squeda no ha producido ning?n resultado", "B?squeda",
305
                JOptionPane.INFORMATION_MESSAGE);
306
        }
307
    }
308
    
309
    /**
310
     * This methos calls to present results form
311
     * @param nodesRecords
312
     */
313

    
314
    public void showResults(XMLNode[] nodesRecords) {
315
        JDialog dialog = new ShowResultsDialog(client, nodesRecords, 1);
316
     }
317

    
318
    /* (non-Javadoc)
319
     * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
320
     * This methodhave to be implemented in gvSIG to load the bbox to o the search
321
     */
322
    public void itemStateChanged(ItemEvent e) {
323
        
324
        
325
    }  
326
    
327
    /**
328
     * It sets the title field
329
     * @param title
330
     */
331
    
332
    public void setTitle(String title){
333
        upperPanel.setTitle(title);
334
    }
335
        
336
    /**
337
     * @param isMinimized The isMinimized to set.
338
     */
339
    public void setMinimized(boolean isMinimized) {
340
        this.isMinimized = isMinimized;
341
    }
342

    
343
    /**
344
     * @return Returns the currentServer.
345
     */
346
    public String getCurrentServer() {
347
        return currentServer;
348
    }
349
    /**
350
     * @param currentServer The currentServer to set.
351
     */
352
    public void setCurrentServer(String currentServer) {
353
        this.currentServer = currentServer;
354
    }
355
    /**
356
     * @param parent The parent to set.
357
     */
358
    public void setParent(JFrame parent) {
359
        this.parent = parent;
360
    }
361
    /**
362
     * Sets the CatalogClient 
363
     * @param client
364
     * CatalogClient
365
     */
366
    public void setCatalogClient(CatalogClient client) {
367
        this.client = client;
368
    }
369
}