Statistics
| Revision:

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 @ 47426

History | View | Annotate | Download (4.3 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.FeaturesFormContext;
27
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm;
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.fmap.dal.swing.impl.DefaultDALSwingLibrary;
33
import static org.gvsig.fmap.dal.swing.impl.DefaultDALSwingLibrary.LIBRARY_NAME;
34
import org.gvsig.tools.dataTypes.DataTypes;
35
import org.gvsig.tools.dynform.DynFormFieldDefinition;
36
import org.gvsig.tools.dynform.JDynForm;
37
import org.gvsig.tools.dynform.JDynFormField;
38
import org.gvsig.tools.dynform.spi.DynFormSPILocator;
39
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
40
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldFactory;
41
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
42
import org.gvsig.tools.swing.api.ToolsSwingUtils;
43
import org.gvsig.tools.swing.impl.ToolsSwingDefaultImplLibrary;
44

    
45
public class JDynFormFieldForeingKeyFactory extends AbstractJDynFormFieldFactory {
46

    
47
    public JDynFormFieldForeingKeyFactory() {
48
        super("FOREINGKEY", DataTypes.UNKNOWN, null);
49
    }
50

    
51
    @Override
52
    public JDynFormField create(
53
            DynFormSPIManager serviceManager,
54
            DynFormSPIManager.ComponentsFactory componentsFactory,
55
            DynFormFieldDefinition fieldDefinition,
56
            Object value
57
    ) {
58
        return new JDynFormFieldForeingKey(serviceManager, componentsFactory, this, fieldDefinition, value);
59
    }
60

    
61
    @Override
62
    public int getPriority() {
63
        return 500;
64
    }
65
    
66
    @Override
67
    public boolean isApplicableTo(JDynForm.DynFormContext context, DynFormFieldDefinition fieldDefinition) {
68
        if( !(context instanceof FeaturesFormContext) ) {
69
            return false;
70
        }
71
        FeatureType featureType = ((FeaturesFormContext)context).getFeatureType();
72
        FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(fieldDefinition.getName());
73
        if( attribute == null ) {
74
            return false;
75
        }
76
        ForeingKey foreingKey = attribute.getForeingKey();
77
        if( foreingKey==null ) {
78
            return false;
79
        }
80
        return foreingKey.isForeingKey() && !foreingKey.isClosedList();
81
    }
82
    
83
    public static void selfRegister() {
84
        DynFormSPIManager manager;
85
        try {
86
            manager = DynFormSPILocator.getDynFormSPIManager();
87
        } catch(ReferenceNotRegisteredException ex) {
88
            return;
89
        }
90
        manager.registerDynFieldFactory(new JDynFormFieldForeingKeyFactory());
91
        
92
        boolean n = ToolsSwingUtils.registerIcons( 
93
                DefaultDALSwingLibrary.class,
94
                "/org/gvsig/featureform/swing/impl",
95
                LIBRARY_NAME,
96
                new String[]{ "picker", "picker-foreingkey-link", "picker-foreingkey"},
97
                new String[]{ "picker", "picker-foreingkey-unlink", "picker-foreingkey"},
98
                new String[]{ "picker", "picker-foreingkey-showform", "picker-foreingkey"}
99
        );
100
        ToolsSwingUtils.registerSubgroupIconScreenshot(
101
                DefaultDALSwingLibrary.class, 
102
                "picker",
103
                "picker-foreingkey",
104
                "/org/gvsig/fmap/dal/screenshots/picker-foreingkey.png"
105
        );
106
    }
107
    
108
}