Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / ShowResultsDialogPanel.java @ 3036

History | View | Annotate | Download (6.79 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

    
44
import es.gva.cit.catalogClient.CatalogClient;
45
import es.gva.cit.catalogClient.metadataXML.XMLTreeNumberOfRecordsAnswer;
46
import es.gva.cit.catalogClient.parsers.Resource;
47

    
48
import org.w3c.dom.Node;
49

    
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52

    
53
import javax.swing.JButton;
54
import javax.swing.JPanel;
55

    
56

    
57
/**
58
 * @author Jorge Piera Llodra (piera_jor@gva.es)
59
 */
60
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
61
    public ShowResultsPanel ppalPanel = null;
62
    public Node[] nodes = null;
63
    CatalogClient client = null;
64
    int currentRecord = 0;
65
    JButton nextButton = null;
66
    JButton lastButton = null;
67
    JButton descriptionButton = null;
68
    JButton mapButton = null;
69
    JButton closeButton = null;
70

    
71
    public ShowResultsDialogPanel(CatalogClient client, Node[] nodes,
72
        int currentRecord) {
73
        this.nodes = nodes;
74
        this.client = client;
75
        this.currentRecord = currentRecord;
76

    
77
        int numRecords = XMLTreeNumberOfRecordsAnswer.getNumberOfRecords(nodes[0]);
78
        ppalPanel = new ShowResultsPanel(nodes[currentRecord],
79
                client.getProtocol(), numRecords,client.getUrl());
80
        ppalPanel = new ShowResultsPanel(nodes[currentRecord],
81
                client.getProtocol(), numRecords,client.getUrl());
82

    
83
        setDefaultButtonListeners();
84
        enableMapButton();
85

    
86
        add(ppalPanel);
87
    }
88
    
89
    public void enableMapButton(){
90
            getMapButton().setEnabled(false);
91
            Resource[] resources = ppalPanel.getTags().getResources();
92
        if (resources == null)
93
            return;
94
            for (int i = 0; i < resources.length; i++) {
95
                String protocol = resources[i].getProtocol();
96
                        
97
                        if (protocol != null){                
98
                            if ((protocol.toLowerCase().indexOf("ogc:wcs") >= 0) ||
99
                                    (protocol.toLowerCase().indexOf("ogc:wms") >=0) ||
100
                                    (protocol.toLowerCase().indexOf("ogc:wfs") >=0) ||
101
                                    (protocol.toLowerCase().indexOf("postgis") >=0) ||
102
                                    (protocol.toLowerCase().indexOf("www:link") >=0) ||
103
                                    (protocol.toLowerCase().indexOf("www:download") >=0)){
104
                                getMapButton().setEnabled(true);
105
                                return;
106
                            }
107
                        }
108
        }        
109
            
110
    }
111

    
112
    public void setDefaultButtonListeners() {
113
        nextButton = ppalPanel.getNextButton();
114
        lastButton = ppalPanel.getLastButton();
115
        descriptionButton = ppalPanel.getDescriptionButton();
116
        mapButton = ppalPanel.getMapButton();
117
        closeButton = ppalPanel.getCloseButton();
118

    
119
        nextButton.addActionListener(this);
120
        lastButton.addActionListener(this);
121
        descriptionButton.addActionListener(this);
122
        mapButton.addActionListener(this);
123
        closeButton.addActionListener(this);
124
    }
125

    
126
    public JButton getDescriptionButton() {
127
        return descriptionButton;
128
    }
129

    
130
    public JButton getMapButton() {
131
        return mapButton;
132
    }
133
    
134
    public JButton getCloseButton(){
135
        return closeButton;
136
    }
137

    
138
    public void createNewSearch(int firstRecord) {
139
        Node[] nodesRecords = null;
140

    
141
        nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(),
142
                null, firstRecord);
143

    
144
        this.nodes = nodesRecords;
145
    }
146

    
147
    public int getCurrentNode() {
148
        if ((currentRecord % 10) == 0) {
149
            return 10;
150
        } else {
151
            return (currentRecord % 10);
152
        }
153
    }
154

    
155
    public void actionPerformed(ActionEvent e) {
156
        if (e.getActionCommand().equals("Siguiente")) {
157
            nextButtonActionPerformed();
158
        } 
159
        if (e.getActionCommand().equals("Anterior")) {
160
            lastButtonActionPerformed();
161
        } 
162
        if (e.getActionCommand().equals("Descripcion")) {
163
            descriptionButtonActionPerformed();
164
        } 
165
        if (e.getActionCommand().equals("A?adir Capa")) {
166
            mapButtonActionPerformed();
167
        } 
168
        if (e.getActionCommand().equals("Cerrar")) {
169
            closeButtonActionPerformed();
170
        }
171
       
172
    }
173

    
174
    public void nextButtonActionPerformed() {
175
        this.currentRecord = this.currentRecord + 1;
176

    
177
        if (this.currentRecord == XMLTreeNumberOfRecordsAnswer.getNumberOfRecords(
178
                    nodes[0])) {
179
            nextButton.setEnabled(false);
180
        } else {
181
            nextButton.setEnabled(true);
182
        }
183

    
184
        lastButton.setEnabled(true);
185

    
186
        if ((this.currentRecord % 10) == 1) {
187
            createNewSearch(currentRecord);
188
        }
189

    
190
        ppalPanel.loadTextNewRecord(nodes[getCurrentNode()],
191
            client.getProtocol());
192
        ppalPanel.actualizaLabel(currentRecord);
193
        
194
        enableMapButton();
195
    }
196

    
197
    public void lastButtonActionPerformed() {
198
        this.currentRecord = this.currentRecord - 1;
199

    
200
        if (this.currentRecord == 1) {
201
            lastButton.setEnabled(false);
202
        } else {
203
            lastButton.setEnabled(true);
204
        }
205

    
206
        nextButton.setEnabled(true);
207

    
208
        if ((this.currentRecord % 10) == 0) {
209
            createNewSearch(currentRecord - 10 + 1);
210
        }
211

    
212
        ppalPanel.loadTextNewRecord(nodes[getCurrentNode()],
213
            client.getProtocol());
214
        ppalPanel.actualizaLabel(currentRecord);
215
        
216
        enableMapButton();
217
    }
218

    
219
    public void descriptionButtonActionPerformed() {
220
        ShowTreeDialog frame = new ShowTreeDialog(nodes[getCurrentNode()]);
221
    }
222

    
223
    public void mapButtonActionPerformed() {
224
        Resource[] resources = ppalPanel.getTags().getResources();
225
        ChooseResourceDialog dialog = new ChooseResourceDialog(resources);
226
               
227
    }
228
    
229
    public void closeButtonActionPerformed() {
230
        setVisible(false);
231
    }
232
}