Revision 24759 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/FiltroExtension.java

View differences:

FiltroExtension.java
45 45

  
46 46
import javax.swing.JOptionPane;
47 47

  
48
import org.gvsig.fmap.data.DataException;
49
import org.gvsig.fmap.data.ReadException;
50
import org.gvsig.fmap.data.feature.Feature;
51
import org.gvsig.fmap.data.feature.FeatureCollection;
52
import org.gvsig.fmap.data.feature.FeatureStore;
53
import org.gvsig.fmap.data.feature.MemoryFeatureCollection;
48
import org.gvsig.fmap.dal.DALLocator;
49
import org.gvsig.fmap.dal.DataManager;
50
import org.gvsig.fmap.dal.exception.DataException;
51
import org.gvsig.fmap.dal.exception.ReadException;
52
import org.gvsig.fmap.dal.feature.Feature;
53
import org.gvsig.fmap.dal.feature.FeatureQuery;
54
import org.gvsig.fmap.dal.feature.FeatureSelection;
55
import org.gvsig.fmap.dal.feature.FeatureSet;
56
import org.gvsig.fmap.dal.feature.FeatureStore;
54 57
import org.gvsig.fmap.mapcontext.layers.FLayer;
55 58
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
56 59

  
......
214 217
		// By Pablo: if no filter expression -> no element selected
215 218
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
216 219
			try {
217
				FeatureCollection sel = doSet(expression);
220
				FeatureSet set = doSet(expression);
218 221

  
219
				if (sel == null) {
222
				if (set == null) {
220 223
					//throw new RuntimeException("Not a 'where' clause?");
221 224
					return;
222 225
				}
223
				featureStore.setSelection(sel);
226
				featureStore.setSelection(set);
224 227

  
225
//				FBitSet selection = new FBitSet();
226
//
227
//				for (int i = 0; i < sel.length; i++) {
228
//					selection.set((int) sel[i]);
229
//				}
230
//
231
//				featureStore.getSelection().clear();
232
//				featureStore.setSelection(selection);
228
				set.dispose();
233 229
			}catch(Exception e){
234 230
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "Asegurate de que la consulta es correcta.");
235 231
			}
236 232
		}
237 233
		else {
238 234
			// By Pablo: if no expression -> no element selected
239
			featureStore.getSelection().clear();
235
			featureStore.getFeatureSelection().deselectAll();
240 236
		}
241 237
	}
242 238

  
243 239
	/**
244
	 * @throws ReadException
240
	 * @throws DataException
245 241
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
246 242
	 */
247
	private FeatureCollection doSet(String expression) throws ReadException {
248
		return (FeatureCollection)featureStore.getDataCollection(featureStore.getDefaultFeatureType(),expression,null);
243
	private FeatureSet doSet(String expression) throws DataException {
244
		FeatureQuery query = featureStore.createFeatureQuery();
245
		DataManager manager = DALLocator.getDataManager();
246
		query.setFilter(manager.createExpresion(expression));
247
		return featureStore.getFeatureSet(query);
249 248
//		try {
250 249
//			DataSource ds = LayerFactory.getDataSourceFactory().executeSQL(expression,
251 250
//					DataSourceFactory.MANUAL_OPENING);
......
279 278
	public void addToSet(String expression) throws DataException {
280 279
		// By Pablo: if no filter expression -> don't add more elements to set
281 280
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
282
			FeatureCollection sel=null;
283
			try {
284
				sel = doSet(expression);
285
			} catch (ReadException e) {
286
				// TODO Auto-generated catch block
287
				e.printStackTrace();
288
			}
281
			FeatureSet set = null;
282
			set = doSet(expression);
289 283

  
290
			if (sel == null) {
284
			if (set == null) {
291 285
				//throw new RuntimeException("Not a 'where' clause?");
292 286
				return;
293 287
			}
294
			FeatureCollection oldSelection=(FeatureCollection)featureStore.getSelection();
295
			oldSelection.addAll(sel);
296
			featureStore.setSelection(oldSelection);
288
			featureStore.getFeatureSelection().select(set);
297 289

  
290
			set.dispose();
291

  
298 292
//			FBitSet selection = new FBitSet();
299 293
//
300 294
//			for (int i = 0; i < sel.length; i++) {
......
317 311
		try{
318 312
			if (! this.filterExpressionFromWhereIsEmpty(expression)) {
319 313

  
320
				FeatureCollection sel=null;
321
				sel = doSet(expression);
314
				FeatureSet set = null;
315
				set = doSet(expression);
322 316

  
323
				if (sel == null) {
317
				if (set == null) {
324 318
					throw new RuntimeException("Not a 'where' clause?");
325 319
				}
326
				FeatureCollection oldSelection=(FeatureCollection)featureStore.getSelection();
327 320

  
328
				MemoryFeatureCollection mfc=new MemoryFeatureCollection(featureStore);
329
				Iterator iterator=sel.iterator();
321
				FeatureSelection oldSelection = featureStore
322
						.getFeatureSelection();
323

  
324
				FeatureSelection newSelection = featureStore
325
						.createFeatureSelection();
326
				Iterator iterator = set.iterator();
330 327
				while (iterator.hasNext()) {
331 328
					Feature feature = (Feature) iterator.next();
332
					if (oldSelection.contains(feature)){
333
						mfc.add(feature);
329
					if (oldSelection.isSelected(feature)) {
330
						newSelection.select(feature);
334 331
					}
335 332
				}
336
				featureStore.setSelection(mfc);
333
				featureStore.setSelection(newSelection);
334
				set.dispose();
337 335

  
338 336

  
339 337

  
......
350 348
					//			featureStore.setSelection(fbs);
351 349
			} else {
352 350
					// By Pablo: if no expression -> no element selected
353
					featureStore.setSelection(featureStore.createSelection());
351
					featureStore.getFeatureSelection().deselectAll();
352
				;
354 353
				}
355 354
			} catch (DataException e) {
356 355
				NotificationManager.addError(e);

Also available in: Unified diff