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 / SelectionSetAction.java @ 44263
History | View | Annotate | Download (2.39 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 org.gvsig.expressionevaluator.Expression; |
7 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
8 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
9 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
12 |
import org.gvsig.tools.ToolsLocator; |
13 |
import org.gvsig.tools.i18n.I18nManager; |
14 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
15 |
import org.slf4j.Logger; |
16 |
import org.slf4j.LoggerFactory; |
17 |
|
18 |
/**
|
19 |
*
|
20 |
* @author jjdelcerro
|
21 |
*/
|
22 |
@SuppressWarnings("UseSpecificCatch") |
23 |
public class SelectionSetAction |
24 |
extends AbstractAction |
25 |
{ |
26 |
|
27 |
public static class SelectionSetActionFactory implements FeatureStoreSearchPanel.ActionFactory { |
28 |
|
29 |
@Override
|
30 |
public String getName() { |
31 |
return "SelectionSet"; |
32 |
} |
33 |
|
34 |
@Override
|
35 |
public Action createAction(FeatureStoreSearchPanel panel) { |
36 |
return new SelectionSetAction(panel); |
37 |
} |
38 |
|
39 |
} |
40 |
|
41 |
private static final Logger LOGGER = LoggerFactory.getLogger(SelectionSetAction.class); |
42 |
|
43 |
private final FeatureStoreSearchPanel searchPanel; |
44 |
|
45 |
public SelectionSetAction(FeatureStoreSearchPanel searchPanel) {
|
46 |
this.searchPanel = searchPanel;
|
47 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
48 |
this.putValue(
|
49 |
Action.SHORT_DESCRIPTION,
|
50 |
i18n.getTranslation("_New_selection")
|
51 |
); |
52 |
this.putValue(
|
53 |
Action.SMALL_ICON,
|
54 |
ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-action-select")
|
55 |
); |
56 |
} |
57 |
|
58 |
@Override
|
59 |
public void actionPerformed(ActionEvent e) { |
60 |
try {
|
61 |
FeatureStore store = this.searchPanel.getStore();
|
62 |
FeatureSelection currentSelection = store.getFeatureSelection(); |
63 |
|
64 |
Expression filter = this.searchPanel.getCurrentSearch(); |
65 |
FeatureQuery query = store.createFeatureQuery(); |
66 |
query.setFilter(filter); |
67 |
FeatureSet selection = store.getFeatureSet(query); |
68 |
currentSelection.deselectAll(); |
69 |
currentSelection.select(selection); |
70 |
} catch (Exception ex) { |
71 |
LOGGER.warn("Can't build selecction.", ex);
|
72 |
} |
73 |
} |
74 |
|
75 |
} |