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 / JDynFormFieldSelectableForeingKeyFactory.java @ 44262
History | View | Annotate | Download (3.28 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
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.featureform.swing.impl.dynformfield.selectableforeingkey; |
25 |
|
26 |
import org.apache.commons.lang3.StringUtils; |
27 |
import org.gvsig.featureform.swing.JFeaturesForm; |
28 |
import org.gvsig.fmap.dal.DataManager; |
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.dataTypes.DataTypes; |
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.DynFormSPILocator; |
37 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
38 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
39 |
|
40 |
public class JDynFormFieldSelectableForeingKeyFactory extends AbstractJDynFormFieldFactory { |
41 |
|
42 |
public JDynFormFieldSelectableForeingKeyFactory() {
|
43 |
super(
|
44 |
"FOREINGKEY_SELECTABLE",
|
45 |
DataTypes.UNKNOWN, |
46 |
null
|
47 |
); |
48 |
} |
49 |
|
50 |
@Override
|
51 |
public JDynFormField create(
|
52 |
DynFormSPIManager serviceManager, |
53 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
54 |
DynFormFieldDefinition fieldDefinition, |
55 |
Object value
|
56 |
) { |
57 |
return new JDynFormFieldSelectableForeingKey(serviceManager, componentsFactory, this, fieldDefinition, value); |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public int getPriority() { |
62 |
return 500; |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public boolean isApplicableTo(JDynForm.DynFormContext context, DynFormFieldDefinition fieldDefinition) { |
67 |
if( !(context instanceof JFeaturesForm.FeaturesFormContext) ) { |
68 |
return false; |
69 |
} |
70 |
FeatureType featureType = ((JFeaturesForm.FeaturesFormContext)context).getFeatureType(); |
71 |
FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(fieldDefinition.getName()); |
72 |
if( attribute == null ) { |
73 |
return false; |
74 |
} |
75 |
ForeingKey foreingKey = attribute.getForeingKey(); |
76 |
if( foreingKey==null ) { |
77 |
return false; |
78 |
} |
79 |
return foreingKey.isForeingKey() && foreingKey.isSelectable();
|
80 |
} |
81 |
|
82 |
public static void selfRegister() { |
83 |
DynFormSPIManager manager = DynFormSPILocator.getDynFormSPIManager(); |
84 |
manager.registerDynFieldFactory(new JDynFormFieldSelectableForeingKeyFactory());
|
85 |
} |
86 |
|
87 |
} |