Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / project / documents / table / FieldSelectionModel.java @ 36443

History | View | Annotate | Download (3.09 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
package org.gvsig.app.project.documents.table;
23

    
24
import java.util.ArrayList;
25
import java.util.Iterator;
26
import java.util.List;
27

    
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.tools.dataTypes.DataTypes;
32
import org.gvsig.utils.swing.objectSelection.ObjectSelectionModel;
33
import org.gvsig.utils.swing.objectSelection.SelectionException;
34

    
35
/**
36
 * @author Fernando Gonz?lez Cort?s
37
 */
38
public class FieldSelectionModel implements ObjectSelectionModel {
39

    
40
    // final static private Logger logger =
41
    // LoggerFactory.getLogger(FieldSelectionModel.class);
42

    
43
    private FeatureStore fs;
44
    private String msg;
45
    private int type = DataTypes.INVALID;
46
    private boolean selectAll = false;
47

    
48
    /**
49
     * Crea un nuevo FirstFieldSelectionModel.
50
     * 
51
     */
52
    public FieldSelectionModel(FeatureStore fs, String msg, int type) {
53
        this.fs = fs;
54
        this.msg = msg;
55
        this.type = type;
56
    }
57

    
58
    public FieldSelectionModel(FeatureStore fs, String msg) {
59
        this(fs, msg, DataTypes.UNKNOWN);
60
        selectAll = true;
61
    }
62

    
63
    @SuppressWarnings("unchecked")
64
    public Object[] getObjects() throws SelectionException {
65

    
66
        List<String> fields = new ArrayList<String>();
67
        Iterator<FeatureAttributeDescriptor> iterator = null;
68
        try {
69
            iterator = fs.getDefaultFeatureType().iterator();
70
        } catch (DataException e) {
71
            throw new SelectionException(
72
                "Can't create iterator for the atribute of feature type", e);
73
        }
74
        while (iterator.hasNext()) {
75
            FeatureAttributeDescriptor descriptor = iterator.next();
76
            if (type != DataTypes.INVALID) {
77
                if ((descriptor.getType() == type) || selectAll) {
78
                    fields.add(descriptor.getName());
79
                }
80
            } else {
81
                fields.add(descriptor.getName());
82
            }
83
        }
84

    
85
        return (String[]) fields.toArray(new String[fields.size()]);
86
    }
87

    
88
    /**
89
     * @see org.gvsig.utils.swing.objectSelection.ObjectSelectionModel#getMsg()
90
     */
91
    public String getMsg() {
92
        return msg;
93
    }
94
}