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 @ 33278
History | View | Annotate | Download (3.31 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 |
|
38 |
/**
|
39 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
40 |
*/
|
41 |
public class FeatuteAttributeCombo extends JComboBox{ |
42 |
private FeatureStore featureStore;
|
43 |
private boolean isNullable = true; |
44 |
|
45 |
public FeatuteAttributeCombo(FeatureStore featureStore, boolean isNullable) throws DataException { |
46 |
super();
|
47 |
this.featureStore = featureStore;
|
48 |
setNullable(isNullable); |
49 |
addFields(); |
50 |
} |
51 |
|
52 |
public FeatuteAttributeCombo(FeatureStore featureStore, int dataType, boolean isNullable) throws DataException { |
53 |
super();
|
54 |
this.featureStore = featureStore;
|
55 |
setNullable(isNullable); |
56 |
addFields(dataType); |
57 |
} |
58 |
|
59 |
private void setNullable(boolean isNullable){ |
60 |
this.isNullable = isNullable;
|
61 |
if (isNullable){
|
62 |
this.addItem(new String("- " + Messages.getText("default") + " -")); |
63 |
} |
64 |
} |
65 |
|
66 |
private void addFields() throws DataException { |
67 |
FeatureAttributeDescriptor[] featureAttributeDescriptors = featureStore.getDefaultFeatureType().getAttributeDescriptors();
|
68 |
for (int i=0; i<featureAttributeDescriptors.length ; i++){ |
69 |
this.addItem(featureAttributeDescriptors[i].getName());
|
70 |
} |
71 |
} |
72 |
|
73 |
private void addFields(int dataType) throws DataException { |
74 |
FeatureAttributeDescriptor[] featureAttributeDescriptors = featureStore.getDefaultFeatureType().getAttributeDescriptors();
|
75 |
for (int i=0; i<featureAttributeDescriptors.length ; i++){ |
76 |
if (featureAttributeDescriptors[i].getDataType() == dataType){
|
77 |
this.addItem(featureAttributeDescriptors[i].getName());
|
78 |
} |
79 |
//Double fields includes Integers
|
80 |
if (DataTypes.DOUBLE == dataType){
|
81 |
if (DataTypes.INT == featureAttributeDescriptors[i].getDataType()){
|
82 |
this.addItem(featureAttributeDescriptors[i].getName());
|
83 |
}else if (DataTypes.LONG == featureAttributeDescriptors[i].getDataType()){ |
84 |
this.addItem(featureAttributeDescriptors[i].getName());
|
85 |
} |
86 |
} |
87 |
} |
88 |
} |
89 |
|
90 |
public String getSelectedAttribute() { |
91 |
if (isNullable){
|
92 |
int index = super.getSelectedIndex(); |
93 |
if (index == 0){ |
94 |
return null; |
95 |
}else{
|
96 |
return (String)super.getSelectedItem(); |
97 |
} |
98 |
}else{
|
99 |
return (String)super.getSelectedItem(); |
100 |
} |
101 |
} |
102 |
} |
103 |
|