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