Revision 262

View differences:

org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.36/org.gvsig.wfs.app.mainplugin/buildNumber.properties
1
#Wed Feb 17 01:41:20 CET 2016
2
buildNumber=2118
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.36/org.gvsig.wfs.app.mainplugin/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.store.wfs.WFSLibrary
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.36/org.gvsig.wfs.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
<!--
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
      <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes>
32
        <include>org.gvsig:org.gvsig.wfs.app.mainplugin</include>
33
      </includes>
34
    </dependencySet>
35
  </dependencySets>
36
-->
37

  
38
</assembly>
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.36/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/wfs/gui/panels/AbstractWFSPanel.java
1
package org.gvsig.wfs.gui.panels;
2

  
3
import java.awt.Dimension;
4

  
5
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
6
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
7
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
8
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeatureManager;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12

  
13

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

  
55
/* CVS MESSAGES:
56
 *
57
 * $Id$
58
 * $Log$
59
 *
60
 */
61

  
62
/**
63
 * <p>Default panel used to create a WFS group's panel.</p>
64
 * 
65
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
66
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
67
 */
68
public abstract class AbstractWFSPanel extends AbstractPanel implements IWFSPanel {
69
	// Default dimensions of all WFS panels
70
	static final int PANEL_WIDTH = 475;
71
	static final int PANEL_HEIGHT = 365;
72
	protected static final Logger logger = LoggerFactory.getLogger(AbstractWFSPanel.class);
73

  
74
	/**
75
	 * Initializes an WFS panel.
76
	 */
77
	public AbstractWFSPanel() {
78
		super();
79
		setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
80
	}
81

  
82
	/*
83
	 * (non-Javadoc)
84
	 * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#initialize()
85
	 */
86
	protected void initialize() {
87
		// By default all panels will be at the GUI
88
		setVisible(true);
89
	}
90

  
91
	/**
92
	 * <p>Gets the information of the wizard used to add or load panels.</p>
93
	 * 
94
	 * @return the wizard data
95
	 */
96
	public WFSServerExplorer getServerExplorer(){
97
		return (getPanelGroup() == null)? null: ((WFSParamsPanel)getPanelGroup()).getServerExplorer();  
98
	}
99
	
100
	public WFSSelectedFeatureManager getSelectedFeatureManager(){
101
		return (getPanelGroup() == null)? null: ((WFSParamsPanel)getPanelGroup()).getSelectedFeatureManager();
102
	}
103

  
104
	/*
105
	 * (non-Javadoc)
106
	 * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
107
	 */
108
	public void setReference(Object ref) {
109
		super.setReference(ref);
110
	}	
111
 
112
	/*
113
	 * (non-Javadoc)
114
	 * @see com.iver.cit.gvsig.gui.panels.IWFSPanel#refresh(com.iver.cit.gvsig.fmap.layers.WFSLayerNode)
115
	 */
116
	public void refresh(WFSSelectedFeature layer) {
117
	}
118

  
119
	/*
120
	 * (non-Javadoc)
121
	 * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
122
	 */
123
	public void accept() {
124
	}
125

  
126
	/*
127
	 * (non-Javadoc)
128
	 * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#apply()
129
	 */
130
	public void apply() {
131
	}
132

  
133
	/*
134
	 * (non-Javadoc)
135
	 * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
136
	 */
137
	public void cancel() {
138
	}
139

  
140
	/*
141
	 * (non-Javadoc)
142
	 * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#selected()
143
	 */
144
	public void selected() {
145
	}
146
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.36/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/wfs/gui/panels/WFSParamsPanel.java
1
package org.gvsig.wfs.gui.panels;
2

  
3
import java.awt.Container;
4
import java.util.List;
5

  
6
import javax.swing.JTabbedPane;
7

  
8
import org.cresques.cts.IProjection;
9
import org.gvsig.andami.PluginServices;
10
import org.gvsig.app.gui.ILayerPanel;
11
import org.gvsig.app.gui.WizardPanel;
12
import org.gvsig.fmap.crs.CRSFactory;
13
import org.gvsig.fmap.dal.DALLocator;
14
import org.gvsig.fmap.dal.DataManager;
15
import org.gvsig.fmap.dal.DataStore;
16
import org.gvsig.fmap.dal.exception.DataException;
17
import org.gvsig.fmap.dal.exception.InitializeException;
18
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
19
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
20
import org.gvsig.fmap.dal.store.wfs.WFSStoreParameters;
21
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider;
22
import org.gvsig.fmap.geom.Geometry;
23
import org.gvsig.fmap.geom.primitive.Envelope;
24
import org.gvsig.fmap.mapcontext.MapContextLocator;
25
import org.gvsig.fmap.mapcontext.MapContextManager;
26
import org.gvsig.fmap.mapcontext.exceptions.CreateLayerException;
27
import org.gvsig.fmap.mapcontext.layers.FLayer;
28
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
29
import org.gvsig.gui.beans.panelGroup.exceptions.EmptyPanelGroupException;
30
import org.gvsig.gui.beans.panelGroup.exceptions.EmptyPanelGroupGUIException;
31
import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntAddPanelException;
32
import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader;
33
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
34
import org.gvsig.gui.beans.panelGroup.panels.IPanel;
35
import org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel;
36
import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding;
37
import org.gvsig.remoteclient.wfs.schema.XMLNameSpace;
38
import org.gvsig.tools.dynobject.DynObject;
39
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
40
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeatureManager;
41
import org.gvsig.wfs.gui.wizards.WFSWizard;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

  
45

  
46
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
47
 *
48
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
49
 *
50
 * This program is free software; you can redistribute it and/or
51
 * modify it under the terms of the GNU General Public License
52
 * as published by the Free Software Foundation; either version 2
53
 * of the License, or (at your option) any later version.
54
 *
55
 * This program is distributed in the hope that it will be useful,
56
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58
 * GNU General Public License for more details.
59
 *
60
 * You should have received a copy of the GNU General Public License
61
 * along with this program; if not, write to the Free Software
62
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
63
 *
64
 * For more information, contact:
65
 *
66
 *  Generalitat Valenciana
67
 *   Conselleria d'Infraestructures i Transport
68
 *   Av. Blasco Ib??ez, 50
69
 *   46010 VALENCIA
70
 *   SPAIN
71
 *
72
 *      +34 963862235
73
 *   gvsig@gva.es
74
 *      www.gvsig.gva.es
75
 *
76
 *    or
77
 *
78
 *   IVER T.I. S.A
79
 *   Salamanca 50
80
 *   46005 Valencia
81
 *   Spain
82
 *
83
 *   +34 963163400
84
 *   dac@iver.es
85
 */
86
/* CVS MESSAGES:
87
 *
88
 * $Id: WFSParamsPanel.java 17736 2008-01-02 16:53:48Z ppiqueras $
89
 * $Log$
90
 * Revision 1.42  2007-09-19 16:14:50  jaume
91
 * removed unnecessary imports
92
 *
93
 * Revision 1.41  2007/06/26 09:33:54  jorpiell
94
 * Information tab refreshed
95
 *
96
 * Revision 1.40  2007/04/11 12:08:55  ppiqueras
97
 * Varios cambios:
98
 * - Corregida etiqueta "Campo"
99
 * - Cambiada actualizaci?n
100
 * - Corregido bug: actualizar ?rea visible despu?s de pulsar "Aplicar" en la interfaz gr?fica.
101
 *
102
 * Revision 1.39  2007/03/15 13:33:44  ppiqueras
103
 * Corregido bug de excepci?n que se lanzaba cuando se filtraba y no se pod?a cargar la capa.
104
 *
105
 * Revision 1.38  2007/03/05 13:49:42  ppiqueras
106
 * Si una capa WFS no tiene campos (y por tanto no tiene un campo obligatorio de tipo geometr?a), que avise al usuario y no permita que se intente cargar dicha capa.
107
 *
108
 * Revision 1.37  2007/03/01 13:12:09  ppiqueras
109
 * Mejorado el filtrado por ?rea.
110
 *
111
 * Revision 1.36  2007/02/22 12:30:59  ppiqueras
112
 * - Eliminado m?todo que sobraba.
113
 * - Mejorada la relaci?n con el panel del ?rea.
114
 * - A?adido JOptionPanel de aviso que no se aplicar? ?rea porque es incorrecta.
115
 *
116
 * Revision 1.35  2007/02/20 11:31:11  ppiqueras
117
 * Eliminados comentarios que sobraban.
118
 *
119
 * Revision 1.34  2007/02/19 11:44:42  jorpiell
120
 * Añadidos los filtros por área
121
 *
122
 * Revision 1.33  2007/02/16 13:36:53  ppiqueras
123
 * Que el ?rea seleccionada en el panel WFSArea sea accesible una vez se va a aplicar.
124
 *
125
 * Revision 1.32  2007/02/12 11:37:00  ppiqueras
126
 * A?adidos comentarios y m?todo para refrescar el MapControl de la pesta?a del ?rea.
127
 *
128
 * Revision 1.31  2007/02/09 14:12:39  jorpiell
129
 * Soporte para WFS 1.1 y WFS-T
130
 *
131
 * Revision 1.30  2007/02/02 12:22:22  ppiqueras
132
 * Corregido alg?n bug.
133
 *
134
 * Revision 1.29  2007/01/08 09:37:39  ppiqueras
135
 * Eliminado comentario que sobraba
136
 *
137
 * Revision 1.28  2006/12/29 09:27:02  ppiqueras
138
 * Corregidos varios bugs:
139
 *
140
 * - Se ejecuta 2 veces "Aplicar" o "Aceptar" en los filtros WFS.
141
 * - Cuando se carga por primera vez una capa WFS, si se pone un
142
 * filtro incorrecto, se ignora el filtro (cargando toda la información posible de la capa, y borrando el texto de filtrado).
143
 *
144
 * Revision 1.27  2006/12/26 09:19:40  ppiqueras
145
 * 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).
146
 *
147
 * Revision 1.26  2006/12/20 14:22:06  ppiqueras
148
 * Añadido comentario
149
 *
150
 * Revision 1.25  2006/12/15 13:59:36  ppiqueras
151
 * -Permite que se almacenen y/o recojan todos los campos y valores conocidos de la capa actual.
152
 *
153
 * -Además, control frentre a consultas de filtro erróneas, (esto a medias aún).
154
 *
155
 * - Algún comentario más.
156
 *
157
 * Revision 1.24  2006/12/12 10:24:45  ppiqueras
158
 * Nueva funcionalidad: Pulsando doble 'click' sobre una capa de un servidor, se carga (igual que antes), pero además se avanza a la siguiente pestaña sin tener que pulsar el botón 'Siguiente'.
159
 *
160
 * Revision 1.23  2006/12/11 11:02:24  ppiqueras
161
 * Corregido bug -> que se mantenga la frase de filtrado
162
 *
163
 * Revision 1.22  2006/12/04 08:59:47  ppiqueras
164
 * Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todavía no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
165
 *
166
 * Revision 1.21  2006/11/28 08:05:13  jorpiell
167
 * Se escribe la query en la pesta?a del filtro
168
 *
169
 * Revision 1.20  2006/11/14 13:45:49  ppiqueras
170
 * Añadida pequeña funcionalidad:
171
 * Cuando se pulsa el botón "Aplicar", (al seleccionar un nuevo filtro), si el árbol de campos posee alguno seleccionado, actualiza los valores (con los nuevos), asociados a éste campo seleccionado.
172
 *
173
 * Revision 1.19  2006/10/27 12:10:02  ppiqueras
174
 * Nueva funcionalidad
175
 *
176
 * Revision 1.16  2006/10/23 07:37:04  jorpiell
177
 * Ya funciona el filterEncoding
178
 *
179
 * Revision 1.14  2006/10/13 13:05:32  ppiqueras
180
 * Permite el refrescado de datos del panel de filtrado sobre capa WFS.
181
 *
182
 * Revision 1.13  2006/10/10 12:55:06  jorpiell
183
 * Se ha a?adido el soporte de features complejas
184
 *
185
 * Revision 1.12  2006/10/02 09:17:48  jorpiell
186
 * A?adido el setCRS a la capa
187
 *
188
 * Revision 1.11  2006/09/29 13:02:38  ppiqueras
189
 * Filtro para WFS. De momento sólo interfaz gráfica.
190
 *
191
 * Revision 1.10  2006/07/21 11:50:31  jaume
192
 * improved appearance
193
 *
194
 * Revision 1.9  2006/06/21 12:35:45  jorpiell
195
 * 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
196
 *
197
 * Revision 1.8  2006/06/15 07:50:58  jorpiell
198
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
199
 *
200
 * Revision 1.7  2006/05/25 16:22:47  jorpiell
201
 * Se limpia el panel cada vez que se conecta con un servidor distinto
202
 *
203
 * Revision 1.6  2006/05/25 16:01:43  jorpiell
204
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
205
 *
206
 * Revision 1.5  2006/05/25 10:31:06  jorpiell
207
 * Como ha cambiado la forma de mostrar las capas (una tabla, en lugar de una lista), los paneles han tenido que ser modificados
208
 *
209
 * Revision 1.4  2006/05/23 08:09:39  jorpiell
210
 * 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
211
 *
212
 * Revision 1.3  2006/05/19 12:57:08  jorpiell
213
 * Modificados algunos paneles
214
 *
215
 * Revision 1.2  2006/04/20 16:38:24  jorpiell
216
 * 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().
217
 *
218
 * Revision 1.1  2006/04/19 12:50:16  jorpiell
219
 * Primer commit de la aplicaci?n. Se puede hacer un getCapabilities y ver el mensaje de vienvenida del servidor
220
 *
221
 */
222

  
223
/**
224
 * <p>Container of the WFS panels, that works as a {@linkplain TabbedPanel TabbedPanel}.</p>
225
 *
226
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
227
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
228
 */
229
public class WFSParamsPanel extends TabbedPanel implements ILayerPanel {
230
	private static final long serialVersionUID = 150328995058481516L;
231

  
232
	private static Logger logger = LoggerFactory.getLogger(WFSParamsPanel.class);
233

  
234
	private WFSServerExplorer serverExplorer = null;
235
	private WFSSelectedFeatureManager selectedFeatureManager = null;
236

  
237
	private static final MapContextManager MAP_CONTEXT_MANAGER = MapContextLocator.getMapContextManager();
238

  
239
	// Tab positions
240
	private int infoTabPosition = -1;
241
	private int featureTabPosition = -1;
242
	private int fieldsTabPosition = -1;
243
	private int optionsTabPosition = -1;
244
	// private int filterTabPosition = -1;
245
	private int areaTabPosition = -1;
246

  
247
	// Tabs
248
	private WFSInfoPanel infoPanel = null;
249
	private WFSSelectFeaturePanel featurePanel = null;
250
	private WFSSelectFieldsPanel fieldsPanel = null;
251
	private WFSOptionsPanel optionsPanel = null;
252
	// private WFSFilterPanel filterPanel = null;
253
	private WFSAreaPanel areaPanel = null;
254

  
255
	private String cacheSelected = null;
256

  
257
	/**
258
	 * This method initializes jTabbedPane
259
	 *
260
	 * @return javax.swing.JTabbedPane
261
	 */
262
	public WFSParamsPanel(Object reference) {
263
		super(reference);
264
		initialize();
265
	}
266

  
267
	/*
268
	 * (non-Javadoc)
269
	 * @see org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel#initialize()
270
	 */
271
	protected void initialize() {
272
		super.initialize();
273

  
274
		this.setVisible(false);
275
	}
276

  
277
	/**
278
	 * Sets the focus to the next tab of the current one.
279
	 */
280
	public void goToNextTab() {
281
		int tabIndex = getSelectedIndex();
282

  
283
		if ((tabIndex - 1) < getPanelInGUICount()) {
284
			int nextIndex = nextPageEnabled();
285

  
286
			if (nextIndex > -1)
287
				setSelectedIndex(nextIndex);
288
		}
289
	}
290

  
291
	/**
292
	 * Sets the focus to the tab previous to the current one.
293
	 */
294
	public void goToPreviousTab(){
295
		setSelectedIndex(previousEnabledPage());
296
	}
297

  
298
	/**
299
	 * @see JTabbedPane#getSelectedIndex()
300
	 */
301
	public int getSelectedIndex(){
302
		return this.getJTabbedPane().getSelectedIndex();
303
	}
304

  
305
	/**
306
	 * @see JTabbedPane#setSelectedIndex(int)
307
	 */
308
	public void setSelectedIndex(int index) {
309
		this.getJTabbedPane().setSelectedIndex(index);
310
	}
311

  
312
	/**
313
	 * This method initializes infoPanel
314
	 *
315
	 * @return the information panel
316
	 */
317
	public WFSInfoPanel getInfoPanel() {
318
		if (infoPanel != null)
319
			return infoPanel;
320

  
321
		if (infoTabPosition == -1)
322
			return null;
323

  
324
		return (infoPanel = (WFSInfoPanel) values().toArray()[infoTabPosition]);
325
	}
326

  
327
	/**
328
	 * This method initializes featurePanel
329
	 *
330
	 * @return javax.swing.JPanel
331
	 */
332
	public WFSSelectFeaturePanel getFeaturesPanel() {
333
		if (featurePanel != null)
334
			return featurePanel;
335

  
336
		if (featureTabPosition == -1)
337
			return null;
338

  
339
		return (featurePanel = (WFSSelectFeaturePanel) values().toArray()[featureTabPosition]);
340
	}
341

  
342
	/**
343
	 * This method initializes fieldsPanel
344
	 *
345
	 * @return javax.swing.JPanel
346
	 */
347
	public WFSSelectFieldsPanel getFieldsPanel() {
348
		if (fieldsPanel != null)
349
			return fieldsPanel;
350

  
351
		if (fieldsTabPosition == -1)
352
			return null;
353

  
354
		return (fieldsPanel = (WFSSelectFieldsPanel) values().toArray()[fieldsTabPosition]);
355
	}
356

  
357
	/**
358
	 * This method initializes optionsPanel
359
	 *
360
	 * @return javax.swing.JPanel
361
	 */
362
	public WFSOptionsPanel getOptionsPanel() {
363
		if (optionsPanel != null)
364
			return optionsPanel;
365

  
366
		if (optionsTabPosition == -1)
367
			return null;
368

  
369
		return (optionsPanel = (WFSOptionsPanel) values().toArray()[optionsTabPosition]);
370
	}
371

  
372
	/**
373
	 * This method initializes filterPanel
374
	 *
375
	 * @return javax.swing.JPanel
376
	 */
377

  
378
	/*
379
	public WFSFilterPanel getFilterPanel(){
380
		if (filterPanel != null)
381
			return filterPanel;
382

  
383
		if (filterTabPosition == -1)
384
			return null;
385

  
386
		return (filterPanel = (WFSFilterPanel) values().toArray()[filterTabPosition]);
387
	}
388
	*/
389

  
390
	/**
391
	 * This method initializes areaPanel
392
	 *
393
	 * @return javax.swing.JPanel
394
	 */
395
	public WFSAreaPanel getAreaPanel() {
396
		if (areaPanel != null)
397
			return areaPanel;
398

  
399
		if (areaTabPosition == -1)
400
			return null;
401

  
402
		return (areaPanel = (WFSAreaPanel) values().toArray()[areaTabPosition]);
403
	}
404

  
405
	/**
406
	 * Verifies that the selected parameters are enough to request
407
	 * the coverage to the server.
408
	 *
409
	 * @return boolean <code>true</code> if its correctly configured;
410
	 * otherwise returns <code>false</code>
411
	 */
412
	public boolean isCorretlyConfigured() {
413

  
414
	    if (featurePanel == null) {
415
	        return false;
416
	    }
417

  
418
	    int n_sel = featurePanel.getSelectedFeaturesCount();
419
	    return (n_sel > 0);
420
	}
421

  
422
	/**
423
	 * Enable or disable the default tabs
424
	 */
425
	public void enableDefaultTabs(boolean isEnabled) {
426
		if (fieldsTabPosition != -1)
427
			setEnabledAt(fieldsTabPosition, isEnabled);
428

  
429
		/*
430
		if (filterTabPosition != -1)
431
			setEnabledAt(filterTabPosition, isEnabled);
432
			*/
433

  
434
		if (areaTabPosition != -1)
435
			setEnabledAt(areaTabPosition, isEnabled);
436
	}
437

  
438
	/*
439
	 * (non-Javadoc)
440
	 * @see org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel#loadPanel(org.gvsig.gui.beans.panelGroup.panels.IPanel)
441
	 */
442
	protected void loadPanel(IPanel panel) {
443
		super.loadPanel(panel);
444

  
445
		if (((AbstractPanel)panel).getClass() ==  WFSInfoPanel.class) {
446
			infoTabPosition = getPanelInGUICount() - 1;
447
			return;
448
		}
449

  
450
		if (((AbstractPanel)panel).getClass() ==  WFSSelectFeaturePanel.class) {
451
			featureTabPosition = getPanelInGUICount() - 1;
452
			return;
453
		}
454

  
455
		if (((AbstractPanel)panel).getClass() ==  WFSSelectFieldsPanel.class) {
456
			fieldsTabPosition = getPanelInGUICount() - 1;
457
			return;
458
		}
459

  
460
		if (((AbstractPanel)panel).getClass() ==  WFSOptionsPanel.class) {
461
			optionsTabPosition = getPanelInGUICount() - 1;
462
			return;
463
		}
464

  
465
		/*
466
		if (((AbstractPanel)panel).getClass() ==  WFSFilterPanel.class) {
467
			filterTabPosition = getPanelInGUICount() - 1;
468
			return;
469
		}
470
		*/
471

  
472
		if (((AbstractPanel)panel).getClass() ==  WFSAreaPanel.class) {
473
			areaTabPosition = getPanelInGUICount() - 1;
474
			return;
475
		}
476
	}
477

  
478
	/**
479
	 * Refresh all the panels with the WFS capabilities information.
480
	 */
481
	public void refreshCapabilitiesInfo(){
482
		WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
483
		if (selectedFeature != null) {
484
			selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
485
		} else {
486
			getFeaturesPanel().refresh(null);
487
		}
488
		serverExplorer.setUserName(getOptionsPanel().getUserName());
489
		serverExplorer.setMaxFeatures(getOptionsPanel().getBuffer());
490
		serverExplorer.setTimeOut(getOptionsPanel().getTimeout());
491

  
492
		getInfoPanel().refresh(selectedFeature);
493
	}
494

  
495
	/**
496
	 * Gets the information used to add or load a WFS layer.
497
	 *
498
	 * @return information used to add or load a WFS layer
499
	 */
500
	public WFSServerExplorer getServerExplorer() {
501
		return serverExplorer;
502
	}
503

  
504
	/**
505
	 * Sets the information used to add or load a WFS layer.
506
	 *
507
	 * @param wizardData information used to add or load a WFS layer
508
	 */
509
	public void setServerExplorer(WFSServerExplorer serverExplorer) {
510
		this.serverExplorer = serverExplorer;
511
		this.selectedFeatureManager =
512
			WFSSelectedFeatureManager.getInstance(serverExplorer);
513
	}
514

  
515
	/**
516
	 * Returns the next enabled tab's index, or -1 if there isn't any.
517
	 *
518
	 * @return The index or -1 if there is no one.
519
	 */
520
	public int nextPageEnabled() {
521
		int currentPage = getSelectedIndex();
522
		int nPages = getPanelInGUICount();
523

  
524
		if (currentPage == nPages)
525
			return -1;
526

  
527
		for (int i = currentPage + 1; i < nPages; i++){
528
			if (getJTabbedPane().isEnabledAt(i)){
529
				return i;
530
			}
531
		}
532

  
533
		return -1;
534
	}
535

  
536
	/**
537
	 * Returns the index of the current tab.
538
	 *
539
	 * @return index of the current tab
540
	 */
541
	public int currentPage() {
542
		return getSelectedIndex();
543
	}
544

  
545
	/**
546
	 * Returns the index of the previous enabled tab.
547
	 *
548
	 * @return The index, or -1 if there is no one.
549
	 */
550
	public int previousEnabledPage() {
551
		int currentPage = getSelectedIndex();
552

  
553
		if (currentPage == 0)
554
			return -1;
555

  
556
		for (int i = currentPage - 1; i > -1; i--) {
557
			if (isEnabledAt(i)) {
558
				return i;
559
			}
560
		}
561

  
562
		return -1;
563
	}
564

  
565
	/*
566
	 *  (non-Javadoc)
567
	 * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
568
	 */
569
	public void initWizard() {
570

  
571
	}
572

  
573
	/*
574
	 *  (non-Javadoc)
575
	 * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
576
	 */
577
	public void execute() {
578

  
579
	}
580

  
581
	/*
582
	 *  (non-Javadoc)
583
	 * @see com.iver.cit.gvsig.gui.ILayerPanel#getLayer()
584
	 */
585
	public FLayer getLayer() {
586
	    try {
587
	        FLayer layer = (FLyrVect) createLayer();
588
	        logger.warn("El flujo de la apliaci?n tal vez no deber?a haber pasado por aqu?.");
589
	        return layer;
590
	    } catch (CreateLayerException e) {
591
	        // do nothing
592
	    }
593
	    return null;
594
	}
595

  
596
	public FLayer createLayer() throws CreateLayerException {
597
		try {
598
		    FLyrVect layerAux =
599
		        (FLyrVect)MAP_CONTEXT_MANAGER.createLayer(getFeaturesPanel().getLayerName(), getDataStoreParameters());
600

  
601
			if((cacheSelected != null) && (!this.cacheSelected.equals(PluginServices.getText(this, "none")))){
602
				layerAux.getFeatureStore().createCache(cacheSelected, getParameters(cacheSelected));
603
			}
604
			return layerAux;
605
		} catch (Exception e) {
606
			logger.warn("Can't create layer.",e);
607
			throw new CreateLayerException(getFeaturesPanel().getLayerName(), e);
608
		}
609

  
610
	}
611

  
612

  
613
	 protected DynObject getParameters(String nameCacheProvider) throws DataException {
614
		 DataManager dataManager = DALLocator.getDataManager();
615
		 return dataManager.createCacheParameters(nameCacheProvider);
616
	 }
617

  
618
	public WFSStoreParameters getDataStoreParameters() throws InitializeException, ProviderNotRegisteredException{
619
		DataManager dataManager = DALLocator.getDataManager();
620
		WFSStoreParameters parameters = (WFSStoreParameters) dataManager
621
		.createStoreParameters(WFSStoreProvider.NAME);
622
		refreshDataStoreParameters(parameters);
623
		return parameters;
624
	}
625

  
626
	private void refreshDataStoreParameters(WFSStoreParameters parameters){
627
		WFSSelectedFeature selectedFeature = getSelectedFeature();
628
		parameters.setUrl(serverExplorer.getUrl());
629
		parameters.setFeatureType(selectedFeature.getNameSpace(),
630
				selectedFeature.getName());
631
		parameters.setFields(getFieldsPanel().getSelectedFieldsAsString());
632
		parameters.setUser(getOptionsPanel().getUserName());
633
		parameters.setPassword(getOptionsPanel().getPassword());
634
		parameters.setMaxFeatures(getOptionsPanel().getBuffer());
635
		parameters.setTimeOut(getOptionsPanel().getTimeout());
636

  
637
		boolean useAxisOrderYX = getOptionsPanel().getUseAxisOrderYX();
638
		parameters.setUseAxisOrderYX(useAxisOrderYX);
639

  
640
		// MapServer no funciona con filtros por intersecci?n de pol?gonos
641

  
642
//		parameters.setFilterByAreaGeometry(getAreaPanel().getArea());
643
		Geometry area = getAreaPanel().getArea();
644
		if (area != null) {
645

  
646
			Envelope envelope = area.getEnvelope();
647
			parameters.setFilterByAreaEnvelope(envelope);
648
		}
649
		parameters.setFilterByAreaCrs(getAreaPanel().getSrs());
650

  
651
		XMLNameSpace ns = selectedFeature.getWFSFeature().getNamespace();
652
		if (ns != null) {
653
	        String ns_pre = ns.getPrefix();
654
	        parameters.setDynValue(
655
	            WFSStoreParameters.DYNFIELDNAME_NAMESPACEPREFIX, ns_pre);
656
		}
657
		// serverExplorer.getServerExplorerProviderServices();
658

  
659
		parameters.setVersion(getOptionsPanel().getVersion());
660

  
661
		parameters.setFilterByAreaOperation(FilterEncoding.GEOMETRIC_OPERATOR_CONTAINS); //(int)AbstractFilter.GEOMETRY_INTERSECTS);
662
		parameters.setFilterByAreaAttribute(selectedFeature.getGeometryField().getName());
663
		parameters.setCrs(getOptionsPanel().getSRS());
664

  
665
		// parameters.setFilterEncodingByAttribute(getFilterPanel().getQuery());
666
	}
667

  
668
    /**
669
     * Sets the forms from a
670
     */
671
    public void setDataStore(DataStore dataStore){
672
        WFSStoreParameters storeParameters =
673
            (WFSStoreParameters)dataStore.getParameters();
674
        WFSSelectedFeature selectedFeature =
675
            selectedFeatureManager.getFeatureInfo(storeParameters.getFeatureNamespace(),
676
                storeParameters.getFeatureType());
677
        getFeaturesPanel().setSelectedFeature(selectedFeature);
678
        getFieldsPanel().setSelectedFields(storeParameters.getFields());
679
        getOptionsPanel().setUserName(storeParameters.getUser());
680
        getOptionsPanel().setPassword(storeParameters.getPassword());
681
        getOptionsPanel().setBuffer(storeParameters.getMaxFeatures());
682
        getOptionsPanel().setTimeOut(storeParameters.getTimeOut());
683
        getAreaPanel().setArea(storeParameters.getFilterByAreaGeometry());
684
        getAreaPanel().setSrs(storeParameters.getFilterByAreaCrs());
685

  
686
        getOptionsPanel().setSRS(storeParameters.getCrs());
687
        getOptionsPanel().setVersion(storeParameters.getVersion());
688

  
689
        // getFilterPanel().setFilterExpressionIntoInterface(storeParameters.getFilterEncodingByAttribute());
690

  
691
        //The filter panel needs to store to update the attributes list
692
        // getFilterPanel().setDataStore(dataStore);
693
    }
694

  
695
    /**
696
     * Gets the node of the layer selected as a feature, with the selected fields and the filter defined.
697
     *
698
     * @return gets the node of the layer selected as a feature, with the selected fields and the filter defined
699
     */
700
    private WFSSelectedFeature getSelectedFeature(){
701
        WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
702
        selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
703
        // selectedFeature.setFilter(getFilterPanel().getQuery());
704
        return selectedFeature;
705
    }
706

  
707
	/**
708
	 * @see WFSWizard#doClickOnNextButton()
709
	 */
710
	public void doClickOnNextButton() {
711
		Object obj = this.getParent();
712

  
713
		if (obj == null)
714
			return;
715

  
716
		// When we start to connect to a server -> the interface is the dialog WFSWizard
717
		if (obj instanceof WFSWizard)
718
			((WFSWizard)this.getParent()).doClickOnNextButton();
719
		else {
720
			// When we are modifying a loaded layer -> the interface is the dialog WFSPropsDialog
721
			this.advanceCurrentTab();
722
		}
723
	}
724

  
725
	/**
726
	 * Selects the next tab
727
	 */
728
	public void advanceCurrentTab() {
729
		int currentTabIndex = this.getJTabbedPane().getSelectedIndex();
730

  
731
		// Ensure we can select next tab
732
		if ((currentTabIndex != -1) && (currentTabIndex < (values().size() -1)))
733
			setSelectedIndex(currentTabIndex + 1);
734
	}
735

  
736
	/**
737
	 * Refreshes the data of the inner <code>WFSSelectFeaturePanel</code>.
738
	 */
739
	public void refreshWFSSelectFeaturePanel() {
740
		WFSSelectFeaturePanel panel = getFeaturesPanel();
741

  
742
		if (panel != null) {
743
			panel.refresh(null);
744
		}
745
	}
746

  
747
	/**
748
	 * @return the selected projection
749
	 */
750
	public IProjection getSelectedFeatureProjection(){
751
		WFSSelectedFeature selectedFeature = getSelectedFeature();
752
		if (selectedFeature.getSrs().size() > 0){
753
			String crs = (String)selectedFeature.getSrs().get(0);
754
			crs = getSRS(crs);
755
			IProjection projection = CRSFactory.getCRS(crs);
756
			if (projection != null){
757
				return projection;
758
			}
759
		}
760
		return null;
761
	}
762

  
763
	/**
764
	 * Removing the URN prefix
765
	 * @param srs
766
	 * @return
767
	 */
768
	private String getSRS(String srs){
769
		if (srs == null){
770
			return null;
771
		}
772
		if (srs.startsWith("urn:x-ogc:def:crs:")){
773
			String newString = srs.substring(srs.lastIndexOf(":") + 1, srs.length());
774
			if (srs.indexOf("EPSG") > 0){
775
				if (newString.indexOf("EPSG") < 0){
776
					newString = "EPSG:" + newString;
777
				}
778
			}
779
			return newString;
780
		}
781
		if (srs.toLowerCase().startsWith("crs:")){
782
			return srs.substring(4, srs.length());
783
		}
784
		return srs;
785
	}
786

  
787
	/**
788
	 * Refresh all the panels every time that a different layer is selected. The info panel is refreshed every time the user
789
	 * makes a click on it.
790
	 *
791
	 * @param selectedFeature the selected layer
792
	 */
793
	public void refresh(WFSSelectedFeature selectedFeature, List vers_list){
794
		boolean hasFields = false;
795

  
796
		if (selectedFeature!=null){
797
			//Update the layer information
798
			selectedFeature = selectedFeatureManager.getFeatureInfo(selectedFeature.getNameSpace(),
799
					selectedFeature.getName());
800

  
801
			// If there is no fields -> disable not necessary tabs
802
			if (selectedFeature.getWFSFeature().getFieldSize() == 0) {
803
				setApplicable(false);
804
				hasFields = false;
805
			}else{
806
				getFieldsPanel().refresh(selectedFeature);
807
				getOptionsPanel().refresh(selectedFeature);
808
                getOptionsPanel().refreshVersions(vers_list);
809
				// getFilterPanel().refresh(selectedFeature);
810
				getAreaPanel().refresh(selectedFeature);
811
				hasFields = true;
812
			}
813
		}
814

  
815
		enableDefaultTabs(hasFields);
816
	}
817

  
818
	/**
819
	 * Changes the <i>enable</i> status of the "<i>apply</i>" button
820
	 *
821
	 * @param isApplicable the <i>enable</i> status of the "<i>apply</i>" button
822
	 */
823
	public void setApplicable(boolean isApplicable){
824
		setEnabledApplyButton(isApplicable);
825
	}
826

  
827
	/*
828
	 * (non-Javadoc)
829
	 * @see org.gvsig.gui.beans.buttonspanel.IButtonsPanel#setEnabledApplyButton(boolean)
830
	 */
831
	public void setEnabledApplyButton(boolean b) {
832
		super.setEnabledApplyButton(b);
833

  
834
		Container parent = getParent();
835

  
836
		if ((parent != null) && (parent instanceof WizardPanel))
837
			((WizardPanel)parent).callStateChanged(b);
838
	}
839

  
840
	/*
841
	 * (non-Javadoc)
842
	 * @see org.gvsig.gui.beans.panelGroup.AbstractPanelGroup#loadPanels(org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader)
843
	 */
844
	public void loadPanels(IPanelGroupLoader loader) throws ListCouldntAddPanelException, EmptyPanelGroupException, EmptyPanelGroupGUIException {
845
		// This code will be executed when is creating the dialog of properties
846
		if (getReference() != null) {
847
			FLyrVect lyr = (FLyrVect) getReference();
848

  
849
			DataManager dataManager = DALLocator.getDataManager();
850
			//Create the datastore parameters and fill them
851
			WFSStoreParameters parameters;
852
			try {
853
				parameters = (WFSStoreParameters) dataManager
854
				.createStoreParameters(WFSStoreProvider.NAME);
855
				parameters.setUrl(serverExplorer.getUrl());
856
				parameters.setVersion(serverExplorer.getVersion());
857
				//parameters.setFeatureType(namespacePrefix, namespace, featureType);
858

  
859
				//dataSource.setDriver(lyr.getWfsDriver());
860

  
861
				//setServerExplorer(dataSource);
862

  
863
				super.loadPanels(loader);
864

  
865
				//				HashMap<String, Object> info = lyr.getProperties();
866
				//				setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
867
				//				setStatus((WFSStatus)info.get("status"));
868
				//				setLayerName(lyr.getName());
869
				//				setVisible(true);
870
				//				refreshInfo();
871
			} catch (InitializeException e) {
872
				// TODO Auto-generated catch block
873
				e.printStackTrace();
874
			} catch (ProviderNotRegisteredException e) {
875
				// TODO Auto-generated catch block
876
				e.printStackTrace();
877
			}
878
			return;
879
		}
880

  
881
		// This will executed when is adding a new WFS layer:
882
		super.loadPanels(loader);
883
	}
884

  
885
	///// BEGIN: METHODS FOR INITIALIZE THIS PANEL AS A COMPONENT OF A PROPERTIES DIALOG /////
886

  
887

  
888
	/**
889
	 * @see WFSSelectFeaturePanel#setLayerName(String)
890
	 */
891
	public void setLayerName(String name) {
892
		getFeaturesPanel().setLayerName(name);
893
	}
894

  
895
	/**
896
	 * Updates the information stored at the wizard's data and <i>info</i> panel.
897
	 */
898
	public void refreshInfo(){
899
		WFSSelectedFeature selectedFeature = getFeaturesPanel().getSelectedFeature();
900

  
901
		if (selectedFeature != null) {
902
			selectedFeature.setSelectedFields(getFieldsPanel().getSelectedFields());
903
		}
904

  
905
		serverExplorer.setUserName(getOptionsPanel().getUserName());
906
		serverExplorer.setMaxFeatures(getOptionsPanel().getBuffer());
907
		serverExplorer.setTimeOut(getOptionsPanel().getTimeout());
908
		getInfoPanel().refresh(selectedFeature);
909
	}
910

  
911
	/**
912
	 * @return the selectedFeatureManager
913
	 */
914
	public WFSSelectedFeatureManager getSelectedFeatureManager() {
915
		return selectedFeatureManager;
916
	}
917

  
918
	public void setSelectedCache(String selectedCache) {
919
		this.cacheSelected = selectedCache;
920
	}
921
}
org.gvsig.wfs.app/tags/org.gvsig.wfs.app-2.0.36/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/wfs/gui/panels/WFSFilterPanel.java
1
package org.gvsig.wfs.gui.panels;
2

  
3
import java.awt.Color;
4
import java.awt.event.MouseAdapter;
5
import java.awt.event.MouseEvent;
6
import java.io.ByteArrayInputStream;
7
import java.io.InputStream;
8
import java.text.DateFormat;
9
import java.text.ParseException;
10
import java.util.Comparator;
11
import java.util.HashMap;
12
import java.util.Iterator;
13
import java.util.Map;
14
import java.util.Set;
15
import java.util.StringTokenizer;
16
import java.util.TreeSet;
17
import java.util.Vector;
18

  
19
import javax.swing.DefaultListModel;
20
import javax.swing.JOptionPane;
21
import javax.swing.event.DocumentEvent;
22
import javax.swing.event.DocumentListener;
23
import javax.swing.event.TreeSelectionEvent;
24
import javax.swing.event.TreeSelectionListener;
25
import javax.swing.tree.DefaultMutableTreeNode;
26
import javax.swing.tree.DefaultTreeModel;
27
import javax.swing.tree.TreePath;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.messages.NotificationManager;
31
import org.gvsig.app.gui.filter.ExpressionDataSource;
32
import org.gvsig.app.gui.filter.FilterException;
33
import org.gvsig.app.sqlQueryValidation.SQLQueryValidation;
34
import org.gvsig.fmap.dal.DataStore;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.gui.beans.Messages;
39
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.FilterQueryJPanel;
40
import org.gvsig.gui.beans.panelGroup.IPanelGroup;
41
import org.gvsig.remoteclient.wfs.WFSFeatureField;
42
import org.gvsig.tools.dataTypes.DataTypes;
43
import org.gvsig.tools.dispose.DisposableIterator;
44
import org.gvsig.utils.stringNumberUtilities.StringNumberUtilities;
45
import org.gvsig.wfs.gui.panels.fieldstree.FieldsTreeTableModel;
46
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
47
import org.gvsig.xmlschema.lib.api.som.IXSElementDeclaration;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

  
51
import Zql.ZExp;
52
import Zql.ZqlParser;
53

  
54

  
55

  
56
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
57
 *
58
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
59
 *
60
 * This program is free software; you can redistribute it and/or
61
 * modify it under the terms of the GNU General Public License
62
 * as published by the Free Software Foundation; either version 2
63
 * of the License, or (at your option) any later version.
64
 *
65
 * This program is distributed in the hope that it will be useful,
66
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
68
 * GNU General Public License for more details.
69
 *
70
 * You should have received a copy of the GNU General Public License
71
 * along with this program; if not, write to the Free Software
72
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
73
 *
74
 * For more information, contact:
75
 *
76
 *  Generalitat Valenciana
77
 *   Conselleria d'Infraestructures i Transport
78
 *   Av. Blasco Ib??ez, 50
79
 *   46010 VALENCIA
80
 *   SPAIN
81
 *
82
 *      +34 963862235
83
 *   gvsig@gva.es
84
 *      www.gvsig.gva.es
85
 *
86
 *    or
87
 *
88
 *   IVER T.I. S.A
89
 *   Salamanca 50
90
 *   46005 Valencia
91
 *   Spain
92
 *
93
 *   +34 963163400
94
 *   dac@iver.es
95
 */
96

  
97
/**
98
 * <p>Panel that provides tools to apply a filter to the values of a feature.</p>
99
 * <p>Improves the functionality of {@link FilterQueryJPanel FilterQueryJPanel}.</p>
100
 *
101
 * @see FilterQueryJPanel
102
 * 
103
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
104
 */
105
public class WFSFilterPanel extends FilterQueryJPanel implements IWFSPanel {
106
    private static final long serialVersionUID = -6041218260822015810L;
107
    private static final Logger LOG = LoggerFactory.getLogger(WFSFilterPanel.class);
108

  
109
    private static Logger logger = LoggerFactory.getLogger(WFSFilterPanel.class);
110
    private ExpressionDataSource model = null;
111
    private FieldsTreeTableModel fieldsTreeTableModel;
112
    private boolean panelAsATabForWFSLayersLoad;
113
    private TreePath currentPath;
114
    private Map<String, Map<String, String>> allFieldsAndValuesKnownOfCurrentLayer; // This will have all values (not repeated) known of all fields (not repeated)
115

  
116
    private DataStore dataStore = null;
117

  
118
    ///// GUI METHODS ////
119

  
120
    /**
121
     * This method initializes
122
     *
123
     * @param parent A reference to the parent container component of this component
124
     */
125
    public WFSFilterPanel() {
126
        super();
127
        currentPath = null;  
128
        allFieldsAndValuesKnownOfCurrentLayer = new HashMap<String, Map<String, String>>(); // Initial capacity = 0
129

  
130
        // At beginning, the JList is disabled (and its set a particular color for user could knew it)
131
        super.getValuesJList().setEnabled(false);
132
        //getValuesJList().setBackground(new Color(220, 220, 220));
133

  
134
        //The validation option is disabled by default
135
        this.getValidateFilterExpressionJCheckBox().setSelected(false);
136
    }
137

  
138
    /*
139
     *  (non-Javadoc)
140
     * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
141
     */
142
    protected void initialize() {
143
        setLabel(PluginServices.getText(this, "filter"));
144
        setLabelGroup(PluginServices.getText(this, "wfs"));
145
        super.initialize();
146
        this.resizeHeight(380);
147

  
148
        defaultTreeModel = (DefaultTreeModel)fieldsJTree.getModel();
149

  
150
        this.addNewListeners();
151
        panelAsATabForWFSLayersLoad = true;
152
        getValidateFilterExpressionJCheckBox().setSelected(true);
153

  
154
        getValuesJLabel().setToolTipText(Messages.getText("values_of_the_selected_field_explanation"));
155
        getFieldsJLabel().setToolTipText(Messages.getText("fields_of_the_selected_feature_explanation"));
156
    }
157

  
158
    /**
159
     * Adds some more listener to the components of the panel
160
     */
161
    private void addNewListeners() {
162
        // Enable "Apply" button when user changes the filter query
163
        txtExpression.getDocument().addDocumentListener(new DocumentListener() {
164
            /*
165
             *  (non-Javadoc)
166
             * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
167
             */
168
            public void changedUpdate(DocumentEvent e) {
169
            }
170

  
171
            /*
172
             *  (non-Javadoc)
173
             * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
174
             */
175
            public void insertUpdate(DocumentEvent e) {
176
                if (!panelAsATabForWFSLayersLoad) {
177
                    IPanelGroup panelGroup = getPanelGroup();
178

  
179
                    if (panelGroup == null)
180
                        return;
181

  
182
                    ((WFSParamsPanel)panelGroup).setApplicable(true);
183
                }
184
            }
185

  
186
            /*
187
             *  (non-Javadoc)
188
             * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
189
             */
190
            public void removeUpdate(DocumentEvent e) {
191
                if (!panelAsATabForWFSLayersLoad) {
192
                    IPanelGroup panelGroup = getPanelGroup();
193

  
194
                    if (panelGroup == null)
195
                        return;
196

  
197
                    ((WFSParamsPanel)panelGroup).setApplicable(true);
198
                }
199
            }
200
        });
201

  
202
        // Listener for "fieldsJTree"
203
        getFieldsJTree().addMouseListener(new MouseAdapter() {
204
            /*
205
             *  (non-Javadoc)
206
             * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
207
             */
208
            public void mouseClicked(MouseEvent e) {
209
                int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
210
                TreePath treePath = fieldsJTree.getPathForLocation(e.getX(), e.getY());
211

  
212
                if (row > -1) {
213
                    switch (e.getClickCount()) {
214
                    case 2:
215
                        putSymbolOfSelectedByMouseBranch(treePath);
216
                        break;
217
                    }
218
                }
219
            }
220
        });
221

  
222
        // Listener for "valuesJList"
223
        getValuesJList().addMouseListener(new MouseAdapter() {
224
            /*
225
             *  (non-Javadoc)
226
             * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
227
             */
228
            public void mouseClicked(MouseEvent e) {
229
                int index = getValuesJList().getSelectedIndex();
230

  
231
                // Avoids exception when no value is in the list
232
                if (index == -1)
233
                    return;
234

  
235
                if (e.getClickCount() == 2){
236
                    String valor = valuesListModel.getElementAt(index).toString();
237

  
238
                    // If value is an string -> set it between apostrophes
239
                    if (getNodeOfCurrentPath().getDataType().getType() == DataTypes.STRING) {
240
                        putSymbol("'" + valor + "'");
241
                    }
242
                    else {
243
                        putSymbol(valor);
244
                    }
245
                }
246
            }
247
        });
248

  
249
        // Listener for a branch of the tree selection
250
        getFieldsJTree().addTreeSelectionListener(new TreeSelectionListener() {
251
            /*
252
             *  (non-Javadoc)
253
             * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
254
             */
255
            public void valueChanged(TreeSelectionEvent e) {
256
                if (dataStore != null){
257
                    currentPath = e.getPath();
258
                    fillValuesByPath(currentPath);
259
                }
260
            }
261
        });
262

  
263
        // Listener: when a user writes something on the textarea -> set it's foreground color to black
264
        getTxtExpression().getDocument().addDocumentListener(new DocumentListener() {
265
            /*
266
             *  (non-Javadoc)
267
             * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
268
             */
269
            public void changedUpdate(DocumentEvent e) {
270
            }
271

  
272
            /*
273
             *  (non-Javadoc)
274
             * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
275
             */
276
            public void insertUpdate(DocumentEvent e) {
277
                getTxtExpression().setForeground(Color.BLACK);
278
            }
279

  
280
            /*
281
             *  (non-Javadoc)
282
             * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
283
             */
284
            public void removeUpdate(DocumentEvent e) {
285
                getTxtExpression().setForeground(Color.BLACK);
286
            }
287
        });
288
    }
289

  
290
    /**
291
     * Gets the element that the 'currentPath' field aims
292
     *
293
     * @return An XMLElement
294
     */
295
    private WFSFeatureField getNodeOfCurrentPath() {
296

  
297
        if (currentPath != null) {
298
            Object node = currentPath.getLastPathComponent();
299

  
300
            if ((node != null) && (node instanceof WFSFeatureField)) {
301
                return (WFSFeatureField) node;
302
            }
303
        }
304

  
305
        return null;
306
    }
307

  
308
    /**
309
     * Puts the symbol of selected branch
310
     *
311
     * @param mouseEvent A MouseEvent with information  of the selected branch
312
     */
313
    public void putSymbolOfSelectedByMouseBranch(TreePath treePath) {
314
        // Sets the node selected
315
        if (treePath != null) {
316
            putSymbol("\"" + this.getPathOfLeafWithoutRoot(treePath.getLastPathComponent().toString()) + "\"");
317
        }
318
    }
319

  
320
    /**
321
     * This method returns the path without the root, of a node of a tree
322
     * Each node is separated from its parent with the symbol "/"
323
     *
324
     * @param node A leaf node
325
     * @return An string with the path
326
     */
327
    private String getPathOfLeafWithoutRoot(Object node) {
328
        String path = "";
329

  
330
        if ((node != null) && (node instanceof IXSElementDeclaration)) {
331
            IXSElementDeclaration element = (IXSElementDeclaration) node;
332
            IXSElementDeclaration parent = element.getParentElement();
333
            path = element.getNodeName();
334

  
335
            while (parent.getParentElement() != null){
336
                path = parent.getNodeName() + "/" + path;
337
                parent = parent.getParentElement();
338
            }
339
        }else if (node instanceof String){
340
            path = node.toString();
341
        }
342

  
343
        return path;
344
    }
345

  
346
    /**
347
     * Gets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
348
     *
349
     * @return A boolean value
350
     */
351
    public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() {
352
        return this.panelAsATabForWFSLayersLoad;
353
    }
354

  
355
    /**
356
     * Refresh all information about fields
357
     *
358
     * @param feature a feature with fields
359
     */
360
    public void refresh(WFSSelectedFeature feature) {
361
        setFields(feature);	       
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff