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 / SelectionAddAction.java @ 45234
History | View | Annotate | Download (2.95 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 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
@SuppressWarnings("UseSpecificCatch") |
25 |
public class SelectionAddAction |
26 |
extends AbstractAction |
27 |
{ |
28 |
|
29 |
public static class SelectionAddActionFactory extends AbstractDALActionFactory { |
30 |
|
31 |
public static final String ACTION_NAME = "SelectionAdd"; |
32 |
|
33 |
public SelectionAddActionFactory() {
|
34 |
super(ACTION_NAME);
|
35 |
} |
36 |
|
37 |
@Override
|
38 |
public Action createAction(DALActionContext context) { |
39 |
return new SelectionAddAction(context); |
40 |
} |
41 |
} |
42 |
|
43 |
private static final Logger LOGGER = LoggerFactory.getLogger(SelectionAddAction.class); |
44 |
|
45 |
private final DALActionContext context; |
46 |
|
47 |
public SelectionAddAction(DALActionContext context) {
|
48 |
this.context = context;
|
49 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
50 |
this.putValue(
|
51 |
Action.ACTION_COMMAND_KEY,
|
52 |
SelectionAddActionFactory.ACTION_NAME |
53 |
); |
54 |
this.putValue(
|
55 |
Action.SHORT_DESCRIPTION,
|
56 |
i18n.getTranslation("_Add_to_selection")
|
57 |
); |
58 |
this.putValue(
|
59 |
Action.SMALL_ICON,
|
60 |
ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-action-select-add")
|
61 |
); |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void actionPerformed(ActionEvent e) { |
66 |
try {
|
67 |
DataStore store = this.context.getStore();
|
68 |
if( !(store instanceof FeatureStore) ) { |
69 |
return ;
|
70 |
} |
71 |
FeatureStore featureStore = (FeatureStore) store; |
72 |
FeatureSelection currentSelection = featureStore.getFeatureSelection(); |
73 |
|
74 |
Expression filter = this.context.getFilterForSelecteds(); |
75 |
if( filter == null ) { |
76 |
FeatureQuery query = this.context.getQuery();
|
77 |
if( query != null ) { |
78 |
filter = query.getExpressionFilter(); |
79 |
} |
80 |
} |
81 |
FeatureQuery query = featureStore.createFeatureQuery(); |
82 |
query.setFilter(filter); |
83 |
FeatureSet selection = featureStore.getFeatureSet(query); |
84 |
currentSelection.select(selection); |
85 |
} catch (Exception ex) { |
86 |
LOGGER.warn("Can't build selecction.", ex);
|
87 |
} |
88 |
} |
89 |
|
90 |
} |