root / branches / v2_0_0_prep / extensions / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / components / FeatureTypeAttributesCombo.java @ 38552
History | View | Annotate | Download (3.88 KB)
1 | 28893 | jpiera | /* 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 | * 2009 {Iver T.I.} {Task}
|
||
26 | */
|
||
27 | |||
28 | 35509 | nfrancisco | package org.gvsig.daltransform.swing.impl.components; |
29 | 28893 | jpiera | |
30 | 38552 | jldominguez | import java.util.ArrayList; |
31 | |||
32 | 28893 | jpiera | import javax.swing.DefaultComboBoxModel; |
33 | import javax.swing.JComboBox; |
||
34 | |||
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
37 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
39 | import org.slf4j.Logger; |
||
40 | import org.slf4j.LoggerFactory; |
||
41 | |||
42 | /**
|
||
43 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
44 | */
|
||
45 | public class FeatureTypeAttributesCombo extends JComboBox { |
||
46 | 35605 | nfrancisco | /**
|
47 | *
|
||
48 | */
|
||
49 | private static final long serialVersionUID = -8843843810490892699L; |
||
50 | protected static final Logger logger = LoggerFactory.getLogger(FeatureTypeAttributesCombo.class); |
||
51 | 28893 | jpiera | |
52 | public FeatureTypeAttributesCombo() {
|
||
53 | super();
|
||
54 | this.setModel(new DefaultComboBoxModel()); |
||
55 | } |
||
56 | |||
57 | 38552 | jldominguez | /**
|
58 | * Removes all items then adds atts
|
||
59 | *
|
||
60 | * @param featureStore
|
||
61 | * @return the number of items added (equals total item count)
|
||
62 | *
|
||
63 | * @throws DataException
|
||
64 | */
|
||
65 | public int addFeatureAttrubutes(FeatureStore featureStore) throws DataException{ |
||
66 | return addFeatureAttributes(featureStore.getDefaultFeatureType());
|
||
67 | 28893 | jpiera | } |
68 | |||
69 | 38552 | jldominguez | /**
|
70 | * Removes all items then adds atts
|
||
71 | *
|
||
72 | * @param featureType
|
||
73 | * @return the number of items added (equals total item count)
|
||
74 | */
|
||
75 | public int addFeatureAttributes(FeatureType featureType){ |
||
76 | 28893 | jpiera | removeAllItems(); |
77 | FeatureAttributeDescriptor[] descriptors = featureType.getAttributeDescriptors();
|
||
78 | for (int i=0 ; i<descriptors.length ; i++){ |
||
79 | addFeatureAttributeDescriptor(descriptors[i]); |
||
80 | } |
||
81 | 38552 | jldominguez | return descriptors.length;
|
82 | 28893 | jpiera | } |
83 | |||
84 | 38552 | jldominguez | |
85 | /**
|
||
86 | * Removes all items then adds atts whose type is
|
||
87 | * contained by list
|
||
88 | *
|
||
89 | * @param featureType
|
||
90 | * @param type
|
||
91 | * @return the number of items added (equals total item count)
|
||
92 | */
|
||
93 | public int addFeatureAttributes( |
||
94 | FeatureType featureType, |
||
95 | ArrayList<Integer> types){ |
||
96 | |||
97 | removeAllItems(); |
||
98 | |||
99 | int count = 0; |
||
100 | FeatureAttributeDescriptor[] descriptors = featureType.getAttributeDescriptors();
|
||
101 | for (int i=0 ; i<descriptors.length ; i++){ |
||
102 | if (isIn(descriptors[i].getType(), types)) {
|
||
103 | addFeatureAttributeDescriptor(descriptors[i]); |
||
104 | count++; |
||
105 | } |
||
106 | } |
||
107 | return count;
|
||
108 | } |
||
109 | |||
110 | /**
|
||
111 | * @param type
|
||
112 | * @param types
|
||
113 | * @return
|
||
114 | */
|
||
115 | private boolean isIn(int t, ArrayList<Integer> list) { |
||
116 | |||
117 | int len = list.size();
|
||
118 | for (int i=0; i<len; i++) { |
||
119 | if (list.get(i).intValue() == t) {
|
||
120 | return true; |
||
121 | } |
||
122 | } |
||
123 | return false; |
||
124 | } |
||
125 | |||
126 | public void addFeatureAttributeDescriptor(FeatureAttributeDescriptor featureAttributeDescriptor){ |
||
127 | 28893 | jpiera | ((DefaultComboBoxModel)getModel()).addElement(new FeatureTypeAttributeWrapper(featureAttributeDescriptor)); |
128 | } |
||
129 | |||
130 | public FeatureAttributeDescriptor getSelectedFeatureAttributeDescriptor(){
|
||
131 | return ((FeatureTypeAttributeWrapper)getSelectedItem()).getFeatureAttributeDescriptor();
|
||
132 | } |
||
133 | 38552 | jldominguez | |
134 | |||
135 | 28893 | jpiera | } |