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 / selectableforeingkey / JDynFormFieldSelectableForeingKey.java @ 44262

History | View | Annotate | Download (3.15 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 org.gvsig.featureform.swing.JFeaturesForm.FeaturesFormContext;
26
import org.gvsig.fmap.dal.StoresRepository;
27
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
28
import org.gvsig.fmap.dal.feature.FeatureType;
29
import org.gvsig.fmap.dal.feature.ForeingKey;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dynform.DynFormFieldDefinition;
32
import org.gvsig.tools.dynform.JDynForm;
33
import org.gvsig.tools.dynform.JDynFormField;
34
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
35
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList;
36
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory;
37
import org.gvsig.tools.dynobject.DynObjectValueItem;
38

    
39
@SuppressWarnings("UseSpecificCatch")
40
public class JDynFormFieldSelectableForeingKey extends AbstractJDynFormFieldWithValueList implements JDynFormField {
41

    
42
    public JDynFormFieldSelectableForeingKey(
43
            DynFormSPIManager serviceManager,
44
            DynFormSPIManager.ComponentsFactory componentsFactory,
45
            JDynFormFieldFactory factory,
46
            DynFormFieldDefinition definition,
47
            Object value
48
    ) {
49
        super(serviceManager, componentsFactory, factory, definition, value);
50
    }
51

    
52

    
53
    private ForeingKey getForeingKey() {
54
        JDynForm.DynFormContext context = this.getForm().getContext();
55
        if( !(context instanceof FeaturesFormContext) ) {
56
            return null;
57
        }
58
        FeatureType featureType = ((FeaturesFormContext)context).getFeatureType();
59
        if( featureType==null ) {
60
            return null;
61
        }
62
        FeatureAttributeDescriptor attribute = featureType.getAttributeDescriptor(this.getName());
63
        if( attribute == null ) {
64
            return null;
65
        }
66
        ForeingKey foreingKey = attribute.getForeingKey();
67
        return foreingKey;
68
    }
69
    
70
    @Override
71
    protected DynObjectValueItem[] getAvailableValues() {
72
        final ForeingKey foreingKey = this.getForeingKey();
73
        if( foreingKey==null || !foreingKey.isSelectable() ) {
74
            return null;
75
        }
76
        DynObjectValueItem[] values = foreingKey.getAvailableValues(null);
77
        return values;
78
    }
79

    
80
}