root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / table / FieldSelectionModel.java @ 33331
History | View | Annotate | Download (1.75 KB)
1 |
package org.gvsig.app.project.documents.table; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
import java.util.List; |
6 |
|
7 |
import org.gvsig.fmap.dal.exception.DataException; |
8 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
9 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
10 |
import org.gvsig.tools.dataTypes.DataTypes; |
11 |
import org.gvsig.utils.swing.objectSelection.ObjectSelectionModel; |
12 |
import org.gvsig.utils.swing.objectSelection.SelectionException; |
13 |
|
14 |
|
15 |
|
16 |
/**
|
17 |
* @author Fernando Gonz?lez Cort?s
|
18 |
*/
|
19 |
public class FieldSelectionModel implements ObjectSelectionModel { |
20 |
// final static private Logger logger = LoggerFactory.getLogger(FieldSelectionModel.class);
|
21 |
|
22 |
private FeatureStore fs;
|
23 |
private String msg; |
24 |
private int type = DataTypes.INVALID; |
25 |
|
26 |
/**
|
27 |
* Crea un nuevo FirstFieldSelectionModel.
|
28 |
*
|
29 |
*/
|
30 |
public FieldSelectionModel(FeatureStore fs, String msg, int type) { |
31 |
this.fs = fs;
|
32 |
this.msg = msg;
|
33 |
this.type = type;
|
34 |
} |
35 |
|
36 |
@SuppressWarnings("unchecked") |
37 |
public Object[] getObjects() throws SelectionException { |
38 |
|
39 |
List<String> fields = new ArrayList<String>(); |
40 |
Iterator<FeatureAttributeDescriptor> iterator=null; |
41 |
try {
|
42 |
iterator = fs.getDefaultFeatureType().iterator(); |
43 |
} catch (DataException e) {
|
44 |
throw new SelectionException("Can't create iterator for the atribute of feature type",e); |
45 |
} |
46 |
while (iterator.hasNext()) {
|
47 |
FeatureAttributeDescriptor descriptor = iterator.next(); |
48 |
if ( type != DataTypes.INVALID ){
|
49 |
if (descriptor.getType() == type) {
|
50 |
fields.add(descriptor.getName()); |
51 |
} |
52 |
}else{
|
53 |
fields.add(descriptor.getName()); |
54 |
} |
55 |
} |
56 |
|
57 |
return (String[]) fields.toArray(); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* @see org.gvsig.utils.swing.objectSelection.ObjectSelectionModel#getMsg()
|
62 |
*/
|
63 |
public String getMsg() { |
64 |
return msg;
|
65 |
} |
66 |
} |