Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / SearchDialogPanel.java @ 2967

History | View | Annotate | Download (7.65 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.gazetteer.ui;
42

    
43

    
44
import org.w3c.dom.Node;
45

    
46
import es.gva.cit.gazetteer.GazetteerClient;
47
import es.gva.cit.gazetteer.parsers.adl.adlFeatureParser;
48
import es.gva.cit.gazetteer.parsers.wfsg.wfsgDescribeFeatureTypeParser;
49
import es.gva.cit.gazetteer.querys.Feature;
50
import es.gva.cit.gazetteer.querys.ThesaurusName;
51
import es.gva.cit.gazetteer.querys.Query;
52

    
53
import java.awt.Dimension;
54
import java.awt.FlowLayout;
55
import java.awt.event.ActionEvent;
56
import java.awt.event.ActionListener;
57

    
58
import javax.swing.BoxLayout;
59
import javax.swing.JButton;
60
import javax.swing.JOptionPane;
61
import javax.swing.JPanel;
62
import javax.swing.event.TreeSelectionEvent;
63
import javax.swing.event.TreeSelectionListener;
64

    
65

    
66
/**
67
 * @author Jorge Piera Llodra (piera_jor@gva.es)
68
 */
69
public class SearchDialogPanel extends JPanel implements ActionListener,TreeSelectionListener {
70
    //Panels
71
    protected JPanel ppalPanel = null;
72
    protected SearchPanel controlsPanel = null;
73
    protected JPanel buttonsPanel = null;
74

    
75
    //Buttons
76
    private JButton searchButton = null;
77
    private JButton closeButton = null;
78

    
79
    //Otros
80
    protected GazetteerClient client = null;
81
    protected Node[] nodesRecords = null;
82
    protected ThesaurusName currentFeature = null;
83

    
84
    /**
85
     * This method initializes
86
     *
87
     */
88
    public SearchDialogPanel(GazetteerClient client) {
89
        super();
90
        this.client = client;
91
        initialize();
92
       
93
    }
94

    
95
    /**
96
     * This method initializes this
97
     *
98
     * @return void
99
     */
100
    private void initialize() {
101
        ppalPanel = new JPanel();
102
        ppalPanel.setLocation(0, 0);
103
        ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS));
104

    
105
        ppalPanel.add(getControlsPanel(), null);
106
        ppalPanel.add(getButtonPanel(), null);
107

    
108
        add(ppalPanel);
109

    
110
        setDefaultButtonListeners();
111
    }
112

    
113
    public void setCatalogClient(GazetteerClient catCli) {
114
        this.client = catCli;
115
    }
116

    
117
    public JPanel getControlsPanel() {
118
        if (controlsPanel == null) {
119
            controlsPanel = new SearchPanel(client.getLnkIGazetteerDriver().getVectorFeatures());
120
            controlsPanel.setPreferredSize(new java.awt.Dimension(727, 455));
121
            controlsPanel.setLocation(0, 0);
122
            
123
        }
124

    
125
        return controlsPanel;
126
    }
127

    
128
    public JPanel getButtonPanel() {
129
        if (buttonsPanel == null) {
130
            buttonsPanel = new JPanel(new FlowLayout());
131
            buttonsPanel.add(getSearchButton());
132
            buttonsPanel.add(getCloseButton());
133
        }
134

    
135
        return buttonsPanel;
136
    }
137

    
138
    public JButton getSearchButton() {
139
        if (searchButton == null) {
140
            searchButton = new JButton("Buscar");
141
            searchButton.setSize(new Dimension(30, 20));
142
            searchButton.setActionCommand("Buscar");
143
        }
144

    
145
        return searchButton;
146
    }
147
    
148
    public JButton getCloseButton() {
149
        if (closeButton == null) {
150
            closeButton = new JButton("Cerrar");
151
            closeButton.setSize(new Dimension(30, 20));
152
            closeButton.setActionCommand("Cerrar");
153
        }
154

    
155
        return closeButton;
156
    }   
157
    
158
    public ThesaurusName getFeatureSelected(){
159
        //return (Feature) controlsPanel.getTipoList().getSelectedValue();
160
        return controlsPanel.getType();
161
    }
162
    
163
    public void setDefaultButtonListeners() {
164
        getSearchButton().addActionListener(this);
165
        getCloseButton().addActionListener(this);
166
        controlsPanel.getTipoList().addTreeSelectionListener(this);
167
    }
168

    
169
    /* (non-Javadoc)
170
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
171
     */
172
    public void actionPerformed(ActionEvent e) {
173
        //Buscar
174
        if (e.getActionCommand() == "Buscar") {
175
            searchButtonActionPerformed();
176
        } 
177
        if (e.getActionCommand() == "Cerrar") {
178
            closeButtonActionPerformed();
179
        }
180
    }
181
    
182
    protected void searchButtonActionPerformed(){
183
        Query currentQuery = doQuery();
184
        doSearch();
185

    
186
        if ((nodesRecords != null) && (nodesRecords.length > 0)) {
187
            showResults();
188
        }
189
    }
190
    
191
    protected void closeButtonActionPerformed(){
192
        this.setVisible(false);
193
    }
194

    
195
    public Query doQuery() {
196
       return new Query(controlsPanel.getName(),
197
            controlsPanel.getConcordancia(),
198
            controlsPanel.getType(),
199
            controlsPanel.getNPaginas(),
200
            controlsPanel.getCoordenadas(),
201
            controlsPanel.getCoordenadasOpcion());
202
    }
203

    
204
    public void doSearch() {
205
        nodesRecords = client.getLnkIGazetteerDriver().getFeature(client.getUrl(),
206
                doQuery());
207

    
208
        if (nodesRecords == null) {
209
            JOptionPane.showMessageDialog(this,
210
                "Se ha producido un error al hacer el get records", "Error",
211
                JOptionPane.ERROR_MESSAGE);
212
        } 
213
        
214
    }
215

    
216
    public void showResults() {
217
        Feature[] features = new adlFeatureParser().parse(nodesRecords[0]);
218
        if (features.length == 0){
219
            JOptionPane.showMessageDialog(this,
220
                    "La b?squeda no ha producido ning?n resultado", "B?squeda de Gazetteer",
221
                    JOptionPane.INFORMATION_MESSAGE);
222
        }else{
223
            ShowResultsActionPerformed(features);
224
        }
225
    }
226
    
227
    public void ShowResultsActionPerformed(Feature[] features){
228
        new ShowResultsDialog(this.client,features,controlsPanel.getNPaginas());
229
    }
230
    
231
    
232
   
233
    /**
234
     * It loads the fields for the feature
235
     * @param feature
236
     */
237
    protected void loadCurrentFeature(ThesaurusName feature){
238
        Node[] fields = client.getLnkIGazetteerDriver().describeFeatureType(client.getUrl(),
239
               feature.getName());
240
       
241
        if (client.getProtocol().equals("WFS-G"))        
242
            new wfsgDescribeFeatureTypeParser().parse(fields[0],feature);
243
     
244
        System.out.println(currentFeature.getName());
245
    }
246

    
247
    /* (non-Javadoc)
248
     * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
249
     */
250
    public void valueChanged(TreeSelectionEvent e) {
251
        if (currentFeature == null){
252
            currentFeature = getFeatureSelected();
253
            loadCurrentFeature(currentFeature);
254
       }else{
255
            ThesaurusName feature = getFeatureSelected();
256
            if (!(currentFeature.equals(feature))){
257
               if (feature != null){
258
                   currentFeature = feature;
259
                   loadCurrentFeature(currentFeature);
260
               }
261
            }
262
        }
263
        
264
    }
265
}