svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / project / documents / table / FieldSelectionModel.java @ 47784
History | View | Annotate | Download (3.13 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40558 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40558 | jjdelcerro | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.app.project.documents.table; |
||
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.Iterator; |
||
28 | import java.util.List; |
||
29 | |||
30 | import org.gvsig.fmap.dal.exception.DataException; |
||
31 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
32 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
33 | import org.gvsig.tools.dataTypes.DataTypes; |
||
34 | import org.gvsig.utils.swing.objectSelection.ObjectSelectionModel; |
||
35 | import org.gvsig.utils.swing.objectSelection.SelectionException; |
||
36 | |||
37 | /**
|
||
38 | * @author Fernando Gonz?lez Cort?s
|
||
39 | */
|
||
40 | public class FieldSelectionModel implements ObjectSelectionModel { |
||
41 | |||
42 | // final static private Logger logger =
|
||
43 | // LoggerFactory.getLogger(FieldSelectionModel.class);
|
||
44 | |||
45 | private FeatureStore fs;
|
||
46 | private String msg; |
||
47 | private int type = DataTypes.INVALID; |
||
48 | private boolean selectAll = false; |
||
49 | |||
50 | /**
|
||
51 | * Crea un nuevo FirstFieldSelectionModel.
|
||
52 | *
|
||
53 | */
|
||
54 | public FieldSelectionModel(FeatureStore fs, String msg, int type) { |
||
55 | this.fs = fs;
|
||
56 | this.msg = msg;
|
||
57 | this.type = type;
|
||
58 | } |
||
59 | |||
60 | public FieldSelectionModel(FeatureStore fs, String msg) { |
||
61 | this(fs, msg, DataTypes.UNKNOWN);
|
||
62 | selectAll = true;
|
||
63 | } |
||
64 | |||
65 | @SuppressWarnings("unchecked") |
||
66 | public Object[] getObjects() throws SelectionException { |
||
67 | |||
68 | List<String> fields = new ArrayList<String>(); |
||
69 | Iterator<FeatureAttributeDescriptor> iterator = null; |
||
70 | try {
|
||
71 | iterator = fs.getDefaultFeatureType().iterator(); |
||
72 | } catch (DataException e) {
|
||
73 | throw new SelectionException( |
||
74 | "Can't create iterator for the atribute of feature type", e);
|
||
75 | } |
||
76 | while (iterator.hasNext()) {
|
||
77 | FeatureAttributeDescriptor descriptor = iterator.next(); |
||
78 | if (type != DataTypes.INVALID) {
|
||
79 | if ((descriptor.getType() == type) || selectAll) {
|
||
80 | fields.add(descriptor.getName()); |
||
81 | } |
||
82 | } else {
|
||
83 | fields.add(descriptor.getName()); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | return (String[]) fields.toArray(new String[fields.size()]); |
||
88 | } |
||
89 | |||
90 | /**
|
||
91 | * @see org.gvsig.utils.swing.objectSelection.ObjectSelectionModel#getMsg()
|
||
92 | */
|
||
93 | public String getMsg() { |
||
94 | return msg;
|
||
95 | } |
||
96 | } |