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 / TablesListItem.java @ 40557
History | View | Annotate | Download (6.84 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 |
package org.gvsig.geodb.vectorialdb.wizard; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
28 |
|
29 |
import javax.swing.JCheckBox; |
30 |
|
31 |
import org.cresques.cts.IProjection; |
32 |
import org.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
import org.gvsig.andami.messages.NotificationManager; |
36 |
import org.gvsig.app.addlayer.AddLayerDialog; |
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.serverexplorer.db.DBServerExplorer; |
41 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
42 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
43 |
|
44 |
|
45 |
|
46 |
/**
|
47 |
* Utility class that represents a table list item as a selectable check box.
|
48 |
*
|
49 |
* @author jldominguez
|
50 |
*
|
51 |
*/
|
52 |
public class TablesListItem extends JCheckBox { |
53 |
|
54 |
private static Logger logger = LoggerFactory.getLogger(TablesListItem.class); |
55 |
|
56 |
protected String tableName = ""; |
57 |
protected String schemaName = ""; |
58 |
|
59 |
private UserSelectedFieldsPanel selectedFieldsPanel = null; |
60 |
protected WizardDB parent = null; |
61 |
private boolean activated = false; |
62 |
// private CRSSelectPanel jPanelProj;
|
63 |
protected DBStoreParameters parameters;
|
64 |
protected DBServerExplorer explorer;
|
65 |
protected UserTableSettingsPanel tableSettingsPanel = null; |
66 |
|
67 |
public TablesListItem(DBServerExplorer explorer,
|
68 |
DBStoreParameters param, |
69 |
WizardDB _parent) { |
70 |
|
71 |
tableName = param.getTable(); |
72 |
schemaName = getSchema(param); |
73 |
|
74 |
setText(toString()); |
75 |
this.parameters = param;
|
76 |
this.explorer=explorer;
|
77 |
parent = _parent; |
78 |
} |
79 |
|
80 |
|
81 |
|
82 |
/**
|
83 |
* @param param
|
84 |
* @return
|
85 |
*/
|
86 |
private String getSchema(DBStoreParameters dynobj) { |
87 |
|
88 |
String resp = null; |
89 |
try {
|
90 |
resp = (String) dynobj.getDynValue(
|
91 |
JDBCConnectionParameters.SCHEMA_PARAMTER_NAME); |
92 |
} catch (Exception ex) { |
93 |
// logger.info("did not find schema in DB parameters.");
|
94 |
} |
95 |
return resp;
|
96 |
} |
97 |
|
98 |
public void activate() { |
99 |
activated = true;
|
100 |
selectedFieldsPanel.loadValues(); |
101 |
tableSettingsPanel.loadValues(); |
102 |
} |
103 |
|
104 |
public boolean isActivated() { |
105 |
return activated;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Tells whether this item prevents the wizard from being in a valid final state.
|
110 |
* @return whether this item prevents the wizard from being in a valid final state.
|
111 |
*/
|
112 |
public boolean disturbsWizardValidity() { |
113 |
if (isSelected()) {
|
114 |
return (!hasValidValues());
|
115 |
} |
116 |
else {
|
117 |
return false; |
118 |
} |
119 |
} |
120 |
|
121 |
private boolean hasValidValues() { |
122 |
return tableSettingsPanel.hasValidValues();
|
123 |
} |
124 |
|
125 |
public String toString() { |
126 |
if (schemaName == null || schemaName.length() == 0) { |
127 |
return tableName;
|
128 |
} else {
|
129 |
return schemaName + "." + tableName; |
130 |
} |
131 |
|
132 |
} |
133 |
|
134 |
public String getTableName() { |
135 |
return tableName;
|
136 |
} |
137 |
|
138 |
public void setEnabledPanels(boolean b) { |
139 |
selectedFieldsPanel.enableControls(b); |
140 |
tableSettingsPanel.enableAlphaControls(b); |
141 |
tableSettingsPanel.enableSpatialControls(b); |
142 |
|
143 |
} |
144 |
|
145 |
public UserSelectedFieldsPanel getUserSelectedFieldsPanel() {
|
146 |
if (selectedFieldsPanel == null) { |
147 |
FeatureType ft=null;
|
148 |
try {
|
149 |
ft = explorer.getFeatureType(parameters); |
150 |
} catch (DataException e) {
|
151 |
NotificationManager.addError(e); |
152 |
return null; |
153 |
} |
154 |
ArrayList<FeatureAttributeDescriptor> attList = new ArrayList<FeatureAttributeDescriptor>(); |
155 |
|
156 |
Iterator<FeatureAttributeDescriptor> iter = ft.iterator();
|
157 |
while (iter.hasNext()) {
|
158 |
attList.add(iter.next()); |
159 |
} |
160 |
|
161 |
FeatureAttributeDescriptor[] allf = attList
|
162 |
.toArray(new FeatureAttributeDescriptor[0]); |
163 |
|
164 |
|
165 |
selectedFieldsPanel = new UserSelectedFieldsPanel(allf, false, |
166 |
parent); |
167 |
} |
168 |
|
169 |
return selectedFieldsPanel;
|
170 |
} |
171 |
|
172 |
public UserTableSettingsPanel getUserTableSettingsPanel() {
|
173 |
if (tableSettingsPanel == null) { |
174 |
|
175 |
String[] ids = new String[0]; |
176 |
FeatureType ft = null;
|
177 |
|
178 |
try {
|
179 |
ft = explorer.getFeatureType(parameters); |
180 |
} catch (DataException e) {
|
181 |
NotificationManager.addError(e); |
182 |
return null; |
183 |
} |
184 |
|
185 |
ArrayList auxAll = new ArrayList(); |
186 |
ArrayList auxId = new ArrayList(); |
187 |
Iterator iter = ft.iterator();
|
188 |
while (iter.hasNext()) {
|
189 |
FeatureAttributeDescriptor dbattr = (FeatureAttributeDescriptor) iter |
190 |
.next(); |
191 |
if (dbattr.isPrimaryKey()) {
|
192 |
auxId.add(dbattr.getName()); |
193 |
} |
194 |
auxAll.add(dbattr.getName()); |
195 |
|
196 |
} |
197 |
|
198 |
if (auxId.size() > 0) { |
199 |
StringBuilder strb = new StringBuilder(); |
200 |
strb.append('{');
|
201 |
for (int i = 0; i < auxId.size()-1; i++) { |
202 |
strb.append(auxId.get(i)); |
203 |
strb.append(',');
|
204 |
} |
205 |
strb.append(auxId.get(auxId.size() - 1));
|
206 |
|
207 |
strb.append('}');
|
208 |
if (auxId.size() == 1) { |
209 |
auxAll.remove(auxId.get(0));
|
210 |
} |
211 |
auxAll.add(0, strb.toString());
|
212 |
} |
213 |
ids = (String[]) auxAll.toArray(new String[auxAll.size()]); |
214 |
int ids_size = ids.length;
|
215 |
FieldComboItem[] ids_ci = new FieldComboItem[ids_size]; |
216 |
|
217 |
for (int i = 0; i < ids_size; i++) { |
218 |
ids_ci[i] = new FieldComboItem(ids[i]);
|
219 |
} |
220 |
|
221 |
|
222 |
|
223 |
tableSettingsPanel = new UserTableSettingsPanel(ids_ci, tableName,
|
224 |
true, parent, getParameters());
|
225 |
} |
226 |
|
227 |
return tableSettingsPanel;
|
228 |
} |
229 |
|
230 |
|
231 |
public IProjection currentProjection(String espView, |
232 |
FieldComboItem[] ids_ci, FieldComboItem[] geos_ci) { |
233 |
IProjection proj = AddLayerDialog.getLastProjection(); |
234 |
try {
|
235 |
ArrayList list = new ArrayList(1); |
236 |
list.add(espView); |
237 |
FeatureType ft = null;
|
238 |
try {
|
239 |
ft = explorer.getFeatureType(parameters); |
240 |
} catch (DataException e) {
|
241 |
// TODO Auto-generated catch block
|
242 |
e.printStackTrace(); |
243 |
} |
244 |
} catch (Exception e) { |
245 |
NotificationManager.addInfo("Incorrect projection", e);
|
246 |
} |
247 |
return proj;
|
248 |
} |
249 |
|
250 |
public DBStoreParameters getParameters() {
|
251 |
return parameters;
|
252 |
} |
253 |
} |