Revision 9563

View differences:

branches/v10/applications/appgvSIG/src/com/iver/cit/gvsig/TableOperations.java
352 352
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
353 353
	 */
354 354
	public void newSet(String expression) {
355
		long[] sel = doSet(expression);
356

  
357
		if (sel == null) {
358
			throw new RuntimeException("Not a 'where' clause?");
355
		// By Pablo: if no expression -> no element selected
356
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
357
			long[] sel = doSet(expression);
358
	
359
			if (sel == null) {
360
				throw new RuntimeException("Not a 'where' clause?");
361
			}
362
	
363
			FBitSet selection = new FBitSet();
364
	
365
			for (int i = 0; i < sel.length; i++) {
366
				selection.set((int) sel[i]);
367
			}
368
	
369
			dataSource.clearSelection();
370
			dataSource.setSelection(selection);
359 371
		}
360

  
361
		FBitSet selection = new FBitSet();
362

  
363
		for (int i = 0; i < sel.length; i++) {
364
			selection.set((int) sel[i]);
372
		else {
373
			// By Pablo: if no expression -> no element selected
374
			dataSource.clearSelection();
365 375
		}
366

  
367
		dataSource.clearSelection();
368
		dataSource.setSelection(selection);
369 376
	}
370 377

  
371 378
	/**
......
398 405
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#addToSet(java.lang.String)
399 406
	 */
400 407
	public void addToSet(String expression) {
401
		long[] sel = doSet(expression);
402

  
403
		if (sel == null) {
404
			throw new RuntimeException("Not a 'where' clause?");
408
		// By Pablo: if no expression -> don't add more elements to set
409
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
410
			long[] sel = doSet(expression);
411
	
412
			if (sel == null) {
413
				throw new RuntimeException("Not a 'where' clause?");
414
			}
415
	
416
			FBitSet selection = new FBitSet();
417
	
418
			for (int i = 0; i < sel.length; i++) {
419
				selection.set((int) sel[i]);
420
			}
421
	
422
			FBitSet fbs = dataSource.getSelection();
423
			fbs.or(selection);
424
			dataSource.setSelection(fbs);
405 425
		}
406

  
407
		FBitSet selection = new FBitSet();
408

  
409
		for (int i = 0; i < sel.length; i++) {
410
			selection.set((int) sel[i]);
411
		}
412

  
413
		FBitSet fbs = dataSource.getSelection();
414
		fbs.or(selection);
415
		dataSource.setSelection(fbs);
416 426
	}
417 427

  
418 428
	/**
419 429
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#fromSet(java.lang.String)
420 430
	 */
421 431
	public void fromSet(String expression) {
422
		long[] sel = doSet(expression);
423

  
424
		if (sel == null) {
425
			throw new RuntimeException("Not a 'where' clause?");
432
		// By Pablo: if no expression -> no element selected
433
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
434
			long[] sel = doSet(expression);
435
	
436
			if (sel == null) {
437
				throw new RuntimeException("Not a 'where' clause?");
438
			}
439
	
440
			FBitSet selection = new FBitSet();
441
	
442
			for (int i = 0; i < sel.length; i++) {
443
				selection.set((int) sel[i]);
444
			}
445
	
446
			FBitSet fbs = dataSource.getSelection();
447
			fbs.and(selection);
448
			dataSource.setSelection(fbs);
426 449
		}
427

  
428
		FBitSet selection = new FBitSet();
429

  
430
		for (int i = 0; i < sel.length; i++) {
431
			selection.set((int) sel[i]);
450
		else {
451
			// By Pablo: if no expression -> no element selected
452
			dataSource.clearSelection();
432 453
		}
433

  
434
		FBitSet fbs = dataSource.getSelection();
435
		fbs.and(selection);
436
		dataSource.setSelection(fbs);
437 454
	}
455
	
456
	/**
457
	 * Returns true if the WHERE subconsultation of the filterExpression is empty ("")
458
	 * 
459
	 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
460
	 * @param expression An string
461
	 * @return A boolean value 
462
	 */
463
	private boolean filterExpressionFromWhereIsEmpty(String expression) {
464
		String subExpression = expression.trim();
465
		int pos;	
466
		
467
		// Remove last ';' if exists
468
		if (subExpression.charAt(subExpression.length() -1) == ';')
469
			subExpression = subExpression.substring(0, subExpression.length() -1).trim();
470
		
471
		// If there is no 'where' clause
472
		if ((pos = subExpression.indexOf("where")) == -1)
473
			return false;
474
		
475
		// If there is no subexpression in the WHERE clause -> true
476
		subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where'
477
		if ( subExpression.length() == 0 )
478
			return true;
479
		else
480
			return false;
481
	}
438 482

  
439 483
	/**
440 484
	 * @see com.iver.mdiApp.plugins.IExtension#isVisible()
branches/v10/applications/appgvSIG/src/com/iver/cit/gvsig/FiltroExtension.java
212 212
	 * @param expression DOCUMENT ME!
213 213
	 */
214 214
	public void newSet(String expression) {
215
		// By Pablo: if no filter expression -> no element selected
216
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
217
			try {
218
				long[] sel = doSet(expression);
215 219
		
216
		try {
217
			long[] sel = doSet(expression);
218
	
219
			if (sel == null) {
220
				//throw new RuntimeException("Not a 'where' clause?");
221
				return;
220
				if (sel == null) {
221
					//throw new RuntimeException("Not a 'where' clause?");
222
					return;
223
				}
224
		
225
				FBitSet selection = new FBitSet();
226
		
227
				for (int i = 0; i < sel.length; i++) {
228
					selection.set((int) sel[i]);
229
				}
230
		
231
				dataSource.clearSelection();
232
				dataSource.setSelection(selection);
233
			}catch(Exception e){
234
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "Asegurate de que la consulta es correcta.");
222 235
			}
223
	
224
			FBitSet selection = new FBitSet();
225
	
226
			for (int i = 0; i < sel.length; i++) {
227
				selection.set((int) sel[i]);
228
			}
229
	
236
		}
237
		else {
238
			// By Pablo: if no expression -> no element selected
230 239
			dataSource.clearSelection();
231
			dataSource.setSelection(selection);
232
		}catch(Exception e){
233
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "Asegurate de que la consulta es correcta.");
234 240
		}
235
		
236 241
	}
237 242

  
238 243
	/**
......
267 272
	 * @param expression DOCUMENT ME!
268 273
	 */
269 274
	public void addToSet(String expression) {
270
		long[] sel = doSet(expression);
271

  
272
		if (sel == null) {
273
			//throw new RuntimeException("Not a 'where' clause?");
274
			return;
275
		// By Pablo: if no filter expression -> don't add more elements to set
276
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
277
			long[] sel = doSet(expression);
278
	
279
			if (sel == null) {
280
				//throw new RuntimeException("Not a 'where' clause?");
281
				return;
282
			}
283
	
284
			FBitSet selection = new FBitSet();
285
	
286
			for (int i = 0; i < sel.length; i++) {
287
				selection.set((int) sel[i]);
288
			}
289
	
290
			FBitSet fbs = dataSource.getSelection();
291
			fbs.or(selection);
292
			dataSource.setSelection(fbs);
275 293
		}
276

  
277
		FBitSet selection = new FBitSet();
278

  
279
		for (int i = 0; i < sel.length; i++) {
280
			selection.set((int) sel[i]);
281
		}
282

  
283
		FBitSet fbs = dataSource.getSelection();
284
		fbs.or(selection);
285
		dataSource.setSelection(fbs);
286 294
	}
287 295

  
288 296
	/**
......
291 299
	 * @param expression DOCUMENT ME!
292 300
	 */
293 301
	public void fromSet(String expression) {
294
		long[] sel = doSet(expression);
295

  
296
		if (sel == null) {
297
			throw new RuntimeException("Not a 'where' clause?");
302
		// By Pablo: if no filter expression -> no element selected
303
		if (! this.filterExpressionFromWhereIsEmpty(expression)) {
304
			long[] sel = doSet(expression);
305
	
306
			if (sel == null) {
307
				throw new RuntimeException("Not a 'where' clause?");
308
			}
309
	
310
			FBitSet selection = new FBitSet();
311
	
312
			for (int i = 0; i < sel.length; i++) {
313
				selection.set((int) sel[i]);
314
			}
315
	
316
			FBitSet fbs = dataSource.getSelection();
317
			fbs.and(selection);
318
			dataSource.setSelection(fbs);
298 319
		}
299

  
300
		FBitSet selection = new FBitSet();
301

  
302
		for (int i = 0; i < sel.length; i++) {
303
			selection.set((int) sel[i]);
320
		else {
321
			// By Pablo: if no expression -> no element selected
322
			dataSource.clearSelection();
304 323
		}
324
	}	
305 325

  
306
		FBitSet fbs = dataSource.getSelection();
307
		fbs.and(selection);
308
		dataSource.setSelection(fbs);
326
	/**
327
	 * Returns true if the WHERE subconsultation of the filterExpression is empty ("")
328
	 * 
329
	 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
330
	 * @param expression An string
331
	 * @return A boolean value 
332
	 */
333
	private boolean filterExpressionFromWhereIsEmpty(String expression) {
334
		String subExpression = expression.trim();
335
		int pos;	
336
		
337
		// Remove last ';' if exists
338
		if (subExpression.charAt(subExpression.length() -1) == ';')
339
			subExpression = subExpression.substring(0, subExpression.length() -1).trim();
340
		
341
		// If there is no 'where' clause
342
		if ((pos = subExpression.indexOf("where")) == -1)
343
			return false;
344
		
345
		// If there is no subexpression in the WHERE clause -> true
346
		subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where'
347
		if ( subExpression.length() == 0 )
348
			return true;
349
		else
350
			return false;
309 351
	}
310 352
}

Also available in: Unified diff