Statistics
| Revision:

root / trunk / extensions / extSDE / src / com / iver / cit / gvsig / sde / gui / sdewizard2 / TablesListItem.java @ 11193

History | View | Annotate | Download (5.82 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package com.iver.cit.gvsig.sde.gui.sdewizard2;
44

    
45
import java.sql.SQLException;
46

    
47
import javax.swing.JCheckBox;
48

    
49
import com.esri.sde.sdk.client.SeConnection;
50
import com.esri.sde.sdk.client.SeException;
51
import com.esri.sde.sdk.client.SeRegisteredColumn;
52
import com.esri.sde.sdk.client.SeTable;
53
import com.iver.cit.gvsig.fmap.MapControl;
54
import com.iver.cit.gvsig.fmap.drivers.sde.VectorialSDEDriver;
55

    
56

    
57
/**
58
 * Utility class that represents a table list item as a selectable check box.
59
 *
60
 * @author jldominguez
61
 *
62
 */
63
public class TablesListItem extends JCheckBox {
64
    private String tableName = "";
65
    private UserSelectedFieldsPanel selectedFieldsPanel = null;
66
    private UserTableSettingsPanel tableSettingsPanel = null;
67
    private VectorialSDEDriver driver = null;
68
    private SeConnection conn = null;
69
    private MapControl mc;
70
    private WizardSDE parent = null;
71
    private boolean activated = false;
72

    
73
    public TablesListItem(String name, VectorialSDEDriver drv, SeConnection _conn,
74
        MapControl _mc, WizardSDE _parent) {
75
        tableName = name;
76
        setText(name);
77
        driver = drv;
78
        conn = _conn;
79
        mc = _mc;
80
        parent = _parent;
81
    }
82

    
83
    public void activate() {
84
        activated = true;
85
        selectedFieldsPanel.loadValues();
86
        tableSettingsPanel.loadValues();
87
    }
88

    
89
    public boolean isActivated() {
90
        return activated;
91
    }
92

    
93
    /**
94
     * Tells whether this item prevents the wizard from being in a valid final state.
95
     * @return whether this item prevents the wizard from being in a valid final state.
96
     */
97
    public boolean disturbsWizardValidity() {
98
        if (isSelected()) {
99
            return (!hasValidValues());
100
        }
101
        else {
102
            return false;
103
        }
104
    }
105

    
106
    private boolean hasValidValues() {
107
        return tableSettingsPanel.hasValidValues();
108
    }
109

    
110
    public String toString() {
111
        return tableName;
112
    }
113

    
114
    public String getTableName() {
115
        return tableName;
116
    }
117

    
118
    public void setEnabledPanels(boolean b) {
119
        selectedFieldsPanel.enableControls(b);
120
        tableSettingsPanel.enableControls(b);
121
    }
122

    
123
    public UserSelectedFieldsPanel getUserSelectedFieldsPanel()
124
        throws SQLException {
125
        if (selectedFieldsPanel == null) {
126
            String[] allf = getAllFields(conn, tableName);
127
            String[] allt = getAllFieldTypeNames(conn, tableName);
128
            selectedFieldsPanel = new UserSelectedFieldsPanel(allf, allt, true,
129
                    parent);
130
        }
131

    
132
        return selectedFieldsPanel;
133
    }
134

    
135
    public UserTableSettingsPanel getUserTableSettingsPanel()
136
        throws SQLException {
137
        if (tableSettingsPanel == null) {
138
            String[] ids = getIdFieldsCandidates(conn, tableName);
139
            String[] geos = getGeometryFieldsCandidates(conn, tableName);
140

    
141
            int ids_size = ids.length;
142
            FieldComboItem[] ids_ci = new FieldComboItem[ids_size];
143

    
144
            for (int i = 0; i < ids_size; i++)
145
                ids_ci[i] = new FieldComboItem(ids[i]);
146

    
147
            int geos_size = geos.length;
148
            FieldComboItem[] geos_ci = new FieldComboItem[geos_size];
149

    
150
            for (int i = 0; i < geos_size; i++)
151
                geos_ci[i] = new FieldComboItem(geos[i]);
152

    
153
            tableSettingsPanel = new UserTableSettingsPanel(ids_ci, geos_ci,
154
                    tableName, mc, true, parent);
155
        }
156

    
157
        return tableSettingsPanel;
158
    }
159

    
160

    
161

    
162
    public String[] getAllFields(Object conex, String tableName) {
163
                try {
164
                        SeTable table = new SeTable(((SeConnection)conex),tableName);
165
                        SeRegisteredColumn[] columns=table.getColumnList();
166
                        String[] fieldNames=new String[columns.length];
167
                        for (int i=0; i < columns.length; i++){
168
                                fieldNames[i]=columns[i].getName();
169
                        }
170
                        return fieldNames;
171
                } catch (SeException e) {
172
                        e.printStackTrace();
173
                }
174
                return null;
175
        }
176
        public String[] getAllFieldTypeNames(Object conex, String tableName) {
177
                try {
178
                        SeTable table = new SeTable(((SeConnection)conex),tableName);
179
                        SeRegisteredColumn[] columns=table.getColumnList();
180
                        String[] fieldNames=new String[columns.length];
181
                        for (int i=0; i < columns.length; i++){
182
                                fieldNames[i]=String.valueOf(columns[i].getType());
183
                        }
184
                        return fieldNames;
185
                } catch (SeException e) {
186
                        e.printStackTrace();
187
                }
188
                return null;
189
        }
190
        public String[] getIdFieldsCandidates(Object conn2, String tableName) {
191
                return new String[]{"OBJECTID"};//getAllFields(conn2,tableName);
192
        }
193
        public String[] getGeometryFieldsCandidates(Object conn2, String tableName) {
194
                return new String[]{"SHAPE"};//getAllFields(conn2,tableName);
195
        }
196

    
197
}