Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.annotation / org.gvsig.annotation.swing / org.gvsig.annotation.swing.impl / src / main / java / org / gvsig / annotation / swing / impl / panel / FeatuteAttributeCombo.java @ 33272

History | View | Annotate | Download (3.35 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Prodevelop}   {Task}
26
*/
27
 
28
package org.gvsig.annotation.swing.impl.panel;
29

    
30
import javax.swing.JComboBox;
31

    
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.i18n.Messages;
37
import org.gvsig.tools.dataTypes.DataType;
38

    
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
41
 */
42
public class FeatuteAttributeCombo extends JComboBox{
43
        private FeatureStore featureStore;
44
        private boolean isNullable = true;
45
        
46
        public FeatuteAttributeCombo(FeatureStore featureStore, boolean isNullable) throws DataException {
47
                super();
48
                this.featureStore = featureStore;
49
                setNullable(isNullable);
50
                addFields();
51
        }
52
        
53
        public FeatuteAttributeCombo(FeatureStore featureStore, int dataType, boolean isNullable) throws DataException {
54
                super();
55
                this.featureStore = featureStore;
56
                setNullable(isNullable);
57
                addFields(dataType);
58
        }
59
        
60
        private void setNullable(boolean isNullable){
61
                this.isNullable = isNullable;
62
                if (isNullable){
63
                        this.addItem(new String("- " + Messages.getText("default") + " -"));
64
                }
65
        }        
66

    
67
        private void addFields() throws DataException {
68
                FeatureAttributeDescriptor[] featureAttributeDescriptors = featureStore.getDefaultFeatureType().getAttributeDescriptors();
69
                for (int i=0; i<featureAttributeDescriptors.length ; i++){
70
                        this.addItem(featureAttributeDescriptors[i].getName());
71
                }
72
        }
73
        
74
        private void addFields(int dataType) throws DataException {
75
                FeatureAttributeDescriptor[] featureAttributeDescriptors = featureStore.getDefaultFeatureType().getAttributeDescriptors();
76
                for (int i=0; i<featureAttributeDescriptors.length ; i++){
77
                        if (featureAttributeDescriptors[i].getDataType() == dataType){
78
                                this.addItem(featureAttributeDescriptors[i].getName());
79
                        }
80
                        //Double fields includes Integers
81
                        if (DataTypes.DOUBLE == dataType){
82
                                if (DataTypes.INT == featureAttributeDescriptors[i].getDataType()){
83
                                        this.addItem(featureAttributeDescriptors[i].getName());
84
                                }else if (DataTypes.LONG == featureAttributeDescriptors[i].getDataType()){
85
                                        this.addItem(featureAttributeDescriptors[i].getName());
86
                                }
87
                        }                                
88
                }
89
        }
90

    
91
        public String getSelectedAttribute() {
92
                if (isNullable){
93
                        int index = super.getSelectedIndex();
94
                        if (index == 0){
95
                                return null;
96
                        }else{
97
                                return (String)super.getSelectedItem();
98
                        }
99
                }else{
100
                        return (String)super.getSelectedItem();
101
                }
102
        }        
103
}
104