Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / TablesListItemVectorial.java @ 29628

History | View | Annotate | Download (3.83 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
* 2009 IVER T.I   {{Task}}
26
*/
27

    
28
package org.gvsig.geodb.vectorialdb.wizard;
29

    
30
import java.util.ArrayList;
31
import java.util.Iterator;
32

    
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.fmap.dal.DataTypes;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureType;
38
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer;
39
import org.gvsig.fmap.dal.store.db.DBStoreParameters;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41

    
42

    
43
public class TablesListItemVectorial extends TablesListItem {
44
        private MapControl mc;
45

    
46

    
47
        public TablesListItemVectorial(DBServerExplorer explorer,
48
                        DBStoreParameters param,
49
                        MapControl _mc, WizardVectorialDB _parent) {
50
                super(explorer, param, _parent);
51
                mc = _mc;
52
        }
53

    
54
    public UserTableSettingsPanel getUserTableSettingsPanel(String espView) {
55
                if (tableSettingsPanel == null) {
56

    
57
                        String[] ids = new String[0];
58
                        FeatureType ft = null;
59

    
60
                        try {
61
                                ft = explorer.getFeatureType(parameters);
62
                        } catch (DataException e) {
63
                                NotificationManager.addError(e);
64
                                return null;
65
                        }
66

    
67
                        ArrayList auxAll = new ArrayList();
68
                        String[] geos = new String[0];
69
                        ArrayList auxGeo = new ArrayList();
70
                        ArrayList auxId = new ArrayList();
71
                        Iterator iter = ft.iterator();
72
                        while (iter.hasNext()) {
73
                                FeatureAttributeDescriptor dbattr = (FeatureAttributeDescriptor) iter
74
                                                .next();
75
                                if (dbattr.getDataType() == DataTypes.GEOMETRY) {
76
                                        auxGeo.add(dbattr.getName());
77
                                }
78
                                if (dbattr.isPrimaryKey()) {
79
                                        auxId.add(dbattr.getName());
80
                                }
81
                                auxAll.add(dbattr.getName());
82

    
83
                        }
84

    
85
                        geos = (String[]) auxGeo.toArray(new String[0]);
86
                        if (auxId.size() > 0) {
87
                                StringBuilder strb = new StringBuilder();
88
                                strb.append('{');
89
                                for (int i = 0; i < auxId.size() - 1; i++) {
90
                                        strb.append(((FeatureAttributeDescriptor) auxId.get(i))
91
                                                        .getName());
92
                                        strb.append(',');
93
                                }
94
                                strb.append(auxId.get(auxId.size() - 1));
95

    
96
                                strb.append('}');
97
                                if (auxId.size() == 1) {
98
                                        auxAll.remove(auxId.get(0));
99
                                }
100
                                auxAll.add(0, strb.toString());
101
                        }
102
                        ids = (String[]) auxAll.toArray(new String[auxAll.size()]);
103
                        int ids_size = ids.length;
104
                        FieldComboItem[] ids_ci = new FieldComboItem[ids_size];
105

    
106
                        for (int i = 0; i < ids_size; i++) {
107
                                ids_ci[i] = new FieldComboItem(ids[i]);
108
                        }
109

    
110

    
111
                        int geos_size = geos.length;
112
                        FieldComboItem[] geos_ci = new FieldComboItem[geos_size];
113

    
114
                        for (int i = 0; i < geos_size; i++) {
115
                                geos_ci[i] = new FieldComboItem(geos[i]);
116
                        }
117

    
118
                        tableSettingsPanel = new UserTableSettingsVectorialPanel(ids_ci,
119
                                        geos_ci,
120
                                        tableName, mc, false, (WizardVectorialDB) parent,
121
                                        getParameters(),
122
                                        currentProjection(espView,
123
                                                        ids_ci, geos_ci));
124
                }
125

    
126
                return tableSettingsPanel;
127
        }
128

    
129
    public void setEnabledPanels(boolean b) {
130
            super.setEnabledPanels(b);
131
                tableSettingsPanel.enableSpatialControls(b);
132
                tableSettingsPanel.enableAlphaControls(b);
133
        }
134

    
135
}