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 / featureform / swing / impl / DefaultJFeatureForm.java @ 46010
History | View | Annotate | Download (3.03 KB)
1 | 42775 | jjdelcerro | |
---|---|---|---|
2 | 42112 | jjdelcerro | package org.gvsig.featureform.swing.impl; |
3 | |||
4 | 45726 | jjdelcerro | import java.util.Objects; |
5 | 42112 | jjdelcerro | import javax.swing.JComponent; |
6 | import org.gvsig.featureform.swing.JFeatureForm; |
||
7 | import org.gvsig.fmap.dal.DALLocator; |
||
8 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
9 | import org.gvsig.fmap.dal.feature.Feature; |
||
10 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
11 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
12 | import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager; |
||
13 | 45726 | jjdelcerro | import org.gvsig.tools.dynform.DynFormDefinition; |
14 | 42112 | jjdelcerro | import org.gvsig.tools.dynform.DynFormLocator; |
15 | import org.gvsig.tools.dynform.JDynForm; |
||
16 | import org.gvsig.tools.dynobject.DynClass; |
||
17 | 42775 | jjdelcerro | import org.slf4j.Logger; |
18 | import org.slf4j.LoggerFactory; |
||
19 | 42112 | jjdelcerro | |
20 | |||
21 | 45726 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
22 | 42775 | jjdelcerro | public class DefaultJFeatureForm implements JFeatureForm { |
23 | private static final Logger logger = LoggerFactory.getLogger(DefaultJFeatureForm.class); |
||
24 | 45826 | fdiaz | |
25 | 42775 | jjdelcerro | Feature feature; |
26 | FeatureStore store; |
||
27 | 45726 | jjdelcerro | DynFormDefinition definition; |
28 | 42775 | jjdelcerro | JDynForm form; |
29 | |||
30 | 42489 | jjdelcerro | @Override
|
31 | 42112 | jjdelcerro | public JComponent asJComponent() { |
32 | 42775 | jjdelcerro | return this.form.asJComponent(); |
33 | 42112 | jjdelcerro | } |
34 | |||
35 | 42775 | jjdelcerro | public DefaultJFeatureForm() {
|
36 | this.feature = null; |
||
37 | this.store = null; |
||
38 | 42112 | jjdelcerro | } |
39 | 44253 | jjdelcerro | |
40 | @Override
|
||
41 | public FeatureStore getFeatureStore() {
|
||
42 | return store;
|
||
43 | } |
||
44 | 42775 | jjdelcerro | |
45 | @Override
|
||
46 | public void setStore(FeatureStore store) { |
||
47 | 45726 | jjdelcerro | if( Objects.equals(this.store, store) ) { |
48 | 42112 | jjdelcerro | return;
|
49 | } |
||
50 | this.store = store;
|
||
51 | 42775 | jjdelcerro | if( store == null ) { |
52 | this.form = null; |
||
53 | return;
|
||
54 | 42112 | jjdelcerro | } |
55 | 42489 | jjdelcerro | try {
|
56 | 42775 | jjdelcerro | FeatureType featureType = this.store.getDefaultFeatureType();
|
57 | FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
||
58 | DynClass dynClass = featureTypeDefinitionsManager.get(store,featureType); |
||
59 | 46010 | jjdelcerro | this.form = DynFormLocator.getDynFormManager().createJDynForm(new DefaultFeaturesFormContext(this.store) { |
60 | public Feature getCurrentFeature() {
|
||
61 | return feature;
|
||
62 | } |
||
63 | }, dynClass); |
||
64 | 42775 | jjdelcerro | } catch (Exception ex) { |
65 | logger.warn("Can't create form.",ex);
|
||
66 | throw new RuntimeException("Can't create form.",ex); |
||
67 | 42489 | jjdelcerro | } |
68 | } |
||
69 | 42775 | jjdelcerro | |
70 | 42489 | jjdelcerro | @Override
|
71 | 45726 | jjdelcerro | public void setDefinition(DynFormDefinition definition) { |
72 | try {
|
||
73 | this.form = DynFormLocator.getDynFormManager().createJDynForm(definition);
|
||
74 | this.definition = definition;
|
||
75 | } catch (Exception ex) { |
||
76 | logger.warn("Can't create form.",ex);
|
||
77 | throw new RuntimeException("Can't create form.",ex); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | @Override
|
||
82 | 42775 | jjdelcerro | public void setFeature(Feature feature) { |
83 | this.feature = feature;
|
||
84 | 45726 | jjdelcerro | if( this.definition==null ) { |
85 | this.setStore(this.feature.getStore()); |
||
86 | } |
||
87 | 42775 | jjdelcerro | this.form.setValues(feature.getAsDynObject());
|
88 | 42112 | jjdelcerro | } |
89 | 42775 | jjdelcerro | |
90 | 42489 | jjdelcerro | @Override
|
91 | 42775 | jjdelcerro | public JDynForm getDynForm() {
|
92 | return this.form; |
||
93 | 42112 | jjdelcerro | } |
94 | 42775 | jjdelcerro | |
95 | 42489 | jjdelcerro | @Override
|
96 | 42775 | jjdelcerro | public void fetch(EditableFeature feature) { |
97 | this.form.getValues(feature.getAsDynObject());
|
||
98 | 42112 | jjdelcerro | } |
99 | 42775 | jjdelcerro | |
100 | 42112 | jjdelcerro | } |