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 @ 47426
History | View | Annotate | Download (3.77 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.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.DataStore; |
8 |
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 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory; |
13 |
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 |
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
19 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
20 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
21 |
import org.gvsig.tools.dispose.DisposeUtils; |
22 |
|
23 |
/**
|
24 |
*
|
25 |
* @author jjdelcerro
|
26 |
*/
|
27 |
@SuppressWarnings("UseSpecificCatch") |
28 |
public class SelectionSetAction |
29 |
extends AbstractAction |
30 |
{ |
31 |
|
32 |
public static class SelectionSetActionFactory extends AbstractDALActionFactory { |
33 |
|
34 |
public static final String ACTION_NAME = "SelectionSet"; |
35 |
|
36 |
public SelectionSetActionFactory() {
|
37 |
super(ACTION_NAME);
|
38 |
} |
39 |
|
40 |
@Override
|
41 |
public Action createAction(DALActionContext context) { |
42 |
return new SelectionSetAction(context); |
43 |
} |
44 |
|
45 |
public static void selfRegister() { |
46 |
DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager(); |
47 |
dalSwingManager.registerStoreAction(new SelectionSetActionFactory());
|
48 |
} |
49 |
} |
50 |
|
51 |
private static final Logger LOGGER = LoggerFactory.getLogger(SelectionSetAction.class); |
52 |
|
53 |
private final DALActionContext context; |
54 |
|
55 |
public SelectionSetAction(DALActionContext context) {
|
56 |
this.context = context;
|
57 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
58 |
this.putValue(
|
59 |
Action.ACTION_COMMAND_KEY,
|
60 |
SelectionSetActionFactory.ACTION_NAME |
61 |
); |
62 |
this.putValue(
|
63 |
Action.SHORT_DESCRIPTION,
|
64 |
i18n.getTranslation("_New_selection")
|
65 |
); |
66 |
this.putValue(
|
67 |
Action.SMALL_ICON,
|
68 |
ToolsSwingLocator.getIconThemeManager().getCurrent().get("storeaction-select")
|
69 |
); |
70 |
} |
71 |
|
72 |
@Override
|
73 |
public void actionPerformed(ActionEvent e) { |
74 |
FeatureSet selection = null;
|
75 |
try {
|
76 |
DataStore store = this.context.getStore();
|
77 |
if (!(store instanceof FeatureStore)) { |
78 |
return;
|
79 |
} |
80 |
FeatureStore featureStore = (FeatureStore) store; |
81 |
FeatureSelection currentSelection = this.context.getSelecteds();
|
82 |
if (currentSelection != null) { |
83 |
featureStore.setSelection(currentSelection); |
84 |
return;
|
85 |
} |
86 |
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 |
selection = featureStore.getFeatureSet(query); |
102 |
currentSelection.deselectAll(); |
103 |
currentSelection.select(selection); |
104 |
} catch (Exception ex) { |
105 |
LOGGER.warn("Can't build selecction.", ex);
|
106 |
} finally {
|
107 |
DisposeUtils.disposeQuietly(selection); |
108 |
} |
109 |
} |
110 |
|
111 |
} |