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 / ShowFormAction.java @ 47049
History | View | Annotate | Download (4.46 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 javax.swing.event.ListSelectionEvent; |
||
7 | import javax.swing.event.ListSelectionListener; |
||
8 | import org.gvsig.expressionevaluator.Expression; |
||
9 | import org.gvsig.featureform.swing.JFeaturesForm; |
||
10 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
11 | 44263 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
12 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
13 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
14 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.swing.AbstractDALActionFactory; |
15 | 44263 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
16 | import org.gvsig.fmap.dal.swing.DataSwingManager; |
||
17 | import org.gvsig.tools.ToolsLocator; |
||
18 | import org.gvsig.tools.i18n.I18nManager; |
||
19 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
20 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
21 | import org.slf4j.Logger; |
||
22 | import org.slf4j.LoggerFactory; |
||
23 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
24 | 44263 | jjdelcerro | |
25 | /**
|
||
26 | *
|
||
27 | * @author jjdelcerro
|
||
28 | */
|
||
29 | @SuppressWarnings("UseSpecificCatch") |
||
30 | public class ShowFormAction |
||
31 | extends AbstractAction |
||
32 | implements ListSelectionListener |
||
33 | { |
||
34 | 44281 | jjdelcerro | |
35 | public static class ShowFormActionFactory extends AbstractDALActionFactory { |
||
36 | 44263 | jjdelcerro | |
37 | 44281 | jjdelcerro | public static final String ACTION_NAME = "ShowForm"; |
38 | |||
39 | public ShowFormActionFactory() {
|
||
40 | super(ACTION_NAME);
|
||
41 | 44263 | jjdelcerro | } |
42 | |||
43 | @Override
|
||
44 | 44281 | jjdelcerro | public Action createAction(DALActionContext context) { |
45 | return new ShowFormAction(context); |
||
46 | 44263 | jjdelcerro | } |
47 | 47049 | jjdelcerro | |
48 | public static void selfRegister() { |
||
49 | DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager(); |
||
50 | dalSwingManager.registerStoreAction(new ShowFormActionFactory());
|
||
51 | } |
||
52 | 44263 | jjdelcerro | } |
53 | |||
54 | |||
55 | private static final Logger LOGGER = LoggerFactory.getLogger(ShowFormAction.class); |
||
56 | |||
57 | 44281 | jjdelcerro | private final DALActionContext context; |
58 | 44263 | jjdelcerro | private boolean showFormSingleElement; |
59 | |||
60 | 44281 | jjdelcerro | public ShowFormAction(DALActionContext context) {
|
61 | this.context = context;
|
||
62 | 44263 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
63 | this.putValue(
|
||
64 | 44281 | jjdelcerro | Action.ACTION_COMMAND_KEY,
|
65 | ShowFormActionFactory.ACTION_NAME |
||
66 | ); |
||
67 | this.putValue(
|
||
68 | 44263 | jjdelcerro | Action.SHORT_DESCRIPTION,
|
69 | i18n.getTranslation("_Show_form")
|
||
70 | ); |
||
71 | this.putValue(
|
||
72 | Action.SMALL_ICON,
|
||
73 | 46400 | jjdelcerro | ToolsSwingLocator.getIconThemeManager().getCurrent().get("common-showform")
|
74 | 44263 | jjdelcerro | ); |
75 | try {
|
||
76 | this.showFormSingleElement = true; |
||
77 | 44281 | jjdelcerro | DataStore store = this.context.getStore();
|
78 | if( !(store instanceof FeatureStore) ) { |
||
79 | return;
|
||
80 | } |
||
81 | FeatureStore featureStore = (FeatureStore) store; |
||
82 | FeatureAttributeDescriptor[] pks = featureStore.getDefaultFeatureType().getPrimaryKey();
|
||
83 | 44263 | jjdelcerro | if (pks == null || pks.length < 1) { |
84 | this.showFormSingleElement = false; |
||
85 | } |
||
86 | } catch (Exception ex) { |
||
87 | } |
||
88 | } |
||
89 | |||
90 | @Override
|
||
91 | public void actionPerformed(ActionEvent e) { |
||
92 | try {
|
||
93 | this.setEnabled(false); |
||
94 | 44281 | jjdelcerro | DataStore store = this.context.getStore();
|
95 | if( !(store instanceof FeatureStore) ) { |
||
96 | return ;
|
||
97 | } |
||
98 | FeatureStore featureStore = (FeatureStore) store; |
||
99 | Expression filter = this.context.getFilterForSelecteds(); |
||
100 | 44263 | jjdelcerro | if( filter==null ) { |
101 | 44712 | jjdelcerro | FeatureQuery query = this.context.getQuery();
|
102 | if( query != null ) { |
||
103 | filter = query.getExpressionFilter(); |
||
104 | } |
||
105 | 44263 | jjdelcerro | } |
106 | DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
||
107 | |||
108 | 44281 | jjdelcerro | FeatureQuery query = featureStore.createFeatureQuery(); |
109 | 44263 | jjdelcerro | query.setFilter(filter); |
110 | query.retrievesAllAttributes(); |
||
111 | 44281 | jjdelcerro | JFeaturesForm form = dataSwingManager.createJFeaturesForm(featureStore); |
112 | 44263 | jjdelcerro | form.setQuery(query); |
113 | form.showForm(WindowManager.MODE.WINDOW); |
||
114 | } catch (Exception ex) { |
||
115 | LOGGER.warn("Can't show form", ex);
|
||
116 | } finally {
|
||
117 | this.setEnabled(true); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | @Override
|
||
122 | public void valueChanged(ListSelectionEvent e) { |
||
123 | if (e.getValueIsAdjusting()) {
|
||
124 | return;
|
||
125 | } |
||
126 | 44281 | jjdelcerro | if (this.context.getSelectedsCount()== 0) { |
127 | 44263 | jjdelcerro | this.setEnabled(true); |
128 | return;
|
||
129 | } |
||
130 | this.setEnabled(showFormSingleElement);
|
||
131 | } |
||
132 | |||
133 | } |