Statistics
| Revision:

gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.lib / src / main / java / org / gvsig / catalog / ui / showresults / ShowResultsDialogPanel.java @ 55

History | View | Annotate | Download (7.15 KB)

1

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

    
47
import javax.swing.JButton;
48
import javax.swing.JDialog;
49
import javax.swing.JPanel;
50

    
51
import org.gvsig.catalog.CatalogClient;
52
import org.gvsig.catalog.drivers.GetRecordsReply;
53
import org.gvsig.catalog.schemas.Record;
54
import org.gvsig.catalog.schemas.Resource;
55
import org.gvsig.catalog.ui.chooseresource.ChooseResourceDialog;
56
import org.gvsig.catalog.ui.showtree.ShowTreeDialog;
57

    
58
/**
59
 * 
60
 * 
61
 * 
62
 * @author Jorge Piera Llodra (piera_jor@gva.es)
63
 */
64
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
65
        private JDialog parent;
66
        protected ShowResultsPanel controlsPanel = null;
67
        private CatalogClient client = null;
68
        private int currentRecord = 0;
69
        private JButton nextButton = null;
70
        private JButton lastButton = null;
71
        private JButton descriptionButton = null;
72
        private JButton mapButton = null;
73
        private JButton closeButton = null;
74
        protected GetRecordsReply recordsReply = null;
75

    
76
        /**
77
         * @param client 
78
         * @param nodes 
79
         * @param currentRecord 
80
         * @param translator 
81
         */
82
        public  ShowResultsDialogPanel(CatalogClient client, GetRecordsReply recordsReply, int currentRecord) {        
83
                this.recordsReply = recordsReply;
84
                this.client = client;
85
                this.currentRecord = currentRecord;
86
                controlsPanel = new ShowResultsPanel(client,
87
                                recordsReply.getRecordsNumber());  
88
                controlsPanel.loadTextNewRecord(recordsReply.getRecordAt(currentRecord - 1));
89
                setDefaultButtonListeners();
90
                enableLoadResourcesButton();
91
                add(controlsPanel);
92
        } 
93

    
94
        /**
95
         *  Enable the button to load online resources
96
         */
97
        public void enableLoadResourcesButton() {        
98
                getMapButton().setEnabled(false);
99
                if (controlsPanel.getRecord() != null){
100
                        Resource[] resources = controlsPanel.getRecord().getResources();
101
                        if (resources == null)
102
                                return;
103
                        for (int i = 0; i < resources.length; i++) {
104
                                String protocol = resources[i].getProtocol();
105

    
106
                                if (protocol != null){                
107
                                        if ((protocol.toUpperCase().indexOf(Resource.WMS) >= 0) ||
108
                                                        (protocol.toUpperCase().indexOf(Resource.WFS) >=0) ||
109
                                                        (protocol.toUpperCase().indexOf(Resource.WCS) >=0) ||
110
                                                        (protocol.toUpperCase().indexOf(Resource.POSTGIS) >=0) ||
111
                                                        (protocol.toUpperCase().indexOf(Resource.WEBSITE) >=0) ||
112
                                                        (protocol.toUpperCase().indexOf(Resource.ARCIMS_IMAGE) >=0) ||
113
                                                        (protocol.toUpperCase().indexOf(Resource.ARCIMS_VECTORIAL) >=0) ||
114
                                                        (protocol.toUpperCase().indexOf(Resource.DOWNLOAD) >=0)){
115
                                                getMapButton().setEnabled(true);
116
                                                return;
117
                                        }
118
                                }
119
                        }
120
                }
121

    
122
        } 
123

    
124
        /**
125
         * 
126
         * 
127
         */
128
        public void setDefaultButtonListeners() {        
129
                nextButton = controlsPanel.getNextButton();
130
                lastButton = controlsPanel.getLastButton();
131
                descriptionButton = controlsPanel.getDescriptionButton();
132
                mapButton = controlsPanel.getMapButton();
133
                closeButton = controlsPanel.getCloseButton();
134
                nextButton.addActionListener(this);
135
                lastButton.addActionListener(this);
136
                descriptionButton.addActionListener(this);
137
                mapButton.addActionListener(this);
138
                closeButton.addActionListener(this);
139
        } 
140

    
141
        /**
142
         * 
143
         * 
144
         * 
145
         * @return 
146
         */
147
        public JButton getDescriptionButton() {        
148
                return descriptionButton;
149
        } 
150

    
151
        /**
152
         * 
153
         * 
154
         * 
155
         * @return 
156
         */
157
        public JButton getMapButton() {        
158
                return mapButton;
159
        } 
160

    
161
        /**
162
         * 
163
         * 
164
         * 
165
         * @return 
166
         */
167
        public JButton getCloseButton() {        
168
                return closeButton;
169
        } 
170

    
171
        /**
172
         * 
173
         * 
174
         * 
175
         * @param firstRecord 
176
         */
177
        public void createNewSearch(int firstRecord) {        
178
                recordsReply = client.getRecords(null, firstRecord);
179
        } 
180

    
181
        /**
182
         * @return 
183
         */
184
        public int getCurrentNode() {        
185
                return currentRecord - 1;
186
        } 
187

    
188
        /*
189
         * (non-Javadoc)
190
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
191
         */
192
        public void actionPerformed(ActionEvent e) {        
193
                if (e.getActionCommand().equals("next")) {
194
                        nextButtonActionPerformed();
195
                } 
196
                if (e.getActionCommand().equals("last")) {
197
                        lastButtonActionPerformed();
198
                } 
199
                if (e.getActionCommand().equals("description")) {
200
                        descriptionButtonActionPerformed();
201
                } 
202
                if (e.getActionCommand().equals("layer")) {
203
                        mapButtonActionPerformed();
204
                } 
205
                if (e.getActionCommand().equals("close")) {
206
                        closeButtonActionPerformed();
207
                }
208

    
209
        } 
210

    
211
        protected void nextButtonActionPerformed() {        
212
                this.currentRecord = this.currentRecord + 1;
213
                if (this.currentRecord == recordsReply.getRecordsNumber()){
214
                        nextButton.setEnabled(false);
215
                } else {
216
                        nextButton.setEnabled(true);
217
                }
218
                lastButton.setEnabled(true);
219
                if ((this.currentRecord % 10) == 1) {
220
                        if (recordsReply.getRetrievedRecordsNumber() + 1 == this.currentRecord){
221
                                createNewSearch(currentRecord);
222
                        }
223
                }
224
                controlsPanel.loadTextNewRecord(recordsReply.getRecordAt(getCurrentNode()));
225
                controlsPanel.actualizaLabel(currentRecord);
226

    
227
                enableLoadResourcesButton();
228
        } 
229

    
230
        protected void lastButtonActionPerformed() {        
231
                this.currentRecord = this.currentRecord - 1;
232
                if (this.currentRecord == 1) {
233
                        lastButton.setEnabled(false);
234
                } else {
235
                        lastButton.setEnabled(true);
236
                }
237
                nextButton.setEnabled(true);
238
                controlsPanel.loadTextNewRecord(recordsReply.getRecordAt(getCurrentNode()));
239
                controlsPanel.actualizaLabel(currentRecord);
240

    
241
                enableLoadResourcesButton();
242
        } 
243

    
244
        protected void descriptionButtonActionPerformed() {        
245
                Record record = recordsReply.getRecordAt(getCurrentNode());
246
                if (record == null){
247
                        //Impossible to parse
248
                }else{
249
                        new ShowTreeDialog(record.getNode());
250
                }
251
        } 
252

    
253
        protected void mapButtonActionPerformed() {        
254
                Resource[] resources = controlsPanel.getRecord().getResources();
255
                Collection col = new java.util.ArrayList();
256
                for (int i=0 ; i<resources.length ; i++){
257
                        col.add(resources[i]);
258
                }
259
                new ChooseResourceDialog(col);
260

    
261
        } 
262

    
263
        protected void closeButtonActionPerformed() {        
264
                parent.setVisible(false);
265
        } 
266

    
267
        /**
268
         * 
269
         * 
270
         * 
271
         * @param parent The parent to set.
272
         */
273
        public void setParent(JDialog parent) {        
274
                this.parent = parent;
275
        } 
276
}