root / branches / v10 / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / gui / jdbcwizard / TablesListItem.java @ 13995
History | View | Annotate | Download (5.47 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 es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard; |
44 |
|
45 |
import com.iver.andami.PluginServices; |
46 |
import com.iver.cit.gvsig.fmap.MapControl; |
47 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
48 |
|
49 |
import java.sql.Connection; |
50 |
import java.sql.SQLException; |
51 |
|
52 |
import javax.swing.JCheckBox; |
53 |
import javax.swing.JOptionPane; |
54 |
|
55 |
|
56 |
/**
|
57 |
* Utility class that represents a table list item as a selectable check box.
|
58 |
*
|
59 |
* @author jldominguez
|
60 |
*
|
61 |
*/
|
62 |
public class TablesListItem extends JCheckBox { |
63 |
private String tableName = ""; |
64 |
private UserSelectedFieldsPanel selectedFieldsPanel = null; |
65 |
private UserTableSettingsPanel tableSettingsPanel = null; |
66 |
private DefaultDBDriver driver = null; |
67 |
private Connection conn = null; |
68 |
private MapControl mc;
|
69 |
private WizardJDBC parent = null; |
70 |
private boolean activated = false; |
71 |
|
72 |
public TablesListItem(String name, DefaultDBDriver drv, Connection _conn, |
73 |
MapControl _mc, WizardJDBC _parent) { |
74 |
tableName = name; |
75 |
setText(name); |
76 |
driver = drv; |
77 |
conn = _conn; |
78 |
mc = _mc; |
79 |
parent = _parent; |
80 |
} |
81 |
|
82 |
public void activate() { |
83 |
activated = true;
|
84 |
selectedFieldsPanel.loadValues(); |
85 |
tableSettingsPanel.loadValues(); |
86 |
} |
87 |
|
88 |
public boolean isActivated() { |
89 |
return activated;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Tells whether this item prevents the wizard from being in a valid final state.
|
94 |
* @return whether this item prevents the wizard from being in a valid final state.
|
95 |
*/
|
96 |
public boolean disturbsWizardValidity() { |
97 |
if (isSelected()) {
|
98 |
return (!hasValidValues());
|
99 |
} |
100 |
else {
|
101 |
return false; |
102 |
} |
103 |
} |
104 |
|
105 |
private boolean hasValidValues() { |
106 |
return tableSettingsPanel.hasValidValues();
|
107 |
} |
108 |
|
109 |
public String toString() { |
110 |
return tableName;
|
111 |
} |
112 |
|
113 |
public String getTableName() { |
114 |
return tableName;
|
115 |
} |
116 |
|
117 |
public void setEnabledPanels(boolean b) { |
118 |
selectedFieldsPanel.enableControls(b); |
119 |
tableSettingsPanel.enableControls(b); |
120 |
} |
121 |
|
122 |
public UserSelectedFieldsPanel getUserSelectedFieldsPanel()
|
123 |
throws SQLException { |
124 |
if (selectedFieldsPanel == null) { |
125 |
String[] allf = driver.getAllFields(conn, tableName); |
126 |
String[] allt = driver.getAllFieldTypeNames(conn, tableName); |
127 |
selectedFieldsPanel = new UserSelectedFieldsPanel(allf, allt, true, |
128 |
parent); |
129 |
} |
130 |
|
131 |
return selectedFieldsPanel;
|
132 |
} |
133 |
|
134 |
public UserTableSettingsPanel getUserTableSettingsPanel()
|
135 |
throws SQLException { |
136 |
if (tableSettingsPanel == null) { |
137 |
|
138 |
String[] ids = new String[0]; |
139 |
try {
|
140 |
ids = driver.getIdFieldsCandidates(conn, tableName); |
141 |
} catch (SQLException se) { |
142 |
String msg = PluginServices.getText(this, "id_not_available") + " " + tableName |
143 |
+ ":\n" + se.getMessage();
|
144 |
String title = PluginServices.getText(this, "id_error"); |
145 |
JOptionPane.showMessageDialog(parent, msg, title, JOptionPane.ERROR_MESSAGE); |
146 |
setSelected(false);
|
147 |
} |
148 |
|
149 |
String[] geos = new String[0]; |
150 |
try {
|
151 |
geos = driver.getGeometryFieldsCandidates(conn, tableName); |
152 |
} catch (SQLException se) { |
153 |
String msg = PluginServices.getText(this, "geo_field_not_available") |
154 |
+ ":\n" + PluginServices.getText(this, se.getMessage()) + ": " + tableName; |
155 |
String title = PluginServices.getText(this, "geo_field_error"); |
156 |
JOptionPane.showMessageDialog(parent, msg, title, JOptionPane.ERROR_MESSAGE); |
157 |
setSelected(false);
|
158 |
} |
159 |
|
160 |
int ids_size = ids.length;
|
161 |
FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
162 |
|
163 |
for (int i = 0; i < ids_size; i++) |
164 |
ids_ci[i] = new FieldComboItem(ids[i]);
|
165 |
|
166 |
int geos_size = geos.length;
|
167 |
FieldComboItem[] geos_ci = new FieldComboItem[geos_size]; |
168 |
|
169 |
for (int i = 0; i < geos_size; i++) |
170 |
geos_ci[i] = new FieldComboItem(geos[i]);
|
171 |
|
172 |
tableSettingsPanel = new UserTableSettingsPanel(ids_ci, geos_ci,
|
173 |
tableName, mc, true, parent);
|
174 |
} |
175 |
|
176 |
return tableSettingsPanel;
|
177 |
} |
178 |
} |