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 / actions / SelectionSetAction.java @ 47049
History | View | Annotate | Download (3.77 KB)
1 | 44281 | jjdelcerro | package org.gvsig.fmap.dal.swing.impl.actions; |
---|---|---|---|
2 | 44263 | jjdelcerro | |
3 | import java.awt.event.ActionEvent; |
||
4 | import javax.swing.AbstractAction; |
||
5 | import javax.swing.Action; |
||
6 | import org.gvsig.expressionevaluator.Expression; |
||
7 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
8 | 44263 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureQuery; |
9 | import org.gvsig.fmap.dal.feature.FeatureSelection; |
||
10 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
11 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
12 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.swing.AbstractDALActionFactory; |
13 | 44263 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
14 | import org.gvsig.tools.i18n.I18nManager; |
||
15 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
16 | import org.slf4j.Logger; |
||
17 | import org.slf4j.LoggerFactory; |
||
18 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
19 | 47049 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
20 | import org.gvsig.fmap.dal.swing.DataSwingManager; |
||
21 | 45295 | omartinez | import org.gvsig.tools.dispose.DisposeUtils; |
22 | 44263 | jjdelcerro | |
23 | /**
|
||
24 | *
|
||
25 | * @author jjdelcerro
|
||
26 | */
|
||
27 | @SuppressWarnings("UseSpecificCatch") |
||
28 | public class SelectionSetAction |
||
29 | extends AbstractAction |
||
30 | { |
||
31 | |||
32 | 44281 | jjdelcerro | public static class SelectionSetActionFactory extends AbstractDALActionFactory { |
33 | 44263 | jjdelcerro | |
34 | 44281 | jjdelcerro | public static final String ACTION_NAME = "SelectionSet"; |
35 | |||
36 | public SelectionSetActionFactory() {
|
||
37 | super(ACTION_NAME);
|
||
38 | 44263 | jjdelcerro | } |
39 | 44281 | jjdelcerro | |
40 | 44263 | jjdelcerro | @Override
|
41 | 44281 | jjdelcerro | public Action createAction(DALActionContext context) { |
42 | return new SelectionSetAction(context); |
||
43 | 44263 | jjdelcerro | } |
44 | 47049 | jjdelcerro | |
45 | public static void selfRegister() { |
||
46 | DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager(); |
||
47 | dalSwingManager.registerStoreAction(new SelectionSetActionFactory());
|
||
48 | } |
||
49 | 44263 | jjdelcerro | } |
50 | |||
51 | private static final Logger LOGGER = LoggerFactory.getLogger(SelectionSetAction.class); |
||
52 | |||
53 | 44281 | jjdelcerro | private final DALActionContext context; |
54 | 44263 | jjdelcerro | |
55 | 44281 | jjdelcerro | public SelectionSetAction(DALActionContext context) {
|
56 | this.context = context;
|
||
57 | 44263 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
58 | this.putValue(
|
||
59 | 44281 | jjdelcerro | Action.ACTION_COMMAND_KEY,
|
60 | SelectionSetActionFactory.ACTION_NAME |
||
61 | ); |
||
62 | this.putValue(
|
||
63 | 44263 | jjdelcerro | Action.SHORT_DESCRIPTION,
|
64 | i18n.getTranslation("_New_selection")
|
||
65 | ); |
||
66 | this.putValue(
|
||
67 | Action.SMALL_ICON,
|
||
68 | ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-action-select")
|
||
69 | ); |
||
70 | } |
||
71 | |||
72 | @Override
|
||
73 | public void actionPerformed(ActionEvent e) { |
||
74 | 45295 | omartinez | FeatureSet selection = null;
|
75 | 44263 | jjdelcerro | try {
|
76 | 44281 | jjdelcerro | DataStore store = this.context.getStore();
|
77 | 46900 | jjdelcerro | if (!(store instanceof FeatureStore)) { |
78 | return;
|
||
79 | 44281 | jjdelcerro | } |
80 | FeatureStore featureStore = (FeatureStore) store; |
||
81 | 46900 | jjdelcerro | FeatureSelection currentSelection = this.context.getSelecteds();
|
82 | if (currentSelection != null) { |
||
83 | featureStore.setSelection(currentSelection); |
||
84 | return;
|
||
85 | 44281 | jjdelcerro | } |
86 | 46900 | jjdelcerro | Expression filter = null; |
87 | FeatureQuery query = null;
|
||
88 | FeatureQuery contextQuery = this.context.getQuery();
|
||
89 | if (contextQuery != null) { |
||
90 | filter = contextQuery.getExpressionFilter(); |
||
91 | if (filter != null) { |
||
92 | query = featureStore.createFeatureQuery(); |
||
93 | query.setFilter(filter); |
||
94 | } |
||
95 | } |
||
96 | currentSelection = featureStore.getFeatureSelection(); |
||
97 | if( query == null ) { |
||
98 | currentSelection.selectAll(); |
||
99 | return;
|
||
100 | } |
||
101 | 45295 | omartinez | selection = featureStore.getFeatureSet(query); |
102 | 44263 | jjdelcerro | currentSelection.deselectAll(); |
103 | currentSelection.select(selection); |
||
104 | } catch (Exception ex) { |
||
105 | LOGGER.warn("Can't build selecction.", ex);
|
||
106 | 45295 | omartinez | } finally {
|
107 | DisposeUtils.disposeQuietly(selection); |
||
108 | 44263 | jjdelcerro | } |
109 | } |
||
110 | |||
111 | } |