root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSFilterPanel.java @ 8585
History | View | Annotate | Download (20.6 KB)
1 |
package com.iver.cit.gvsig.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.event.MouseAdapter; |
5 |
import java.awt.event.MouseEvent; |
6 |
import java.text.NumberFormat; |
7 |
import java.text.ParseException; |
8 |
import java.util.ArrayList; |
9 |
import java.util.Comparator; |
10 |
import java.util.Iterator; |
11 |
import java.util.TreeSet; |
12 |
import java.util.Vector; |
13 |
import java.util.regex.Matcher; |
14 |
import java.util.regex.Pattern; |
15 |
|
16 |
import javax.swing.DefaultListModel; |
17 |
import javax.swing.event.DocumentEvent; |
18 |
import javax.swing.event.DocumentListener; |
19 |
import javax.swing.tree.DefaultMutableTreeNode; |
20 |
import javax.swing.tree.DefaultTreeModel; |
21 |
import javax.swing.tree.TreePath; |
22 |
|
23 |
import org.apache.log4j.Logger; |
24 |
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.FilterQueryJPanel; |
25 |
import org.gvsig.remoteClient.gml.schemas.IXMLType; |
26 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
27 |
|
28 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
29 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
30 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
31 |
import com.hardcode.gdbms.engine.values.ComplexValue; |
32 |
import com.hardcode.gdbms.engine.values.NullValue; |
33 |
import com.hardcode.gdbms.engine.values.Value; |
34 |
import com.iver.andami.messages.NotificationManager; |
35 |
import com.iver.andami.ui.mdiManager.IWindow; |
36 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
37 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
38 |
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode; |
39 |
import com.iver.cit.gvsig.gui.filter.ExpressionDataSource; |
40 |
import com.iver.cit.gvsig.gui.filter.ExpressionListener; |
41 |
import com.iver.cit.gvsig.gui.filter.FilterException; |
42 |
import com.iver.cit.gvsig.gui.panels.attributesTree.AttributesTreeTableModel; |
43 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
44 |
import com.iver.utiles.DefaultCharSet; |
45 |
import com.iver.utiles.StringUtilities; |
46 |
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport; |
47 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
48 |
|
49 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
50 |
*
|
51 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
52 |
*
|
53 |
* This program is free software; you can redistribute it and/or
|
54 |
* modify it under the terms of the GNU General Public License
|
55 |
* as published by the Free Software Foundation; either version 2
|
56 |
* of the License, or (at your option) any later version.
|
57 |
*
|
58 |
* This program is distributed in the hope that it will be useful,
|
59 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
60 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
61 |
* GNU General Public License for more details.
|
62 |
*
|
63 |
* You should have received a copy of the GNU General Public License
|
64 |
* along with this program; if not, write to the Free Software
|
65 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
66 |
*
|
67 |
* For more information, contact:
|
68 |
*
|
69 |
* Generalitat Valenciana
|
70 |
* Conselleria d'Infraestructures i Transport
|
71 |
* Av. Blasco Ib??ez, 50
|
72 |
* 46010 VALENCIA
|
73 |
* SPAIN
|
74 |
*
|
75 |
* +34 963862235
|
76 |
* gvsig@gva.es
|
77 |
* www.gvsig.gva.es
|
78 |
*
|
79 |
* or
|
80 |
*
|
81 |
* IVER T.I. S.A
|
82 |
* Salamanca 50
|
83 |
* 46005 Valencia
|
84 |
* Spain
|
85 |
*
|
86 |
* +34 963163400
|
87 |
* dac@iver.es
|
88 |
*/
|
89 |
|
90 |
/**
|
91 |
* This will be the tab for add a filter to a WFS query.
|
92 |
* This class gets the graphical interface from FilterQueryJPanel and add logic.
|
93 |
*
|
94 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
95 |
*/
|
96 |
public class WFSFilterPanel extends FilterQueryJPanel implements IWindow, IWindowListener { |
97 |
private static Logger logger = Logger.getLogger(Table.class.getName()); |
98 |
private WFSParamsPanel parent = null; |
99 |
private ArrayList expressionListeners = new ArrayList(); |
100 |
private ExpressionDataSource model = null; |
101 |
private NumberFormat nf = NumberFormat.getNumberInstance(); |
102 |
private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport(); |
103 |
private AttributesTreeTableModel attributesTreeTableModel;
|
104 |
private boolean panelAsATabForWFSLayersLoad; |
105 |
|
106 |
/**
|
107 |
* This method initializes
|
108 |
*
|
109 |
*/
|
110 |
public WFSFilterPanel(WFSParamsPanel parent) {
|
111 |
super();
|
112 |
this.parent = parent;
|
113 |
|
114 |
// At beginning, the JList is disabled (and its set a particular color for user could knew it)
|
115 |
super.getValuesJList().setEnabled(false); |
116 |
getValuesJList().setBackground(new Color(220, 220, 220)); |
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
|
122 |
*/
|
123 |
protected void initialize() { |
124 |
super.initialize();
|
125 |
this.resizeHeight(380); |
126 |
|
127 |
defaultTreeModel = (DefaultTreeModel)fieldsJTree.getModel();
|
128 |
|
129 |
this.addNewListeners();
|
130 |
panelAsATabForWFSLayersLoad = true;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Adds some more listener to the components of the panel
|
135 |
*/
|
136 |
private void addNewListeners() { |
137 |
txtExpression.getDocument().addDocumentListener(new DocumentListener() { |
138 |
/*
|
139 |
* (non-Javadoc)
|
140 |
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
141 |
*/
|
142 |
public void changedUpdate(DocumentEvent e) { |
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
148 |
*/
|
149 |
public void insertUpdate(DocumentEvent e) { |
150 |
if (!panelAsATabForWFSLayersLoad)
|
151 |
parent.isApplicable(true);
|
152 |
} |
153 |
|
154 |
/*
|
155 |
* (non-Javadoc)
|
156 |
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
157 |
*/
|
158 |
public void removeUpdate(DocumentEvent e) { |
159 |
if (!panelAsATabForWFSLayersLoad)
|
160 |
parent.isApplicable(true);
|
161 |
} |
162 |
}); |
163 |
|
164 |
// Listener for "fieldsJTree"
|
165 |
getFieldsJTree().addMouseListener(new MouseAdapter() { |
166 |
/*
|
167 |
* (non-Javadoc)
|
168 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
169 |
*/
|
170 |
public void mouseClicked(MouseEvent e) { |
171 |
int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
|
172 |
TreePath treePath = fieldsJTree.getPathForLocation(e.getX(), e.getY());
|
173 |
|
174 |
if (row > -1) { |
175 |
switch (e.getClickCount()) {
|
176 |
case 1: |
177 |
if (!panelAsATabForWFSLayersLoad) {
|
178 |
DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource(); |
179 |
|
180 |
if ((data != null) && (data.getData() != null)) { |
181 |
setModel(data.getData()); |
182 |
fillValuesByPath(treePath); |
183 |
} |
184 |
} |
185 |
break;
|
186 |
case 2: |
187 |
putSymbolOfSelectedByMouseBranch(treePath); |
188 |
break;
|
189 |
} |
190 |
} |
191 |
} |
192 |
}); |
193 |
|
194 |
// Listener for "valuesJList"
|
195 |
getValuesJList().addMouseListener(new MouseAdapter() { |
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
199 |
*/
|
200 |
public void mouseClicked(MouseEvent e) { |
201 |
if (e.getClickCount() == 2) { |
202 |
Value valor = (Value) valuesListModel.getElementAt(getValuesJList().getSelectedIndex()); |
203 |
|
204 |
putSymbol(valor.toString()); |
205 |
} |
206 |
} |
207 |
}); |
208 |
} |
209 |
|
210 |
/**
|
211 |
* Sets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
|
212 |
*
|
213 |
* @param b A boolean value
|
214 |
*/
|
215 |
public void setWFSFilterPanelIsAsTabForWFSLayersLoad (boolean b) { |
216 |
this.panelAsATabForWFSLayersLoad = b;
|
217 |
|
218 |
if (this.panelAsATabForWFSLayersLoad == true) { |
219 |
// At beginning, the JList is disabled (and its set a particular color for user could knew it)
|
220 |
super.getValuesJList().setEnabled(false); |
221 |
super.getValuesJList().setBackground(new Color(220, 220, 220)); |
222 |
} |
223 |
else {
|
224 |
super.getValuesJList().setEnabled(true); |
225 |
super.getValuesJList().setBackground(Color.WHITE); |
226 |
} |
227 |
} |
228 |
|
229 |
/**
|
230 |
* Rellena la lista con los valores del campo seleccionado
|
231 |
*/
|
232 |
private void fillValuesByPath(TreePath treePath) { |
233 |
// Duplicates are removed
|
234 |
TreeSet conjunto = new TreeSet(new Comparator() { |
235 |
public int compare(Object o1, Object o2) { |
236 |
if ((o1 != null) && (o2 != null)) { |
237 |
Value v2 = (Value) o2; |
238 |
Value v1 = (Value) o1; |
239 |
BooleanValue boolVal; |
240 |
|
241 |
try {
|
242 |
boolVal = (BooleanValue) (v1.greater(v2)); |
243 |
|
244 |
if (boolVal.getValue()) {
|
245 |
return 1; |
246 |
} |
247 |
|
248 |
boolVal = (BooleanValue) (v1.less(v2)); |
249 |
|
250 |
if (boolVal.getValue()) {
|
251 |
return -1; |
252 |
} |
253 |
} catch (IncompatibleTypesException e) {
|
254 |
throw new RuntimeException(e); |
255 |
} |
256 |
} |
257 |
|
258 |
return 0; |
259 |
} |
260 |
}); // For ordernation
|
261 |
|
262 |
// Remove the previous items
|
263 |
valuesListModel.clear(); |
264 |
|
265 |
try {
|
266 |
//Object root = treePath.getPath()[0];
|
267 |
XMLElement element = ((XMLElement)treePath.getLastPathComponent()); |
268 |
|
269 |
// Gets the values associated to the selected branch
|
270 |
switch (element.getEntityType().getType()) {
|
271 |
case IXMLType.SIMPLE:
|
272 |
|
273 |
if(element.getParentElement().getParentElement() == null){ |
274 |
|
275 |
// Find the selected field and try to obtein values related
|
276 |
for (int i = 0; i < model.getFieldCount(); i++) { |
277 |
String name = model.getFieldName(i);
|
278 |
|
279 |
// If we find the field (this means that are loaded its values and we can obtein them)
|
280 |
if (name.equals(element.getName())) {
|
281 |
for (int j = 0; j < model.getRowCount(); j++) { |
282 |
Value value = model.getFieldValue(j, i); |
283 |
|
284 |
if (value instanceof NullValue) |
285 |
continue;
|
286 |
|
287 |
if (!conjunto.contains(value)) {
|
288 |
conjunto.add(value); |
289 |
} |
290 |
} |
291 |
|
292 |
break;
|
293 |
} |
294 |
} |
295 |
}else{
|
296 |
//create a vector with the parent names from the leaf until the root
|
297 |
XMLElement parent = element.getParentElement(); |
298 |
Vector parentNames = new Vector(); |
299 |
parentNames.add(element.getName()); |
300 |
while (parent != null){ |
301 |
parentNames.add(parent.getName()); |
302 |
parent = parent.getParentElement(); |
303 |
} |
304 |
|
305 |
//The field name (in the gvSIG table) is the second field name
|
306 |
String fieldName = (String)parentNames.get(parentNames.size()-2); |
307 |
|
308 |
for (int i = 0; i < model.getFieldCount(); i++) { |
309 |
String name = model.getFieldName(i);
|
310 |
|
311 |
// If we find the field (this means that are loaded its values and we can obtein them)
|
312 |
if (name.equals(fieldName)) {
|
313 |
for (int j = 0; j < model.getRowCount(); j++) { |
314 |
Value value = model.getFieldValue(j, i); |
315 |
|
316 |
if (value instanceof NullValue) |
317 |
continue;
|
318 |
|
319 |
if (value instanceof ComplexValue){ |
320 |
for (int k=parentNames.size()-3 ; k>=0 ; k--){ |
321 |
ComplexValue complex = (ComplexValue)value; |
322 |
Value childValue = (Value)complex.get(parentNames.get(k)); |
323 |
if (k==0){ |
324 |
if (!conjunto.contains(childValue)) {
|
325 |
conjunto.add(childValue); |
326 |
} |
327 |
}else{
|
328 |
value = childValue; |
329 |
} |
330 |
} |
331 |
} |
332 |
} |
333 |
|
334 |
break;
|
335 |
} |
336 |
} |
337 |
} |
338 |
break;
|
339 |
case IXMLType.COMPLEX:
|
340 |
break;
|
341 |
default:
|
342 |
// Do Nothing
|
343 |
} |
344 |
|
345 |
// Add the values to the model of the graphic list
|
346 |
Iterator it = conjunto.iterator();
|
347 |
|
348 |
while (it.hasNext())
|
349 |
valuesListModel.addElement(it.next()); |
350 |
} catch (Exception e) { |
351 |
throwException(e); |
352 |
} |
353 |
} |
354 |
|
355 |
/**
|
356 |
* Puts the symbol of selected brach
|
357 |
*
|
358 |
* @param mouseEvent A MouseEvent with information of the selected branch
|
359 |
*/
|
360 |
public void putSymbolOfSelectedByMouseBranch(TreePath treePath) { |
361 |
// Sets the node selected
|
362 |
if (treePath != null) { |
363 |
Object node = treePath.getLastPathComponent();
|
364 |
if ((node != null) && (node instanceof XMLElement)) { |
365 |
XMLElement element = (XMLElement) node; |
366 |
XMLElement parent = element.getParentElement(); |
367 |
String path = element.getName();
|
368 |
while (parent.getParentElement() != null){ |
369 |
path = parent.getName() + "/" + path;
|
370 |
parent = parent.getParentElement(); |
371 |
} |
372 |
putSymbol("\"" + path + "\""); |
373 |
} |
374 |
} |
375 |
} |
376 |
|
377 |
/**
|
378 |
* Gets the query that will be send to the server
|
379 |
* @return
|
380 |
* SQL query (just the where part)
|
381 |
*/
|
382 |
public String getQuery(){ |
383 |
try {
|
384 |
return this.validateExpression(); |
385 |
} catch (ParseException e) { |
386 |
e.printStackTrace(); |
387 |
return null; |
388 |
} |
389 |
} |
390 |
|
391 |
/**
|
392 |
* Writes the query in the user interface
|
393 |
* @param query
|
394 |
* SQL query (just the where part)
|
395 |
*/
|
396 |
public void setQuery(String query){ |
397 |
this.txtExpression.setText(query);
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* DOCUMENT ME!
|
402 |
*
|
403 |
* @param arg0
|
404 |
*
|
405 |
* @return
|
406 |
*/
|
407 |
public boolean addExpressionListener(ExpressionListener arg0) { |
408 |
return expressionListeners.add(arg0);
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* DOCUMENT ME!
|
413 |
*
|
414 |
* @param arg0
|
415 |
*
|
416 |
* @return
|
417 |
*/
|
418 |
public boolean removeExpressionListener(ExpressionListener arg0) { |
419 |
return expressionListeners.remove(arg0);
|
420 |
} |
421 |
/**
|
422 |
* DOCUMENT ME!
|
423 |
*
|
424 |
* @param o DOCUMENT ME!
|
425 |
*
|
426 |
* @return DOCUMENT ME!
|
427 |
*/
|
428 |
public boolean removeExceptionListener(ExceptionListener o) { |
429 |
return exceptionHandlingSupport.removeExceptionListener(o);
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* DOCUMENT ME!
|
434 |
*
|
435 |
* @param t DOCUMENT ME!
|
436 |
*/
|
437 |
private void throwException(Throwable t) { |
438 |
exceptionHandlingSupport.throwException(t); |
439 |
} |
440 |
|
441 |
/**
|
442 |
* DOCUMENT ME!
|
443 |
*
|
444 |
* @param t DOCUMENT ME!
|
445 |
*/
|
446 |
public void setModel(ExpressionDataSource t) { |
447 |
try {
|
448 |
model = t; |
449 |
model.start(); |
450 |
} catch (DriverException e1) {
|
451 |
NotificationManager.addError(e1.getMessage(), e1); |
452 |
} |
453 |
|
454 |
try {
|
455 |
int numberOfFields = model.getFieldCount();
|
456 |
|
457 |
if (numberOfFields > 0) { |
458 |
Vector fields = new Vector(0, 1); |
459 |
int j = 0; |
460 |
|
461 |
for (int i = 0; i < numberOfFields; i++) { |
462 |
Object field = model.getFieldName(i);
|
463 |
|
464 |
if (field != null) { |
465 |
fields.add(field); |
466 |
j++; |
467 |
} |
468 |
} |
469 |
|
470 |
attributesTreeTableModel = new AttributesTreeTableModel(fields.toArray());
|
471 |
} |
472 |
} catch (FilterException e) {
|
473 |
throwException(e); |
474 |
} |
475 |
} |
476 |
|
477 |
/**
|
478 |
* DOCUMENT ME!
|
479 |
*
|
480 |
* @param expresion DOCUMENT ME!
|
481 |
* @param substring DOCUMENT ME!
|
482 |
* @param startingPos DOCUMENT ME!
|
483 |
*
|
484 |
* @return DOCUMENT ME!
|
485 |
*/
|
486 |
private int getIndex(String expresion, String substring, int startingPos) { |
487 |
int index = startingPos;
|
488 |
|
489 |
do {
|
490 |
index = expresion.indexOf(substring, index); |
491 |
} while ((StringUtilities.isBetweenSymbols(expresion, index, "\"")) && |
492 |
(index != -1));
|
493 |
|
494 |
return index;
|
495 |
} |
496 |
|
497 |
/**
|
498 |
* DOCUMENT ME!
|
499 |
*
|
500 |
* @param expresion DOCUMENT ME!
|
501 |
* @param word DOCUMENT ME!
|
502 |
* @param translation DOCUMENT ME!
|
503 |
*
|
504 |
* @return DOCUMENT ME!
|
505 |
*
|
506 |
* @throws ParseException DOCUMENT ME!
|
507 |
*/
|
508 |
private String translateWord(String expresion, String word, |
509 |
String translation) throws ParseException { |
510 |
int booleanIndex = 0; |
511 |
int endIndex = 0; |
512 |
StringBuffer res = new StringBuffer(); |
513 |
|
514 |
while ((booleanIndex = getIndex(expresion, word, booleanIndex)) != -1) { |
515 |
res.append(expresion.substring(endIndex, booleanIndex)); |
516 |
endIndex = booleanIndex + word.length(); |
517 |
booleanIndex++; |
518 |
res.append(translation); |
519 |
} |
520 |
|
521 |
if (endIndex < expresion.length()) {
|
522 |
res.append(expresion.substring(endIndex)); |
523 |
} |
524 |
|
525 |
return res.toString();
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* DOCUMENT ME!
|
530 |
*
|
531 |
* @param expresion DOCUMENT ME!
|
532 |
*
|
533 |
* @return DOCUMENT ME!
|
534 |
*
|
535 |
* @throws ParseException DOCUMENT ME!
|
536 |
*/
|
537 |
private String translateDates(String expresion) throws ParseException { |
538 |
//Se obtiene el valor de la fecha
|
539 |
String date = StringUtilities.substringDelimited(expresion, "Date(", |
540 |
")", 0); |
541 |
|
542 |
if (date == null) { |
543 |
return expresion;
|
544 |
} |
545 |
|
546 |
//Se comprueba que no est? entre comillas
|
547 |
int startIndex = expresion.indexOf(date);
|
548 |
|
549 |
while (startIndex != -1) { |
550 |
if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) { |
551 |
|
552 |
//Se sustituye por el valor ordinal de la fecha
|
553 |
expresion = expresion.substring(0, startIndex - 5) + |
554 |
expresion.substring(startIndex).replaceFirst(date + "\\)",
|
555 |
new Long((filterButtonsJPanel.getDateFormat().parse(date)).getTime()).toString()); |
556 |
; |
557 |
} else {
|
558 |
startIndex += date.length(); |
559 |
} |
560 |
|
561 |
if (date == null) { |
562 |
return expresion;
|
563 |
} |
564 |
|
565 |
startIndex = expresion.indexOf(date, startIndex); |
566 |
} |
567 |
|
568 |
return expresion;
|
569 |
} |
570 |
|
571 |
/**
|
572 |
* DOCUMENT ME!
|
573 |
*
|
574 |
* @param expresion DOCUMENT ME!
|
575 |
*
|
576 |
* @return DOCUMENT ME!
|
577 |
*
|
578 |
* @throws ParseException DOCUMENT ME!
|
579 |
*/
|
580 |
public String translateNumber(String expresion) throws ParseException { |
581 |
DefaultCharSet ss = new DefaultCharSet();
|
582 |
ss.addInterval('0', '9'); |
583 |
ss.addCharacter(',');
|
584 |
ss.addCharacter('.');
|
585 |
|
586 |
String number = StringUtilities.substringWithSymbols(expresion, ss, 0); |
587 |
|
588 |
if (number == null) { |
589 |
return expresion;
|
590 |
} |
591 |
|
592 |
int startIndex = expresion.indexOf(number);
|
593 |
|
594 |
while (startIndex != -1) { |
595 |
Number n = nf.parse(number);
|
596 |
|
597 |
if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) { |
598 |
|
599 |
//Se sustituye por el valor ordinal de la fecha
|
600 |
expresion = expresion.substring(0, startIndex) +
|
601 |
expresion.substring(startIndex).replaceFirst(number, |
602 |
n.toString()); |
603 |
} else {
|
604 |
startIndex += n.toString().length(); |
605 |
} |
606 |
|
607 |
number = StringUtilities.substringWithSymbols(expresion, ss, |
608 |
startIndex); |
609 |
|
610 |
if (number == null) { |
611 |
return expresion;
|
612 |
} |
613 |
|
614 |
startIndex = expresion.indexOf(number, startIndex); |
615 |
} |
616 |
|
617 |
return expresion;
|
618 |
} |
619 |
|
620 |
/**
|
621 |
* DOCUMENT ME!
|
622 |
*
|
623 |
* @return DOCUMENT ME!
|
624 |
*
|
625 |
* @throws ParseException DOCUMENT ME!
|
626 |
*/
|
627 |
private String validateExpression() throws ParseException { |
628 |
String expression = txtExpression.getText();
|
629 |
// HashSet variablesIndexes = new HashSet();
|
630 |
//
|
631 |
// StringBuffer traducida = new StringBuffer();
|
632 |
|
633 |
//Se transforman los nombres de los campos en las variables xix que analizar?n
|
634 |
//Se quitan los Date(fecha) y se mete la fecha correspondiente
|
635 |
expression = translateDates(expression); |
636 |
expression = translateNumber(expression); |
637 |
expression = translateWord(expression, "true", "1"); |
638 |
expression = translateWord(expression, "false", "0"); |
639 |
|
640 |
// String replacement;
|
641 |
// Pattern patron = Pattern.compile("[^<>!]=");
|
642 |
// Matcher m = patron.matcher(expression);
|
643 |
// int index = 0;
|
644 |
//
|
645 |
// while (m.find(index)) {
|
646 |
// index = m.start();
|
647 |
// replacement = expression.charAt(index) + "==";
|
648 |
// m.replaceFirst(replacement);
|
649 |
// index++;
|
650 |
// }
|
651 |
//
|
652 |
// expression = expression.replaceAll("[^<>!]=", "==");
|
653 |
|
654 |
logger.debug(expression); |
655 |
|
656 |
return expression;
|
657 |
} |
658 |
|
659 |
/**
|
660 |
* DOCUMENT ME!
|
661 |
*
|
662 |
* @return DOCUMENT ME!
|
663 |
*
|
664 |
* @throws ParseException DOCUMENT ME!
|
665 |
*/
|
666 |
private String oldValidateExpressionMethod() throws ParseException { |
667 |
String expression = txtExpression.getText();
|
668 |
// HashSet variablesIndexes = new HashSet();
|
669 |
//
|
670 |
// StringBuffer traducida = new StringBuffer();
|
671 |
|
672 |
//Se transforman los nombres de los campos en las variables xix que analizar?n
|
673 |
//Se quitan los Date(fecha) y se mete la fecha correspondiente
|
674 |
expression = translateDates(expression); |
675 |
expression = translateNumber(expression); |
676 |
expression = translateWord(expression, "true", "1"); |
677 |
expression = translateWord(expression, "false", "0"); |
678 |
|
679 |
String replacement;
|
680 |
Pattern patron = Pattern.compile("[^<>!]="); |
681 |
Matcher m = patron.matcher(expression);
|
682 |
int index = 0; |
683 |
|
684 |
while (m.find(index)) {
|
685 |
index = m.start(); |
686 |
replacement = expression.charAt(index) + "==";
|
687 |
m.replaceFirst(replacement); |
688 |
index++; |
689 |
} |
690 |
|
691 |
expression = expression.replaceAll("[^<>!]=", "=="); |
692 |
|
693 |
logger.debug(expression); |
694 |
|
695 |
return expression;
|
696 |
} |
697 |
|
698 |
/* (non-Javadoc)
|
699 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
700 |
*/
|
701 |
public void windowActivated() { |
702 |
} |
703 |
|
704 |
/* (non-Javadoc)
|
705 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
706 |
*/
|
707 |
public void windowClosed() { |
708 |
try {
|
709 |
model.stop(); |
710 |
} catch (DriverException e) {
|
711 |
NotificationManager.addError(e.getMessage(), e); |
712 |
} |
713 |
} |
714 |
|
715 |
public WindowInfo getWindowInfo() {
|
716 |
// TODO Auto-generated method stub
|
717 |
return null; |
718 |
} |
719 |
|
720 |
public void refresh(WFSLayerNode feature) { |
721 |
setFields(feature); |
722 |
} |
723 |
|
724 |
/**
|
725 |
* Sets Fields
|
726 |
*
|
727 |
* @param feature
|
728 |
*/
|
729 |
private void setFields(WFSLayerNode feature) { |
730 |
Vector fields = feature.getFields();
|
731 |
|
732 |
this.resetFieldsAndValuesData();
|
733 |
|
734 |
int numberOfFields = fields.size();
|
735 |
|
736 |
if (numberOfFields > 0) { |
737 |
int j = 0; |
738 |
Vector fieldBranches = new Vector(0, 1); |
739 |
|
740 |
for (int i=0 ; i<fields.size() ;i++) { |
741 |
XMLElement field = (XMLElement)fields.get(i); |
742 |
|
743 |
IXMLType type = field.getEntityType(); |
744 |
|
745 |
if (type != null) { |
746 |
switch (type.getType()) {
|
747 |
case IXMLType.GML_GEOMETRY:
|
748 |
break;
|
749 |
case IXMLType.COMPLEX:
|
750 |
fieldBranches.add(field); |
751 |
j++; |
752 |
break;
|
753 |
case IXMLType.SIMPLE:
|
754 |
fieldBranches.add(field); |
755 |
j++; |
756 |
break;
|
757 |
} |
758 |
} |
759 |
} |
760 |
|
761 |
attributesTreeTableModel = new AttributesTreeTableModel(fieldBranches.get(0)); |
762 |
fieldsJTree.setModel(attributesTreeTableModel); |
763 |
} |
764 |
} |
765 |
|
766 |
/**
|
767 |
* Resets the data of fields and their values of the current layer feature, and removes the branches of JTree
|
768 |
*/
|
769 |
private void resetFieldsAndValuesData() { |
770 |
fieldsJTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); |
771 |
txtExpression.setText("");
|
772 |
((DefaultListModel)valuesJList.getModel()).removeAllElements();
|
773 |
} |
774 |
|
775 |
|
776 |
/**
|
777 |
* @see WFSParamsPanel#isApplicable(boolean)
|
778 |
*
|
779 |
* @param b A boolean value
|
780 |
*/
|
781 |
private void setApplicate(boolean b) { |
782 |
parent.isApplicable(b); |
783 |
} |
784 |
} |