Revision 36719

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/gui/filter/FilterDialog.java
56 56
import javax.swing.tree.DefaultMutableTreeNode;
57 57
import javax.swing.tree.DefaultTreeModel;
58 58

  
59
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61

  
59 62
import org.gvsig.andami.PluginServices;
60 63
import org.gvsig.andami.messages.NotificationManager;
61 64
import org.gvsig.andami.ui.mdiManager.IWindow;
62 65
import org.gvsig.andami.ui.mdiManager.IWindowListener;
63 66
import org.gvsig.andami.ui.mdiManager.WindowInfo;
64 67
import org.gvsig.fmap.dal.exception.DataException;
65
import org.gvsig.tools.dispose.DisposableIterator;
66 68
import org.gvsig.fmap.dal.feature.Feature;
67 69
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
68 70
import org.gvsig.fmap.dal.feature.FeatureQuery;
69 71
import org.gvsig.fmap.dal.feature.FeatureSet;
70 72
import org.gvsig.fmap.dal.feature.FeatureStore;
71 73
import org.gvsig.gui.beans.filterPanel.tableFilterQueryPanel.TableFilterQueryJPanel;
74
import org.gvsig.tools.dispose.DisposableIterator;
72 75
import org.gvsig.tools.dispose.DisposeUtils;
73 76
import org.gvsig.utils.DefaultCharSet;
74 77
import org.gvsig.utils.StringUtilities;
75 78
import org.gvsig.utils.exceptionHandling.ExceptionHandlingSupport;
76 79
import org.gvsig.utils.exceptionHandling.ExceptionListener;
77
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
79 80

  
80

  
81 81
/**
82
 * This class substitutes the old "FilterDialog" class made by "Fernando Gonz?lez Cort?s"
83
 * The functionality is the same, but now the class is made from separately (and reusable) components
84
 *
82
 * This class substitutes the old "FilterDialog" class made by
83
 * "Fernando Gonz?lez Cort?s"
84
 * The functionality is the same, but now the class is made from separately (and
85
 * reusable) components
86
 * 
85 87
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
86 88
 */
87
public class FilterDialog extends TableFilterQueryJPanel implements IWindow, IWindowListener {
88
    private static final Logger logger = LoggerFactory
89
            .getLogger(FilterDialog.class);
90
	private FeatureStore model = null;
91
	private ArrayList expressionListeners = new ArrayList();
92
	private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport();
93
	private NumberFormat nf = NumberFormat.getNumberInstance();
89
public class FilterDialog extends TableFilterQueryJPanel implements IWindow,
90
    IWindowListener {
94 91

  
95
	private String title;
92
    /**
93
     * 
94
     */
95
    private static final long serialVersionUID = -149317534873551735L;
96
    private static final Logger logger =
97
        LoggerFactory.getLogger(FilterDialog.class);
98
    private FeatureStore model = null;
99
    private ArrayList expressionListeners = new ArrayList();
100
    private ExceptionHandlingSupport exceptionHandlingSupport =
101
        new ExceptionHandlingSupport();
102
    private NumberFormat nf = NumberFormat.getNumberInstance();
96 103

  
97
	private final int filterDialog_Width = 500;
98
	private final int filterDialog_Height = 362;
99
	private final int widthIncrementForAndami = 20; // This is necessary because when the panel is sent to Andami, that needs a bit more width-space to show that panel.
104
    private String title;
100 105

  
106
    private final int filterDialog_Width = 500;
107
    private final int filterDialog_Height = 362;
108
    private final int widthIncrementForAndami = 20; // This is necessary because
109
                                                    // when the panel is sent to
110
                                                    // Andami, that needs a bit
111
                                                    // more width-space to show
112
                                                    // that panel.
101 113

  
102
	/**
103
	 * This is the default constructor
104
	 */
105
	public FilterDialog(String _title) {
106
		super();
107
		title = _title;
108
		defaultTreeModel = (DefaultTreeModel)fieldsJTree.getModel();
109
	}
110
	/**
111
	 * This is the default constructor
112
	 */
113
	public FilterDialog() {
114
		super();
115
		defaultTreeModel = (DefaultTreeModel)fieldsJTree.getModel();
116
	}
114
    /**
115
     * This is the default constructor
116
     */
117
    public FilterDialog(String _title) {
118
        super();
119
        title = _title;
120
        defaultTreeModel = (DefaultTreeModel) fieldsJTree.getModel();
121
    }
117 122

  
118
	/*
119
	 *  (non-Javadoc)
120
	 * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
121
	 */
122
	protected void initialize() {
123
		super.initialize();
123
    /**
124
     * This is the default constructor
125
     */
126
    public FilterDialog() {
127
        super();
128
        defaultTreeModel = (DefaultTreeModel) fieldsJTree.getModel();
129
    }
124 130

  
125
		super.resizeHeight(filterDialog_Height);
126
		super.resizeWidth(filterDialog_Width - widthIncrementForAndami);
131
    /*
132
     * (non-Javadoc)
133
     * 
134
     * @see
135
     * org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
136
     */
137
    @Override
138
    protected void initialize() {
139
        super.initialize();
127 140

  
128
		this.addNewListeners();
129
	}
141
        super.resizeHeight(filterDialog_Height);
142
        super.resizeWidth(filterDialog_Width - widthIncrementForAndami);
130 143

  
131
	/**
132
	 * Adds some listeners
133
	 */
134
	private void addNewListeners() {
135
		// Listener for "btnAdd"
136
		// Adds more elements to the current set
137
		getBtnAddToCurrentSet().addActionListener(new java.awt.event.ActionListener() {
138
			/*
139
			 *  (non-Javadoc)
140
			 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
141
			 */
142
			public void actionPerformed(java.awt.event.ActionEvent e) {
143
//				final String expr = "select * from '" +
144
//					model.getName() + "' where " +
145
//					getTxtExpression().getText() + ";";
146
				final String expr = getTxtExpression().getText();
147
				logger.debug(expr);
144
        this.addNewListeners();
145
    }
148 146

  
149
				PluginServices.backgroundExecution(new Runnable() {
150
						public void run() {
151
							for (int i = 0;
152
									i < expressionListeners.size();
153
									i++) {
154
								ExpressionListener l = (ExpressionListener) expressionListeners.get(i);
155
								try {
156
										l.addToSet(expr);
157
									} catch (DataException e) {
158
										e.printStackTrace();
159
									}
160
							}
161
						}
162
					});
163
			}
164
		});
147
    /**
148
     * Adds some listeners
149
     */
150
    private void addNewListeners() {
151
        // Listener for "btnAdd"
152
        // Adds more elements to the current set
153
        getBtnAddToCurrentSet().addActionListener(
154
            new java.awt.event.ActionListener() {
165 155

  
166
		// Listener for "btnNuevo"
167
		// Adds a new set
168
		getBtnNewSet().addActionListener(new java.awt.event.ActionListener() {
169
			public void actionPerformed(java.awt.event.ActionEvent e) {
170
//				final String expr = "select * from '" +
171
//					model.getName() + "' where " +
172
//					getTxtExpression().getText() + ";";
173
				final String expr = getTxtExpression().getText();
156
                /*
157
                 * (non-Javadoc)
158
                 * 
159
                 * @see
160
                 * java.awt.event.ActionListener#actionPerformed(java.awt.event
161
                 * .ActionEvent)
162
                 */
163
                public void actionPerformed(java.awt.event.ActionEvent e) {
164
                    // final String expr = "select * from '" +
165
                    // model.getName() + "' where " +
166
                    // getTxtExpression().getText() + ";";
167
                    final String expr = getTxtExpression().getText();
168
                    logger.debug(expr);
174 169

  
175
				logger.debug(expr);
170
                    PluginServices.backgroundExecution(new Runnable() {
176 171

  
177
				PluginServices.backgroundExecution(new Runnable() {
178
					public void run() {
179
						for (int i = 0; i < expressionListeners.size(); i++) {
180
							ExpressionListener l = (ExpressionListener) expressionListeners.get(i);
181
							try {
182
								l.newSet(expr);
183
							} catch (DataException e) {
184
								// TODO Auto-generated catch block
185
								NotificationManager.addError(e);
186
							}
187
						}
188
					}
189
				});
190
			}
191
		});
172
                        public void run() {
173
                            for (int i = 0; i < expressionListeners.size(); i++) {
174
                                ExpressionListener l =
175
                                    (ExpressionListener) expressionListeners
176
                                        .get(i);
177
                                try {
178
                                    l.addToSet(expr);
179
                                } catch (DataException e) {
180
                                    e.printStackTrace();
181
                                }
182
                            }
183
                        }
184
                    });
185
                }
186
            });
192 187

  
193
		// Listener for "btnFromSet"
194
		// Selects elements from the current filtered selection
195
		getBtnFromSet().addActionListener(new java.awt.event.ActionListener() {
196
			public void actionPerformed(java.awt.event.ActionEvent e) {
197
//				final String expr = "select * from '" +
198
//					model.getName() + "' where " +
199
//					getTxtExpression().getText() + ";";
200
				final String expr = getTxtExpression().getText();
201
				logger.debug(expr);
188
        // Listener for "btnNuevo"
189
        // Adds a new set
190
        getBtnNewSet().addActionListener(new java.awt.event.ActionListener() {
202 191

  
203
				PluginServices.backgroundExecution(new Runnable() {
204
					public void run() {
205
						for (int i = 0; i < expressionListeners.size(); i++) {
206
							ExpressionListener l = (ExpressionListener) expressionListeners.get(i);
207
							try {
208
								l.fromSet(expr);
209
							} catch (DataException e) {
210
								NotificationManager.addError(e);
211
							}
212
						}
213
					}
214
				});
215
			}
216
		});
192
            public void actionPerformed(java.awt.event.ActionEvent e) {
193
                // final String expr = "select * from '" +
194
                // model.getName() + "' where " +
195
                // getTxtExpression().getText() + ";";
196
                final String expr = getTxtExpression().getText();
217 197

  
218
		// Listener for "fieldsJTree"
219
		getFieldsJTree().addMouseListener(new MouseAdapter() {
220
			/*
221
			 *  (non-Javadoc)
222
			 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
223
			 */
224
			public void mouseClicked(MouseEvent e) {
225
				int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
198
                logger.debug(expr);
226 199

  
227
				if (row > -1) {
228
					switch (e.getClickCount()) {
229
						case 1:
230
							fillValues(row);
231
							break;
232
						case 2:
233
							putSymbol(jtreeRoot.getChildAt(row).toString());
234
							break;
235
					}
236
				}
237
			}
238
		});
200
                PluginServices.backgroundExecution(new Runnable() {
239 201

  
240
		// Listener for "valuesJList"
241
		getValuesJList().addMouseListener(new MouseAdapter() {
242
			/*
243
			 *  (non-Javadoc)
244
			 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
245
			 */
246
			public void mouseClicked(MouseEvent e) {
247
				if (e.getClickCount() == 2) {
248
					Object valor = valuesListModel.getElementAt(getValuesJList().getSelectedIndex());
202
                    public void run() {
203
                        for (int i = 0; i < expressionListeners.size(); i++) {
204
                            ExpressionListener l =
205
                                (ExpressionListener) expressionListeners.get(i);
206
                            try {
207
                                l.newSet(expr);
208
                            } catch (DataException e) {
209
                                // TODO Auto-generated catch block
210
                                NotificationManager.addError(e);
211
                            }
212
                        }
213
                    }
214
                });
215
            }
216
        });
249 217

  
250
					if (valor instanceof Date) {
251
						putSymbol("date('" + valor + "')");
252
					} else if (valor instanceof Boolean) {
253
						putSymbol("boolean('" + valor.toString() + "')");
254
					} else if (valor instanceof String) {
255
						putSymbol("'" + valor + "'");
256
					} else {
257
						putSymbol(valor.toString());
258
					}
259
				}
260
			}
261
		});
262
	}
218
        // Listener for "btnFromSet"
219
        // Selects elements from the current filtered selection
220
        getBtnFromSet().addActionListener(new java.awt.event.ActionListener() {
263 221

  
264
	/**
265
	 * Rellena la lista con los valores del campo seleccionado
266
	 */
267
	private void fillValues(int row) {
268
		//int index = lstCampos.getSelectedIndex();
222
            public void actionPerformed(java.awt.event.ActionEvent e) {
223
                // final String expr = "select * from '" +
224
                // model.getName() + "' where " +
225
                // getTxtExpression().getText() + ";";
226
                final String expr = getTxtExpression().getText();
227
                logger.debug(expr);
269 228

  
270
		//Index es ahora el ?ndice del campo seleccionado
271
		//Se eliminan los duplicados
272
		Collection conjunto = new TreeSet(new Comparator() {
273
			public int compare(Object o1, Object o2) {
274
				return ((Comparable)o1).compareTo(o2);
275
			}
276
		}); // Para poder ordenar
229
                PluginServices.backgroundExecution(new Runnable() {
277 230

  
231
                    public void run() {
232
                        for (int i = 0; i < expressionListeners.size(); i++) {
233
                            ExpressionListener l =
234
                                (ExpressionListener) expressionListeners.get(i);
235
                            try {
236
                                l.fromSet(expr);
237
                            } catch (DataException e) {
238
                                NotificationManager.addError(e);
239
                            }
240
                        }
241
                    }
242
                });
243
            }
244
        });
278 245

  
279
		valuesListModel.clear();
280
		FeatureSet fs = null;
281
		DisposableIterator iterator = null;
282
		try {
283
			String[] fieldName = new String[] {
284
				((FeatureAttributeDescriptor)model.getDefaultFeatureType().get(row)).getName()
285
				};
246
        // Listener for "fieldsJTree"
247
        getFieldsJTree().addMouseListener(new MouseAdapter() {
286 248

  
249
            /*
250
             * (non-Javadoc)
251
             * 
252
             * @see
253
             * java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent
254
             * )
255
             */
256
            @Override
257
            public void mouseClicked(MouseEvent e) {
258
                int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
287 259

  
288
			FeatureQuery query = model.createFeatureQuery();
289
			query.setAttributeNames(fieldName);
290
			fs = model.getFeatureSet(query);
291
			iterator = fs.iterator();
292
			while (iterator.hasNext()) {
293
				Feature feature = (Feature) iterator.next();
294
				Object value = feature.get(fieldName[0]);
295
				if (value == null) {
296
					continue;
297
				}
260
                if (row > -1) {
261
                    switch (e.getClickCount()) {
262
                    case 1:
263
                        fillValues(row);
264
                        break;
265
                    case 2:
266
                        putSymbol(jtreeRoot.getChildAt(row).toString());
267
                        break;
268
                    }
269
                }
270
            }
271
        });
298 272

  
299
				conjunto.add(value);
300
			}
273
        // Listener for "valuesJList"
274
        getValuesJList().addMouseListener(new MouseAdapter() {
301 275

  
302
			Iterator it = conjunto.iterator();
276
            /*
277
             * (non-Javadoc)
278
             * 
279
             * @see
280
             * java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent
281
             * )
282
             */
283
            @Override
284
            public void mouseClicked(MouseEvent e) {
285
                if (e.getClickCount() == 2) {
286
                    Object valor =
287
                        valuesListModel.getElementAt(getValuesJList()
288
                            .getSelectedIndex());
303 289

  
304
			while (it.hasNext()) {
305
				valuesListModel.addElement(it.next());
306
			}
307
		} catch (DataException e) {
308
			throwException(e);
309
		} finally {
310
			DisposeUtils.dispose(iterator);
311
			DisposeUtils.dispose(fs);
312
		}
313
	}
290
                    if (valor instanceof Date) {
291
                        putSymbol("date('" + valor + "')");
292
                    } else
293
                        if (valor instanceof Boolean) {
294
                            putSymbol("boolean('" + valor.toString() + "')");
295
                        } else
296
                            if (valor instanceof String) {
297
                                putSymbol("'" + valor + "'");
298
                            } else {
299
                                putSymbol(valor.toString());
300
                            }
301
                }
302
            }
303
        });
304
    }
314 305

  
315
	/**
316
	 * DOCUMENT ME!
317
	 *
318
	 * @param t DOCUMENT ME!
319
	 */
320
	public void setModel(FeatureStore t) {
321
//		try {
322
			model = t;
323
//            model.start();
324
//        } catch (ReadException e1) {
325
//            NotificationManager.addError(e1.getMessage(), e1);
326
//        }
306
    /**
307
     * Rellena la lista con los valores del campo seleccionado
308
     */
309
    private void fillValues(int row) {
310
        // int index = lstCampos.getSelectedIndex();
327 311

  
312
        // Index es ahora el ?ndice del campo seleccionado
313
        // Se eliminan los duplicados
314
        Collection conjunto = new TreeSet(new Comparator() {
315

  
316
            public int compare(Object o1, Object o2) {
317
                return ((Comparable) o1).compareTo(o2);
318
            }
319
        }); // Para poder ordenar
320

  
321
        valuesListModel.clear();
322
        FeatureSet fs = null;
323
        DisposableIterator iterator = null;
324
        try {
325
            String[] fieldName =
326
                new String[] { ((FeatureAttributeDescriptor) model
327
                    .getDefaultFeatureType().get(row)).getName() };
328

  
329
            FeatureQuery query = model.createFeatureQuery();
330
            query.setAttributeNames(fieldName);
331
            fs = model.getFeatureSet(query);
332
            iterator = fs.iterator();
333
            while (iterator.hasNext()) {
334
                Feature feature = (Feature) iterator.next();
335
                Object value = feature.get(fieldName[0]);
336
                if (value == null) {
337
                    continue;
338
                }
339

  
340
                conjunto.add(value);
341
            }
342

  
343
            Iterator it = conjunto.iterator();
344

  
345
            while (it.hasNext()) {
346
                valuesListModel.addElement(it.next());
347
            }
348
        } catch (DataException e) {
349
            throwException(e);
350
        } finally {
351
            DisposeUtils.dispose(iterator);
352
            DisposeUtils.dispose(fs);
353
        }
354
    }
355

  
356
    /**
357
     * DOCUMENT ME!
358
     * 
359
     * @param t
360
     *            DOCUMENT ME!
361
     */
362
    public void setModel(FeatureStore t) {
363
        // try {
364
        model = t;
365
        // model.start();
366
        // } catch (ReadException e1) {
367
        // NotificationManager.addError(e1.getMessage(), e1);
368
        // }
369

  
328 370
        jtreeRoot.removeAllChildren();
329 371

  
330 372
        try {
331
        	Iterator attributes=model.getDefaultFeatureType().iterator();
332
        	while (attributes.hasNext()) {
333
				FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) attributes.next();
334
				Object field = descriptor.getName();
373
            Iterator attributes = model.getDefaultFeatureType().iterator();
374
            while (attributes.hasNext()) {
375
                FeatureAttributeDescriptor descriptor =
376
                    (FeatureAttributeDescriptor) attributes.next();
377
                Object field = descriptor.getName();
335 378

  
336
				if (field != null) {
337
					jtreeRoot.add(new DefaultMutableTreeNode(field.toString()));
338
				}
339
			}
340
//        	for (int i = 0; i < model.getFieldCount(); i++) {
341
//				Object field = model.getFieldName(i);
342
//
343
//				if (field != null) {
344
//					jtreeRoot.add(new DefaultMutableTreeNode(field.toString()));
345
//				}
346
//			}
379
                if (field != null) {
380
                    jtreeRoot.add(new DefaultMutableTreeNode(field.toString()));
381
                }
382
            }
383
            // for (int i = 0; i < model.getFieldCount(); i++) {
384
            // Object field = model.getFieldName(i);
385
            //
386
            // if (field != null) {
387
            // jtreeRoot.add(new DefaultMutableTreeNode(field.toString()));
388
            // }
389
            // }
347 390

  
348
			defaultTreeModel.setRoot(jtreeRoot);
349
		} catch (DataException e) {
350
			throwException(e);
351
		}
352
	}
391
            defaultTreeModel.setRoot(jtreeRoot);
392
        } catch (DataException e) {
393
            throwException(e);
394
        }
395
    }
353 396

  
354
		/**
355
		 * DOCUMENT ME!
356
		 *
357
		 * @return DOCUMENT ME!
358
		 *
359
		 * @throws ParseException DOCUMENT ME!
360
		 */
361
		private String validateExpression() throws ParseException {
362
			String expression = txtExpression.getText();
363
	//		HashSet variablesIndexes = new HashSet();
364
	//
365
	//		StringBuffer traducida = new StringBuffer();
397
    /**
398
     * DOCUMENT ME!
399
     * 
400
     * @return DOCUMENT ME!
401
     * 
402
     * @throws ParseException
403
     *             DOCUMENT ME!
404
     */
405
    private String validateExpression() throws ParseException {
406
        String expression = txtExpression.getText();
407
        // HashSet variablesIndexes = new HashSet();
408
        //
409
        // StringBuffer traducida = new StringBuffer();
366 410

  
367
			//Se transforman los nombres de los campos en las variables xix que analizar?n
368
			//Se quitan los Date(fecha) y se mete la fecha correspondiente
369
			expression = translateDates(expression);
370
			expression = translateNumber(expression);
371
			expression = translateWord(expression, "true", "1");
372
			expression = translateWord(expression, "false", "0");
411
        // Se transforman los nombres de los campos en las variables xix que
412
        // analizar?n
413
        // Se quitan los Date(fecha) y se mete la fecha correspondiente
414
        expression = translateDates(expression);
415
        expression = translateNumber(expression);
416
        expression = translateWord(expression, "true", "1");
417
        expression = translateWord(expression, "false", "0");
373 418

  
374
			String replacement;
375
			Pattern patron = Pattern.compile("[^<>!]=");
376
			Matcher m = patron.matcher(expression);
377
			int index = 0;
419
        String replacement;
420
        Pattern patron = Pattern.compile("[^<>!]=");
421
        Matcher m = patron.matcher(expression);
422
        int index = 0;
378 423

  
379
			while (m.find(index)) {
380
				index = m.start();
381
				replacement = expression.charAt(index) + "==";
382
				m.replaceFirst(replacement);
383
				index++;
384
			}
424
        while (m.find(index)) {
425
            index = m.start();
426
            replacement = expression.charAt(index) + "==";
427
            m.replaceFirst(replacement);
428
            index++;
429
        }
385 430

  
386
			expression = expression.replaceAll("[^<>!]=", "==");
431
        expression = expression.replaceAll("[^<>!]=", "==");
387 432

  
388
			logger.debug(expression);
433
        logger.debug(expression);
389 434

  
390
			return expression;
391
		}
392
	/**
393
	 * Redefinition of the 'putSymbol' method of AbstractFilterQueryJPanel
394
	 *   (I've made this redefinition for write the same code as the 'putSymbol'
395
	 *    code of the original class (FilterDialog) that was in this project
396
	 *    (appgvSIG) and didn't has path troubles to find 'StringUtilities').
397
	 *
398
	 * Sets a symbol on the filter expression (JTextArea that stores and shows
399
	 *   the current filter expression)
400
	 *
401
	 * @param symbol A symbol: character, characters, number, ...
402
	 */
403
	protected void putSymbol(String symbol) {
404
		int position = txtExpression.getCaretPosition();
405
		txtExpression.setText(StringUtilities.insert(txtExpression.getText(),
406
				position, symbol));
435
        return expression;
436
    }
407 437

  
408
		if (symbol.equals(" () ")) {
409
			position = position + 2;
410
		} else {
411
			position = position + symbol.length();
412
		}
438
    /**
439
     * Redefinition of the 'putSymbol' method of AbstractFilterQueryJPanel
440
     * (I've made this redefinition for write the same code as the 'putSymbol'
441
     * code of the original class (FilterDialog) that was in this project
442
     * (appgvSIG) and didn't has path troubles to find 'StringUtilities').
443
     * 
444
     * Sets a symbol on the filter expression (JTextArea that stores and shows
445
     * the current filter expression)
446
     * 
447
     * @param symbol
448
     *            A symbol: character, characters, number, ...
449
     */
450
    @Override
451
    protected void putSymbol(String symbol) {
452
        int position = txtExpression.getCaretPosition();
453
        txtExpression.setText(StringUtilities.insert(txtExpression.getText(),
454
            position, symbol));
413 455

  
414
		txtExpression.setCaretPosition(position);
415
	}
456
        if (symbol.equals(" () ")) {
457
            position = position + 2;
458
        } else {
459
            position = position + symbol.length();
460
        }
416 461

  
417
	/**
418
	 * DOCUMENT ME!
419
	 *
420
	 * @param expresion DOCUMENT ME!
421
	 * @param substring DOCUMENT ME!
422
	 * @param startingPos DOCUMENT ME!
423
	 *
424
	 * @return DOCUMENT ME!
425
	 */
426
	private int getIndex(String expresion, String substring, int startingPos) {
427
		int index = startingPos;
462
        txtExpression.setCaretPosition(position);
463
    }
428 464

  
429
		do {
430
			index = expresion.indexOf(substring, index);
431
		} while ((StringUtilities.isBetweenSymbols(expresion, index, "\"")) &&
432
				(index != -1));
465
    /**
466
     * DOCUMENT ME!
467
     * 
468
     * @param expresion
469
     *            DOCUMENT ME!
470
     * @param substring
471
     *            DOCUMENT ME!
472
     * @param startingPos
473
     *            DOCUMENT ME!
474
     * 
475
     * @return DOCUMENT ME!
476
     */
477
    private int getIndex(String expresion, String substring, int startingPos) {
478
        int index = startingPos;
433 479

  
434
		return index;
435
	}
480
        do {
481
            index = expresion.indexOf(substring, index);
482
        } while ((StringUtilities.isBetweenSymbols(expresion, index, "\""))
483
            && (index != -1));
436 484

  
437
	/**
438
	 * DOCUMENT ME!
439
	 *
440
	 * @param expresion DOCUMENT ME!
441
	 * @param word DOCUMENT ME!
442
	 * @param translation DOCUMENT ME!
443
	 *
444
	 * @return DOCUMENT ME!
445
	 *
446
	 * @throws ParseException DOCUMENT ME!
447
	 */
448
	private String translateWord(String expresion, String word,
449
		String translation) throws ParseException {
450
		int booleanIndex = 0;
451
		int endIndex = 0;
452
		StringBuffer res = new StringBuffer();
485
        return index;
486
    }
453 487

  
454
		while ((booleanIndex = getIndex(expresion, word, booleanIndex)) != -1) {
455
			res.append(expresion.substring(endIndex, booleanIndex));
456
			endIndex = booleanIndex + word.length();
457
			booleanIndex++;
458
			res.append(translation);
459
		}
488
    /**
489
     * DOCUMENT ME!
490
     * 
491
     * @param expresion
492
     *            DOCUMENT ME!
493
     * @param word
494
     *            DOCUMENT ME!
495
     * @param translation
496
     *            DOCUMENT ME!
497
     * 
498
     * @return DOCUMENT ME!
499
     * 
500
     * @throws ParseException
501
     *             DOCUMENT ME!
502
     */
503
    private String translateWord(String expresion, String word,
504
        String translation) throws ParseException {
505
        int booleanIndex = 0;
506
        int endIndex = 0;
507
        StringBuffer res = new StringBuffer();
460 508

  
461
		if (endIndex < expresion.length()) {
462
			res.append(expresion.substring(endIndex));
463
		}
509
        while ((booleanIndex = getIndex(expresion, word, booleanIndex)) != -1) {
510
            res.append(expresion.substring(endIndex, booleanIndex));
511
            endIndex = booleanIndex + word.length();
512
            booleanIndex++;
513
            res.append(translation);
514
        }
464 515

  
465
		return res.toString();
466
	}
516
        if (endIndex < expresion.length()) {
517
            res.append(expresion.substring(endIndex));
518
        }
467 519

  
468
	/**
469
	 * DOCUMENT ME!
470
	 *
471
	 * @param expresion DOCUMENT ME!
472
	 *
473
	 * @return DOCUMENT ME!
474
	 *
475
	 * @throws ParseException DOCUMENT ME!
476
	 */
477
	private String translateDates(String expresion) throws ParseException {
478
		//Se obtiene el valor de la fecha
479
		String date = StringUtilities.substringDelimited(expresion, "Date(",
480
				")", 0);
520
        return res.toString();
521
    }
481 522

  
482
		if (date == null) {
483
			return expresion;
484
		}
523
    /**
524
     * DOCUMENT ME!
525
     * 
526
     * @param expresion
527
     *            DOCUMENT ME!
528
     * 
529
     * @return DOCUMENT ME!
530
     * 
531
     * @throws ParseException
532
     *             DOCUMENT ME!
533
     */
534
    private String translateDates(String expresion) throws ParseException {
535
        // Se obtiene el valor de la fecha
536
        String date =
537
            StringUtilities.substringDelimited(expresion, "Date(", ")", 0);
485 538

  
486
		//Se comprueba que no est? entre comillas
487
		int startIndex = expresion.indexOf(date);
539
        if (date == null) {
540
            return expresion;
541
        }
488 542

  
489
		while (startIndex != -1) {
490
			if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) {
491
				//Se sustituye por el valor ordinal de la fecha
492
				expresion = expresion.substring(0, startIndex - 5) +
493
					expresion.substring(startIndex).replaceFirst(date + "\\)",
494
						new Long((filterButtonsJPanel.getDateFormat().parse(date)).getTime()).toString());
495
				;
496
			} else {
497
				startIndex += date.length();
498
			}
543
        // Se comprueba que no est? entre comillas
544
        int startIndex = expresion.indexOf(date);
499 545

  
500
			//Se obtiene el valor de la fecha
546
        while (startIndex != -1) {
547
            if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) {
548
                // Se sustituye por el valor ordinal de la fecha
549
                expresion =
550
                    expresion.substring(0, startIndex - 5)
551
                        + expresion.substring(startIndex).replaceFirst(
552
                            date + "\\)",
553
                            new Long((filterButtonsJPanel.getDateFormat()
554
                                .parse(date)).getTime()).toString());
555
                ;
556
            } else {
557
                startIndex += date.length();
558
            }
501 559

  
502
			/*            date = StringUtilities.substringDelimited(expresion, "Date(", ")",
503
			   startIndex);
504
			 */
505
			if (date == null) {
506
				return expresion;
507
			}
560
            // Se obtiene el valor de la fecha
508 561

  
509
			startIndex = expresion.indexOf(date, startIndex);
510
		}
562
            /*
563
             * date = StringUtilities.substringDelimited(expresion, "Date(",
564
             * ")",
565
             * startIndex);
566
             */
567
            if (date == null) {
568
                return expresion;
569
            }
511 570

  
512
		return expresion;
513
	}
571
            startIndex = expresion.indexOf(date, startIndex);
572
        }
514 573

  
515
	/**
516
	 * DOCUMENT ME!
517
	 *
518
	 * @param expresion DOCUMENT ME!
519
	 *
520
	 * @return DOCUMENT ME!
521
	 *
522
	 * @throws ParseException DOCUMENT ME!
523
	 */
524
	public String translateNumber(String expresion) throws ParseException {
525
		DefaultCharSet ss = new DefaultCharSet();
526
		ss.addInterval('0', '9');
527
		ss.addCharacter(',');
528
		ss.addCharacter('.');
574
        return expresion;
575
    }
529 576

  
530
		String number = StringUtilities.substringWithSymbols(expresion, ss, 0);
577
    /**
578
     * DOCUMENT ME!
579
     * 
580
     * @param expresion
581
     *            DOCUMENT ME!
582
     * 
583
     * @return DOCUMENT ME!
584
     * 
585
     * @throws ParseException
586
     *             DOCUMENT ME!
587
     */
588
    public String translateNumber(String expresion) throws ParseException {
589
        DefaultCharSet ss = new DefaultCharSet();
590
        ss.addInterval('0', '9');
591
        ss.addCharacter(',');
592
        ss.addCharacter('.');
531 593

  
532
		if (number == null) {
533
			return expresion;
534
		}
594
        String number = StringUtilities.substringWithSymbols(expresion, ss, 0);
535 595

  
536
		int startIndex = expresion.indexOf(number);
596
        if (number == null) {
597
            return expresion;
598
        }
537 599

  
538
		while (startIndex != -1) {
539
			Number n = nf.parse(number);
600
        int startIndex = expresion.indexOf(number);
540 601

  
541
			if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) {
542
				//Se sustituye por el valor ordinal de la fecha
543
				expresion = expresion.substring(0, startIndex) +
544
					expresion.substring(startIndex).replaceFirst(number,
545
						n.toString());
546
			} else {
547
				startIndex += n.toString().length();
548
			}
602
        while (startIndex != -1) {
603
            Number n = nf.parse(number);
549 604

  
550
			number = StringUtilities.substringWithSymbols(expresion, ss,
551
					startIndex);
605
            if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) {
606
                // Se sustituye por el valor ordinal de la fecha
607
                expresion =
608
                    expresion.substring(0, startIndex)
609
                        + expresion.substring(startIndex).replaceFirst(number,
610
                            n.toString());
611
            } else {
612
                startIndex += n.toString().length();
613
            }
552 614

  
553
			if (number == null) {
554
				return expresion;
555
			}
615
            number =
616
                StringUtilities.substringWithSymbols(expresion, ss, startIndex);
556 617

  
557
			startIndex = expresion.indexOf(number, startIndex);
558
		}
618
            if (number == null) {
619
                return expresion;
620
            }
559 621

  
560
		return expresion;
561
	}
622
            startIndex = expresion.indexOf(number, startIndex);
623
        }
562 624

  
563
	/**
564
	 * DOCUMENT ME!
565
	 *
566
	 * @param arg0
567
	 *
568
	 * @return
569
	 */
570
	public boolean addExpressionListener(ExpressionListener arg0) {
571
		return expressionListeners.add(arg0);
572
	}
625
        return expresion;
626
    }
573 627

  
574
	/**
575
	 * DOCUMENT ME!
576
	 *
577
	 * @param arg0
578
	 *
579
	 * @return
580
	 */
581
	public boolean removeExpressionListener(ExpressionListener arg0) {
582
		return expressionListeners.remove(arg0);
583
	}
628
    /**
629
     * DOCUMENT ME!
630
     * 
631
     * @param arg0
632
     * 
633
     * @return
634
     */
635
    public boolean addExpressionListener(ExpressionListener arg0) {
636
        return expressionListeners.add(arg0);
637
    }
584 638

  
585
	/**
586
	 * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
587
	 */
588
	public WindowInfo getWindowInfo() {
589
		WindowInfo vi = new WindowInfo(WindowInfo.ICONIFIABLE);
639
    /**
640
     * DOCUMENT ME!
641
     * 
642
     * @param arg0
643
     * 
644
     * @return
645
     */
646
    public boolean removeExpressionListener(ExpressionListener arg0) {
647
        return expressionListeners.remove(arg0);
648
    }
590 649

  
591
		//if (System.getProperty("os.name")co.compareTo(arg0))
592
		vi.setHeight(this.filterDialog_Height);
593
		vi.setWidth(this.filterDialog_Width);
650
    /**
651
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
652
     */
653
    public WindowInfo getWindowInfo() {
654
        WindowInfo vi = new WindowInfo(WindowInfo.ICONIFIABLE);
594 655

  
595
		// Old instructions
596
//		vi.setWidth(480);
597
//		vi.setHeight(362);
598
		vi.setTitle(PluginServices.getText( this, "filtro") + " (" + title + ")");
599
		return vi;
600
	}
656
        // if (System.getProperty("os.name")co.compareTo(arg0))
657
        vi.setHeight(this.filterDialog_Height);
658
        vi.setWidth(this.filterDialog_Width);
601 659

  
602
	/**
603
	 * DOCUMENT ME!
604
	 *
605
	 * @param o DOCUMENT ME!
606
	 */
607
	public void addExceptionListener(ExceptionListener o) {
608
		exceptionHandlingSupport.addExceptionListener(o);
609
	}
660
        // Old instructions
661
        // vi.setWidth(480);
662
        // vi.setHeight(362);
663
        vi
664
            .setTitle(PluginServices.getText(this, "filtro") + " (" + title
665
                + ")");
666
        return vi;
667
    }
610 668

  
611
	/**
612
	 * DOCUMENT ME!
613
	 *
614
	 * @param o DOCUMENT ME!
615
	 *
616
	 * @return DOCUMENT ME!
617
	 */
618
	public boolean removeExceptionListener(ExceptionListener o) {
619
		return exceptionHandlingSupport.removeExceptionListener(o);
620
	}
669
    /**
670
     * DOCUMENT ME!
671
     * 
672
     * @param o
673
     *            DOCUMENT ME!
674
     */
675
    public void addExceptionListener(ExceptionListener o) {
676
        exceptionHandlingSupport.addExceptionListener(o);
677
    }
621 678

  
622
	/**
623
	 * DOCUMENT ME!
624
	 *
625
	 * @param t DOCUMENT ME!
626
	 */
627
	private void throwException(Throwable t) {
628
		exceptionHandlingSupport.throwException(t);
629
	}
679
    /**
680
     * DOCUMENT ME!
681
     * 
682
     * @param o
683
     *            DOCUMENT ME!
684
     * 
685
     * @return DOCUMENT ME!
686
     */
687
    public boolean removeExceptionListener(ExceptionListener o) {
688
        return exceptionHandlingSupport.removeExceptionListener(o);
689
    }
630 690

  
631
    /* (non-Javadoc)
691
    /**
692
     * DOCUMENT ME!
693
     * 
694
     * @param t
695
     *            DOCUMENT ME!
696
     */
697
    private void throwException(Throwable t) {
698
        exceptionHandlingSupport.throwException(t);
699
    }
700

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

  
637
    /* (non-Javadoc)
709
    /*
710
     * (non-Javadoc)
711
     * 
638 712
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
639 713
     */
640 714
    public void windowClosed() {
641
//        try {
642
//            model.stop();
643
//        } catch (ReadDriverException e) {
644
//            NotificationManager.addError(e.getMessage(), e);
645
//        }
715
        // try {
716
        // model.stop();
717
        // } catch (ReadDriverException e) {
718
        // NotificationManager.addError(e.getMessage(), e);
719
        // }
646 720
    }
647 721

  
648 722
    public Object getWindowProfile() {
649
		return WindowInfo.TOOL_PROFILE;
650
	}
651
}
723
        return WindowInfo.TOOL_PROFILE;
724
    }
725
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/extension/FiltroExtension.java
67 67

  
68 68
/**
69 69
 * Extensi?n que abre un di?logo para poder hacer un filtro de una capa o tabla.
70
 *
70
 * 
71 71
 * @author Vicente Caballero Navarro
72 72
 */
73 73
public class FiltroExtension extends Extension implements ExpressionListener {
74
	protected FeatureStore featureStore = null;
75
	private String filterTitle;
76 74

  
77
	/**
78
	 * DOCUMENT ME!
79
	 */
80
	public void initialize() {
81
		registerIcons();
82
	}
75
    protected FeatureStore featureStore = null;
76
    private String filterTitle;
83 77

  
84
	private void registerIcons(){
85
		PluginServices.getIconTheme().registerDefault(
86
				"table-filter",
87
				this.getClass().getClassLoader().getResource("images/Filtro.png")
88
		);
89
	}
78
    /**
79
     * DOCUMENT ME!
80
     */
81
    public void initialize() {
82
        registerIcons();
83
    }
90 84

  
91
	/**
92
	 * DOCUMENT ME!
93
	 *
94
	 * @param actionCommand DOCUMENT ME!
95
	 */
96
	public void execute(String actionCommand) {
97
		if ("FILTRO".equals(actionCommand)) {
98
//			try {
99
				IWindow v = PluginServices.getMDIManager().getActiveWindow();
85
    private void registerIcons() {
86
        PluginServices.getIconTheme().registerDefault("table-filter",
87
            this.getClass().getClassLoader().getResource("images/Filtro.png"));
88
    }
100 89

  
90
    /**
91
     * DOCUMENT ME!
92
     * 
93
     * @param actionCommand
94
     *            DOCUMENT ME!
95
     */
96
    public void execute(String actionCommand) {
97
        if ("FILTRO".equals(actionCommand)) {
98
            // try {
99
            IWindow v = PluginServices.getMDIManager().getActiveWindow();
100

  
101 101
            if (v instanceof org.gvsig.app.project.documents.view.gui.DefaultViewPanel) {
102
					ViewDocument pv = ((org.gvsig.app.project.documents.view.gui.DefaultViewPanel) v).getModel();
103
					filterTitle = ((org.gvsig.app.project.documents.view.gui.DefaultViewPanel) v).getModel().getName();
104
					FLayer layer = pv.getMapContext()
105
					.getLayers().getActives()[0];
106
					featureStore = ((FLyrVect)layer).getFeatureStore();//pv.getProject().getDataSourceByLayer(layer);
107
					((AbstractDocument)pv).setModified(true);
108
				}
109
//			}  catch (ReadException e) {
110
//				NotificationManager.addError("Error filtrando", e);
111
//			}
102
                ViewDocument pv =
103
                    ((org.gvsig.app.project.documents.view.gui.DefaultViewPanel) v)
104
                        .getModel();
105
                filterTitle =
106
                    ((org.gvsig.app.project.documents.view.gui.DefaultViewPanel) v)
107
                        .getModel().getName();
108
                FLayer layer = pv.getMapContext().getLayers().getActives()[0];
109
                featureStore = ((FLyrVect) layer).getFeatureStore();// pv.getProject().getDataSourceByLayer(layer);
110
                ((AbstractDocument) pv).setModified(true);
111
            }
112
            // } catch (ReadException e) {
113
            // NotificationManager.addError("Error filtrando", e);
114
            // }
112 115

  
113
			doExecute();
114
		}
115
	}
116
            doExecute();
117
        }
118
    }
116 119

  
117
	/**
118
	 * "execute" method action.
119
	 *
120
	 */
121
	protected void doExecute(){
122
		//		DefaultExpressionDataSource ds = new DefaultExpressionDataSource();
123
		//		ds.setTable(featureStore);
124
		FilterDialog dlg = new FilterDialog(filterTitle);
125
		dlg.addExpressionListener(this);
126
		dlg.addExceptionListener(new ExceptionListener() {
127
			public void exceptionThrown(Throwable t) {
128
				NotificationManager.addError(t.getMessage(), t);
129
			}
130
		});
131
		dlg.setModel(featureStore);
132
		PluginServices.getMDIManager().addWindow(dlg);
133
	}
120
    /**
121
     * "execute" method action.
122
     * 
123
     */
124
    protected void doExecute() {
125
        // DefaultExpressionDataSource ds = new DefaultExpressionDataSource();
126
        // ds.setTable(featureStore);
127
        FilterDialog dlg = new FilterDialog(filterTitle);
128
        dlg.addExpressionListener(this);
129
        dlg.addExceptionListener(new ExceptionListener() {
134 130

  
135
	/**
136
	 * DOCUMENT ME!
137
	 *
138
	 * @return DOCUMENT ME!
139
	 */
140
	public boolean isEnabled() {
141
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
131
            public void exceptionThrown(Throwable t) {
132
                NotificationManager.addError(t.getMessage(), t);
133
            }
134
        });
135
        dlg.setModel(featureStore);
136
        PluginServices.getMDIManager().addWindow(dlg);
137
    }
142 138

  
139
    /**
140
     * DOCUMENT ME!
141
     * 
142
     * @return DOCUMENT ME!
143
     */
144
    public boolean isEnabled() {
145
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
146

  
143 147
        if (v == null) {
144 148
            return false;
145 149
        }
......
153 157

  
154 158
            if (seleccionadas.length == 1) {
155 159
                if (seleccionadas[0].isAvailable()
156
                    && seleccionadas[0] instanceof FLyrVect) {
160
                    && (seleccionadas[0] instanceof FLyrVect)) {
157 161
                    return true;
158 162
                }
159 163
            }
160 164
        }
161 165
        return false;
162
	}
166
    }
163 167

  
164
	/**
165
	 * DOCUMENT ME!
166
	 *
167
	 * @return DOCUMENT ME!
168
	 */
169
	public boolean isVisible() {
168
    /**
169
     * DOCUMENT ME!
170
     * 
171
     * @return DOCUMENT ME!
172
     */
173
    public boolean isVisible() {
170 174
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
171 175

  
172 176
        if (v == null) {
......
188 192
        }
189 193

  
190 194
        return false;
191
	}
195
    }
192 196

  
193
	/**
194
	 * DOCUMENT ME!
195
	 *
196
	 * @param expression DOCUMENT ME!
197
	 */
198
	// By Pablo: if no filter expression -> no element selected
199
	public void newSet(String expression) throws DataException {
200
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
201
			FeatureSet set = null;
202
			try {
203
				set = doSet(expression);
197
    /**
198
     * DOCUMENT ME!
199
     * 
200
     * @param expression
201
     *            DOCUMENT ME!
202
     */
203
    // By Pablo: if no filter expression -> no element selected
204
    public void newSet(String expression) throws DataException {
205
        if (!this.filterExpressionFromWhereIsEmpty(expression)) {
206
            FeatureSet set = null;
207
            try {
208
                set = doSet(expression);
204 209

  
205
				if (set == null) {
206
					//throw new RuntimeException("Not a 'where' clause?");
207
					return;
208
				}
209
				featureStore.setSelection(set);
210
                if (set == null) {
211
                    // throw new RuntimeException("Not a 'where' clause?");
212
                    return;
213
                }
214
                featureStore.setSelection(set);
210 215

  
211
			}catch(Exception e){
212
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "Asegurate de que la consulta es correcta.");
213
			}
214
			finally {
215
				if (set != null) {
216
					set.dispose();
217
				}
218
			}
219
		}
220
		else {
221
			// By Pablo: if no expression -> no element selected
222
			featureStore.getFeatureSelection().deselectAll();
223
		}
224
	}
216
            } catch (Exception e) {
217
                JOptionPane.showMessageDialog((Component) PluginServices
218
                    .getMainFrame(),
219
                    "Asegurate de que la consulta es correcta.");
220
            } finally {
221
                if (set != null) {
222
                    set.dispose();
223
                }
224
            }
225
        } else {
226
            // By Pablo: if no expression -> no element selected
227
            featureStore.getFeatureSelection().deselectAll();
228
        }
229
    }
225 230

  
226
	/**
227
	 * @throws DataException
228
	 * @see org.gvsig.app.gui.filter.ExpressionListener#newSet(java.lang.String)
229
	 */
230
	private FeatureSet doSet(String expression) throws DataException {
231
		FeatureQuery query = featureStore.createFeatureQuery();
232
		DataManager manager = DALLocator.getDataManager();
233
		query.setFilter(manager.createExpresion(expression));
234
		return featureStore.getFeatureSet(query);
235
		//		try {
236
		//			DataSource ds = LayerFactory.getDataSourceFactory().executeSQL(expression,
237
		//					DataSourceFactory.MANUAL_OPENING);
238
		//
239
		//			return ds.getWhereFilter();
240
		//		} catch (DriverLoadException e) {
241
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"driver_error")+"\n"+e.getMessage());
242
		//		} catch (ReadDriverException e) {
243
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"driver_error")+"\n"+e.getMessage());
244
		//		} catch (ParseException e) {
245
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"parse_expresion_error")+"\n"+e.getMessage());
246
		//		} catch (SemanticException e) {
247
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"semantic_expresion_error")+"\n"+e.getMessage());
248
		//		} catch (IOException e) {
249
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"input_output_error")+"\n"+e.getMessage());
250
		//		} catch (EvaluationException e) {
251
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"parse_expresion_error")+"\n"+e.getMessage());
252
		//		} catch (com.hardcode.gdbms.parser.TokenMgrError e) {
253
		//			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"expresion_error")+"\n"+e.getMessage());
254
		//		}
255
		//		return null;
256
	}
231
    /**
232
     * @throws DataException
233
     * @see org.gvsig.app.gui.filter.ExpressionListener#newSet(java.lang.String)
234
     */
235
    private FeatureSet doSet(String expression) throws DataException {
236
        FeatureQuery query = featureStore.createFeatureQuery();
237
        DataManager manager = DALLocator.getDataManager();
238
        query.setFilter(manager.createExpresion(expression));
239
        return featureStore.getFeatureSet(query);
240
        // try {
241
        // DataSource ds =
242
        // LayerFactory.getDataSourceFactory().executeSQL(expression,
243
        // DataSourceFactory.MANUAL_OPENING);
244
        //
245
        // return ds.getWhereFilter();
246
        // } catch (DriverLoadException e) {
247
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"driver_error")+"\n"+e.getMessage());
248
        // } catch (ReadDriverException e) {
249
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"driver_error")+"\n"+e.getMessage());
250
        // } catch (ParseException e) {
251
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"parse_expresion_error")+"\n"+e.getMessage());
252
        // } catch (SemanticException e) {
253
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"semantic_expresion_error")+"\n"+e.getMessage());
254
        // } catch (IOException e) {
255
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"input_output_error")+"\n"+e.getMessage());
256
        // } catch (EvaluationException e) {
257
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"parse_expresion_error")+"\n"+e.getMessage());
258
        // } catch (com.hardcode.gdbms.parser.TokenMgrError e) {
259
        // JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"expresion_error")+"\n"+e.getMessage());
260
        // }
261
        // return null;
262
    }
257 263

  
258
	/**
259
	 * DOCUMENT ME!
260
	 *
261
	 * @param expression
262
	 *            DOCUMENT ME!
263
	 * @throws DataException
264
	 */
265
	public void addToSet(String expression) throws DataException {
266
		// By Pablo: if no filter expression -> don't add more elements to set
267
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
268
			FeatureSet set = null;
269
			try {
270
				set = doSet(expression);
264
    /**
265
     * DOCUMENT ME!
266
     * 
267
     * @param expression
268
     *            DOCUMENT ME!
269
     * @throws DataException
270
     */
271
    public void addToSet(String expression) throws DataException {
272
        // By Pablo: if no filter expression -> don't add more elements to set
273
        if (!this.filterExpressionFromWhereIsEmpty(expression)) {
274
            FeatureSet set = null;
275
            try {
276
                set = doSet(expression);
271 277

  
272
				if (set == null) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff