Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / ShowResultsDialogPanel.java @ 3081

History | View | Annotate | Download (7.07 KB)

1 2820 jorpiell
/* 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 2145 jorpiell
package es.gva.cit.catalogClient.ui;
42
43 2628 jorpiell
44 2724 jorpiell
import es.gva.cit.catalogClient.CatalogClient;
45 3073 jorpiell
import es.gva.cit.catalogClient.metadataXML.XMLNode;
46 2724 jorpiell
import es.gva.cit.catalogClient.metadataXML.XMLTreeNumberOfRecordsAnswer;
47
import es.gva.cit.catalogClient.parsers.Resource;
48
49
50 2145 jorpiell
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52 2724 jorpiell
53 2145 jorpiell
import javax.swing.JButton;
54 3081 jorpiell
import javax.swing.JDialog;
55 2145 jorpiell
import javax.swing.JPanel;
56
57
58 2724 jorpiell
/**
59 2820 jorpiell
 * @author Jorge Piera Llodra (piera_jor@gva.es)
60 2724 jorpiell
 */
61
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
62 3081 jorpiell
    //It is needed to close the frame
63
    private JDialog parent;
64
65 2724 jorpiell
    public ShowResultsPanel ppalPanel = null;
66 3073 jorpiell
    public XMLNode[] nodes = null;
67 2724 jorpiell
    CatalogClient client = null;
68
    int currentRecord = 0;
69 3081 jorpiell
70 2724 jorpiell
    JButton nextButton = null;
71
    JButton lastButton = null;
72
    JButton descriptionButton = null;
73
    JButton mapButton = null;
74 2868 jorpiell
    JButton closeButton = null;
75 2145 jorpiell
76 3073 jorpiell
    public ShowResultsDialogPanel(CatalogClient client, XMLNode[] nodes,
77 2724 jorpiell
        int currentRecord) {
78
        this.nodes = nodes;
79
        this.client = client;
80
        this.currentRecord = currentRecord;
81 2145 jorpiell
82 2724 jorpiell
        int numRecords = XMLTreeNumberOfRecordsAnswer.getNumberOfRecords(nodes[0]);
83
        ppalPanel = new ShowResultsPanel(nodes[currentRecord],
84 2842 jorpiell
                client.getProtocol(), numRecords,client.getUrl());
85 2724 jorpiell
        ppalPanel = new ShowResultsPanel(nodes[currentRecord],
86 2842 jorpiell
                client.getProtocol(), numRecords,client.getUrl());
87 2145 jorpiell
88 2724 jorpiell
        setDefaultButtonListeners();
89 2820 jorpiell
        enableMapButton();
90 2724 jorpiell
91
        add(ppalPanel);
92
    }
93 2820 jorpiell
94
    public void enableMapButton(){
95
            getMapButton().setEnabled(false);
96
            Resource[] resources = ppalPanel.getTags().getResources();
97
        if (resources == null)
98
            return;
99
            for (int i = 0; i < resources.length; i++) {
100
                String protocol = resources[i].getProtocol();
101
102 2826 jorpiell
                        if (protocol != null){
103 2824 jorpiell
                            if ((protocol.toLowerCase().indexOf("ogc:wcs") >= 0) ||
104 2826 jorpiell
                                    (protocol.toLowerCase().indexOf("ogc:wms") >=0) ||
105 2872 jorpiell
                                    (protocol.toLowerCase().indexOf("ogc:wfs") >=0) ||
106
                                    (protocol.toLowerCase().indexOf("postgis") >=0) ||
107 2832 jorpiell
                                    (protocol.toLowerCase().indexOf("www:link") >=0) ||
108
                                    (protocol.toLowerCase().indexOf("www:download") >=0)){
109 2824 jorpiell
                                getMapButton().setEnabled(true);
110
                                return;
111
                            }
112 2826 jorpiell
                        }
113 2820 jorpiell
        }
114
115
    }
116 2724 jorpiell
117
    public void setDefaultButtonListeners() {
118
        nextButton = ppalPanel.getNextButton();
119
        lastButton = ppalPanel.getLastButton();
120
        descriptionButton = ppalPanel.getDescriptionButton();
121
        mapButton = ppalPanel.getMapButton();
122 2868 jorpiell
        closeButton = ppalPanel.getCloseButton();
123 2724 jorpiell
124
        nextButton.addActionListener(this);
125
        lastButton.addActionListener(this);
126
        descriptionButton.addActionListener(this);
127
        mapButton.addActionListener(this);
128 2868 jorpiell
        closeButton.addActionListener(this);
129 2724 jorpiell
    }
130
131
    public JButton getDescriptionButton() {
132
        return descriptionButton;
133
    }
134
135
    public JButton getMapButton() {
136
        return mapButton;
137
    }
138 2868 jorpiell
139
    public JButton getCloseButton(){
140
        return closeButton;
141
    }
142 2724 jorpiell
143
    public void createNewSearch(int firstRecord) {
144 3073 jorpiell
        XMLNode[] nodesRecords = null;
145 2724 jorpiell
146
        nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(),
147
                null, firstRecord);
148
149
        this.nodes = nodesRecords;
150
    }
151
152
    public int getCurrentNode() {
153
        if ((currentRecord % 10) == 0) {
154
            return 10;
155
        } else {
156
            return (currentRecord % 10);
157
        }
158
    }
159
160
    public void actionPerformed(ActionEvent e) {
161
        if (e.getActionCommand().equals("Siguiente")) {
162
            nextButtonActionPerformed();
163 2868 jorpiell
        }
164
        if (e.getActionCommand().equals("Anterior")) {
165 2724 jorpiell
            lastButtonActionPerformed();
166 2868 jorpiell
        }
167
        if (e.getActionCommand().equals("Descripcion")) {
168 2724 jorpiell
            descriptionButtonActionPerformed();
169 2868 jorpiell
        }
170 3036 jorpiell
        if (e.getActionCommand().equals("A?adir Capa")) {
171 2724 jorpiell
            mapButtonActionPerformed();
172 2868 jorpiell
        }
173
        if (e.getActionCommand().equals("Cerrar")) {
174
            closeButtonActionPerformed();
175 2724 jorpiell
        }
176 2868 jorpiell
177 2724 jorpiell
    }
178
179
    public void nextButtonActionPerformed() {
180
        this.currentRecord = this.currentRecord + 1;
181
182
        if (this.currentRecord == XMLTreeNumberOfRecordsAnswer.getNumberOfRecords(
183
                    nodes[0])) {
184
            nextButton.setEnabled(false);
185
        } else {
186
            nextButton.setEnabled(true);
187
        }
188
189
        lastButton.setEnabled(true);
190
191
        if ((this.currentRecord % 10) == 1) {
192
            createNewSearch(currentRecord);
193
        }
194
195
        ppalPanel.loadTextNewRecord(nodes[getCurrentNode()],
196
            client.getProtocol());
197
        ppalPanel.actualizaLabel(currentRecord);
198 2820 jorpiell
199
        enableMapButton();
200 2724 jorpiell
    }
201
202
    public void lastButtonActionPerformed() {
203
        this.currentRecord = this.currentRecord - 1;
204
205
        if (this.currentRecord == 1) {
206
            lastButton.setEnabled(false);
207
        } else {
208
            lastButton.setEnabled(true);
209
        }
210
211
        nextButton.setEnabled(true);
212
213
        if ((this.currentRecord % 10) == 0) {
214
            createNewSearch(currentRecord - 10 + 1);
215
        }
216
217
        ppalPanel.loadTextNewRecord(nodes[getCurrentNode()],
218
            client.getProtocol());
219
        ppalPanel.actualizaLabel(currentRecord);
220 2836 jorpiell
221
        enableMapButton();
222 2724 jorpiell
    }
223
224
    public void descriptionButtonActionPerformed() {
225
        ShowTreeDialog frame = new ShowTreeDialog(nodes[getCurrentNode()]);
226
    }
227
228
    public void mapButtonActionPerformed() {
229
        Resource[] resources = ppalPanel.getTags().getResources();
230 2820 jorpiell
        ChooseResourceDialog dialog = new ChooseResourceDialog(resources);
231
232 2724 jorpiell
    }
233 2868 jorpiell
234
    public void closeButtonActionPerformed() {
235 3081 jorpiell
        parent.setVisible(false);
236 2868 jorpiell
    }
237 3081 jorpiell
    /**
238
     * @param parent The parent to set.
239
     */
240
    public void setParent(JDialog parent) {
241
        this.parent = parent;
242
    }
243 2145 jorpiell
}