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 / linkforeingkey / JDynFormFieldForeingKeyFactory.java @ 44338
History | View | Annotate | Download (3.12 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.linkforeingkey; |
25 |
|
26 |
import org.gvsig.featureform.swing.JFeaturesForm.FeaturesFormContext; |
27 |
import org.gvsig.fmap.dal.DataManager; |
28 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
29 |
import org.gvsig.fmap.dal.feature.FeatureType; |
30 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
31 |
import org.gvsig.tools.dataTypes.DataTypes; |
32 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
33 |
import org.gvsig.tools.dynform.JDynForm; |
34 |
import org.gvsig.tools.dynform.JDynFormField; |
35 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
36 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
37 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory; |
38 |
|
39 |
public class JDynFormFieldForeingKeyFactory extends AbstractJDynFormFieldFactory { |
40 |
|
41 |
public JDynFormFieldForeingKeyFactory() {
|
42 |
super("FOREINGKEY", DataTypes.UNKNOWN, null); |
43 |
} |
44 |
|
45 |
@Override
|
46 |
public JDynFormField create(
|
47 |
DynFormSPIManager serviceManager, |
48 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
49 |
DynFormFieldDefinition fieldDefinition, |
50 |
Object value
|
51 |
) { |
52 |
return new JDynFormFieldForeingKey(serviceManager, componentsFactory, this, fieldDefinition, value); |
53 |
} |
54 |
|
55 |
@Override
|
56 |
public int getPriority() { |
57 |
return 500; |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public boolean isApplicableTo(JDynForm.DynFormContext context, DynFormFieldDefinition fieldDefinition) { |
62 |
if( !(context instanceof FeaturesFormContext) ) { |
63 |
return false; |
64 |
} |
65 |
FeatureType featureType = ((FeaturesFormContext)context).getFeatureType(); |
66 |
FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(fieldDefinition.getName()); |
67 |
if( attribute == null ) { |
68 |
return false; |
69 |
} |
70 |
ForeingKey foreingKey = attribute.getForeingKey(); |
71 |
if( foreingKey==null ) { |
72 |
return false; |
73 |
} |
74 |
return foreingKey.isForeingKey() && !foreingKey.isClosedList();
|
75 |
} |
76 |
|
77 |
public static void selfRegister() { |
78 |
DynFormSPIManager manager = DynFormSPILocator.getDynFormSPIManager(); |
79 |
manager.registerDynFieldFactory(new JDynFormFieldForeingKeyFactory());
|
80 |
} |
81 |
|
82 |
} |