Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / WFSSelectFieldsPanel.java @ 34026

History | View | Annotate | Download (13.1 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.Vector;
7

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

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

    
22

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

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

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

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

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

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

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

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

    
225
        /*
226
         * (non-Javadoc)
227
         * @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#refresh(com.iver.cit.gvsig.fmap.layers.WFSLayerNode)
228
         */
229
        public void refresh(WFSSelectedFeature feature){
230
                setFields(feature);        
231
                setSelectedFields(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(WFSSelectedFeature feature){
255
                Vector<Object> selectedFields = feature.getSelectedFields();
256
                getFieldsTreeTable().setSelectedFields(selectedFields);
257
        }
258

    
259
        /**
260
         * Gets the name of the field which is a geometry
261
         * 
262
         * @return name of the field which is a geometry
263
         */
264
        public String getGeometryFieldName(){
265
                return getFieldsTreeTable().getGeometryField();                
266
        }
267

    
268
        /**
269
         * Gets only the selected fields.
270
         *
271
         * @return the selected fields
272
         */
273
        public WFSFeatureField[] getSelectedFields(){
274
                return fieldsTreeTable.getSelectedElements();
275
        }
276

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

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

    
304
                        gridBagConstraints = new java.awt.GridBagConstraints();
305
                        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
306
                        gridBagConstraints.weightx = 1.0;
307
                        gridBagConstraints.weighty = 1.0;
308
                        treeTablePanel.add(getFieldsScroll(), gridBagConstraints);
309
                }
310
                return treeTablePanel;
311
        }
312

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

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

    
330
                if (panelGroup == null)
331
                        return;
332

    
333
                ((WFSParamsPanel)panelGroup).setApplicable(applicable);
334
        }
335

    
336
        /**
337
         * Resets the value of the field 'fieldsSelectedOfSameLayerHasChanged'
338
         * 
339
         * @return A boolean value
340
         */
341
        public void resetFieldsSelectedOfSameLayerHasChanged() {
342
                this.fieldsSelectedOfSameLayerHasChanged = false;
343
        }
344

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

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

    
375
                /**
376
                 * @see JScrollPane#JScrollPane()
377
                 */
378
                public JScrollPaneML() {
379
                        super();
380
                }
381

    
382
                /**
383
                 * @see JScrollPane#JScrollPane(Component, int, int)
384
                 */
385
                public JScrollPaneML(Component view, int vsbPolicy, int hsbPolicy) {
386
                        super(view, vsbPolicy, hsbPolicy);
387
                }
388

    
389
                /**
390
                 * @see JScrollPane#JScrollPane(Component)
391
                 */
392
                public JScrollPaneML(Component view) {
393
                        super(view);
394
                }
395

    
396
                /**
397
                 * @see JScrollPane#JScrollPane(int, int)
398
                 */
399
                public JScrollPaneML(int vsbPolicy, int hsbPolicy) {
400
                        super(vsbPolicy, hsbPolicy);
401
                }
402

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