Revision 9532 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/FiltroExtension.java
FiltroExtension.java | ||
---|---|---|
64 | 64 |
import com.iver.cit.gvsig.gui.filter.DefaultExpressionDataSource; |
65 | 65 |
import com.iver.cit.gvsig.gui.filter.ExpressionListener; |
66 | 66 |
import com.iver.cit.gvsig.gui.filter.FilterDialog; |
67 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
|
67 | 68 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
68 | 69 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
69 | 70 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
... | ... | |
98 | 99 |
if (v instanceof Table) { |
99 | 100 |
vista = (Table) v; |
100 | 101 |
|
101 |
dataSource = (SelectableDataSource)vista.getModel().getModelo().getRecordset();
|
|
102 |
dataSource = vista.getModel().getModelo().getRecordset(); |
|
102 | 103 |
filterTitle = vista.getModel().getName(); |
103 |
|
|
104 |
vista.getModel().setModified(true); |
|
104 | 105 |
} else if (v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
105 | 106 |
IProjectView pv = ((com.iver.cit.gvsig.project.documents.view.gui.View) v).getModel(); |
106 | 107 |
filterTitle = ((com.iver.cit.gvsig.project.documents.view.gui.View) v).getModel().getName(); |
107 | 108 |
FLayer layer = pv.getMapContext() |
108 | 109 |
.getLayers().getActives()[0]; |
109 | 110 |
dataSource = pv.getProject().getDataSourceByLayer(layer); |
111 |
((ProjectDocument)pv).setModified(true); |
|
110 | 112 |
} |
111 | 113 |
} catch (DriverException e) { |
112 | 114 |
NotificationManager.addError("Error filtrando", e); |
... | ... | |
216 | 218 |
if (! this.filterExpressionFromWhereIsEmpty(expression)) { |
217 | 219 |
try { |
218 | 220 |
long[] sel = doSet(expression); |
219 |
|
|
221 |
|
|
220 | 222 |
if (sel == null) { |
221 | 223 |
//throw new RuntimeException("Not a 'where' clause?"); |
222 | 224 |
return; |
223 | 225 |
} |
224 |
|
|
226 |
|
|
225 | 227 |
FBitSet selection = new FBitSet(); |
226 |
|
|
228 |
|
|
227 | 229 |
for (int i = 0; i < sel.length; i++) { |
228 | 230 |
selection.set((int) sel[i]); |
229 | 231 |
} |
230 |
|
|
232 |
|
|
231 | 233 |
dataSource.clearSelection(); |
232 | 234 |
dataSource.setSelection(selection); |
233 | 235 |
}catch(Exception e){ |
... | ... | |
237 | 239 |
else { |
238 | 240 |
// By Pablo: if no expression -> no element selected |
239 | 241 |
dataSource.clearSelection(); |
240 |
}
|
|
242 |
} |
|
241 | 243 |
} |
242 | 244 |
|
243 | 245 |
/** |
... | ... | |
275 | 277 |
// By Pablo: if no filter expression -> don't add more elements to set |
276 | 278 |
if (! this.filterExpressionFromWhereIsEmpty(expression)) { |
277 | 279 |
long[] sel = doSet(expression); |
278 |
|
|
280 |
|
|
279 | 281 |
if (sel == null) { |
280 | 282 |
//throw new RuntimeException("Not a 'where' clause?"); |
281 | 283 |
return; |
282 | 284 |
} |
283 |
|
|
285 |
|
|
284 | 286 |
FBitSet selection = new FBitSet(); |
285 |
|
|
287 |
|
|
286 | 288 |
for (int i = 0; i < sel.length; i++) { |
287 | 289 |
selection.set((int) sel[i]); |
288 | 290 |
} |
289 |
|
|
291 |
|
|
290 | 292 |
FBitSet fbs = dataSource.getSelection(); |
291 | 293 |
fbs.or(selection); |
292 | 294 |
dataSource.setSelection(fbs); |
... | ... | |
302 | 304 |
// By Pablo: if no filter expression -> no element selected |
303 | 305 |
if (! this.filterExpressionFromWhereIsEmpty(expression)) { |
304 | 306 |
long[] sel = doSet(expression); |
305 |
|
|
307 |
|
|
306 | 308 |
if (sel == null) { |
307 | 309 |
throw new RuntimeException("Not a 'where' clause?"); |
308 | 310 |
} |
309 |
|
|
311 |
|
|
310 | 312 |
FBitSet selection = new FBitSet(); |
311 |
|
|
313 |
|
|
312 | 314 |
for (int i = 0; i < sel.length; i++) { |
313 | 315 |
selection.set((int) sel[i]); |
314 | 316 |
} |
315 |
|
|
317 |
|
|
316 | 318 |
FBitSet fbs = dataSource.getSelection(); |
317 | 319 |
fbs.and(selection); |
318 | 320 |
dataSource.setSelection(fbs); |
... | ... | |
322 | 324 |
dataSource.clearSelection(); |
323 | 325 |
} |
324 | 326 |
} |
325 |
|
|
327 |
|
|
326 | 328 |
/** |
327 | 329 |
* Returns true if the WHERE subconsultation of the filterExpression is empty ("") |
328 |
*
|
|
330 |
* |
|
329 | 331 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
330 | 332 |
* @param expression An string |
331 |
* @return A boolean value
|
|
333 |
* @return A boolean value |
|
332 | 334 |
*/ |
333 | 335 |
private boolean filterExpressionFromWhereIsEmpty(String expression) { |
334 | 336 |
String subExpression = expression.trim(); |
335 |
int pos;
|
|
336 |
|
|
337 |
int pos; |
|
338 |
|
|
337 | 339 |
// Remove last ';' if exists |
338 | 340 |
if (subExpression.charAt(subExpression.length() -1) == ';') |
339 | 341 |
subExpression = subExpression.substring(0, subExpression.length() -1).trim(); |
340 |
|
|
342 |
|
|
341 | 343 |
// If there is no 'where' clause |
342 | 344 |
if ((pos = subExpression.indexOf("where")) == -1) |
343 | 345 |
return false; |
344 |
|
|
346 |
|
|
345 | 347 |
// If there is no subexpression in the WHERE clause -> true |
346 | 348 |
subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where' |
347 | 349 |
if ( subExpression.length() == 0 ) |
Also available in: Unified diff