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 / dynformfield / selectableforeingkey / JDynFormFieldSelectableForeingKey.java @ 45827
History | View | Annotate | Download (3.63 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.featureform.swing.impl.dynformfield.selectableforeingkey; |
24 |
|
25 |
import java.util.Objects; |
26 |
import org.apache.commons.lang3.StringUtils; |
27 |
import org.gvsig.featureform.swing.FeaturesFormContext; |
28 |
import org.gvsig.fmap.dal.StoresRepository; |
29 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
30 |
import org.gvsig.fmap.dal.feature.FeatureType; |
31 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
34 |
import org.gvsig.tools.dynform.JDynForm; |
35 |
import org.gvsig.tools.dynform.JDynFormField; |
36 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
37 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
38 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
39 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
40 |
|
41 |
@SuppressWarnings("UseSpecificCatch") |
42 |
public class JDynFormFieldSelectableForeingKey extends AbstractJDynFormFieldWithValueList implements JDynFormField { |
43 |
|
44 |
public JDynFormFieldSelectableForeingKey(
|
45 |
DynFormSPIManager serviceManager, |
46 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
47 |
JDynFormFieldFactory factory, |
48 |
DynFormFieldDefinition definition, |
49 |
Object value
|
50 |
) { |
51 |
super(serviceManager, componentsFactory, factory, definition, value);
|
52 |
} |
53 |
|
54 |
|
55 |
private ForeingKey getForeingKey() {
|
56 |
JDynForm.DynFormContext context = this.getForm().getContext();
|
57 |
if( !(context instanceof FeaturesFormContext) ) { |
58 |
return null; |
59 |
} |
60 |
FeatureType featureType = ((FeaturesFormContext)context).getFeatureType(); |
61 |
if( featureType==null ) { |
62 |
return null; |
63 |
} |
64 |
FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(this.getName());
|
65 |
if( attribute == null ) { |
66 |
return null; |
67 |
} |
68 |
ForeingKey foreingKey = attribute.getForeingKey(); |
69 |
return foreingKey;
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
protected DynObjectValueItem[] getAvailableValues() { |
74 |
final ForeingKey foreingKey = this.getForeingKey(); |
75 |
if( foreingKey==null || !foreingKey.isClosedList() ) { |
76 |
return null; |
77 |
} |
78 |
DynObjectValueItem[] values = foreingKey.getAvailableValues(null); |
79 |
return values;
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public boolean isModified() { |
84 |
String s = getValueFromJComponent();
|
85 |
Object assigned = getAssignedValue();
|
86 |
if (StringUtils.isBlank(s)) {
|
87 |
return assigned != null; |
88 |
} |
89 |
try {
|
90 |
Object value = this.getDefinition().coerce(s); |
91 |
return !Objects.equals(value, assigned);
|
92 |
} catch (Exception ex) { |
93 |
return false; |
94 |
} |
95 |
} |
96 |
|
97 |
|
98 |
} |