Statistics
| Revision:

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

History | View | Annotate | Download (7.31 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.showResults;
42

    
43

    
44
import es.gva.cit.catalogClient.CatalogClient;
45
import es.gva.cit.catalogClient.metadataXML.XMLNode;
46
import es.gva.cit.catalogClient.metadataXML.XMLTreeNumberOfRecordsAnswer;
47
import es.gva.cit.catalogClient.parsers.Resource;
48
import es.gva.cit.catalogClient.traductor.ITranslator;
49
import es.gva.cit.catalogClient.ui.chooseResource.ChooseResourceDialog;
50
import es.gva.cit.catalogClient.ui.showTree.ShowTreeDialog;
51

    
52

    
53
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
55

    
56
import javax.swing.JButton;
57
import javax.swing.JDialog;
58
import javax.swing.JPanel;
59

    
60

    
61
/**
62
 * @author Jorge Piera Llodra (piera_jor@gva.es)
63
 */
64
public class ShowResultsDialogPanel extends JPanel implements ActionListener {
65
    //It is needed to close the frame
66
    private JDialog parent;
67
    
68
    public ShowResultsPanel ppalPanel = null;
69
    public XMLNode[] nodes = null;
70
    CatalogClient client = null;
71
    int currentRecord = 0;
72
    
73
    private JButton nextButton = null;
74
    private JButton lastButton = null;
75
    private JButton descriptionButton = null;
76
    private JButton mapButton = null;
77
    private JButton closeButton = null;
78
    
79
    private ITranslator translator = null;
80

    
81
    public ShowResultsDialogPanel(CatalogClient client, XMLNode[] nodes,
82
        int currentRecord,ITranslator translator) {
83
        this.nodes = nodes;
84
        this.client = client;
85
        this.currentRecord = currentRecord;
86
        this.translator = translator;
87

    
88
        int numRecords = XMLTreeNumberOfRecordsAnswer.getNumberOfRecords(nodes[0]);
89
        ppalPanel = new ShowResultsPanel(nodes[currentRecord],
90
                client.getProtocol(), numRecords,client.getUrl(),translator);
91
        
92
  
93
        setDefaultButtonListeners();
94
        enableMapButton();
95

    
96
        add(ppalPanel);
97
    }
98
    
99
    public void enableMapButton(){
100
            getMapButton().setEnabled(false);
101
            Resource[] resources = ppalPanel.getTags().getResources();
102
        if (resources == null)
103
            return;
104
            for (int i = 0; i < resources.length; i++) {
105
                String protocol = resources[i].getProtocol();
106
                        
107
                        if (protocol != null){                
108
                            if ((protocol.toUpperCase().indexOf(Resource.WMS) >= 0) ||
109
                                    (protocol.toUpperCase().indexOf(Resource.WFS) >=0) ||
110
                                    (protocol.toUpperCase().indexOf(Resource.WCS) >=0) ||
111
                                    (protocol.toUpperCase().indexOf(Resource.POSTGIS) >=0) ||
112
                                    (protocol.toUpperCase().indexOf(Resource.WEBSITE) >=0) ||
113
                                    (protocol.toUpperCase().indexOf(Resource.DOWNLOAD) >=0)){
114
                                getMapButton().setEnabled(true);
115
                                return;
116
                            }
117
                        }
118
        }        
119
            
120
    }
121

    
122
    public void setDefaultButtonListeners() {
123
        nextButton = ppalPanel.getNextButton();
124
        lastButton = ppalPanel.getLastButton();
125
        descriptionButton = ppalPanel.getDescriptionButton();
126
        mapButton = ppalPanel.getMapButton();
127
        closeButton = ppalPanel.getCloseButton();
128

    
129
        nextButton.addActionListener(this);
130
        lastButton.addActionListener(this);
131
        descriptionButton.addActionListener(this);
132
        mapButton.addActionListener(this);
133
        closeButton.addActionListener(this);
134
    }
135

    
136
    public JButton getDescriptionButton() {
137
        return descriptionButton;
138
    }
139

    
140
    public JButton getMapButton() {
141
        return mapButton;
142
    }
143
    
144
    public JButton getCloseButton(){
145
        return closeButton;
146
    }
147

    
148
    public void createNewSearch(int firstRecord) {
149
        XMLNode[] nodesRecords = null;
150

    
151
        nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(),
152
                null, firstRecord);
153

    
154
        this.nodes = nodesRecords;
155
    }
156

    
157
    public int getCurrentNode() {
158
        if ((currentRecord % 10) == 0) {
159
            return 10;
160
        } else {
161
            return (currentRecord % 10);
162
        }
163
    }
164

    
165
    public void actionPerformed(ActionEvent e) {
166
        if (e.getActionCommand().equals("next")) {
167
            nextButtonActionPerformed();
168
        } 
169
        if (e.getActionCommand().equals("last")) {
170
            lastButtonActionPerformed();
171
        } 
172
        if (e.getActionCommand().equals("description")) {
173
            descriptionButtonActionPerformed();
174
        } 
175
        if (e.getActionCommand().equals("layer")) {
176
            mapButtonActionPerformed();
177
        } 
178
        if (e.getActionCommand().equals("close")) {
179
            closeButtonActionPerformed();
180
        }
181
       
182
    }
183

    
184
    public void nextButtonActionPerformed() {
185
        this.currentRecord = this.currentRecord + 1;
186

    
187
        if (this.currentRecord == XMLTreeNumberOfRecordsAnswer.getNumberOfRecords(
188
                    nodes[0])) {
189
            nextButton.setEnabled(false);
190
        } else {
191
            nextButton.setEnabled(true);
192
        }
193

    
194
        lastButton.setEnabled(true);
195

    
196
        if ((this.currentRecord % 10) == 1) {
197
            createNewSearch(currentRecord);
198
        }
199

    
200
        ppalPanel.loadTextNewRecord(nodes[getCurrentNode()],
201
            client.getProtocol());
202
        ppalPanel.actualizaLabel(currentRecord);
203
        
204
        enableMapButton();
205
    }
206

    
207
    public void lastButtonActionPerformed() {
208
        this.currentRecord = this.currentRecord - 1;
209

    
210
        if (this.currentRecord == 1) {
211
            lastButton.setEnabled(false);
212
        } else {
213
            lastButton.setEnabled(true);
214
        }
215

    
216
        nextButton.setEnabled(true);
217

    
218
        if ((this.currentRecord % 10) == 0) {
219
            createNewSearch(currentRecord - 10 + 1);
220
        }
221

    
222
        ppalPanel.loadTextNewRecord(nodes[getCurrentNode()],
223
            client.getProtocol());
224
        ppalPanel.actualizaLabel(currentRecord);
225
        
226
        enableMapButton();
227
    }
228

    
229
    public void descriptionButtonActionPerformed() {
230
        ShowTreeDialog frame = new ShowTreeDialog(nodes[getCurrentNode()]);
231
    }
232

    
233
    public void mapButtonActionPerformed() {
234
        Resource[] resources = ppalPanel.getTags().getResources();
235
        ChooseResourceDialog dialog = new ChooseResourceDialog(resources);
236
               
237
    }
238
    
239
    public void closeButtonActionPerformed() {
240
        parent.setVisible(false);
241
    }
242
    /**
243
     * @param parent The parent to set.
244
     */
245
    public void setParent(JDialog parent) {
246
        this.parent = parent;
247
    }
248
}