root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / sde / gui / sdewizard2 / TablesListItem.java @ 11012
History | View | Annotate | Download (5.87 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.ArcSdeDriver; |
55 |
import com.iver.cit.gvsig.fmap.drivers.sde.VectorialSDEDriver; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Utility class that represents a table list item as a selectable check box.
|
60 |
*
|
61 |
* @author jldominguez
|
62 |
*
|
63 |
*/
|
64 |
public class TablesListItem extends JCheckBox { |
65 |
private String tableName = ""; |
66 |
private UserSelectedFieldsPanel selectedFieldsPanel = null; |
67 |
private UserTableSettingsPanel tableSettingsPanel = null; |
68 |
private VectorialSDEDriver driver = null; |
69 |
private SeConnection conn = null; |
70 |
private MapControl mc;
|
71 |
private WizardSDE parent = null; |
72 |
private boolean activated = false; |
73 |
|
74 |
public TablesListItem(String name, VectorialSDEDriver drv, SeConnection _conn, |
75 |
MapControl _mc, WizardSDE _parent) { |
76 |
tableName = name; |
77 |
setText(name); |
78 |
driver = drv; |
79 |
conn = _conn; |
80 |
mc = _mc; |
81 |
parent = _parent; |
82 |
} |
83 |
|
84 |
public void activate() { |
85 |
activated = true;
|
86 |
selectedFieldsPanel.loadValues(); |
87 |
tableSettingsPanel.loadValues(); |
88 |
} |
89 |
|
90 |
public boolean isActivated() { |
91 |
return activated;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* Tells whether this item prevents the wizard from being in a valid final state.
|
96 |
* @return whether this item prevents the wizard from being in a valid final state.
|
97 |
*/
|
98 |
public boolean disturbsWizardValidity() { |
99 |
if (isSelected()) {
|
100 |
return (!hasValidValues());
|
101 |
} |
102 |
else {
|
103 |
return false; |
104 |
} |
105 |
} |
106 |
|
107 |
private boolean hasValidValues() { |
108 |
return tableSettingsPanel.hasValidValues();
|
109 |
} |
110 |
|
111 |
public String toString() { |
112 |
return tableName;
|
113 |
} |
114 |
|
115 |
public String getTableName() { |
116 |
return tableName;
|
117 |
} |
118 |
|
119 |
public void setEnabledPanels(boolean b) { |
120 |
selectedFieldsPanel.enableControls(b); |
121 |
tableSettingsPanel.enableControls(b); |
122 |
} |
123 |
|
124 |
public UserSelectedFieldsPanel getUserSelectedFieldsPanel()
|
125 |
throws SQLException { |
126 |
if (selectedFieldsPanel == null) { |
127 |
String[] allf = getAllFields(conn, tableName); |
128 |
String[] allt = getAllFieldTypeNames(conn, tableName); |
129 |
selectedFieldsPanel = new UserSelectedFieldsPanel(allf, allt, true, |
130 |
parent); |
131 |
} |
132 |
|
133 |
return selectedFieldsPanel;
|
134 |
} |
135 |
|
136 |
public UserTableSettingsPanel getUserTableSettingsPanel()
|
137 |
throws SQLException { |
138 |
if (tableSettingsPanel == null) { |
139 |
String[] ids = getIdFieldsCandidates(conn, tableName); |
140 |
String[] geos = getGeometryFieldsCandidates(conn, tableName); |
141 |
|
142 |
int ids_size = ids.length;
|
143 |
FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
144 |
|
145 |
for (int i = 0; i < ids_size; i++) |
146 |
ids_ci[i] = new FieldComboItem(ids[i]);
|
147 |
|
148 |
int geos_size = geos.length;
|
149 |
FieldComboItem[] geos_ci = new FieldComboItem[geos_size]; |
150 |
|
151 |
for (int i = 0; i < geos_size; i++) |
152 |
geos_ci[i] = new FieldComboItem(geos[i]);
|
153 |
|
154 |
tableSettingsPanel = new UserTableSettingsPanel(ids_ci, geos_ci,
|
155 |
tableName, mc, true, parent);
|
156 |
} |
157 |
|
158 |
return tableSettingsPanel;
|
159 |
} |
160 |
|
161 |
|
162 |
|
163 |
public String[] getAllFields(Object conex, String tableName) { |
164 |
try {
|
165 |
SeTable table = new SeTable(((SeConnection)conex),tableName);
|
166 |
SeRegisteredColumn[] columns=table.getColumnList();
|
167 |
String[] fieldNames=new String[columns.length]; |
168 |
for (int i=0; i < columns.length; i++){ |
169 |
fieldNames[i]=columns[i].getName(); |
170 |
} |
171 |
return fieldNames;
|
172 |
} catch (SeException e) {
|
173 |
e.printStackTrace(); |
174 |
} |
175 |
return null; |
176 |
} |
177 |
public String[] getAllFieldTypeNames(Object conex, String tableName) { |
178 |
try {
|
179 |
SeTable table = new SeTable(((SeConnection)conex),tableName);
|
180 |
SeRegisteredColumn[] columns=table.getColumnList();
|
181 |
String[] fieldNames=new String[columns.length]; |
182 |
for (int i=0; i < columns.length; i++){ |
183 |
fieldNames[i]=String.valueOf(columns[i].getType());
|
184 |
} |
185 |
return fieldNames;
|
186 |
} catch (SeException e) {
|
187 |
e.printStackTrace(); |
188 |
} |
189 |
return null; |
190 |
} |
191 |
public String[] getIdFieldsCandidates(Object conn2, String tableName) { |
192 |
return new String[]{"OBJECTID"};//getAllFields(conn2,tableName); |
193 |
} |
194 |
public String[] getGeometryFieldsCandidates(Object conn2, String tableName) { |
195 |
return new String[]{"SHAPE"};//getAllFields(conn2,tableName); |
196 |
} |
197 |
|
198 |
} |