Revision 9576

View differences:

branches/v10/extensions/extWFS2/src/com/iver/cit/gvsig/gui/dialogs/WFSPropsDialog.java
1 1
package com.iver.cit.gvsig.gui.dialogs;
2 2

  
3
import java.awt.Component;
3 4
import java.awt.event.ActionEvent;
4 5
import java.awt.event.ActionListener;
5 6
import java.net.MalformedURLException;
......
7 8
import java.util.HashMap;
8 9

  
9 10
import javax.swing.JButton;
11
import javax.swing.JOptionPane;
10 12
import javax.swing.JPanel;
11 13

  
12 14
import org.gvsig.remoteClient.wfs.WFSStatus;
......
19 21
import com.iver.cit.gvsig.fmap.MapControl;
20 22
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
21 23
import com.iver.cit.gvsig.fmap.layers.FLayer;
24
import com.iver.cit.gvsig.fmap.layers.FLayers;
22 25
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
23 26
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
24 27
import com.iver.cit.gvsig.fmap.layers.FLyrWFSFactory;
25 28
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
26 29
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
27 30
import com.iver.cit.gvsig.gui.layout.Layout;
28
import com.iver.cit.gvsig.gui.panels.WFSFilterPanel;
29 31
import com.iver.cit.gvsig.gui.panels.WFSParamsPanel;
30 32
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
31 33
import com.iver.cit.gvsig.gui.wizards.WizardListener;
......
77 79
 *
78 80
 * $Id$
79 81
 * $Log$
80
 * Revision 1.4.2.11  2007-01-04 10:06:25  jcampos
82
 * Revision 1.4.2.12  2007-01-08 10:09:12  ppiqueras
83
 * Corridos bugs + nueva funcionalidad.
84
 *
85
 * Revision 1.4.2.11  2007/01/04 10:06:25  jcampos
81 86
 * Upgrade new version
82 87
 *
83 88
 * Revision 1.4.2.10  2006/12/19 08:19:55  jorpiell
......
140 145
 */
141 146
/**
142 147
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
148
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
143 149
 */
144 150
public class WFSPropsDialog extends JPanel implements IWindow{
145 151
	private WFSParamsPanel wfsParamsTabbedPane = null;
......
157 163
		super();
158 164
		initialize(layer);
159 165
	}
160
    
166

  
161 167
    private void initialize(FLayer layer) {
162 168
		setLayout(null);		
163 169
        setFLayer(layer);
......
222 228
	 * @return WMSParamsPanel
223 229
	 */
224 230
	public WFSParamsPanel getParamsPanel(HashMap info) {
225
	    if (info != null){
231
	    if (info!=null){
226 232
	    	URL host = (URL) info.get("host");
227 233
	    	WFSWizardData dataSource = new WFSWizardData();
228 234
	    	//dataSource.setHost(host, false);
......
302 308
	
303 309
	public void close() {
304 310
		PluginServices.getMDIManager().closeWindow(this);		
305
	}  
311
	}
306 312
	
307
	 private class CommandListener implements ActionListener {
308
		 public CommandListener(WFSPropsDialog tp) {
313
    /**
314
     * Merge two FLayers in one
315
     * @param group1
316
     * @param group2
317
     * @return
318
     */
319
    private FLayers mergeFLayers(FLayers group1, FLayers group2)
320
    {    	
321
    	FLayer layer;
322
    	for(int i = 0; i < group2.getLayersCount(); i++)
323
    	{
324
    		layer = group2.getLayer( i );
325
    		if(group1.getLayer( layer.getName()) == null ){
326
    			group1.addLayer( layer );
327
    		}
328
    	}
329
    	
330
    	return group1;
331
    }
332
	
333
	private class CommandListener implements ActionListener {
334
		public CommandListener(WFSPropsDialog tp) {
309 335
			 //m_tp = tp;
310
		 }
336
		}
311 337
		 
312
		 /* (non-Javadoc)
313
		  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
314
		  */
315
		 public void actionPerformed(ActionEvent e) {
316
			 if ((e.getActionCommand() == "CANCEL") || (!getBtnApply().isEnabled())){
317
				 close();
318
			 }else{					
338
		/* (non-Javadoc)
339
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
340
		 */
341
		public void actionPerformed(ActionEvent e) {
342
			if ((e.getActionCommand() == "CANCEL") || (!getBtnApply().isEnabled())) {
343
				close();
344
				return;
345
			}else{					
319 346
				 String layerName = fLayer.getName();
320 347
				 VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend();
321 348
				 FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();						
......
329 356
					 }						 
330 357
					 
331 358
				 } catch (MalformedURLException e1) {
332
					 // TODO Auto-generated catch block
333 359
					 e1.printStackTrace();
334 360
				 } catch (FieldNotFoundException e1) {
335
					 // TODO Auto-generated catch block
336 361
					 e1.printStackTrace();
337 362
				 } catch (DriverException e1) {
338
					 // TODO Auto-generated catch block
339 363
					 e1.printStackTrace();
340
				 } 		 
341
				 if (e.getActionCommand() == "APPLY"){
342
					 BaseView vista = (BaseView) PluginServices.getMDIManager().getActiveWindow();
343
					 MapControl mapCtrl = vista.getMapControl();					 
344
					 mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);					 
345
					 mapCtrl.getMapContext().invalidate();
346
					 applied = true;
347
					 getBtnApply().setEnabled(!applied);
348
					 refreshLayouts();						 
349
					 
350
					 // If we load another layer, or the same but we've selected others attributes -> notify it to he WFSFilter panel
351
					 if (getWFSFilterPanelIsAsTabForWFSLayersLoad() || (wfsParamsTabbedPane.getAttributesSelectedOfSameLayerHasChanged())) {
352
						 setWFSFilterPanelIsAsTabForWFSLayersLoad(false);
353
						 wfsParamsTabbedPane.resetAttributesSelectedOfSameLayerHasChanged(); // reset that attribute
354
					 }
355
					 
356
					 wfsParamsTabbedPane.updateWFSFilterFieldValues();
357
					 
358
				 }
359
				 if (e.getActionCommand() == "OK") {
360
					 if (!applied) {
361
						 if (getBtnApply().isEnabled()){
362
							 View vista = (View) PluginServices.getMDIManager().getActiveWindow();
363
							 MapControl mapCtrl = vista.getMapControl();
364
							 mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
365
							 mapCtrl.getMapContext().invalidate();
366
							 refreshLayouts();							 
367
						 }
368
					 }	
369
					 close();		                
370
				 }
371
			 }
372
		 }	 
373
	 }
364
				 } 
365
			
366
				if (e.getActionCommand() == "APPLY"){
367
					// We can't 'apply' if there is a filter query and it's incorrect
368
					if (wfsParamsTabbedPane.getFilterQuery() != null) {					
369
						BaseView vista = (BaseView) PluginServices.getMDIManager().getActiveWindow();
370
						MapControl mapCtrl = vista.getMapControl();					 
371
						mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);					 
372
						mapCtrl.getMapContext().invalidate();
373
						applied = true;
374
						getBtnApply().setEnabled(!applied);
375
						refreshLayouts();						 
376
						 
377
						// If we load another layer, or the same but we've selected others attributes -> notify it to he WFSFilter panel
378
						if (getWFSFilterPanelIsAsTabForWFSLayersLoad() || (wfsParamsTabbedPane.getFieldsSelectedOfSameLayerHasChanged())) {
379
							setWFSFilterPanelIsAsTabForWFSLayersLoad(false);
380
							wfsParamsTabbedPane.resetFieldsSelectedOfSameLayerHasChanged(); // reset that attribute
381
						}
382
						 
383
						// Update values associated to the current selected field
384
						wfsParamsTabbedPane.updateWFSFilterFieldValues();	
385
					}
386
					return;				 
387
				}
388
				 
389
				if (e.getActionCommand() == "OK") {
390
					// We can't 'apply' if there is a filter query and it's incorrect
391
					if (wfsParamsTabbedPane.getFilterQuery() != null) {	
392
						if (!applied) {
393
							if (getBtnApply().isEnabled()){
394
								 
395
								layerName = prepareFlyrWFSLayer();
396
								 
397
								View vista = (View) PluginServices.getMDIManager().getActiveWindow();
398
								MapControl mapCtrl = vista.getMapControl();
399
								mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
400
								mapCtrl.getMapContext().invalidate();
401
								refreshLayouts();	
402
							}
403
						}	
404
						close();
405
						 
406
						// Update all fields and values known about the current layer loaded (and selected)
407
						((FLyrWFS)fLayer).setAllFieldsAndValuesKnown(wfsParamsTabbedPane.getAllFieldsAndValuesKnownOfCurrentLayer());
408
					}
409
				}
410
			}
411
		}
412
		 
413
		/**
414
		 * Updates data in the current layer of current active view
415
		 * 
416
		 * @param currentView The current active view
417
		 * @return Te name of the layer
418
		 */
419
		private String prepareFlyrWFSLayer() {
420
//			 layerName = fLayer.getName();
421
	//	 	 View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
422
			VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend();
423
		 	FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();						
424
		 	try {
425
		 		fLayer = wfsParamsTabbedPane.getLayer();
426
		 		URL host = new URL(wfsParamsTabbedPane.getData().getHost());
427
		 		String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
428
		 		fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,true);
429
		 		if (fLayer != null) {
430
		 			((FLyrWFS)fLayer).setLegend(legend);
431
					
432
		 			 // Update all fields and values known about the current layer loaded (and selected)
433
		 			((FLyrWFS)fLayer).setAllFieldsAndValuesKnown(wfsParamsTabbedPane.getAllFieldsAndValuesKnownOfCurrentLayer());
434
		 		}
435
			} catch (MalformedURLException e1) {
436
				e1.printStackTrace();
437
			} catch (FieldNotFoundException e1) {
438
				e1.printStackTrace();
439
			} catch (DriverException e1) {
440
				e1.printStackTrace();
441
			}
442
			 
443
			return fLayer.getName();
444
		}
445

  
446
		private boolean loadLayer(FLayer flayer) {
447
			try {
448
				((FLyrWFS)fLayer).load();
449
				
450
				if (((FLyrWFS)fLayer).getNumfeatures() == ((FLyrWFS)fLayer).getWfsDriver().getRowCount()) {
451
					JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
452
						PluginServices.getText(this,"maxFeatures_aviso"));	
453
				}
454
			} catch (Exception e1) {
455
				e1.printStackTrace();
456
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
457
						PluginServices.getText(this,"cantLoad"));
458
				return false;
459
			}
460
			return true;
461
		}
462
	}
374 463
	 
375 464
	/**
376 465
	 * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
......
387 476
	}
388 477
	
389 478
	/**
479
	 * Sets all fielsd and values known of current layer to WFSFilterPanel
480
	 */
481
	public void updateAllFieldsAndValuesKnownOfCurrentLayerToWFSFilterPanel() {
482
		this.wfsParamsTabbedPane.setAllFieldsAndValuesKnownOfCurrentLayer(((FLyrWFS)this.getFLayer()).getAllFieldsAndValuesKnown());
483
	}
484
	
485
	/**
390 486
	 * Refresh the layouts
391 487
	 *
392 488
	 */
branches/v10/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSFilterPanel.java
5 5
import java.awt.event.MouseEvent;
6 6
import java.io.UnsupportedEncodingException;
7 7
import java.net.URLEncoder;
8
import java.text.DateFormat;
8 9
import java.text.NumberFormat;
9 10
import java.text.ParseException;
10 11
import java.util.ArrayList;
11 12
import java.util.Comparator;
13
import java.util.HashMap;
12 14
import java.util.Iterator;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.StringTokenizer;
13 18
import java.util.TreeSet;
14 19
import java.util.Vector;
15 20
import java.util.regex.Matcher;
16 21
import java.util.regex.Pattern;
17 22

  
18 23
import javax.swing.DefaultListModel;
24
import javax.swing.JOptionPane;
19 25
import javax.swing.event.DocumentEvent;
20 26
import javax.swing.event.DocumentListener;
21 27
import javax.swing.event.TreeSelectionEvent;
......
25 31
import javax.swing.tree.TreePath;
26 32

  
27 33
import org.apache.log4j.Logger;
34
import org.gvsig.gui.beans.Messages;
28 35
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.FilterQueryJPanel;
29 36
import org.gvsig.remoteClient.gml.schemas.IXMLType;
30 37
import org.gvsig.remoteClient.gml.schemas.XMLElement;
......
53 60
import com.iver.cit.gvsig.gui.filter.ExpressionListener;
54 61
import com.iver.cit.gvsig.gui.filter.FilterException;
55 62
import com.iver.cit.gvsig.gui.panels.attributesTree.AttributesTreeTableModel;
63
import com.iver.cit.gvsig.gui.panels.sqlQueryValidation.SQLQueryValidation;
56 64
import com.iver.cit.gvsig.project.ProjectFactory;
57 65
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
58 66
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
59 67
import com.iver.cit.gvsig.project.documents.table.gui.Table;
60
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
68
import com.iver.cit.gvsig.project.documents.view.gui.View;
61 69
import com.iver.utiles.DefaultCharSet;
62 70
import com.iver.utiles.StringUtilities;
63 71
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport;
64 72
import com.iver.utiles.exceptionHandling.ExceptionListener;
73
import com.iver.utiles.stringNumberUtilities.StringNumberUtilities;
65 74

  
75

  
66 76
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
67 77
 *
68 78
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
......
121 131
	private boolean panelAsATabForWFSLayersLoad;
122 132
	private TreePath currentPath;
123 133
	private String featureName;
134
	private Map allFieldsAndValuesKnownOfCurrentLayer; // This will have all values (not repeated) known of all fields (not repeated)
124 135
	
136
	///// GUI METHODS ////
137
	
125 138
	/**
126 139
	 * This method initializes
127
	 *
140
	 * 
141
	 * @param parent A reference to the parent container component of this component
128 142
	 */
129 143
	public WFSFilterPanel(WFSParamsPanel parent) {
130 144
		super();
131 145
		this.parent = parent;
132 146
		currentPath = null;
133 147
		featureName = null;
148
		allFieldsAndValuesKnownOfCurrentLayer = new HashMap(); // Initial capacity = 0
134 149

  
135 150
		// At beginning, the JList is disabled (and its set a particular color for user could knew it)
136 151
		super.getValuesJList().setEnabled(false);
......
216 231
				// Avoids exception when no value is in the list
217 232
				if (index == -1)
218 233
					return;
219
				
220
				if (e.getClickCount() == 2) {
221
					Value valor = (Value) valuesListModel.getElementAt(index);
222 234
					
235
				if (e.getClickCount() == 2){
236
					String valor = (String) valuesListModel.getElementAt(index);
237
					
238
					// If value is an string -> set it between apostrophes
223 239
					if (getNodeOfCurrentPath().getEntityType().getName().compareTo("xs:string") == 0) {
224
						putSymbol("'" + valor.toString() + "'");
240
						putSymbol("'" + valor + "'");
225 241
					}
226 242
					else {
227
						putSymbol(valor.toString());
228
					}					
243
						putSymbol(valor);
244
					}
229 245
				}
230 246
			}
231 247
		});
......
247 263
					}
248 264
				}
249 265
			}			
250
		});		
266
		});
267
		
268
		// Listener: when a user writes something on the textarea -> set it's foreground color to black
269
		getTxtExpression().getDocument().addDocumentListener(new DocumentListener() {
270
			/*
271
			 *  (non-Javadoc)
272
			 * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
273
			 */
274
			public void changedUpdate(DocumentEvent e) {
275
			}
276

  
277
			/*
278
			 *  (non-Javadoc)
279
			 * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
280
			 */
281
			public void insertUpdate(DocumentEvent e) {
282
				getTxtExpression().setForeground(Color.BLACK);
283
			}
284

  
285
			/*
286
			 *  (non-Javadoc)
287
			 * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
288
			 */
289
			public void removeUpdate(DocumentEvent e) {				
290
				getTxtExpression().setForeground(Color.BLACK);
291
			}			
292
		});
251 293
	}
252 294
	
253 295
	/**
254
	 * If there is a field selected, show its new values
296
	 * Gets the element that the 'currentPath' field aims
297
	 * 
298
	 * @return An XMLElement
255 299
	 */
256
	public void updateFieldValues() {
300
	private XMLElement getNodeOfCurrentPath() {
301
		
257 302
		if (currentPath != null) {
303
			Object node = currentPath.getLastPathComponent();
258 304
			
259
			DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource();
260
						
261
			if ((data != null) && (data.getData() != null)) {
262
				setModel(data.getData());				
263
				fillValuesByPath(currentPath);
264
				
265
				// Updates all tables that their data is about the changed view
266
				this.updateTablesThatHasNewData();
305
			if ((node != null) && (node instanceof XMLElement)) {
306
//				XMLElement element = (XMLElement) node;
307
				return (XMLElement) node;
267 308
			}
268 309
		}
310
		
311
		return null;
269 312
	}
270 313
	
271 314
	/**
272
	 * Updates all tables that their data is about the changed view
315
	 * Puts the symbol of selected brach
316
	 * 
317
	 * @param mouseEvent A MouseEvent with information  of the selected branch
273 318
	 */
274
	private void updateTablesThatHasNewData() {
275
		boolean oneTimeNewDataToTableAdded = false;
276
		
277
		IWindow[] activeNoModalWindows = PluginServices.getMDIManager().getAllWindows();
278
		
279
		for (int i = 0; i < activeNoModalWindows.length; i++) {
280
			IWindow window = activeNoModalWindows[i];
281
			if (window instanceof Table) {
282
				Table table = (Table) window;
283
				
284
				int pos1 = featureName.indexOf(':');
285
				
286
				if ((pos1 >= 0) && (pos1 < featureName.length()))						
287
					featureName = featureName.substring(pos1 +1, featureName.length());
288
				
289
//					String featureOfTable = ((XMLElement)currentPath.getParentPath().getLastPathComponent()).getName();
290
					String featureOfTable = table.getModel().getName();
291
					int pos2 = featureOfTable.indexOf(':');
292
												
293
					if ((pos2 >= 0) && (pos2 < featureName.length()))
294
						featureOfTable = featureOfTable.substring(pos2 +1, featureOfTable.length());						
295
				
296
				if (featureName.trim().compareTo(featureOfTable.trim()) == 0) {
297
					// Only add the new data associated to the table one time
298
					if (oneTimeNewDataToTableAdded == false) {
299
						setNewDataToTable();
300
						oneTimeNewDataToTableAdded = true;
301
					}
302
				
303
					// Refresh the table with the new data
304
					table.refresh();
319
	public void putSymbolOfSelectedByMouseBranch(TreePath treePath) {
320
		// Sets the node selected
321
		if (treePath != null) {
322
			Object node = treePath.getLastPathComponent();
323
			if ((node != null) && (node instanceof XMLElement)) {
324
				XMLElement element = (XMLElement) node;
325
				XMLElement parent = element.getParentElement();
326
				String path = element.getName();
327
				while (parent.getParentElement() != null){
328
					path = parent.getName() + "/" + path;
329
					parent = parent.getParentElement();
305 330
				}
331
				putSymbol("\"" + path + "\"");
306 332
			}
307 333
		}
308 334
	}
309 335
	
310 336
	/**
311
	 * This method is a modification of the "execute" method from the "ShowTable" class 
312
	 * @see com.iver.cit.gvsig.ShowTable#execute(String)
337
	 * Gets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
338
	 * 
339
	 * @return A boolean value
313 340
	 */
314
	private void setNewDataToTable() {
315
		BaseView vista = (BaseView) PluginServices.getMDIManager().getActiveWindow();
316
		FLayer[] actives = vista.getModel().getMapContext().getLayers().getActives();
317

  
318
		try {
319
			for (int i = 0; i < actives.length; i++) {
320
				if (actives[i] instanceof AlphanumericData) {
321
					AlphanumericData co = (AlphanumericData) actives[i];
322

  
323
					//SelectableDataSource dataSource;
324
					//dataSource = co.getRecordset();
325

  
326
					ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
327

  
328
					ProjectTable projectTable = ext.getProject().getTable(co);
329
					EditableAdapter ea=null;
330
					ReadableVectorial rv=((FLyrVect)actives[i]).getSource();
331
					if (rv instanceof VectorialEditableAdapter){
332
						ea=(EditableAdapter)((FLyrVect)actives[i]).getSource();
333
					}else{
334
						ea=new EditableAdapter();
335
						SelectableDataSource sds=((FLyrVect)actives[i]).getRecordset();
336
						ea.setOriginalDataSource(sds);
337
					}
338

  
339
					if (projectTable == null) {
340
						projectTable = ProjectFactory.createTable(PluginServices.getText(this, "Tabla_de_Atributos") + ": " + actives[i].getName(),
341
								ea);
342
						projectTable.setProjectDocumentFactory(new ProjectTableFactory());
343
						projectTable.setAssociatedTable(co);
344
						ext.getProject().addDocument(projectTable);
345
					}
346
					projectTable.setModel(ea);					
347
//					Table t = new Table();
348
//					t.setModel(projectTable);
349
//					PluginServices.getMDIManager().addWindow(t);
350
				}
351
			}
352
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
353
            NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e);
354
        } catch (com.iver.cit.gvsig.fmap.DriverException e) {
355
			e.printStackTrace();
356
			NotificationManager.addError(PluginServices.getText(this,"No_se_pudo_obtener_la_tabla_de_la_capa"), e);
357
        }
341
	public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() {
342
		return this.panelAsATabForWFSLayersLoad;
358 343
	}
359

  
344
	
360 345
	/**
361 346
	 * Sets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
362 347
	 * 
......
368 353
		if (this.panelAsATabForWFSLayersLoad == true) {
369 354
			// At beginning, the JList is disabled (and its set a particular color for user could knew it)
370 355
			super.getValuesJList().setEnabled(false);
371
			super.getValuesJList().setBackground(new Color(220, 220, 220));
356
			super.getValuesJList().setBackground(new Color(220, 220, 220)); // a grey color
357
			
358
			this.allFieldsAndValuesKnownOfCurrentLayer.clear();
372 359
		}
373 360
		else {
374 361
			// Unselect the selected path in the tree (if there was any selected)
......
398 385
//				currentPath = e.getPath();
399 386
//				fillValuesByPath(currentPath);
400 387
			}
388
			
389
			// Loads values known of fields
390
			this.setValuesKnownOfFields();
401 391
		}
402 392
	}
403 393
	
404 394
	/**
405
	 * Gets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
395
	 * Refresh all information about fields
406 396
	 * 
407
	 * @return A boolean value
397
	 * @param feature
408 398
	 */
409
	public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() {
410
		return this.panelAsATabForWFSLayersLoad;
399
	public void refresh(WFSLayerNode feature) {
400
		featureName = feature.getTitle();
401
		setFields(feature);
411 402
	}
412 403
	
413
	/** 
414
	 * FIlls list with the values of selected field
415
	 * 
416
	 * @param treePath A path in the tree
417
	 */
418
	private void fillValuesByPath(TreePath treePath) {
419
		// Duplicates are removed
420
		TreeSet conjunto = new TreeSet(new Comparator() {
421
			public int compare(Object o1, Object o2) {
422
				if ((o1 != null) && (o2 != null)) {
423
					Value v2 = (Value) o2;
424
					Value v1 = (Value) o1;
425
					BooleanValue boolVal;
426
					
427
					try {
428
						boolVal = (BooleanValue) (v1.greater(v2));
429
						
430
						if (boolVal.getValue()) {
431
							return 1;
432
						}
433
						
434
						boolVal = (BooleanValue) (v1.less(v2));
435
						
436
						if (boolVal.getValue()) {
437
							return -1;
438
						}
439
					} catch (IncompatibleTypesException e) {
440
						throw new RuntimeException(e);
441
					}
442
				}
443
				
444
				return 0;
445
			}
446
		}); // For ordernation
447
		
448
		// Remove the previous items
449
		valuesListModel.clear();
450
		
451
		try {
452
			//Object root = treePath.getPath()[0];
453
			XMLElement element = ((XMLElement)treePath.getLastPathComponent());
454
			
455
			// Gets the values associated to the selected branch 
456
			switch (element.getEntityType().getType()) {
457
				case IXMLType.SIMPLE:
458
					
459
					if(element.getParentElement().getParentElement() == null) {					
460
						// Find the selected field and try to obtein values related
461
						for (int i = 0; i < model.getFieldCount(); i++) {					
462
							String name = model.getFieldName(i);
463
							
464
							// If we find the field (this means that are loaded its values and we can obtein them)
465
							if (name.equals(element.getName())) {						
466
								for (int j = 0; j < model.getRowCount(); j++) {					
467
									Value value = model.getFieldValue(j, i);
468
									
469
									if (value instanceof NullValue)
470
									    continue;
471
									
472
									if (!conjunto.contains(value)) {
473
										conjunto.add(value);
474
									}
475
								}
476
								
477
								break;
478
							}
479
						}
480
					}else{
481
						//create a vector with the parent names from the leaf until the root
482
						XMLElement parent = element.getParentElement();
483
						Vector parentNames = new Vector();
484
						parentNames.add(element.getName());
485
						while (parent != null){
486
							parentNames.add(parent.getName());
487
							parent = parent.getParentElement();							
488
						}
489
						
490
						//The field name (in the gvSIG table) is the second field name
491
						String fieldName = (String)parentNames.get(parentNames.size()-2);
492
						
493
						for (int i = 0; i < model.getFieldCount(); i++) {					
494
							String name = model.getFieldName(i);
495
							
496
							// If we find the field (this means that are loaded its values and we can obtein them)
497
							if (name.equals(fieldName)) {						
498
								for (int j = 0; j < model.getRowCount(); j++) {					
499
									Value value = model.getFieldValue(j, i);
500
															
501
									if (value instanceof NullValue)
502
									    continue;
503
									
504
									if (value instanceof ComplexValue){
505
										for (int k=parentNames.size()-3 ; k>=0 ; k--){
506
											ComplexValue complex = (ComplexValue)value;
507
											Value childValue = (Value)complex.get(parentNames.get(k));
508
											if (k==0){
509
												if (!conjunto.contains(childValue)) {
510
													conjunto.add(childValue);
511
												}
512
											}else{
513
												value = childValue;
514
											}
515
										}
516
									}
517
								}
518
								
519
								break;
520
							}
521
						}
522
					}
523
					break;
524
				case IXMLType.COMPLEX:
525
					break;
526
				default:
527
					// Do Nothing
528
			}
529
			
530
			// Add the values to the model of the graphic list
531
			Iterator it = conjunto.iterator();
404
	///// END GUI METHODS /////
532 405

  
533
			while (it.hasNext())
534
				valuesListModel.addElement(it.next());
535
		} catch (Exception e) {
536
			throwException(e);
537
		}
538
	}
406
	///// METHODS FOR THE FILTER QUERY /////
539 407
	
540 408
	/**
541
	 * Puts the symbol of selected brach
542
	 * 
543
	 * @param mouseEvent A MouseEvent with information  of the selected branch
544
	 */
545
	public void putSymbolOfSelectedByMouseBranch(TreePath treePath) {
546
		// Sets the node selected
547
		if (treePath != null) {
548
			Object node = treePath.getLastPathComponent();
549
			if ((node != null) && (node instanceof XMLElement)) {
550
				XMLElement element = (XMLElement) node;
551
				XMLElement parent = element.getParentElement();
552
				String path = element.getName();
553
				while (parent.getParentElement() != null){
554
					path = parent.getName() + "/" + path;
555
					parent = parent.getParentElement();
556
				}
557
				putSymbol("\"" + path + "\"");
558
			}
559
		}
560
	}
561
	
562
	/**
563
	 * Gets the element that the 'currentPath' attribute aims
564
	 * 
565
	 * @return An XMLElement
566
	 */
567
	private XMLElement getNodeOfCurrentPath() {
568
		
569
		if (currentPath != null) {
570
			Object node = currentPath.getLastPathComponent();
571
			
572
			if ((node != null) && (node instanceof XMLElement)) {
573
//				XMLElement element = (XMLElement) node;
574
				return (XMLElement) node;
575
			}
576
		}
577
		
578
		return null;
579
	}
580
	
581
	/**
582 409
	 * Gets the query that will be send to the server
583 410
	 * @return SQL query (just the where part)
584 411
	 */
585 412
	public String getQuery(){
586
		try {
587
			return this.validateExpression();
588
		} catch (ParseException e) {			
589
			e.printStackTrace();
413
		String writtenQuery = txtExpression.getText().trim();
414
		
415
		// Validate expression
416
		if (!this.validateExpression(writtenQuery)) {
417
			getTxtExpression().setForeground(Color.red);
590 418
			return null;
591
		}		
419
		}
420
		else
421
			// Codify expression (only if the validation has been successful)
422
			return this.codifyExpression(writtenQuery); // Ignores the spaces at beginning and end of the chain of characters
592 423
	}
593 424
	
594 425
	/**
......
607 438
	}
608 439
	
609 440
	/**
610
	 * DOCUMENT ME!
611
	 *
612
	 * @param arg0
613
	 *
614
	 * @return
441
	 * Removes text in the JTextArea that has the filter subconsultation
615 442
	 */
616
	public boolean addExpressionListener(ExpressionListener arg0) {
617
		return expressionListeners.add(arg0);
443
	public void removeFilterExpression() {
444
		getTxtExpression().setText("");
618 445
	}
619

  
446
	
620 447
	/**
621
	 * DOCUMENT ME!
622
	 *
623
	 * @param arg0
624
	 *
625
	 * @return
448
	 * Codifies the expression to ISO ISO-8859_1 and a format that the SQL parser could validate
449
	 * 
450
	 * @param expression The expression to be codified 
451
	 * 
452
	 * @return The expression codified
626 453
	 */
627
	public boolean removeExpressionListener(ExpressionListener arg0) {
628
		return expressionListeners.remove(arg0);
454
	private String codifyExpression(String expression) {
455
		String result = new String("");
456
		
457
		try
458
		{			
459
			// Encode each string of the query
460
			int index = 0;
461
			int lastIndex = 0;
462
			boolean endInnerLoop;
463
			// Encodes all inner strings to the equivalent codification in ISO-8859_1 with each ' symbol converted to ''
464
			while (index != -1) {
465
				index = expression.indexOf("'", index);
466
				
467
				// Add the parts of the chain of characters that not are string
468
				if (index == -1) {
469
					result += expression.substring(lastIndex, expression.length());
470
				}
471
				else {
472
					result += expression.substring(lastIndex, index).replaceAll(" [ ]+", " ");
473
				}
474
				
475
				lastIndex = index;
476
				endInnerLoop = false;
477
				
478
				// Tries to find each first apostrophe of each string of the query
479
				if ((index > 0) && (expression.charAt(index - 1) == ' ')) {
480
					index++;
481
					
482
					// Ignore all inner apostrophes and try to find the last of the string
483
					while (!endInnerLoop)  {
484
						index = expression.indexOf("'", index);
485
						index++;
486
						
487
						// If we haven't arrived to the finish of the string
488
						if (index != expression.length()) {
489
							if ((index == -1) || (expression.charAt(index) == ' ')) {
490
								result += translateString(expression.substring(lastIndex, index));
491
								endInnerLoop = true;
492
							}
493
						}
494
						else {
495
							result += translateString(expression.substring(lastIndex, index));
496
							endInnerLoop = true;
497
							index = -1; // Force to finish the external loop
498
						}
499
					}
500
					lastIndex = index;
501
				}
502
			}
503
			
504
			// Field names are transformated in xix variables that will be analyzed
505
			// Date(date) is substituted by the correct date format
506
			result = translateDates(result);
507
			result = translateNumber(result);
508
			result = translateWord(result, "true", "1");
509
			result = translateWord(result, "false", "0");
510
	
511
			logger.debug(result);			
512
		}
513
		catch(Exception e) {
514
			JOptionPane.showMessageDialog(this, Messages.getText("error_coding_filter_query"), Messages.getText("error"), JOptionPane.ERROR_MESSAGE);
515
			return null;
516
		}
517

  
518
		return result;
629 519
	}
520
	
630 521
	/**
631
	 * DOCUMENT ME!
632
	 *
633
	 * @param o DOCUMENT ME!
634
	 *
635
	 * @return DOCUMENT ME!
522
	 * Checks the filter expression if it's correct
523
	 * 
524
	 * @param query The query expression to analyze
525
	 * @return True if it's valid or false if not
636 526
	 */
637
	public boolean removeExceptionListener(ExceptionListener o) {
638
		return exceptionHandlingSupport.removeExceptionListener(o);
527
	private boolean validateExpression(String query) {
528
		SQLQueryValidation sQLQueryValidation = new SQLQueryValidation(query, true);
529
		
530
		// Analyzes tokens in query
531
		StringTokenizer tokens = new StringTokenizer(query, " ");
532
		String token;
533
		Set operatorNamesAndSymbols = getOperatorNamesAndSymbols();
534

  
535
		while (tokens.hasMoreTokens()) {
536
			token = tokens.nextToken().trim();
537
			
538
			// Tries to find an invalid token
539
			if (token.length() > 0) {
540
				// Validates if a supposed field exists
541
				if ( (token.length() > 2) && (token.charAt(0) == '\"') && (token.charAt(token.length()-1) == '\"') ) {
542
					if (! this.isAField(token.substring(1, token.length()-1))) {
543
						JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_validating_sql_filter_query") + ":\n" + PluginServices.getText(null, "the_token") + ": " + token + " " + PluginServices.getText(null, "isnt_a_field_of_layer"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
544
						return false;
545
					}
546
				}
547
				else {
548
					// If it's an string -> ignore
549
					if (! ((token.charAt(0) == token.charAt(token.length() - 1)) && (token.charAt(0) == '\''))) {
550
						
551
						// If it's a date -> ignore
552
						int returnValue = validateDate(token);
553
						
554
						if (returnValue == 1) {
555
							JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_validating_sql_filter_query") + ":\n" + PluginServices.getText(null, "date_format") + " " + token.substring(5, 16) + " " + PluginServices.getText(null, "incorrect"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
556
							return false;
557
						}
558
						
559
						if (returnValue == 2) {								
560
							// Else -> Checks if the current token is a valid number or symbol
561
							if ((! StringNumberUtilities.isNumber(token)) && (! this.isAnOperatorNameOrSymbol(token, operatorNamesAndSymbols))) {
562
								JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_validating_sql_filter_query") + ":\n" + PluginServices.getText(null, "not_valid_token") + ": " + token, PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
563
								return false;
564
							}
565
							else
566
								return true;
567
						}
568
					}
569
				}
570
			}
571
		}
572

  
573
		// Tries to validate the query, and if fails shows a message
574
		if (!sQLQueryValidation.validateQuery()) {
575
			JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error_validating_sql_filter_query") + ":\n" + sQLQueryValidation.getErrorMessage(), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
576
			return false;
577
		}
578
		else	
579
			return true;
639 580
	}
640

  
581
	
641 582
	/**
642
	 * DOCUMENT ME!
643
	 *
644
	 * @param t DOCUMENT ME!
583
	 * Returns true if there is a field with the same name as 'text'
584
	 * 
585
	 * @param text An string
586
	 * @return A boolean value
645 587
	 */
646
	private void throwException(Throwable t) {
647
		exceptionHandlingSupport.throwException(t);
588
	private boolean isAField(String text) {
589
		return this.allFieldsAndValuesKnownOfCurrentLayer.containsKey(text);		
648 590
	}
649

  
591
	
650 592
	/**
651
	 * DOCUMENT ME!
652
	 *
653
	 * @param t DOCUMENT ME!
593
	 * Validates if a text has a correct date format as Date(dd-mmm-yyyy)  (Ex. Date(03-feb-2004) )
594
	 * 
595
	 * @param text
596
	 * @return 0 -> if has a date format; 1 -> if it's a date that has a but format; 2 -> if it isn't a date
654 597
	 */
655
	public void setModel(ExpressionDataSource t) {
656
		try {
657
			model = t;
658
            model.start();
659
        } catch (DriverException e1) {
660
            NotificationManager.addError(e1.getMessage(), e1);
661
        }
662

  
663
        try {
664
        	int numberOfFields = model.getFieldCount();
665

  
666
        	if (numberOfFields > 0) {
667
        		Vector fields = new Vector(0, 1);
668
        		int j = 0;
669
        	
670
				for (int i = 0; i < numberOfFields; i++) {
671
					 Object field = model.getFieldName(i);
672
					
673
					if (field != null) {
674
						fields.add(field);
675
						j++;
676
					}
598
	private int validateDate(String text) {
599
		// If it's a date -> check if format is correct (Ex.  Date(01-feb-2004) )
600
		if ( ((text.length() == 17) && (text.startsWith("Date(")) && (text.endsWith(")"))) && (text.charAt(7) == '-') && (text.charAt(11) == '-') ) {
601
			if ( (StringNumberUtilities.isNaturalNumber(text.substring(5, 7))) && (StringNumberUtilities.isNaturalNumber(text.substring(12, 16))) ) {
602
				try {
603
					// If can parse the date -> date with a correct format 
604
					DateFormat.getDateInstance().parse(text.substring(5, 16));
605
					return 0;
606
				} catch (ParseException e) {
607
					// If can't parse the date -> date with an incorrect format 
608
					return 1;
677 609
				}
678
			
679
				attributesTreeTableModel = new AttributesTreeTableModel(fields.toArray());			
680
        	}
681
		} catch (FilterException e) {
682
			throwException(e);
610
			}
611
			else {
612
				return 1;
613
			}
683 614
		}
615
		
616
		return 2;
617

  
684 618
	}
685 619

  
686 620
	/**
621
	 * Returns true if there is the 'text' is a symbol or a operator name
622
	 * 
623
	 * @param text An string
624
	 * @return A boolean value
625
	 */
626
	private boolean isAnOperatorNameOrSymbol(String text, Set operatorNamesAndSymbols) {		
627
		return operatorNamesAndSymbols.contains(text);
628
	}
629
	
630
	/**
687 631
	 * DOCUMENT ME!
688 632
	 *
689
	 * @param expresion DOCUMENT ME!
690
	 * @param substring DOCUMENT ME!
691
	 * @param startingPos DOCUMENT ME!
633
	 * @return DOCUMENT ME!
692 634
	 *
693
	 * @return DOCUMENT ME!
635
	 * @throws ParseException DOCUMENT ME!
636
	 * @deprecated In this moments its a reference of the old Validate Expression method
694 637
	 */
695
	private int getIndex(String expresion, String substring, int startingPos) {
696
		int index = startingPos;
638
	private String oldValidateExpressionMethod() throws ParseException {
639
		String expression = txtExpression.getText();
640
//		HashSet variablesIndexes = new HashSet();
641
//
642
//		StringBuffer traducida = new StringBuffer();
697 643

  
698
		do {
699
			index = expresion.indexOf(substring, index);
700
		} while ((StringUtilities.isBetweenSymbols(expresion, index, "\"")) &&
701
				(index != -1));
644
		//Se transforman los nombres de los campos en las variables xix que analizar?n
645
		//Se quitan los Date(fecha) y se mete la fecha correspondiente
646
		expression = translateDates(expression);
647
		expression = translateNumber(expression);
648
		expression = translateWord(expression, "true", "1");
649
		expression = translateWord(expression, "false", "0");
702 650

  
703
		return index;
651
		String replacement;
652
		Pattern patron = Pattern.compile("[^<>!]=");
653
		Matcher m = patron.matcher(expression);
654
		int index = 0;
655

  
656
		while (m.find(index)) {
657
			index = m.start();
658
			replacement = expression.charAt(index) + "==";
659
			m.replaceFirst(replacement);
660
			index++;
661
		}
662

  
663
		expression = expression.replaceAll("[^<>!]=", "==");
664

  
665
		logger.debug(expression);
666

  
667
		return expression;
704 668
	}
669
	
670
	///// END METHODS FOR THE FILTER QUERY /////
705 671

  
706
	/**
672
	///// METHODS FOR TRANSLATE DATA IN FILTER SENTENCES /////
673

  
674
	/** 
707 675
	 * DOCUMENT ME!
708 676
	 *
709 677
	 * @param expresion DOCUMENT ME!
......
714 682
	 *
715 683
	 * @throws ParseException DOCUMENT ME!
716 684
	 */
717
	private String translateWord(String expresion, String word,
718
		String translation) throws ParseException {
685
	private String translateWord(String expresion, String word,	String translation) throws ParseException {
719 686
		int booleanIndex = 0;
720 687
		int endIndex = 0;
721 688
		StringBuffer res = new StringBuffer();
......
745 712
	 */
746 713
	private String translateDates(String expresion) throws ParseException {
747 714
		//Se obtiene el valor de la fecha
748
		String date = StringUtilities.substringDelimited(expresion, "Date(",
749
				")", 0);
715
		String date = StringUtilities.substringDelimited(expresion, "Date(", ")", 0);
750 716

  
751 717
		if (date == null) {
752 718
			return expresion;
......
760 726
				
761 727
				//Se sustituye por el valor ordinal de la fecha
762 728
				expresion = expresion.substring(0, startIndex - 5) +
763
					expresion.substring(startIndex).replaceFirst(date + "\\)",
729
					expresion.substring(startIndex).replaceFirst(date + "\\)",							
764 730
						new Long((filterButtonsJPanel.getDateFormat().parse(date)).getTime()).toString());
765 731

  
766 732
			} else {
......
786 752
	 *
787 753
	 * @throws ParseException DOCUMENT ME!
788 754
	 */
789
	public String translateNumber(String expresion) throws ParseException {
755
	private String translateNumber(String expresion) throws ParseException {
790 756
		DefaultCharSet ss = new DefaultCharSet();
791 757
		ss.addInterval('0', '9');
792 758
		ss.addCharacter(',');
......
830 796
	 * Encodes an string to ISO 8859_1 with each ' symbol converted to '' 
831 797
	 * 
832 798
	 * @param text An string started and finished with simple apostrophes
799
	 * 
833 800
	 * @return An string started and finished with simple apostrophes
834 801
	 */
835 802
	private String translateString(String text) {
......
854 821
		return "'" + text + "'";
855 822
	}
856 823
	
824
	///// END METHODS FOR TRANSLATE DATA IN FILTER SENTENCES /////
825
	
826
	///// METHODS FOR MANIPULATE 'fields' and 'values' /////
827
	
857 828
	/**
858 829
	 * DOCUMENT ME!
859
	 * (Queda por implementar, hay una versi?n reducida)
860
	 * 
861
	 * @return An string
862
	 * @throws ParseException An expection produced by the parser
830
	 *
831
	 * @param t DOCUMENT ME!
863 832
	 */
864
	private String validateExpression() throws ParseException {
865
		String expression = txtExpression.getText().trim(); // Ignores the spaces at beginning and end of the chain of characters
866
		String result = new String("");
867
		
868
		// Encode each string of the query
869
		int index = 0;
870
		int lastIndex = 0;
871
		boolean endInnerLoop;
872
		// Encodes all inner strings to the equivalent codification in ISO-8859_1 with each ' symbol converted to ''
873
		while (index != -1) {
874
			index = expression.indexOf("'", index);
875
			
876
			// Add the parts of the chain of characters that not are string
877
			if (index == -1) {
878
				result += expression.substring(lastIndex, expression.length());
879
			}
880
			else {
881
				result += expression.substring(lastIndex, index).replaceAll(" [ ]+", " ");
882
			}
883
			
884
			lastIndex = index;
885
			endInnerLoop = false;
886
			
887
			// Tries to find each first apostrophe of each string of the query
888
			if ((index > 0) && (expression.charAt(index - 1) == ' ')) {
889
				index++;
890
				
891
				// Ignore all inner apostrophes and try to find the last of the string
892
				while (!endInnerLoop)  {
893
					index = expression.indexOf("'", index);
894
					index++;
833
	public void setModel(ExpressionDataSource t) {
834
		try {
835
			model = t;
836
            model.start();
837
        } catch (DriverException e1) {
838
            NotificationManager.addError(e1.getMessage(), e1);
839
        }
840

  
841
        try {
842
        	int numberOfFields = model.getFieldCount();
843

  
844
        	if (numberOfFields > 0) {
845
        		Vector fields = new Vector(0, 1);
846
        		int j = 0;
847
        	
848
				for (int i = 0; i < numberOfFields; i++) {
849
					 Object field = model.getFieldName(i);
895 850
					
896
					// If we haven't arrived to the finish of the string
897
					if (index != expression.length()) {
898
						if ((index == -1) || (expression.charAt(index) == ' ')) {
899
							result += translateString(expression.substring(lastIndex, index));
900
							endInnerLoop = true;
901
						}
851
					if (field != null) {
852
						fields.add(field);
853
						j++;
902 854
					}
903
					else {
904
						result += translateString(expression.substring(lastIndex, index));
905
						endInnerLoop = true;
906
						index = -1; // Force to finish the external loop
907
					}
908 855
				}
909
				lastIndex = index;
910
			}
856
			
857
				attributesTreeTableModel = new AttributesTreeTableModel(fields.toArray());			
858
        	}
859
		} catch (FilterException e) {
860
			throwException(e);
911 861
		}
912
		
913
		//Se transforman los nombres de los campos en las variables xix que analizar?n
914
		//Se quitan los Date(fecha) y se mete la fecha correspondiente
915
		result = translateDates(result);
916
		result = translateNumber(result);
917
		result = translateWord(result, "true", "1");
918
		result = translateWord(result, "false", "0");
919

  
920
		logger.debug(result);
921

  
922
		return result;
923 862
	}
924 863
	
925 864
	/**
926
	 * DOCUMENT ME!
927
	 *
928
	 * @return DOCUMENT ME!
929
	 *
930
	 * @throws ParseException DOCUMENT ME!
931
	 * @deprecated In this moments its a reference of the old Validate Expression method
865
	 * If there is a field selected, show its new values
932 866
	 */
933
	private String oldValidateExpressionMethod() throws ParseException {
934
		String expression = txtExpression.getText();
935
//		HashSet variablesIndexes = new HashSet();
936
//
937
//		StringBuffer traducida = new StringBuffer();
867
	public void updateFieldValues() {
868
		if (currentPath != null) {
869
			
870
			DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource();
871
						
872
			if ((data != null) && (data.getData() != null)) {
873
				setModel(data.getData());				
874
				fillValuesByPath(currentPath);
875
				
876
//				valuesListModel.clear();
877
				
878
				// Updates all tables that their data is about the changed view
879
				this.updateTablesThatHasNewData();				
880
				
881
				// Adjust JScrollPanes to the the beginning
882
				getFieldsJScrollPane().getHorizontalScrollBar().setValue(-1);
883
				getFieldsJScrollPane().getVerticalScrollBar().setValue(-1);
938 884

  
939
		//Se transforman los nombres de los campos en las variables xix que analizar?n
940
		//Se quitan los Date(fecha) y se mete la fecha correspondiente
941
		expression = translateDates(expression);
942
		expression = translateNumber(expression);
943
		expression = translateWord(expression, "true", "1");
944
		expression = translateWord(expression, "false", "0");
885
				// Adjust JScrollPanes to the the beginning
886
				getValuesJScrollPane().getHorizontalScrollBar().setValue(-1);
887
				getValuesJScrollPane().getVerticalScrollBar().setValue(-1);
945 888

  
946
		String replacement;
947
		Pattern patron = Pattern.compile("[^<>!]=");
948
		Matcher m = patron.matcher(expression);
949
		int index = 0;
950

  
951
		while (m.find(index)) {
952
			index = m.start();
953
			replacement = expression.charAt(index) + "==";
954
			m.replaceFirst(replacement);
955
			index++;
889
				// Adjusts valuesJList to the default position
890
				getValuesJList().setSelectedIndex(-1); // No item selected
891
			}
956 892
		}
957

  
958
		expression = expression.replaceAll("[^<>!]=", "==");
959

  
960
		logger.debug(expression);
961

  
962
		return expression;
963 893
	}
964

  
965
    /* (non-Javadoc)
966
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
967
     */
968
    public void windowActivated() {
969
    }
970

  
971
    /* (non-Javadoc)
972
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
973
     */
974
    public void windowClosed() {
975
        try {
976
            model.stop();
977
        } catch (DriverException e) {
978
            NotificationManager.addError(e.getMessage(), e);
979
        }        
980
    }
981

  
982
	public WindowInfo getWindowInfo() {
983
		return null;
984
	}
985

  
986
	public void refresh(WFSLayerNode feature) {
987
		setFields(feature);
988
		featureName = feature.getTitle();
989
	}
990 894
	
991 895
	/**
992 896
	 * Sets Fields
993 897
	 *
994
	 * @param feature
898
	 * @param feature A Layer node with fields information
995 899
	 */
996 900
	private void setFields(WFSLayerNode feature) {
997 901
		Vector fields = feature.getFields();
......
1011 915
				if (type != null) {					
1012 916
					
1013 917
					switch (type.getType()) {
1014
						case IXMLType.GML_GEOMETRY:
918
						case IXMLType.GML_GEOMETRY: // Don't add branch / field
1015 919
							break;
1016
						case IXMLType.COMPLEX: case IXMLType.SIMPLE:
920
						case IXMLType.COMPLEX: case IXMLType.SIMPLE: // Add branch / field
1017 921
							fieldBranches.add(field);
922
							
1018 923
							break;
1019 924
					}
1020 925
				}
......
1022 927
			
1023 928
			attributesTreeTableModel = new AttributesTreeTableModel(fieldBranches.get(0));
1024 929
			fieldsJTree.setModel(new AttributesTreeTableModel(fieldBranches.get(0), false));
930
			
931
			// Stores the name of all leafs (fields) of treeTableModel			
932
			Object root = attributesTreeTableModel.getRoot();
933
			
934
			if (root != null) {
935
				Vector fieldsNames = attributesTreeTableModel.getLeafsFromNodeBranch(root);
936
				
937
				for (int j = 0; j < fieldsNames.size(); j++) {
938
					Object field = fieldsNames.get(j);
939
					
940
					// Avoid errors
941
					if ( (! (field instanceof XMLElement)) || (field == null) )
942
						continue;
943
					
944
					// Don't load a geometry field					
945
					if ( ((XMLElement)field).getEntityType().getType() == IXMLType.GML_GEOMETRY )
946
						continue;					
947
					
948
					if (! allFieldsAndValuesKnownOfCurrentLayer.containsKey( ((XMLElement)field).getName()) ) {
949
						allFieldsAndValuesKnownOfCurrentLayer.put(((XMLElement)field).getName(), new HashMap());
950
					}
951
				}
952
			}
1025 953
		}
1026 954
	}
1027 955

  
1028 956
	/**
957
	 * This method load all values known of all fields known
958
	 * (It's used when a new layer is load)
959
	 */
960
	private void setValuesKnownOfFields() {
961
		// Desde el modelo se deber?a acceder a los campos y sus valores cargados		
962
		try {
963
			for (int i = 0; i < model.getFieldCount(); i++) {
964
				String fieldName = model.getFieldName(i);
965
				HashMap fieldValues = (HashMap) allFieldsAndValuesKnownOfCurrentLayer.get(fieldName);
966
				
967
				if (fieldValues != null) {
968
					for (int j = 0; j < model.getRowCount(); j++) {
969
						Value value = model.getFieldValue(j, i);					
970
						
971
						if (value instanceof NullValue)
972
						    continue;
973
						
974
						Object obj = (Object)value;
975
						
976
						if (obj == null)
977
							continue;
978
						
979
						fieldValues.put(obj.toString(), obj.toString());
980
						
981
					}
982
				}
983
			}
984
		}
985
		catch (Exception e) {
986
			e.printStackTrace();
987
		}
988
	}
989
	
990
	/**
1029 991
	 * Resets the data of fields and their values of the current layer feature, and removes the branches of JTree
1030 992
	 */
1031 993
	private void resetFieldsAndValuesData() {
......
1034 996
		((DefaultListModel)valuesJList.getModel()).removeAllElements();
1035 997
	}
1036 998
	
999
	/** 
1000
	 * FIlls list with the values of selected field
1001
	 * 
1002
	 * @param treePath A path in the tree
1003
	 */
1004
	private void fillValuesByPath(TreePath treePath) {
1005
		// Duplicates are removed
1006
		TreeSet conjunto = new TreeSet(new Comparator() {
1007
			public int compare(Object o1, Object o2) {
1008
				if ((o1 != null) && (o2 != null)) {
1009
					Value v2 = (Value) o2;
1010
					Value v1 = (Value) o1;
1011
					BooleanValue boolVal;
1012
					
1013
					try {
1014
						boolVal = (BooleanValue) (v1.greater(v2));
1015
						
1016
						if (boolVal.getValue()) {
1017
							return 1;
1018
						}
1019
						
1020
						boolVal = (BooleanValue) (v1.less(v2));
1021
						
1022
						if (boolVal.getValue()) {
1023
							return -1;
1024
						}
1025
					} catch (IncompatibleTypesException e) {
1026
						throw new RuntimeException(e);
1027
					}
1028
				}
1029
				
1030
				return 0;
1031
			}
1032
		}); // For ordernation
1033
		
1034
		// Remove the previous items
1035
		valuesListModel.clear();
1036
		
1037
		try {
1038
			//Object root = treePath.getPath()[0];
1039
			XMLElement element = ((XMLElement)treePath.getLastPathComponent());
1040
			
1041
			// Gets the values associated to the selected branch 
1042
			switch (element.getEntityType().getType()) {
1043
				case IXMLType.SIMPLE:
1044
					
1045
					if(element.getParentElement().getParentElement() == null) {					
1046
						// Find the selected field and try to obtein values related
1047
						for (int i = 0; i < model.getFieldCount(); i++) {					
1048
							String name = model.getFieldName(i);
1049
							
1050
							// If we find the field (this means that are loaded its values and we can obtein them)
1051
							if (name.equals(element.getName())) {						
1052
								for (int j = 0; j < model.getRowCount(); j++) {					
1053
									Value value = model.getFieldValue(j, i);
1054
									
1055
									if (value instanceof NullValue)
1056
									    continue;
1057
									
1058
									if (!conjunto.contains(value)) {
1059
										conjunto.add(value);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff