Statistics
| Revision:

root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / wfs / gui / panels / WFSSelectFieldsPanel.java @ 10

History | View | Annotate | Download (13.2 KB)

1
package org.gvsig.wfs.gui.panels;
2

    
3
import java.awt.Component;
4
import java.beans.PropertyChangeEvent;
5
import java.beans.PropertyChangeListener;
6
import java.util.ArrayList;
7
import java.util.List;
8

    
9
import javax.swing.JPanel;
10
import javax.swing.JScrollPane;
11
import javax.swing.JToolTip;
12

    
13
import org.gvsig.andami.PluginServices;
14
import org.gvsig.gui.beans.controls.MultiLineToolTip;
15
import org.gvsig.gui.beans.panelGroup.IPanelGroup;
16
import org.gvsig.remoteclient.wfs.WFSFeature;
17
import org.gvsig.remoteclient.wfs.WFSFeatureField;
18
import org.gvsig.wfs.gui.panels.fieldstree.FieldsTreeTable;
19
import org.gvsig.wfs.gui.panels.fieldstree.FieldsTreeTableModel;
20
import org.gvsig.wfs.gui.panels.fieldstree.TreeTableModelWithCheckBoxes;
21
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
22

    
23

    
24
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
25
 *
26
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
27
 *
28
 * This program is free software; you can redistribute it and/or
29
 * modify it under the terms of the GNU General Public License
30
 * as published by the Free Software Foundation; either version 2
31
 * of the License, or (at your option) any later version.
32
 *
33
 * This program is distributed in the hope that it will be useful,
34
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
 * GNU General Public License for more details.
37
 *
38
 * You should have received a copy of the GNU General Public License
39
 * along with this program; if not, write to the Free Software
40
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
41
 *
42
 * For more information, contact:
43
 *
44
 *  Generalitat Valenciana
45
 *   Conselleria d'Infraestructures i Transport
46
 *   Av. Blasco Ib??ez, 50
47
 *   46010 VALENCIA
48
 *   SPAIN
49
 *
50
 *      +34 963862235
51
 *   gvsig@gva.es
52
 *      www.gvsig.gva.es
53
 *
54
 *    or
55
 *
56
 *   IVER T.I. S.A
57
 *   Salamanca 50
58
 *   46005 Valencia
59
 *   Spain
60
 *
61
 *   +34 963163400
62
 *   dac@iver.es
63
 */
64
/* CVS MESSAGES:
65
 *
66
 * $Id$
67
 * $Log$
68
 * Revision 1.8  2007-04-11 12:10:08  ppiqueras
69
 * Corregido bug: si la capa no tiene campos, no permitir cargarla.
70
 *
71
 * Revision 1.7  2007/02/22 12:24:51  ppiqueras
72
 * A?adidas tool tip text.
73
 *
74
 * Revision 1.6  2007/02/19 11:44:42  jorpiell
75
 * A?adidos los filtros por ?rea
76
 *
77
 * Revision 1.5  2006/12/26 09:19:52  ppiqueras
78
 * Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2).
79
 *
80
 * Revision 1.17  2006/12/15 13:58:25  ppiqueras
81
 * Eliminado un import que sobraba, y reorganizado c?digo
82
 *
83
 * Revision 1.16  2006/12/04 08:59:47  ppiqueras
84
 * Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todav?a no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
85
 *
86
 * Revision 1.15  2006/11/01 17:29:08  jorpiell
87
 * Se ha elimiado el nodo virtual de la raiz. Adem?s ya se cargan los valores de un campo complejo en la pesta?a del filtro
88
 *
89
 * Revision 1.14  2006/10/31 09:39:18  jorpiell
90
 * Cambiado el tama?o del panel
91
 *
92
 * Revision 1.13  2006/10/27 11:33:19  jorpiell
93
 * A?adida la treetable con los check box para seleccionar los atributos
94
 *
95
 * Revision 1.12  2006/10/24 07:58:14  jorpiell
96
 * Eliminado el parametro booleano que hac?a que apareciesen mas de una columna en el tree table
97
 *
98
 * Revision 1.11  2006/10/24 07:27:56  jorpiell
99
 * Algunos cambios en el modelo que usa la tabla
100
 *
101
 * Revision 1.10  2006/10/10 12:55:06  jorpiell
102
 * Se ha a?adido el soporte de features complejas
103
 *
104
 * Revision 1.9  2006/10/02 09:09:45  jorpiell
105
 * Cambios del 10 copiados al head
106
 *
107
 * Revision 1.7.2.1  2006/09/19 12:28:11  jorpiell
108
 * Ya no se depende de geotools
109
 *
110
 * Revision 1.8  2006/09/18 12:07:31  jorpiell
111
 * Se ha sustituido geotools por el driver de remoteservices
112
 *
113
 * Revision 1.7  2006/09/05 13:01:31  jorpiell
114
 * Reducido el tama?o de los botones
115
 *
116
 * Revision 1.6  2006/07/24 07:30:33  jorpiell
117
 * Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
118
 *
119
 * Revision 1.5  2006/07/21 11:50:31  jaume
120
 * improved appearance
121
 *
122
 * Revision 1.4  2006/06/21 12:35:45  jorpiell
123
 * 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
124
 *
125
 * Revision 1.3  2006/06/15 07:50:58  jorpiell
126
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
127
 *
128
 * Revision 1.2  2006/05/26 06:29:42  jorpiell
129
 * Se ha cambiado el tama?o de los botones. Adem?s, al seleccionar todos los atributos se seleccionan en orden.
130
 *
131
 * Revision 1.1  2006/05/25 10:30:13  jorpiell
132
 * Esta clase se ha renombrado. WFSFields era algo confusa
133
 *
134
 * Revision 1.3  2006/05/23 08:09:39  jorpiell
135
 * 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
136
 *
137
 * Revision 1.2  2006/05/19 12:57:08  jorpiell
138
 * Modificados algunos paneles
139
 *
140
 * Revision 1.1  2006/04/20 16:38:24  jorpiell
141
 * 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().
142
 *
143
 *
144
 */
145

    
146
/**
147
 * <p>Panel with the fields of the feature selected of the current layer.</p>
148
 * 
149
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
150
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
151
 */
152
public class WFSSelectFieldsPanel extends AbstractWFSPanel {
153
        private static final long serialVersionUID = -1596729857889892588L;
154

    
155
        private JScrollPaneML fieldsScroll = null;
156
        private FieldsTreeTable fieldsTreeTable = null;
157
        private FieldsTreeTableModel model = null;
158
        private JPanel treeTablePanel = null;
159
        private boolean fieldsSelectedOfSameLayerHasChanged;
160
        private String namespace = null;
161

    
162
        /**
163
         * Gets the name space of the layer which contains the fields stored
164
         * 
165
         * @return the namespace name space of the layer which contains the fields stored
166
         */
167
        public String getNamespace() {
168
                return namespace;
169
        }
170

    
171
        /**
172
         * Creates a new WFS select fields panel.
173
         */
174
        public WFSSelectFieldsPanel(){
175
                super();
176
                initialize();
177
        }
178

    
179
        /**
180
         * This method initializes jScrollPane
181
         *
182
         * @return javax.swing.JScrollPane
183
         */
184
        private JScrollPane getFieldsScroll() {
185
                if (fieldsScroll == null) {
186
                        fieldsScroll = new JScrollPaneML();                        
187
                        fieldsScroll.setViewportView(getFieldsTreeTable());
188
                        MultiLineToolTip tip = new MultiLineToolTip();
189
                        tip.setComponent(fieldsScroll);
190
                        fieldsScroll.setToolTipText(PluginServices.getText(fieldsScroll, "fields_Selection_Info"));
191
                }
192
                return fieldsScroll;
193
        }
194

    
195
        /**
196
         * This method initializes lstTemps
197
         *
198
         * @return javax.swing.JList
199
         */
200
        public FieldsTreeTable getFieldsTreeTable() {
201
                if (fieldsTreeTable == null) {
202
                        model = new TreeTableModelWithCheckBoxes();
203
                        fieldsTreeTable = new FieldsTreeTable(model,this);
204
                        fieldsTreeTable.setToolTipText(PluginServices.getText(fieldsTreeTable, "fields_Selection_Info"));
205

    
206
                        // If user has changed the fields selection in the same layer
207
                        fieldsTreeTable.addPropertyChangeListener(new PropertyChangeListener() {
208
                                /*
209
                                 *  (non-Javadoc)
210
                                 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
211
                                 */
212
                                public void propertyChange(PropertyChangeEvent evt) {
213
                                        // If the selection of the fields of the layer has changed
214
                                        if (evt.getPropertyName().compareTo("tableCellEditor") == 0) {
215
                                                fieldsSelectedOfSameLayerHasChanged = true;                                                
216
                                        }                                        
217
                                        else if (evt.getPropertyName().compareTo("selectionModel") == 0) { // If the layer has changed
218
                                                fieldsSelectedOfSameLayerHasChanged = false;
219
                                        }
220
                                }
221
                        });
222
                }
223
                return fieldsTreeTable;
224
        }
225

    
226
        /*
227
         * (non-Javadoc)
228
         * @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#refresh(com.iver.cit.gvsig.fmap.layers.WFSLayerNode)
229
         */
230
        public void refresh(WFSSelectedFeature feature){
231
                setFields(feature);                        
232
        }
233

    
234
        /**
235
         * <p>Updates the inner tree table with the fields of the layer.</p>
236
         *
237
         * @param feature node with the fields
238
         */
239
        private void setFields(WFSSelectedFeature selectedFeature){
240
                WFSFeature feature = selectedFeature.getWFSFeature();
241

    
242
                model = new TreeTableModelWithCheckBoxes(feature);
243
                getFieldsTreeTable().setModel(model);
244
                if (feature.getNamespace() != null){
245
                    namespace = feature.getNamespace().getLocation();
246
                }
247
        }
248

    
249
        /**
250
         * <p>Changes to enabled the selection value of the selected fields.</p>
251
         * 
252
         * @param feature node with the fields 
253
         */
254
        public void setSelectedFields(String selectedFields){
255
                String[] fields = selectedFields.split(",");
256
                List<Object> listFields = new ArrayList();
257
                for (int i=0 ; i<fields.length ; i++){
258
                    listFields.add(fields[i]);
259
                }
260
                getFieldsTreeTable().setSelectedFields(listFields);
261
        }
262

    
263
        /**
264
         * Gets the name of the field which is a geometry
265
         * 
266
         * @return name of the field which is a geometry
267
         */
268
        public String getGeometryFieldName(){
269
                return getFieldsTreeTable().getGeometryField();                
270
        }
271

    
272
        /**
273
         * Gets only the selected fields.
274
         *
275
         * @return the selected fields
276
         */
277
        public WFSFeatureField[] getSelectedFields(){
278
                return fieldsTreeTable.getSelectedElements();
279
        }
280

    
281
        public String getSelectedFieldsAsString(){
282
                StringBuffer output = new StringBuffer();
283
                WFSFeatureField[] selectedFields= getSelectedFields();
284
                for (int i=0 ; i<selectedFields.length-1 ; i++){
285
                        output.append(selectedFields[i].getName() + ",");
286
                }
287
                if (selectedFields.length > 0){
288
                        output.append(selectedFields[selectedFields.length-1].getName());
289
                }
290
                return output.toString();
291
        }
292

    
293
        /**
294
         * This method initializes treeTablePanel        
295
         *         
296
         * @return javax.swing.JPanel        
297
         */
298
        private JPanel getTreeTablePanel() {
299
                if (treeTablePanel == null) {
300
                        java.awt.GridBagConstraints gridBagConstraints;
301
                        treeTablePanel = new JPanel();
302
                        treeTablePanel.setLayout(new java.awt.GridBagLayout());
303
                        treeTablePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
304
                                        null, PluginServices.getText(this, "select_fields"),
305
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
306
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
307

    
308
                        gridBagConstraints = new java.awt.GridBagConstraints();
309
                        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
310
                        gridBagConstraints.weightx = 1.0;
311
                        gridBagConstraints.weighty = 1.0;
312
                        treeTablePanel.add(getFieldsScroll(), gridBagConstraints);
313
                }
314
                return treeTablePanel;
315
        }
316

    
317
        /**
318
         * Returns true if user has changed the selection of some field of the same layer; else returns false
319
         * 
320
         * @return A boolean value
321
         */
322
        public boolean getFieldsSelectedOfSameLayerHasChanged() {
323
                return this.fieldsSelectedOfSameLayerHasChanged;
324
        }
325

    
326
        /**
327
         * <p>Changes the status to applied.</p>
328
         * 
329
         * @param applicable a boolean value
330
         */
331
        public void setApplicable(boolean applicable) {
332
                IPanelGroup panelGroup = getPanelGroup();
333

    
334
                if (panelGroup == null)
335
                        return;
336

    
337
                ((WFSParamsPanel)panelGroup).setApplicable(applicable);
338
        }
339

    
340
        /**
341
         * Resets the value of the field 'fieldsSelectedOfSameLayerHasChanged'
342
         * 
343
         * @return A boolean value
344
         */
345
        public void resetFieldsSelectedOfSameLayerHasChanged() {
346
                this.fieldsSelectedOfSameLayerHasChanged = false;
347
        }
348

    
349
        /*
350
         * (non-Javadoc)
351
         * @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#initialize()
352
         */
353
        protected void initialize(){
354
                setLabel(PluginServices.getText(this, "fields_uppercase_first"));
355
                setLabelGroup(PluginServices.getText(this, "wfs"));
356
                this.setLayout(new java.awt.GridBagLayout());
357
                
358
                java.awt.GridBagConstraints gridBagConstraints;
359
                gridBagConstraints = new java.awt.GridBagConstraints();
360
                gridBagConstraints.gridx = 0;
361
                gridBagConstraints.gridy = 0;
362
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
363
                gridBagConstraints.weightx = 1.0;
364
                gridBagConstraints.weighty = 1.0;
365
                this.add(getTreeTablePanel(), gridBagConstraints);
366
                fieldsSelectedOfSameLayerHasChanged = false;
367
        }
368

    
369
        /**
370
         * JCrollPane with multi line tool tip text.
371
         * 
372
         * @see JScrollPane
373
         * 
374
         * @author Pablo Piqueras Bartolome (pablo.piqueras@iver.es)
375
         */
376
        private class JScrollPaneML extends JScrollPane {
377
                private static final long serialVersionUID = -5589382813201358787L;
378

    
379
                /**
380
                 * @see JScrollPane#JScrollPane()
381
                 */
382
                public JScrollPaneML() {
383
                        super();
384
                }
385

    
386
                /**
387
                 * @see JScrollPane#JScrollPane(Component, int, int)
388
                 */
389
                public JScrollPaneML(Component view, int vsbPolicy, int hsbPolicy) {
390
                        super(view, vsbPolicy, hsbPolicy);
391
                }
392

    
393
                /**
394
                 * @see JScrollPane#JScrollPane(Component)
395
                 */
396
                public JScrollPaneML(Component view) {
397
                        super(view);
398
                }
399

    
400
                /**
401
                 * @see JScrollPane#JScrollPane(int, int)
402
                 */
403
                public JScrollPaneML(int vsbPolicy, int hsbPolicy) {
404
                        super(vsbPolicy, hsbPolicy);
405
                }
406

    
407
                /*
408
                 * (non-Javadoc)
409
                 * @see javax.swing.JComponent#createToolTip()
410
                 */
411
                public JToolTip createToolTip() {
412
                        // Multiline support
413
                        MultiLineToolTip tip = new MultiLineToolTip();
414
                        tip.setComponent(this);
415
                        return tip;
416
                }
417
        }
418
}