Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSSelectAttributesPanel.java @ 8273

History | View | Annotate | Download (12.9 KB)

1
package com.iver.cit.gvsig.gui.panels;
2

    
3
import java.awt.Component;
4
import java.util.ArrayList;
5
import java.util.Vector;
6

    
7
import javax.swing.ImageIcon;
8
import javax.swing.JList;
9
import javax.swing.JPanel;
10
import javax.swing.JScrollPane;
11

    
12
import org.gvsig.gui.beans.swing.JButton;
13
import org.gvsig.gui.beans.swing.treeTable.TreeTable;
14
import org.gvsig.remoteClient.gml.schemas.GMLGeometryType;
15
import org.gvsig.remoteClient.gml.schemas.IXMLType;
16
import org.gvsig.remoteClient.gml.schemas.XMLElement;
17

    
18
import com.iver.andami.PluginServices;
19
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
20

    
21
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
22
 *
23
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
24
 *
25
 * This program is free software; you can redistribute it and/or
26
 * modify it under the terms of the GNU General Public License
27
 * as published by the Free Software Foundation; either version 2
28
 * of the License, or (at your option) any later version.
29
 *
30
 * This program is distributed in the hope that it will be useful,
31
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
 * GNU General Public License for more details.
34
 *
35
 * You should have received a copy of the GNU General Public License
36
 * along with this program; if not, write to the Free Software
37
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
38
 *
39
 * For more information, contact:
40
 *
41
 *  Generalitat Valenciana
42
 *   Conselleria d'Infraestructures i Transport
43
 *   Av. Blasco Ib??ez, 50
44
 *   46010 VALENCIA
45
 *   SPAIN
46
 *
47
 *      +34 963862235
48
 *   gvsig@gva.es
49
 *      www.gvsig.gva.es
50
 *
51
 *    or
52
 *
53
 *   IVER T.I. S.A
54
 *   Salamanca 50
55
 *   46005 Valencia
56
 *   Spain
57
 *
58
 *   +34 963163400
59
 *   dac@iver.es
60
 */
61
/* CVS MESSAGES:
62
 *
63
 * $Id: WFSSelectAttributesPanel.java 8273 2006-10-24 07:27:56Z jorpiell $
64
 * $Log$
65
 * Revision 1.11  2006-10-24 07:27:56  jorpiell
66
 * Algunos cambios en el modelo que usa la tabla
67
 *
68
 * Revision 1.10  2006/10/10 12:55:06  jorpiell
69
 * Se ha a?adido el soporte de features complejas
70
 *
71
 * Revision 1.9  2006/10/02 09:09:45  jorpiell
72
 * Cambios del 10 copiados al head
73
 *
74
 * Revision 1.7.2.1  2006/09/19 12:28:11  jorpiell
75
 * Ya no se depende de geotools
76
 *
77
 * Revision 1.8  2006/09/18 12:07:31  jorpiell
78
 * Se ha sustituido geotools por el driver de remoteservices
79
 *
80
 * Revision 1.7  2006/09/05 13:01:31  jorpiell
81
 * Reducido el tama?o de los botones
82
 *
83
 * Revision 1.6  2006/07/24 07:30:33  jorpiell
84
 * Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
85
 *
86
 * Revision 1.5  2006/07/21 11:50:31  jaume
87
 * improved appearance
88
 *
89
 * Revision 1.4  2006/06/21 12:35:45  jorpiell
90
 * Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
91
 *
92
 * Revision 1.3  2006/06/15 07:50:58  jorpiell
93
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
94
 *
95
 * Revision 1.2  2006/05/26 06:29:42  jorpiell
96
 * Se ha cambiado el tama?o de los botones. Adem?s, al seleccionar todos los atributos se seleccionan en orden.
97
 *
98
 * Revision 1.1  2006/05/25 10:30:13  jorpiell
99
 * Esta clase se ha renombrado. WFSFields era algo confusa
100
 *
101
 * Revision 1.3  2006/05/23 08:09:39  jorpiell
102
 * Se ha cambiado la forma en la que se leian los valores seleccionados en los paneles y se ha cambiado el comportamiento de los botones
103
 *
104
 * Revision 1.2  2006/05/19 12:57:08  jorpiell
105
 * Modificados algunos paneles
106
 *
107
 * Revision 1.1  2006/04/20 16:38:24  jorpiell
108
 * Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
109
 *
110
 *
111
 */
112
/**
113
 * This panel shows the feature fields list
114
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
115
 */
116
public class WFSSelectAttributesPanel extends JPanel {
117
        private static final long serialVersionUID = 3073243334672620143L;
118
        private JButton addButton = null;
119
        private JButton delButton = null;
120
        private JScrollPane jScrollPane3 = null;
121
        private JScrollPane jScrollPane4 = null;
122
        private AttributesTreeTable attributesTreeTable = null;
123
        private JList selectedAttributesList = null;
124
        private JButton addAllButton = null;
125
        private JButton delAllButton = null;
126
        private WFSParamsPanel parent = null;
127

    
128
        public WFSSelectAttributesPanel(WFSParamsPanel parent){
129
                super();
130
                this.parent = parent;
131
                initialize();
132
        }
133

    
134
        public void initialize(){
135
                this.setLayout(null);
136
                this.setBounds(5, 17, 464, 374);
137
                this.setBorder(javax.swing.BorderFactory.createTitledBorder(
138
                                null, PluginServices.getText(this, "select_fields"),
139
                                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
140
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
141
                this.add(getAddButton(), null);
142
                this.add(getDelButton(), null);
143
                this.add(getJScrollPane3(), null);
144
                this.add(getJScrollPane4(), null);
145
                this.add(getAddAllButton(), null);
146
                this.add(getDelAllButton(), null);
147
        }
148

    
149
        /**
150
         * This method initializes jButton2
151
         *
152
         * @return javax.swing.JButton
153
         */
154
        private JButton getAddButton() {
155
                if (addButton == null) {
156
                        addButton = new JButton();
157
                        addButton.setBounds(245, 170, 50, 25);
158
                        addButton.addActionListener(
159
                                new java.awt.event.ActionListener() {
160
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
161
                                                addAttribute();
162
                                                parent.isApplicable(true);
163
                                        }
164
                                });
165
                        addButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/forward.png")));
166
                }
167
                return addButton;
168
        }
169

    
170
        /**
171
         * This method initializes btnDelTemps
172
         *
173
         * @return javax.swing.JButton
174
         */
175
        private JButton getDelButton() {
176
                if (delButton == null) {
177
                        delButton = new JButton();
178
                        delButton.setBounds(245, 210, 50, 25);
179
                        delButton.addActionListener(
180
                                new java.awt.event.ActionListener() {
181
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
182
                                                delAttribute();
183
                                                parent.isApplicable(true);
184
                                        }
185
                                });
186
                        delButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/backward.png")));
187
                }
188
                return delButton;
189
        }
190

    
191
        /**
192
         * This method initializes jButton
193
         *
194
         * @return javax.swing.JButton
195
         */
196
        private JButton getAddAllButton() {
197
                if (addAllButton == null) {
198
                        addAllButton = new JButton();
199
                        addAllButton.setBounds(new java.awt.Rectangle(245,130,50, 25));
200
                        addAllButton.addActionListener(
201
                                        new java.awt.event.ActionListener() {
202
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
203
                                                        addAllAttributes();
204
                                                        parent.isApplicable(true);
205
                                                }
206
                                        });
207
                        addAllButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/forwardDouble.png")));
208
                }
209
                return addAllButton;
210
        }
211

    
212
        /**
213
         * This method initializes jButton1
214
         *
215
         * @return javax.swing.JButton
216
         */
217
        private JButton getDelAllButton() {
218
                if (delAllButton == null) {
219
                        delAllButton = new JButton();
220
                        delAllButton.setBounds(new java.awt.Rectangle(245,250,50,25));
221
                        delAllButton.addActionListener(
222
                                        new java.awt.event.ActionListener() {
223
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
224
                                                        delAllAttributes();
225
                                                        parent.isApplicable(true);
226
                                                }
227
                                        });
228
                        delAllButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/backwardDouble.png")));
229
                }
230
                return delAllButton;
231
        }
232

    
233

    
234
        /**
235
         * This method initializes jScrollPane3
236
         *
237
         * @return javax.swing.JScrollPane
238
         */
239
        private JScrollPane getJScrollPane3() {
240
                if (jScrollPane3 == null) {
241
                        jScrollPane3 = new JScrollPane();
242
                        jScrollPane3.setBounds(10, 30, 226, 334);
243
                        jScrollPane3.setViewportView(getAttributesList());
244
                }
245
                return jScrollPane3;
246
        }
247

    
248
        /**
249
         * This method initializes jScrollPane4
250
         *
251
         * @return javax.swing.JScrollPane
252
         */
253
        private JScrollPane getJScrollPane4() {
254
                if (jScrollPane4 == null) {
255
                        jScrollPane4 = new JScrollPane();
256
                        jScrollPane4.setBounds(304, 30, 186, 334);
257
                        jScrollPane4.setViewportView(getSelectedAttributesList());
258
                }
259
                return jScrollPane4;
260
        }
261

    
262
        /**
263
         * This method initializes lstTemps
264
         *
265
         * @return javax.swing.JList
266
         */
267
        public AttributesTreeTable getAttributesList() {
268
                if (attributesTreeTable == null) {
269
                        attributesTreeTable = new AttributesTreeTable(new AttributesTreeTableModel(true));
270
                        attributesTreeTable.deleteIcons();
271
                        attributesTreeTable.setRootVisible(false);                                
272
                }
273
                return attributesTreeTable;
274
        }
275

    
276
        /**
277
         * This method initializes selectedAttributesList
278
         *
279
         * @return javax.swing.JList
280
         */
281
        public JList getSelectedAttributesList() {
282
                if (selectedAttributesList == null) {
283
                        selectedAttributesList = new JList();
284
                        selectedAttributesList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
285
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
286
//                                        selectedAttributesList.callStateChanged(isCorretlyConfigured());
287
                                }
288
                        });
289
                }
290
                return selectedAttributesList;
291
        }
292

    
293
        public void refresh(WFSLayerNode feature){
294
                setFields(feature);
295
        }
296

    
297
        /**
298
         *
299
         * @param feature
300
         */
301
        private void setFields(WFSLayerNode feature){
302
                getSelectedAttributesList().setListData(new Object[0]);
303
                Vector fields = feature.getFields();
304
                getAttributesList().setAttributes(fields);
305
                for (int i=0 ; i<fields.size() ;i++){
306
                        XMLElement field = (XMLElement)fields.get(i);
307
                        IXMLType type = field.getEntityType();
308
                        if ((type != null) && (type.getType() == IXMLType.GML_GEOMETRY)){
309
                                Vector geometry = new Vector();
310
                                geometry.add(field);
311
                                getSelectedAttributesList().setListData(geometry.toArray());
312
                                feature.setGeometry((GMLGeometryType)type);
313
                        }
314
                }
315
        }
316
        
317
        public void setSelectedFields(WFSLayerNode feature){
318
//                Vector selectedFields = feature.getSelectedFields();
319
//                Vector addedFields = new Vector();
320
//                Object[] selectableAttributes = getAttributesList().getAllValues();
321
//                for (int i=0 ; i<selectedFields.size() ; i++){
322
//                        XMLElement selectedAttribute = (XMLElement)selectedFields.get(i);
323
//                        for (int j=0; j < selectableAttributes.length; j++) {
324
//                                XMLElement attribute = (XMLElement)selectableAttributes[j];
325
//                                if (attribute.getName().equals(selectedAttribute.getName())){
326
//                                        addedFields.add(attribute);
327
//                                }
328
//                        }
329
//                }
330
//                getSelectedAttributesList().setListData(addedFields.toArray());
331
        }
332

    
333
        /**
334
         * Adds the selected items from the time list to the selected
335
         * features list.
336
         */
337
        private void addAttribute(){
338
                ArrayList times = new ArrayList();
339
                for (int i = 0; i < getSelectedAttributesList()
340
                                .getModel().getSize(); i++) {
341
                        times.add(getSelectedAttributesList().getModel()
342
                                        .getElementAt(i));
343
                }
344
                Object[] obj = getAttributesList().getSelectedValues();        
345
                for (int i = 0; i < obj.length; i++) {
346
                        if (getAttributesList().isQueryable(obj[i])){
347
                                if (!times.contains(obj[i])){
348
                                        times.add(obj[i]);
349
                                }
350
                        }
351
                }
352
                getSelectedAttributesList()
353
                                .setListData(times.toArray());
354

    
355
        }
356

    
357
        /**
358
         * Removes the selected items from the selected features list.
359
         */
360
        private void delAttribute(){
361
                ArrayList features = new ArrayList();
362
                Object[] obj = getSelectedAttributesList()
363
                                .getSelectedValues();
364
                for (int i = 0; i < getSelectedAttributesList()
365
                                .getModel().getSize(); i++)
366
                        features.add(getSelectedAttributesList().getModel()
367
                                        .getElementAt(i));
368

    
369
                for (int j = 0; j < obj.length; j++){
370
                        if (features.contains(obj[j])){
371
                                XMLElement field = (XMLElement)obj[j];
372
                                if (!((field.getEntityType() != null) && (field.getEntityType().getType() == IXMLType.GML_GEOMETRY))){
373
                                        features.remove(obj[j]);
374
                                }
375
                        }
376
                }
377
                obj = new Object[features.size()];
378
                for (int i = 0; i < obj.length; i++) {
379
                        obj[i] = features.get(i);
380
                }
381
                getSelectedAttributesList()
382
                                .setListData(features.toArray());
383
        }
384

    
385
        /**
386
         * Removes all the selected attributes
387
         */
388
        private void delAllAttributes() {
389
                getSelectedAttributesList().setListData(new Object[0]);
390
                Object[] obj = getAttributesList().getAllValues();
391
                for (int i = 0; i < obj.length; i++) {
392
                        XMLElement field = (XMLElement)obj[i];
393
                        if (field.getEntityType().getType() == IXMLType.GML_GEOMETRY){
394
                                Vector geometry = new Vector();
395
                                geometry.add(field);
396
                                getSelectedAttributesList().setListData(geometry.toArray());
397
                        }
398
                }
399
        }
400

    
401
        /**
402
         * Adds all the selectable attributes
403
         *
404
         */
405
        private void addAllAttributes() {
406
                ArrayList attributes = new ArrayList();
407
                for (int i = 0; i < getSelectedAttributesList()
408
                                .getModel().getSize(); i++) {
409
                        attributes.add(getSelectedAttributesList().getModel()
410
                                        .getElementAt(i));
411
                }
412

    
413
                Object[] obj = getAttributesList().getAllValues();
414
                for (int i = 0; i < obj.length; i++) {
415
                        if (!attributes.contains(obj[i]))
416
                                attributes.add(obj[i]);
417
                }
418
                getSelectedAttributesList()
419
                                .setListData(attributes.toArray());
420

    
421
        }
422

    
423
        /**
424
         *
425
         * @return the selected fields.
426
         */
427
        public XMLElement[] getSelectedFields(){
428
                int numSelected = getSelectedAttributesList().getModel().getSize();
429
                XMLElement[] fields = new XMLElement[numSelected];
430
                for (int i=0 ; i<fields.length ; i++){
431
                        fields[i] = ((XMLElement)getSelectedAttributesList().getModel().getElementAt(i));
432
                }
433
                return fields;
434
        }
435
}  //  @jve:decl-index=0:visual-constraint="10,22"