Statistics
| Revision:

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

History | View | Annotate | Download (9.7 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.querys.Query;
45

    
46
import org.w3c.dom.Node;
47

    
48

    
49
import java.awt.Dimension;
50
import java.awt.FlowLayout;
51
import java.awt.event.ActionEvent;
52
import java.awt.event.ActionListener;
53
import java.awt.event.ItemEvent;
54
import java.awt.event.ItemListener;
55

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

    
64

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

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

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

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

    
112
        ppalPanel.add(getControlsPanel(), null);
113
        if (isMinimized)
114
            ppalPanel.add(getCheckBoxPanel(),null);
115
        
116
        ppalPanel.add(getButtonsPanel(), null);
117

    
118
        add(ppalPanel);
119

    
120
        setDefaultButtonListeners();
121
        
122
        setTitle(title);
123
    }
124
    /**
125
     * Sets the CatalogClient 
126
     * @param client
127
     * CatalogClient
128
     */
129
    public void setCatalogClient(CatalogClient client) {
130
        this.client = client;
131
    }
132
    
133
    /**
134
     * It Gets the controlsPanel 
135
     * @return
136
     */
137
    
138
   public AbstractSearchPanel getControlsPanel() {
139
        if (isMinimized){
140
            parent.setSize(300, 130);  
141
            controlsPanel = new SearchMiniPanel();
142
            controlsPanel.setSize(200,55);
143
        }else{
144
            parent.setSize(675, 520);
145
            controlsPanel = new SearchPanel();
146
            controlsPanel.setSize(700,455);
147
        }
148
        return controlsPanel;
149
    }
150
   
151
   /**
152
    * It gets the checkBoxPanel
153
    * @return
154
    */
155
   public JPanel getCheckBoxPanel(){
156
       if (checkBoxPanel == null) {
157
           checkBoxPanel = new JPanel();
158
           checkBoxPanel.add(getAreaCheckBox());
159
       }
160
       return checkBoxPanel;
161
   }
162
   
163
   /**
164
    * It gets the buttons panel
165
    * @return
166
    */
167
    public JPanel getButtonsPanel() {
168
        if (buttonsPanel == null) {
169
            buttonsPanel = new JPanel(new FlowLayout());
170
            buttonsPanel.add(getSearchButton());
171
            buttonsPanel.add(getCloseButton());
172
            buttonsPanel.add(getSizeButton());
173
        }
174
        return buttonsPanel;
175
    }
176
    
177
    /**
178
     * It gets the search button
179
     * @return
180
     */
181
    public JButton getSearchButton() {
182
        if (searchButton == null) {
183
            searchButton = new JButton("Buscar");
184
            searchButton.setSize(new Dimension(30, 20));
185
            searchButton.setActionCommand("Search");
186
        }
187

    
188
        return searchButton;
189
    }
190
    
191
    /**
192
     * It gets the close button
193
     * @return
194
     */
195
    public JButton getCloseButton() {
196
        if (closeButton == null) {
197
            closeButton = new JButton("Cerrar");
198
            closeButton.setSize(new Dimension(30, 20));
199
            closeButton.setActionCommand("Close");
200
        }
201

    
202
        return closeButton;
203
    }
204
    
205
    /**
206
     * It  gets the change size button
207
     * @return
208
     */
209
    public JButton getSizeButton() {
210
        if (sizeButton == null) {
211
            sizeButton = new JButton("Avanzada");
212
            if (!(isMinimized))
213
                sizeButton.setText("Simple");
214
            sizeButton.setSize(new Dimension(30, 20));
215
            sizeButton.setActionCommand("Size");
216
        }
217
        return sizeButton;
218
    }    
219
    
220
    /**
221
     * It gets the checkBox area component
222
     * @return
223
     */
224
    public JCheckBox getAreaCheckBox(){
225
        if (areaCheckBox == null){
226
            areaCheckBox = new JCheckBox("Restringir el area de B?squeda");
227
            areaCheckBox.setActionCommand("areaCheckButton");
228
        }
229
        return areaCheckBox;
230
    }
231
    
232
    /**
233
     * It sets the listeners
234
     *
235
     */
236
    public void setDefaultButtonListeners() {
237
        getSearchButton().addActionListener(this);
238
        getCloseButton().addActionListener(this);
239
        getSizeButton().addActionListener(this);
240
        if (isMinimized){
241
            getAreaCheckBox().addItemListener(this);
242
            
243
        }
244
        
245
    }
246
    
247
     /* (non-Javadoc)
248
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
249
     */
250
    public void actionPerformed(ActionEvent e) {
251
        //Buscar
252
        if (e.getActionCommand() == "Search") {
253
            searchButtonActionPerformed();
254
        } 
255
        if (e.getActionCommand() == "Close") {
256
            closeButtonActionPerformed();
257
        }
258
        if (e.getActionCommand() == "Size") {
259
            sizeButtonActionPerformed();
260
        }        
261
        
262
    }    
263
       
264
    protected void sizeButtonActionPerformed(){
265
        parent.setVisible(false);
266
        SearchDialog panel = new SearchDialog(client,!(isMinimized),controlsPanel.getTitle());
267
    }
268
    
269
    protected void searchButtonActionPerformed(){
270
        Query currentQuery = doQuery();
271
        doSearch();
272

    
273
        if ((nodesRecords != null) && (nodesRecords.length > 1)) {
274
            showResults(nodesRecords);
275
        }
276
    }
277
    
278
    protected void closeButtonActionPerformed(){
279
        parent.setVisible(false);
280
    }
281

    
282
    /**
283
     * It returns the query that the user has selected
284
     * @return
285
     */
286
    public Query doQuery() {
287
        Query query = new Query(controlsPanel.getTitle(),
288
            controlsPanel.getTitleOption(), controlsPanel.getAbstract(),
289
            controlsPanel.getKeys(), controlsPanel.getCathegory(),
290
            controlsPanel.getScale(), controlsPanel.getProvider(),
291
            controlsPanel.getDateFrom(), controlsPanel.getDateTo(),
292
            controlsPanel.getCoordinates(), controlsPanel.getCoordinatesOption());
293
        query.setMinimized(isMinimized);
294
        return query;
295
    }
296
    
297
    /**
298
     * This method realizes the search
299
     *
300
     */
301
    public void doSearch() {
302
        nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(),
303
                doQuery(), 1);
304

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

    
321
    public void showResults(Node[] nodesRecords) {
322
        JDialog dialog = new ShowResultsDialog(client, nodesRecords, 1);
323
    }
324

    
325
    /* (non-Javadoc)
326
     * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
327
     * This methodhave to be implemented in gvSIG to load the bbox to o the search
328
     */
329
    public void itemStateChanged(ItemEvent e) {
330
        
331
        
332
    }
333
    
334
    /**
335
     * It sets the title field into the form
336
     * @param Title
337
     */
338
    public void setTitle(String title){
339
        controlsPanel.setTitle(title);
340
    }
341

    
342

    
343
    /**
344
     * @param isMinimized The isMinimized to set.
345
     */
346
    public void setMinimized(boolean isMinimized) {
347
        this.isMinimized = isMinimized;
348
    }
349

    
350
    /**
351
     * @return Returns the currentServer.
352
     */
353
    public String getCurrentServer() {
354
        return currentServer;
355
    }
356
    /**
357
     * @param currentServer The currentServer to set.
358
     */
359
    public void setCurrentServer(String currentServer) {
360
        this.currentServer = currentServer;
361
    }
362
}