Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / vectorialdb / wizard / TablesListItemVectorial.java @ 40596

History | View | Annotate | Download (3.81 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.geodb.vectorialdb.wizard;
26

    
27
import java.util.ArrayList;
28
import java.util.Iterator;
29

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

    
39

    
40
public class TablesListItemVectorial extends TablesListItem {
41
        private MapControl mc;
42

    
43

    
44
        public TablesListItemVectorial(DBServerExplorer explorer,
45
                        DBStoreParameters param,
46
                        MapControl _mc, WizardVectorialDB _parent) {
47
                super(explorer, param, _parent);
48
                mc = _mc;
49
        }
50

    
51
    public UserTableSettingsPanel getUserTableSettingsPanel(String espView) {
52
                if (tableSettingsPanel == null) {
53

    
54
                        String[] ids = new String[0];
55
                        FeatureType ft = null;
56
                        FeatureAttributeDescriptor dbattr = null;
57

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

    
65
                        ArrayList auxAll = new ArrayList();
66

    
67
                        ArrayList geo_atts = new ArrayList();
68
                        ArrayList auxId = new ArrayList();
69
                        Iterator iter = ft.iterator();
70
                        while (iter.hasNext()) {
71
                                dbattr = (FeatureAttributeDescriptor) iter.next();
72
                                if (dbattr.getDataType().getType() == DataTypes.GEOMETRY) {
73
                                    geo_atts.add(dbattr);
74
                                }
75
                                if (dbattr.isPrimaryKey()) {
76
                                        auxId.add(dbattr.getName());
77
                                }
78
                                auxAll.add(dbattr.getName());
79

    
80
                        }
81

    
82
                        if (auxId.size() > 0) {
83
                                StringBuilder strb = new StringBuilder();
84
                                strb.append('{');
85
                                for (int i = 0; i < auxId.size() - 1; i++) {
86
                                        strb.append(auxId.get(i));
87
                                        strb.append(',');
88
                                }
89
                                strb.append(auxId.get(auxId.size() - 1));
90

    
91
                                strb.append('}');
92
                                if (auxId.size() == 1) {
93
                                        auxAll.remove(auxId.get(0));
94
                                }
95
                                auxAll.add(0, strb.toString());
96
                        }
97
                        ids = (String[]) auxAll.toArray(new String[auxAll.size()]);
98
                        int ids_size = ids.length;
99
                        FieldComboItem[] ids_ci = new FieldComboItem[ids_size];
100

    
101
                        for (int i = 0; i < ids_size; i++) {
102
                                ids_ci[i] = new FieldComboItem(ids[i]);
103
                        }
104

    
105

    
106
                        int geos_size = geo_atts.size();
107
                        FieldComboItem[] geos_ci = new FieldComboItem[geos_size];
108

    
109
                        for (int i = 0; i < geos_size; i++) {
110
                            dbattr = (FeatureAttributeDescriptor) geo_atts.get(i);
111
                                geos_ci[i] = new FieldComboItem(dbattr.getName(), dbattr.getSRS());
112
                        }
113

    
114
                        tableSettingsPanel = new UserTableSettingsVectorialPanel(ids_ci,
115
                                        geos_ci,
116
                                        tableName, mc, false, (WizardVectorialDB) parent,
117
                                        getParameters(),
118
                                        currentProjection(espView,
119
                                                        ids_ci, geos_ci));
120
                }
121

    
122
                return tableSettingsPanel;
123
        }
124

    
125
    public void setEnabledPanels(boolean b) {
126
            super.setEnabledPanels(b);
127
                tableSettingsPanel.enableSpatialControls(b);
128
                tableSettingsPanel.enableAlphaControls(b);
129
        }
130

    
131
}