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 @ 43360

History | View | Annotate | Download (4.94 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 javax.swing.JOptionPane;
31

    
32
import org.gvsig.andami.messages.NotificationManager;
33
import org.gvsig.app.ApplicationLocator;
34
import org.gvsig.app.ApplicationManager;
35
import org.gvsig.app.project.ProjectManager;
36
import org.gvsig.fmap.dal.DataTypes;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.FeatureType;
40
import org.gvsig.fmap.dal.store.db.DBStoreParameters;
41
import org.gvsig.fmap.mapcontrol.MapControl;
42
import org.gvsig.i18n.Messages;
43

    
44

    
45
public class TablesListItemVectorial extends TablesListItem {
46
        private MapControl mc;
47

    
48

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

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

    
58
                        String[] ids = new String[0];
59
                        FeatureType ft = null;
60
                        FeatureAttributeDescriptor dbattr = null;
61

    
62
                        try {
63
                                ft = this.parent.getServerExplorer().getFeatureType(parameters);
64
                        } catch (DataException e) {
65
                                NotificationManager.addError(e);
66
                                return null;
67
                        }
68

    
69
                        ArrayList auxAll = new ArrayList();
70

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

    
84
                        }
85

    
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(auxId.get(i));
91
                                        strb.append(',');
92
                                }
93
                                strb.append(auxId.get(auxId.size() - 1));
94

    
95
                                strb.append('}');
96
                                /*
97
                                 * Only the true PK from the DB
98
                                 */
99
                                auxAll.clear();
100
                                auxAll.add(strb.toString());
101
                        } else {
102
                            /*
103
                             * If the table does not hace PK declared in the DB,
104
                             * we let the user choose any field and show a warning dialog
105
                             */
106
                            showNoPkWarning(this.tableName);
107
                        }
108
                        
109
                        // ===============================
110
                        
111
                        ids = (String[]) auxAll.toArray(new String[auxAll.size()]);
112
                        int ids_size = ids.length;
113
                        FieldComboItem[] ids_ci = new FieldComboItem[ids_size];
114

    
115
                        for (int i = 0; i < ids_size; i++) {
116
                                ids_ci[i] = new FieldComboItem(ids[i]);
117
                        }
118

    
119

    
120
                        int geos_size = geo_atts.size();
121
                        FieldComboItem[] geos_ci = new FieldComboItem[geos_size];
122

    
123
                        for (int i = 0; i < geos_size; i++) {
124
                            dbattr = (FeatureAttributeDescriptor) geo_atts.get(i);
125
                                geos_ci[i] = new FieldComboItem(dbattr.getName(), dbattr.getSRS());
126
                        }
127

    
128
                        tableSettingsPanel = new UserTableSettingsVectorialPanel(ids_ci,
129
                                        geos_ci,
130
                                        tableName, mc, false, (WizardVectorialDB) parent,
131
                                        getParameters(),
132
                                        currentProjection(espView,
133
                                                        ids_ci, geos_ci));
134
                }
135

    
136
                return tableSettingsPanel;
137
        }
138

    
139
    private void showNoPkWarning(String tableName) {
140
        ApplicationManager application = ApplicationLocator.getManager();
141
        String msg = Messages.getText(
142
            "_Table_NAME_does_not_have_declared_PK", new String[] { tableName } );
143
        msg = msg + "\n\n";
144
        msg = msg + Messages.getText(
145
            "_If_layer_edited_saving_edits_will_not_be_possible");
146
        msg = msg + "\n";
147
        msg = msg + Messages.getText(
148
            "_Strange_behavior_if_selected_ID_not_unique_values");
149
        msg = msg + "      ";
150
        
151
        application.messageDialog(
152
            msg, 
153
            null, 
154
            Messages.getText("_Id_field"), 
155
            JOptionPane.WARNING_MESSAGE, 
156
            "show_no_primary_key_warning_in_database_tables"
157
        );
158

    
159
    }
160

    
161
    public void setEnabledPanels(boolean b) {
162
            super.setEnabledPanels(b);
163
                tableSettingsPanel.enableSpatialControls(b);
164
                tableSettingsPanel.enableAlphaControls(b);
165
        }
166

    
167
}