Revision 44262 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchpanel/DefaultSearchPanel.java
DefaultSearchPanel.java | ||
---|---|---|
8 | 8 |
import java.util.List; |
9 | 9 |
import javax.swing.ImageIcon; |
10 | 10 |
import javax.swing.JComponent; |
11 |
import javax.swing.SwingUtilities; |
|
11 | 12 |
import javax.swing.event.ListSelectionEvent; |
12 | 13 |
import javax.swing.event.ListSelectionListener; |
13 | 14 |
import javax.swing.table.AbstractTableModel; |
15 |
import javax.swing.table.TableModel; |
|
14 | 16 |
import org.apache.commons.io.FilenameUtils; |
17 |
import org.apache.commons.lang.mutable.MutableLong; |
|
18 |
import org.apache.commons.lang.mutable.MutableObject; |
|
15 | 19 |
import org.gvsig.expressionevaluator.Expression; |
16 | 20 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
17 | 21 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_AND; |
... | ... | |
21 | 25 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
22 | 26 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
23 | 27 |
import org.gvsig.featureform.swing.JFeaturesForm; |
28 |
import org.gvsig.fmap.dal.complements.Search; |
|
24 | 29 |
import org.gvsig.fmap.dal.exception.DataException; |
25 | 30 |
import org.gvsig.fmap.dal.feature.Feature; |
26 | 31 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
30 | 35 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
31 | 36 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
32 | 37 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
33 |
import org.gvsig.tools.dataTypes.DataType;
|
|
38 |
import org.gvsig.tools.ToolsLocator;
|
|
34 | 39 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
35 | 40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
36 | 41 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
... | ... | |
62 | 67 |
this.featureType = featureType; |
63 | 68 |
if (columnNames == null || columnNames.isEmpty()) { |
64 | 69 |
this.columnNames = new ArrayList<>(); |
65 |
List<FeatureAttributeDescriptor> attributos = SearchUtils.getOrderedAttributes( |
|
66 |
featureType, |
|
67 |
SearchUtils.BASIC_TYPES_FILTER, |
|
68 |
SearchUtils.STR_INT_LONG_LABEL_ORDER, |
|
70 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
|
71 |
Search.COMPLEMENT_MANE, featureType |
|
72 |
); |
|
73 |
List<FeatureAttributeDescriptor> attributos = search.getOrderedAttributes( |
|
74 |
Search.BASIC_TYPES_FILTER, |
|
75 |
Search.STR_INT_LONG_LABEL_ORDER, |
|
69 | 76 |
12 |
70 | 77 |
); |
71 | 78 |
for (FeatureAttributeDescriptor attrdesc : attributos) { |
... | ... | |
228 | 235 |
null |
229 | 236 |
); |
230 | 237 |
this.searchFields.add(controller); |
231 |
|
|
232 |
List<FeatureAttributeDescriptor> orderedAttributes = SearchUtils.getOrderedAttributes( |
|
233 |
this.store, |
|
234 |
SearchUtils.BASIC_TYPES_FILTER, |
|
235 |
SearchUtils.STR_INT_LONG_LABEL_ORDER, |
|
236 |
5 |
|
237 |
); |
|
238 |
int n = 0; |
|
239 |
for (SearchFieldController searchField : searchFields) { |
|
240 |
searchField.setAttribute(orderedAttributes.get(n++).getName()); |
|
238 |
try { |
|
239 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
|
240 |
Search.COMPLEMENT_MANE, this.store.getDefaultFeatureType() |
|
241 |
); |
|
242 |
List<FeatureAttributeDescriptor> orderedAttributes = search.getOrderedAttributes( |
|
243 |
Search.BASIC_TYPES_FILTER, |
|
244 |
Search.STR_INT_LONG_LABEL_ORDER, |
|
245 |
5 |
|
246 |
); |
|
247 |
int n = 0; |
|
248 |
for (SearchFieldController searchField : searchFields) { |
|
249 |
searchField.setAttribute(orderedAttributes.get(n++).getName()); |
|
250 |
} |
|
251 |
} catch (DataException ex) { |
|
252 |
LOGGER.warn("Can't determine order of attributes", ex); |
|
241 | 253 |
} |
242 | 254 |
|
243 | 255 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
... | ... | |
265 | 277 |
} catch (Exception ex) { |
266 | 278 |
} |
267 | 279 |
this.btnShowForm.setEnabled(true); |
268 |
|
|
280 |
|
|
269 | 281 |
this.tblResults.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
270 | 282 |
@Override |
271 | 283 |
public void valueChanged(ListSelectionEvent e) { |
272 |
if( e.getValueIsAdjusting() ) {
|
|
284 |
if (e.getValueIsAdjusting()) {
|
|
273 | 285 |
return; |
274 | 286 |
} |
275 |
if( tblResults.getSelectedRowCount()==0 ) {
|
|
287 |
if (tblResults.getSelectedRowCount() == 0) {
|
|
276 | 288 |
btnShowForm.setEnabled(true); |
277 | 289 |
return; |
278 | 290 |
} |
... | ... | |
290 | 302 |
doSearch(null); |
291 | 303 |
} |
292 | 304 |
|
305 |
@Override |
|
306 |
public void setEnabled(boolean enabled) { |
|
307 |
for (SearchFieldController searchField : searchFields) { |
|
308 |
searchField.setEnabled(enabled); |
|
309 |
} |
|
310 |
this.btnClear.setEnabled(enabled); |
|
311 |
this.btnSearch.setEnabled(enabled); |
|
312 |
this.btnShowForm.setEnabled(enabled); |
|
313 |
this.advancedExpression.setEnabled(enabled); |
|
314 |
} |
|
315 |
|
|
293 | 316 |
public void clear() { |
294 | 317 |
for (SearchFieldController searchField : searchFields) { |
295 | 318 |
searchField.clear(); |
296 |
}
|
|
319 |
} |
|
297 | 320 |
this.advancedExpression.set(null); |
298 | 321 |
} |
299 |
|
|
322 |
|
|
300 | 323 |
private void doSearch() { |
301 | 324 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
302 | 325 |
if (searchMode == 1) { // Avanzada |
... | ... | |
307 | 330 |
doSearch(filter); |
308 | 331 |
return; |
309 | 332 |
} |
310 |
|
|
333 |
|
|
311 | 334 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
312 | 335 |
String relational = OPERATOR_OR; |
313 | 336 |
for (SearchFieldController searchField : searchFields) { |
314 |
if( searchField.getAttribute()!=null && searchField.getValue()!=null ) {
|
|
337 |
if (searchField.getAttribute() != null && searchField.getValue() != null) {
|
|
315 | 338 |
ExpressionBuilder.BinaryOperator cond = builder.binaryOperator( |
316 | 339 |
searchField.getRelationalOperator(), |
317 |
searchField.isAttributeAnExpression()?
|
|
318 |
builder.custom(searchField.getAttribute()):
|
|
319 |
builder.column(searchField.getAttribute()),
|
|
320 |
builder.constant(searchField.getValue())
|
|
340 |
searchField.isAttributeAnExpression() |
|
341 |
? builder.custom(searchField.getAttribute())
|
|
342 |
: builder.column(searchField.getAttribute()),
|
|
343 |
builder.constant(searchField.getValue()) |
|
321 | 344 |
); |
322 |
if( relational.equals(OPERATOR_AND) ) {
|
|
345 |
if (relational.equals(OPERATOR_AND)) {
|
|
323 | 346 |
builder.and(cond); |
324 | 347 |
} else { |
325 | 348 |
builder.or(cond); |
... | ... | |
327 | 350 |
relational = searchField.getLogicalOperator(); |
328 | 351 |
} |
329 | 352 |
} |
330 |
if( builder.isEmpty() ) {
|
|
353 |
if (builder.isEmpty()) {
|
|
331 | 354 |
doSearch(null); |
332 | 355 |
return; |
333 | 356 |
} |
... | ... | |
335 | 358 |
doSearch(ExpressionUtils.createExpression(builder.toString())); |
336 | 359 |
} |
337 | 360 |
|
338 |
private void doSearch(Expression exp) { |
|
339 |
FeaturesTableModel model; |
|
340 |
try { |
|
341 |
List<Feature> features; |
|
342 |
if (exp == null) { |
|
343 |
features = this.store.getFeatures(); |
|
344 |
} else { |
|
345 |
features = this.store.getFeatures(exp); |
|
361 |
private void doSearch(final Expression exp) { |
|
362 |
final MutableObject model = new MutableObject(null); |
|
363 |
|
|
364 |
lblMsg.setText("Searching..."); |
|
365 |
setEnabled(false); |
|
366 |
Thread th = new Thread(new Runnable() { |
|
367 |
@Override |
|
368 |
public void run() { |
|
369 |
try { |
|
370 |
final List<Feature> features; |
|
371 |
if (exp == null) { |
|
372 |
features = store.getFeatures(); |
|
373 |
} else { |
|
374 |
features = store.getFeatures(exp); |
|
375 |
} |
|
376 |
currentSearch = exp; |
|
377 |
model.setValue( new FeaturesTableModel( |
|
378 |
store.getDefaultFeatureType(), |
|
379 |
null, |
|
380 |
features |
|
381 |
) |
|
382 |
); |
|
383 |
} catch (DataException ex) { |
|
384 |
LOGGER.warn("Can't get features or create table model",ex); |
|
385 |
} finally { |
|
386 |
SwingUtilities.invokeLater(new Runnable() { |
|
387 |
@Override |
|
388 |
public void run() { |
|
389 |
TableModel m = (TableModel) model.getValue(); |
|
390 |
tblResults.setModel(m); |
|
391 |
lblMsg.setText(String.format("%d elementos", m.getRowCount())); |
|
392 |
setEnabled(true); |
|
393 |
} |
|
394 |
}); |
|
395 |
} |
|
346 | 396 |
} |
347 |
this.currentSearch = exp; |
|
348 |
model = new FeaturesTableModel( |
|
349 |
this.store.getDefaultFeatureType(), |
|
350 |
null, |
|
351 |
features |
|
352 |
); |
|
353 |
this.tblResults.setModel(model); |
|
354 |
this.lblMsg.setText(String.format("%d elementos", features.size())); |
|
355 |
} catch (DataException ex) { |
|
356 |
|
|
357 |
} |
|
397 |
}); |
|
398 |
th.start(); |
|
358 | 399 |
} |
359 | 400 |
|
360 | 401 |
private void doShowForm() { |
... | ... | |
364 | 405 |
|
365 | 406 |
Expression filter; |
366 | 407 |
int selectedRow = this.tblResults.getSelectedRow(); |
367 |
if( selectedRow<0 ) {
|
|
408 |
if (selectedRow < 0) {
|
|
368 | 409 |
filter = this.currentSearch; |
369 | 410 |
} else { |
370 | 411 |
List<Feature> features = ((FeaturesTableModel) this.tblResults.getModel()).getFeatures(); |
... | ... | |
411 | 452 |
} |
412 | 453 |
|
413 | 454 |
public static void selfRegister() { |
414 |
String[][] iconNames = new String[][] { |
|
415 |
new String[] { "dalswing", "featurestore-search-attribute-selector" } |
|
455 |
String[][] iconNames = new String[][]{ |
|
456 |
new String[]{"dalswing", "featurestore-column"}, |
|
457 |
new String[]{"dalswing", "featurestore-foreing-key"}, |
|
458 |
new String[]{"dalswing", "featurestore-table"} |
|
416 | 459 |
}; |
417 | 460 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
418 | 461 |
for (String[] icon : iconNames) { |
419 |
URL url = DefaultSearchPanel.class.getResource(icon[1]+".png");
|
|
462 |
URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png");
|
|
420 | 463 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
421 | 464 |
} |
422 |
|
|
423 |
|
|
465 |
|
|
424 | 466 |
} |
425 |
} |
|
467 |
}; |
Also available in: Unified diff