Revision 9563 branches/v10/applications/appgvSIG/src/com/iver/cit/gvsig/FiltroExtension.java

View differences:

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