svn-gvsig-desktop / 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 / actions / SelectionFilterAction.java @ 44263
History | View | Annotate | Download (2.83 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel.actions; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import javax.swing.AbstractAction; |
5 |
import javax.swing.Action; |
6 |
import javax.swing.ImageIcon; |
7 |
import org.gvsig.expressionevaluator.Expression; |
8 |
import org.gvsig.fmap.dal.feature.Feature; |
9 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
10 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
11 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
12 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
13 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
14 |
import org.gvsig.tools.ToolsLocator; |
15 |
import org.gvsig.tools.i18n.I18nManager; |
16 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
17 |
import org.slf4j.Logger; |
18 |
import org.slf4j.LoggerFactory; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
@SuppressWarnings("UseSpecificCatch") |
25 |
public class SelectionFilterAction |
26 |
extends AbstractAction |
27 |
{ |
28 |
|
29 |
public static class SelectionFilterActionFactory implements FeatureStoreSearchPanel.ActionFactory { |
30 |
|
31 |
@Override
|
32 |
public String getName() { |
33 |
return "SelectionFilter"; |
34 |
} |
35 |
|
36 |
@Override
|
37 |
public Action createAction(FeatureStoreSearchPanel panel) { |
38 |
return new SelectionFilterAction(panel); |
39 |
} |
40 |
|
41 |
} |
42 |
|
43 |
private static final Logger LOGGER = LoggerFactory.getLogger(SelectionFilterAction.class); |
44 |
|
45 |
private final FeatureStoreSearchPanel searchPanel; |
46 |
|
47 |
public SelectionFilterAction(FeatureStoreSearchPanel searchPanel) {
|
48 |
this.searchPanel = searchPanel;
|
49 |
ImageIcon icon = ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-action-select-filter"); |
50 |
if( icon == null ) { |
51 |
LOGGER.warn("Can't locate icon 'search-action-select-filter'.");
|
52 |
} |
53 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
54 |
this.putValue(
|
55 |
Action.SHORT_DESCRIPTION,
|
56 |
i18n.getTranslation("_Filter_selection")
|
57 |
); |
58 |
this.putValue(
|
59 |
Action.SMALL_ICON,
|
60 |
icon |
61 |
); |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void actionPerformed(ActionEvent e) { |
66 |
try {
|
67 |
FeatureStore store = this.searchPanel.getStore();
|
68 |
FeatureSelection currentSelection = store.getFeatureSelection(); |
69 |
FeatureQuery query = store.createFeatureQuery(); |
70 |
Expression filter = this.searchPanel.getCurrentSearch(); |
71 |
query.setFilter(filter); |
72 |
FeatureSet set = store.getFeatureSet(query); |
73 |
FeatureSelection newSelection = store.createFeatureSelection(); |
74 |
for (Feature feature : set) {
|
75 |
if( currentSelection.isSelected(feature) ) {
|
76 |
newSelection.select(feature); |
77 |
} |
78 |
} |
79 |
store.setSelection(newSelection); |
80 |
} catch (Exception ex) { |
81 |
LOGGER.warn("Can't build selecction.", ex);
|
82 |
} |
83 |
} |
84 |
|
85 |
} |