Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSFilterPanel.java @ 8663

History | View | Annotate | Download (21.9 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.Collection;
10
import java.util.Comparator;
11
import java.util.Iterator;
12
import java.util.Map;
13
import java.util.TreeSet;
14
import java.util.Vector;
15
import java.util.regex.Matcher;
16
import java.util.regex.Pattern;
17

    
18
import javax.swing.DefaultListModel;
19
import javax.swing.event.DocumentEvent;
20
import javax.swing.event.DocumentListener;
21
import javax.swing.tree.DefaultMutableTreeNode;
22
import javax.swing.tree.DefaultTreeModel;
23
import javax.swing.tree.TreePath;
24

    
25
import org.apache.log4j.Logger;
26
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.FilterQueryJPanel;
27
import org.gvsig.remoteClient.gml.schemas.IXMLType;
28
import org.gvsig.remoteClient.gml.schemas.XMLComplexType;
29
import org.gvsig.remoteClient.gml.schemas.XMLElement;
30

    
31
import com.hardcode.gdbms.engine.data.driver.DriverException;
32
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
33
import com.hardcode.gdbms.engine.values.BooleanValue;
34
import com.hardcode.gdbms.engine.values.ComplexValue;
35
import com.hardcode.gdbms.engine.values.NullValue;
36
import com.hardcode.gdbms.engine.values.Value;
37
import com.iver.andami.messages.NotificationManager;
38
import com.iver.andami.ui.mdiManager.IWindow;
39
import com.iver.andami.ui.mdiManager.IWindowListener;
40
import com.iver.andami.ui.mdiManager.WindowInfo;
41
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
42
import com.iver.cit.gvsig.gui.filter.ExpressionDataSource;
43
import com.iver.cit.gvsig.gui.filter.ExpressionListener;
44
import com.iver.cit.gvsig.gui.filter.FilterException;
45
import com.iver.cit.gvsig.gui.panels.attributesTree.AttributesTreeTableModel;
46
import com.iver.cit.gvsig.project.documents.table.gui.Table;
47
import com.iver.utiles.DefaultCharSet;
48
import com.iver.utiles.StringUtilities;
49
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport;
50
import com.iver.utiles.exceptionHandling.ExceptionListener;
51

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

    
93
/**
94
 * This will be the tab for add a filter to a WFS query.
95
 * This class gets the graphical interface from FilterQueryJPanel and add logic.
96
 * 
97
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
98
 */
99
public class WFSFilterPanel extends FilterQueryJPanel implements IWindow, IWindowListener {
100
        private static Logger logger = Logger.getLogger(Table.class.getName());
101
        private WFSParamsPanel parent = null;
102
        private ArrayList expressionListeners = new ArrayList();
103
        private ExpressionDataSource model = null;
104
        private NumberFormat nf = NumberFormat.getNumberInstance();
105
        private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport();
106
        private AttributesTreeTableModel attributesTreeTableModel;
107
        private boolean panelAsATabForWFSLayersLoad;
108
        
109
        /**
110
         * This method initializes
111
         *
112
         */
113
        public WFSFilterPanel(WFSParamsPanel parent) {
114
                super();
115
                this.parent = parent;
116

    
117
                // At beginning, the JList is disabled (and its set a particular color for user could knew it)
118
                super.getValuesJList().setEnabled(false);
119
                getValuesJList().setBackground(new Color(220, 220, 220));
120
        }
121
        
122
        /*
123
         *  (non-Javadoc)
124
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
125
         */
126
        protected void initialize() {
127
                super.initialize();
128
                this.resizeHeight(380);
129

    
130
                defaultTreeModel = (DefaultTreeModel)fieldsJTree.getModel();
131
                
132
                this.addNewListeners();
133
                panelAsATabForWFSLayersLoad = true;                
134
        }
135
        
136
        /**
137
         * Adds some more listener to the components of the panel
138
         */
139
        private void addNewListeners() {
140
                txtExpression.getDocument().addDocumentListener(new DocumentListener() {
141
                        /*
142
                         *  (non-Javadoc)
143
                         * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
144
                         */
145
                        public void changedUpdate(DocumentEvent e) {
146
                        }
147

    
148
                        /*
149
                         *  (non-Javadoc)
150
                         * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
151
                         */
152
                        public void insertUpdate(DocumentEvent e) {
153
                                if (!panelAsATabForWFSLayersLoad)
154
                                        parent.isApplicable(true);
155
                        }
156

    
157
                        /*
158
                         *  (non-Javadoc)
159
                         * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
160
                         */
161
                        public void removeUpdate(DocumentEvent e) {
162
                                if (!panelAsATabForWFSLayersLoad)
163
                                        parent.isApplicable(true);
164
                        }
165
                });
166
                
167
                // Listener for "fieldsJTree" 
168
                getFieldsJTree().addMouseListener(new MouseAdapter() {
169
                        /*
170
                         *  (non-Javadoc)
171
                         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
172
                         */
173
                        public void mouseClicked(MouseEvent e) {
174
                                int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
175
                                TreePath treePath = fieldsJTree.getPathForLocation(e.getX(), e.getY());
176

    
177
                                if (row > -1) {
178
                                        switch (e.getClickCount()) {
179
                                                case 1:
180
                                                        if (!panelAsATabForWFSLayersLoad) {
181
                                                                DataReturnedOfDataLoadingFromActiveView data = DataLoadingFromActiveView.getDefaultExpressionDataSource();
182
                                        
183
                                                                if ((data != null) && (data.getData() != null)) {
184
                                                                        setModel(data.getData());
185
                                                                        fillValuesByPath(treePath);                                                                        
186
                                                                }
187
                                                        }
188
                                                        break;
189
                                                case 2:                                                
190
                                                        putSymbolOfSelectedByMouseBranch(treePath);
191
                                                        break;
192
                                        }
193
                                }
194
                        }
195
                });
196
                
197
                // Listener for "valuesJList"
198
                getValuesJList().addMouseListener(new MouseAdapter() {
199
                        /*
200
                         *  (non-Javadoc)
201
                         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
202
                         */
203
                        public void mouseClicked(MouseEvent e) {
204
                                if (e.getClickCount() == 2) {
205
                                        Value valor = (Value) valuesListModel.getElementAt(getValuesJList().getSelectedIndex());
206

    
207
                                        putSymbol(valor.toString());        
208
                                }
209
                        }
210
                });                
211
        }
212
        
213
        /**
214
         * Sets the value of the inner attribute: 'panelAsATabForWFSLayersLoad'
215
         * 
216
         * @param b A boolean value
217
         */
218
        public void setWFSFilterPanelIsAsTabForWFSLayersLoad (boolean b) {
219
                this.panelAsATabForWFSLayersLoad = b;
220
                
221
                if (this.panelAsATabForWFSLayersLoad == true) {
222
                        // At beginning, the JList is disabled (and its set a particular color for user could knew it)
223
                        super.getValuesJList().setEnabled(false);
224
                        super.getValuesJList().setBackground(new Color(220, 220, 220));
225
                }
226
                else {
227
                        super.getValuesJList().setEnabled(true);
228
                        super.getValuesJList().setBackground(Color.WHITE);
229
                }
230
        }
231
        
232
        /**
233
         * Rellena la lista con los valores del campo seleccionado
234
         */
235
        private void fillValuesByPath(TreePath treePath) {
236
                // Duplicates are removed
237
                TreeSet conjunto = new TreeSet(new Comparator() {
238
                        public int compare(Object o1, Object o2) {
239
                                if ((o1 != null) && (o2 != null)) {
240
                                        Value v2 = (Value) o2;
241
                                        Value v1 = (Value) o1;
242
                                        BooleanValue boolVal;
243
                                        
244
                                        try {
245
                                                boolVal = (BooleanValue) (v1.greater(v2));
246
                                                
247
                                                if (boolVal.getValue()) {
248
                                                        return 1;
249
                                                }
250
                                                
251
                                                boolVal = (BooleanValue) (v1.less(v2));
252
                                                
253
                                                if (boolVal.getValue()) {
254
                                                        return -1;
255
                                                }
256
                                        } catch (IncompatibleTypesException e) {
257
                                                throw new RuntimeException(e);
258
                                        }
259
                                }
260
                                
261
                                return 0;
262
                        }
263
                }); // For ordernation
264
                
265
                // Remove the previous items
266
                valuesListModel.clear();
267
                
268
                try {
269
                        //Object root = treePath.getPath()[0];
270
                        XMLElement element = ((XMLElement)treePath.getLastPathComponent());
271
                        
272
                        // Gets the values associated to the selected branch 
273
                        switch (element.getEntityType().getType()) {
274
                                case IXMLType.SIMPLE:
275
                                        
276
                                        if(element.getParentElement().getParentElement() == null){
277
                                        
278
                                                // Find the selected field and try to obtein values related
279
                                                for (int i = 0; i < model.getFieldCount(); i++) {                                        
280
                                                        String name = model.getFieldName(i);
281
                                                        
282
                                                        // If we find the field (this means that are loaded its values and we can obtein them)
283
                                                        if (name.equals(element.getName())) {                                                
284
                                                                for (int j = 0; j < model.getRowCount(); j++) {                                        
285
                                                                        Value value = model.getFieldValue(j, i);
286
                                                
287
                                                                        if (value instanceof NullValue)
288
                                                                            continue;
289
                                                                        
290
                                                                        if (!conjunto.contains(value)) {
291
                                                                                conjunto.add(value);
292
                                                                        }
293
                                                                }
294
                                                                
295
                                                                break;
296
                                                        }
297
                                                }
298
                                        }else{
299
                                                //create a vector with the parent names from the leaf until the root
300
                                                XMLElement parent = element.getParentElement();
301
                                                Vector parentNames = new Vector();
302
                                                parentNames.add(element.getName());
303
                                                while (parent != null){
304
                                                        parentNames.add(parent.getName());
305
                                                        parent = parent.getParentElement();                                                        
306
                                                }
307
                                                
308
                                                //The field name (in the gvSIG table) is the second field name
309
                                                String fieldName = (String)parentNames.get(parentNames.size()-2);
310
                                                
311
                                                for (int i = 0; i < model.getFieldCount(); i++) {                                        
312
                                                        String name = model.getFieldName(i);
313
                                                        
314
                                                        // If we find the field (this means that are loaded its values and we can obtein them)
315
                                                        if (name.equals(fieldName)) {                                                
316
                                                                for (int j = 0; j < model.getRowCount(); j++) {                                        
317
                                                                        Value value = model.getFieldValue(j, i);
318
                                                                                                                        
319
                                                                        if (value instanceof NullValue)
320
                                                                            continue;
321
                                                                        
322
                                                                        if (value instanceof ComplexValue){
323
                                                                                for (int k=parentNames.size()-3 ; k>=0 ; k--){
324
                                                                                        ComplexValue complex = (ComplexValue)value;
325
                                                                                        Value childValue = (Value)complex.get(parentNames.get(k));
326
                                                                                        if (k==0){
327
                                                                                                if (!conjunto.contains(childValue)) {
328
                                                                                                        conjunto.add(childValue);
329
                                                                                                }
330
                                                                                        }else{
331
                                                                                                value = childValue;
332
                                                                                        }
333
                                                                                }
334
                                                                        }
335
                                                                }
336
                                                                
337
                                                                break;
338
                                                        }
339
                                                }
340
                                        }
341
                                        break;
342
                                case IXMLType.COMPLEX:
343
                                        break;
344
                                default:
345
                                        // Do Nothing
346
                        }
347
                        
348
                        // Add the values to the model of the graphic list
349
                        Iterator it = conjunto.iterator();
350

    
351
                        while (it.hasNext())
352
                                valuesListModel.addElement(it.next());
353
                } catch (Exception e) {
354
                        throwException(e);
355
                }
356
        }
357
        
358
        /**
359
         * Puts the symbol of selected brach
360
         * 
361
         * @param mouseEvent A MouseEvent with information  of the selected branch
362
         */
363
        public void putSymbolOfSelectedByMouseBranch(TreePath treePath) {
364
                // Sets the node selected
365
                if (treePath != null) {
366
                        Object node = treePath.getLastPathComponent();
367
                        if ((node != null) && (node instanceof XMLElement)) {
368
                                XMLElement element = (XMLElement) node;
369
                                XMLElement parent = element.getParentElement();
370
                                String path = element.getName();
371
                                while (parent.getParentElement() != null){
372
                                        path = parent.getName() + "/" + path;
373
                                        parent = parent.getParentElement();
374
                                }
375
                                putSymbol("\"" + path + "\"");
376
                        }
377
                }
378
        }
379
        
380
        /**
381
         * Gets the query that will be send to the server
382
         * @return
383
         * SQL query (just the where part)
384
         */
385
        public String getQuery(){
386
                try {
387
                        return this.validateExpression();
388
                } catch (ParseException e) {                        
389
                        e.printStackTrace();
390
                        return null;
391
                }                
392
        }
393
        
394
        /**
395
         * Writes the query in the user interface
396
         * @param query
397
         * SQL query (just the where part)
398
         */
399
        public void setQuery(String query){
400
                this.txtExpression.setText(query);
401
        }
402
        
403
        /**
404
         * DOCUMENT ME!
405
         *
406
         * @param arg0
407
         *
408
         * @return
409
         */
410
        public boolean addExpressionListener(ExpressionListener arg0) {
411
                return expressionListeners.add(arg0);
412
        }
413

    
414
        /**
415
         * DOCUMENT ME!
416
         *
417
         * @param arg0
418
         *
419
         * @return
420
         */
421
        public boolean removeExpressionListener(ExpressionListener arg0) {
422
                return expressionListeners.remove(arg0);
423
        }
424
        /**
425
         * DOCUMENT ME!
426
         *
427
         * @param o DOCUMENT ME!
428
         *
429
         * @return DOCUMENT ME!
430
         */
431
        public boolean removeExceptionListener(ExceptionListener o) {
432
                return exceptionHandlingSupport.removeExceptionListener(o);
433
        }
434

    
435
        /**
436
         * DOCUMENT ME!
437
         *
438
         * @param t DOCUMENT ME!
439
         */
440
        private void throwException(Throwable t) {
441
                exceptionHandlingSupport.throwException(t);
442
        }
443

    
444
        /**
445
         * DOCUMENT ME!
446
         *
447
         * @param t DOCUMENT ME!
448
         */
449
        public void setModel(ExpressionDataSource t) {
450
                try {
451
                        model = t;
452
            model.start();
453
        } catch (DriverException e1) {
454
            NotificationManager.addError(e1.getMessage(), e1);
455
        }
456
                
457
        try {
458
                int numberOfFields = model.getFieldCount();
459

    
460
                if (numberOfFields > 0) {
461
                        Vector fields = new Vector(0, 1);
462
                        int j = 0;
463
                
464
                                for (int i = 0; i < numberOfFields; i++) {
465
                                         Object field = model.getFieldName(i);
466
                                        
467
                                        if (field != null) {
468
                                                fields.add(field);
469
                                                j++;
470
                                        }
471
                                }
472
                        
473
                                attributesTreeTableModel = new AttributesTreeTableModel(fields.toArray());                        
474
                }
475
                } catch (FilterException e) {
476
                        throwException(e);
477
                }
478
        }
479

    
480
        /**
481
         * DOCUMENT ME!
482
         *
483
         * @param expresion DOCUMENT ME!
484
         * @param substring DOCUMENT ME!
485
         * @param startingPos DOCUMENT ME!
486
         *
487
         * @return DOCUMENT ME!
488
         */
489
        private int getIndex(String expresion, String substring, int startingPos) {
490
                int index = startingPos;
491

    
492
                do {
493
                        index = expresion.indexOf(substring, index);
494
                } while ((StringUtilities.isBetweenSymbols(expresion, index, "\"")) &&
495
                                (index != -1));
496

    
497
                return index;
498
        }
499

    
500
        /**
501
         * DOCUMENT ME!
502
         *
503
         * @param expresion DOCUMENT ME!
504
         * @param word DOCUMENT ME!
505
         * @param translation DOCUMENT ME!
506
         *
507
         * @return DOCUMENT ME!
508
         *
509
         * @throws ParseException DOCUMENT ME!
510
         */
511
        private String translateWord(String expresion, String word,
512
                String translation) throws ParseException {
513
                int booleanIndex = 0;
514
                int endIndex = 0;
515
                StringBuffer res = new StringBuffer();
516

    
517
                while ((booleanIndex = getIndex(expresion, word, booleanIndex)) != -1) {
518
                        res.append(expresion.substring(endIndex, booleanIndex));
519
                        endIndex = booleanIndex + word.length();
520
                        booleanIndex++;
521
                        res.append(translation);
522
                }
523

    
524
                if (endIndex < expresion.length()) {
525
                        res.append(expresion.substring(endIndex));
526
                }
527

    
528
                return res.toString();
529
        }
530

    
531
        /**
532
         * DOCUMENT ME!
533
         *
534
         * @param expresion DOCUMENT ME!
535
         *
536
         * @return DOCUMENT ME!
537
         *
538
         * @throws ParseException DOCUMENT ME!
539
         */
540
        private String translateDates(String expresion) throws ParseException {
541
                //Se obtiene el valor de la fecha
542
                String date = StringUtilities.substringDelimited(expresion, "Date(",
543
                                ")", 0);
544

    
545
                if (date == null) {
546
                        return expresion;
547
                }
548

    
549
                //Se comprueba que no est? entre comillas 
550
                int startIndex = expresion.indexOf(date);
551

    
552
                while (startIndex != -1) {
553
                        if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) {
554
                                
555
                                //Se sustituye por el valor ordinal de la fecha
556
                                expresion = expresion.substring(0, startIndex - 5) +
557
                                        expresion.substring(startIndex).replaceFirst(date + "\\)",
558
                                                new Long((filterButtonsJPanel.getDateFormat().parse(date)).getTime()).toString());
559
                                ;
560
                        } else {
561
                                startIndex += date.length();
562
                        }
563
                        
564
                        if (date == null) {
565
                                return expresion;
566
                        }
567

    
568
                        startIndex = expresion.indexOf(date, startIndex);
569
                }
570

    
571
                return expresion;
572
        }
573

    
574
        /**
575
         * DOCUMENT ME!
576
         *
577
         * @param expresion DOCUMENT ME!
578
         *
579
         * @return DOCUMENT ME!
580
         *
581
         * @throws ParseException DOCUMENT ME!
582
         */
583
        public String translateNumber(String expresion) throws ParseException {
584
                DefaultCharSet ss = new DefaultCharSet();
585
                ss.addInterval('0', '9');
586
                ss.addCharacter(',');
587
                ss.addCharacter('.');
588

    
589
                String number = StringUtilities.substringWithSymbols(expresion, ss, 0);
590

    
591
                if (number == null) {
592
                        return expresion;
593
                }
594

    
595
                int startIndex = expresion.indexOf(number);
596

    
597
                while (startIndex != -1) {
598
                        Number n = nf.parse(number);
599

    
600
                        if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) {
601
                                
602
                                //Se sustituye por el valor ordinal de la fecha
603
                                expresion = expresion.substring(0, startIndex) +
604
                                        expresion.substring(startIndex).replaceFirst(number,
605
                                                n.toString());
606
                        } else {
607
                                startIndex += n.toString().length();
608
                        }
609

    
610
                        number = StringUtilities.substringWithSymbols(expresion, ss,
611
                                        startIndex);
612

    
613
                        if (number == null) {
614
                                return expresion;
615
                        }
616

    
617
                        startIndex = expresion.indexOf(number, startIndex);
618
                }
619

    
620
                return expresion;
621
        }
622
        
623
        /**
624
         * DOCUMENT ME!
625
         *
626
         * @return DOCUMENT ME!
627
         *
628
         * @throws ParseException DOCUMENT ME!
629
         */
630
        private String validateExpression() throws ParseException {
631
                String expression = txtExpression.getText();
632
//                HashSet variablesIndexes = new HashSet();
633
//
634
//                StringBuffer traducida = new StringBuffer();
635

    
636
                //Se transforman los nombres de los campos en las variables xix que analizar?n
637
                //Se quitan los Date(fecha) y se mete la fecha correspondiente
638
                expression = translateDates(expression);
639
                expression = translateNumber(expression);
640
                expression = translateWord(expression, "true", "1");
641
                expression = translateWord(expression, "false", "0");
642

    
643
//                String replacement;
644
//                Pattern patron = Pattern.compile("[^<>!]=");
645
//                Matcher m = patron.matcher(expression);
646
//                int index = 0;
647
//
648
//                while (m.find(index)) {
649
//                        index = m.start();
650
//                        replacement = expression.charAt(index) + "==";
651
//                        m.replaceFirst(replacement);
652
//                        index++;
653
//                }
654
//
655
//                expression = expression.replaceAll("[^<>!]=", "==");
656

    
657
                logger.debug(expression);
658

    
659
                return expression;
660
        }
661

    
662
        /**
663
         * DOCUMENT ME!
664
         *
665
         * @return DOCUMENT ME!
666
         *
667
         * @throws ParseException DOCUMENT ME!
668
         */
669
        private String oldValidateExpressionMethod() throws ParseException {
670
                String expression = txtExpression.getText();
671
//                HashSet variablesIndexes = new HashSet();
672
//
673
//                StringBuffer traducida = new StringBuffer();
674

    
675
                //Se transforman los nombres de los campos en las variables xix que analizar?n
676
                //Se quitan los Date(fecha) y se mete la fecha correspondiente
677
                expression = translateDates(expression);
678
                expression = translateNumber(expression);
679
                expression = translateWord(expression, "true", "1");
680
                expression = translateWord(expression, "false", "0");
681

    
682
                String replacement;
683
                Pattern patron = Pattern.compile("[^<>!]=");
684
                Matcher m = patron.matcher(expression);
685
                int index = 0;
686

    
687
                while (m.find(index)) {
688
                        index = m.start();
689
                        replacement = expression.charAt(index) + "==";
690
                        m.replaceFirst(replacement);
691
                        index++;
692
                }
693

    
694
                expression = expression.replaceAll("[^<>!]=", "==");
695

    
696
                logger.debug(expression);
697

    
698
                return expression;
699
        }
700

    
701
    /* (non-Javadoc)
702
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
703
     */
704
    public void windowActivated() {
705
    }
706

    
707
    /* (non-Javadoc)
708
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
709
     */
710
    public void windowClosed() {
711
        try {
712
            model.stop();
713
        } catch (DriverException e) {
714
            NotificationManager.addError(e.getMessage(), e);
715
        }        
716
    }
717

    
718
        public WindowInfo getWindowInfo() {
719
                // TODO Auto-generated method stub
720
                return null;
721
        }
722

    
723
        public void refresh(WFSLayerNode feature) {
724
                setFields(feature);
725
        }
726
        
727
        /**
728
         * Sets Fields
729
         *
730
         * @param feature
731
         */
732
        private void setFields(WFSLayerNode feature) {
733
                Vector fields = feature.getFields();
734
//                Vector fieldsWithoutGeometry = new Vector(0, 1);
735
                                
736
                this.resetFieldsAndValuesData();
737
                
738
                int numberOfFields = fields.size();
739
                
740
                if (numberOfFields > 0) {
741
//                        int j = 0;
742
                        Vector fieldBranches = new Vector(0, 1);
743
//                        Vector fieldsClone = (Vector)fields.clone();
744
                        
745
                        for (int i=0; i<fields.size(); i++) {
746
                                XMLElement field = (XMLElement)fields.get(i);
747
                                
748
//                                XMLElement aaa = (XMLElement)new Object();
749
//                                aaa.
750
//                                                                
751
                                IXMLType type = field.getEntityType();
752
                                
753
                                if (type != null) {                                        
754
                                        
755
                                        switch (type.getType()) {
756
                                                case IXMLType.GML_GEOMETRY:
757
                                                //        fields.remove(i);
758
                                                        break;
759
                                                case IXMLType.COMPLEX: // Now it's implemented that the first level is always COMPLEX
760
//                                                        Object field_clone = new Object();
761
//                                                        field_clone = field;
762
                                                        
763
//                                                        // If the complex element has a geometry, don't load this field in the tree
764
//                                                        Object field_copy = new Object();
765
//                                                        field_copy = field;
766
//                                                        
767
//                                                        Map c_fields_map = ((XMLComplexType)((XMLElement)field_copy).getEntityType()).getSubtypes();
768
//                                                        
769
//                                                        Collection c_fields = c_fields_map.values();
770
//                                                        
771
//                                                        Iterator iterator = c_fields.iterator();
772
//                                                        XMLElement element = null;
773
//                                                        
774
//                                                        while(iterator.hasNext()) {
775
//                                                                element = (XMLElement)iterator.next();
776
//                                                                
777
//                                                                if (element.getEntityType().getType() == IXMLType.GML_GEOMETRY) {
778
//                                                                        iterator.remove();
779
//                                                                }
780
//                                                        }
781
//                                                        
782
//                                                        fieldBranches.add(field_copy);
783
//                                                        fieldsWithoutGeometry.add(field_clone);
784
                                                        fieldBranches.add(field);
785
//                                                        j++;
786
                                                        break;
787
                                                case IXMLType.SIMPLE:
788
                                                        fieldBranches.add(field);
789
//                                                        fieldsWithoutGeometry.add(field);
790
//                                                        j++;
791
                                                        break;
792
                                        }
793
                                }
794
                        }
795
                        
796
                        attributesTreeTableModel = new AttributesTreeTableModel(fieldBranches.get(0));
797
                        fieldsJTree.setModel(new AttributesTreeTableModel(fieldBranches.get(0), false));
798
                }
799
        }
800

    
801
        /**
802
         * Resets the data of fields and their values of the current layer feature, and removes the branches of JTree
803
         */
804
        private void resetFieldsAndValuesData() {
805
                fieldsJTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
806
                txtExpression.setText("");
807
                ((DefaultListModel)valuesJList.getModel()).removeAllElements();
808
        }
809
        
810
        
811
        /**
812
         * @see WFSParamsPanel#isApplicable(boolean)
813
         * 
814
         * @param b A boolean value
815
         */
816
        private void setApplicate(boolean b) {
817
                parent.isApplicable(b);
818
        }
819
}