48 |
48 |
import java.util.List;
|
49 |
49 |
|
50 |
50 |
import org.cresques.cts.IProjection;
|
|
51 |
import org.slf4j.Logger;
|
|
52 |
import org.slf4j.LoggerFactory;
|
|
53 |
|
51 |
54 |
import org.gvsig.andami.PluginServices;
|
52 |
55 |
import org.gvsig.andami.messages.NotificationManager;
|
53 |
56 |
import org.gvsig.andami.ui.mdiManager.IWindow;
|
... | ... | |
70 |
73 |
import org.gvsig.fmap.mapcontext.layers.FLayers;
|
71 |
74 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
|
72 |
75 |
import org.gvsig.fmap.mapcontrol.MapControl;
|
73 |
|
import org.slf4j.Logger;
|
74 |
|
import org.slf4j.LoggerFactory;
|
75 |
76 |
|
76 |
77 |
|
77 |
78 |
|
... | ... | |
83 |
84 |
*
|
84 |
85 |
*/
|
85 |
86 |
public class WizardVectorialDB extends WizardDB {
|
86 |
|
/**
|
87 |
|
*
|
88 |
|
*/
|
89 |
87 |
private static final long serialVersionUID = -5002685263220038989L;
|
90 |
88 |
|
91 |
89 |
private static Logger logger = LoggerFactory
|
... | ... | |
193 |
191 |
PrepareContext context = this.getPrepareDataStoreContext();
|
194 |
192 |
|
195 |
193 |
|
196 |
|
FLayer layer;
|
197 |
|
for (int i = 0; i < tables.length; i++) {
|
198 |
|
table = tables[i];
|
199 |
|
UserTableSettingsVectorialPanel userTableSettingsPanel = (UserTableSettingsVectorialPanel) table
|
200 |
|
.getUserTableSettingsPanel();
|
201 |
|
parameter = getParameterForTable(table);
|
202 |
|
if (i == 0) {
|
203 |
|
groupName = parameter.getDBName() + " (" + parameter.getHost()
|
204 |
|
+ ")";
|
205 |
|
}
|
206 |
|
try {
|
207 |
|
parameter = (DBStoreParameters) appGvSIGMan
|
208 |
|
.prepareOpenDataStoreParameters(parameter, context);
|
|
194 |
try {
|
209 |
195 |
|
210 |
|
} catch (Exception e2) {
|
211 |
|
NotificationManager.addError(e2);
|
212 |
|
continue;
|
213 |
|
}
|
|
196 |
FLayer layer;
|
|
197 |
for (int i = 0; i < tables.length; i++) {
|
|
198 |
table = tables[i];
|
|
199 |
UserTableSettingsVectorialPanel userTableSettingsPanel =
|
|
200 |
(UserTableSettingsVectorialPanel) table
|
|
201 |
.getUserTableSettingsPanel();
|
|
202 |
parameter = getParameterForTable(table);
|
|
203 |
if (i == 0) {
|
|
204 |
groupName =
|
|
205 |
parameter.getDBName() + " (" + parameter.getHost()
|
|
206 |
+ ")";
|
|
207 |
}
|
|
208 |
try {
|
|
209 |
parameter =
|
|
210 |
(DBStoreParameters) appGvSIGMan
|
|
211 |
.prepareOpenDataStoreParameters(parameter, context);
|
214 |
212 |
|
215 |
|
try {
|
216 |
|
store = (FeatureStore) man.createStore(parameter);
|
217 |
|
} catch (Exception e) {
|
218 |
|
NotificationManager.addError(e);
|
219 |
|
return;
|
220 |
|
}
|
|
213 |
} catch (Exception e2) {
|
|
214 |
NotificationManager.addError(e2);
|
|
215 |
continue;
|
|
216 |
}
|
221 |
217 |
|
222 |
|
try {
|
223 |
|
storeToAdd = (FeatureStore) appGvSIGMan.pepareOpenDataSource(
|
224 |
|
store, context);
|
225 |
|
} catch (Exception e) {
|
226 |
|
NotificationManager.addError(e);
|
227 |
|
store.dispose();
|
228 |
|
continue;
|
229 |
|
}
|
|
218 |
try {
|
|
219 |
store = (FeatureStore) man.createStore(parameter);
|
|
220 |
} catch (Exception e) {
|
|
221 |
NotificationManager.addError(e);
|
|
222 |
return;
|
|
223 |
}
|
230 |
224 |
|
231 |
|
try {
|
|
225 |
try {
|
|
226 |
storeToAdd =
|
|
227 |
(FeatureStore) appGvSIGMan.pepareOpenDataSource(store,
|
|
228 |
context);
|
|
229 |
} catch (Exception e) {
|
|
230 |
NotificationManager.addError(e);
|
|
231 |
store.dispose();
|
|
232 |
continue;
|
|
233 |
}
|
232 |
234 |
|
233 |
|
layer = layerFactory.createLayer(userTableSettingsPanel
|
234 |
|
.getUserLayerName(), storeToAdd);
|
235 |
|
all_layers.add(layer);
|
236 |
|
if (env == null) {
|
237 |
|
env = layer.getFullEnvelope();
|
238 |
|
} else {
|
239 |
|
env.add(layer.getFullEnvelope());
|
240 |
|
}
|
241 |
|
layer.dispose();
|
242 |
|
} catch (Exception e) {
|
243 |
|
storeToAdd.dispose();
|
244 |
|
NotificationManager.addError(e);
|
245 |
|
}
|
246 |
|
}
|
|
235 |
try {
|
247 |
236 |
|
248 |
|
MapContext mc = mapControl.getMapContext();
|
249 |
|
FLayers root = mapControl.getMapContext().getLayers();
|
250 |
|
if (all_layers.size() > 1) {
|
251 |
|
FLayers group = new FLayers();// (mc,root);
|
252 |
|
group.setMapContext(mc);
|
253 |
|
group.setParentLayer(root);
|
254 |
|
group.setName(groupName);
|
|
237 |
layer =
|
|
238 |
layerFactory.createLayer(
|
|
239 |
userTableSettingsPanel.getUserLayerName(),
|
|
240 |
storeToAdd);
|
|
241 |
all_layers.add(layer);
|
|
242 |
if (env == null) {
|
|
243 |
env = layer.getFullEnvelope();
|
|
244 |
} else {
|
|
245 |
env.add(layer.getFullEnvelope());
|
|
246 |
}
|
|
247 |
storeToAdd.dispose();
|
|
248 |
} catch (Exception e) {
|
|
249 |
storeToAdd.dispose();
|
|
250 |
NotificationManager.addError(e);
|
|
251 |
}
|
|
252 |
}
|
255 |
253 |
|
256 |
|
Iterator iter = all_layers.iterator();
|
257 |
|
while (iter.hasNext()) {
|
258 |
|
group.addLayer((FLayer) iter.next());
|
259 |
|
}
|
|
254 |
MapContext mc = mapControl.getMapContext();
|
|
255 |
FLayers root = mapControl.getMapContext().getLayers();
|
|
256 |
if (all_layers.size() > 1) {
|
|
257 |
FLayers group = new FLayers();// (mc,root);
|
|
258 |
group.setMapContext(mc);
|
|
259 |
group.setParentLayer(root);
|
|
260 |
group.setName(groupName);
|
260 |
261 |
|
261 |
|
if ((group != null) && !(group.isOk())) {
|
262 |
|
// if the layer is not okay (it has errors) process them
|
263 |
|
processErrorsOfLayer(group, mapControl);
|
264 |
|
}
|
|
262 |
Iterator iter = all_layers.iterator();
|
|
263 |
while (iter.hasNext()) {
|
|
264 |
group.addLayer((FLayer) iter.next());
|
|
265 |
}
|
265 |
266 |
|
266 |
|
if (group != null) {
|
267 |
|
group.setVisible(true);
|
268 |
|
mapControl.getMapContext().beginAtomicEvent();
|
269 |
|
try {
|
270 |
|
// checkProjection(group, mapControl.getViewPort());
|
271 |
|
try {
|
272 |
|
mapControl.getMapContext().getLayers().addLayer(group);
|
273 |
|
group.dispose();
|
274 |
|
} catch (CancelationException e) {
|
275 |
|
// TODO Auto-generated catch block
|
276 |
|
e.printStackTrace();
|
277 |
|
}
|
278 |
|
if (mapControl.getViewPort().getExtent() == null) {
|
279 |
|
mapControl.getViewPort().setEnvelope(env);
|
280 |
|
}
|
281 |
|
} finally {
|
282 |
|
mapControl.getMapContext().endAtomicEvent();
|
283 |
|
}
|
284 |
|
return;
|
285 |
|
}
|
286 |
|
} else if (all_layers.size() == 1) {
|
287 |
|
layer = (FLayer) all_layers.get(0);
|
288 |
|
if (!(layer.isOk())) {
|
289 |
|
// if the layer is not okay (it has errors) process them
|
290 |
|
processErrorsOfLayer(layer, mapControl);
|
291 |
|
}
|
|
267 |
if ((group != null) && !(group.isOk())) {
|
|
268 |
// if the layer is not okay (it has errors) process them
|
|
269 |
processErrorsOfLayer(group, mapControl);
|
|
270 |
}
|
292 |
271 |
|
293 |
|
layer.setVisible(true);
|
294 |
|
mapControl.getMapContext().beginAtomicEvent();
|
295 |
|
// checkProjection(all_layers[0], mapControl.getViewPort());
|
296 |
|
try {
|
297 |
|
try {
|
298 |
|
mapControl.getMapContext().getLayers().addLayer(layer);
|
299 |
|
} catch (CancelationException e) {
|
300 |
|
return;
|
301 |
|
}
|
|
272 |
if (group != null) {
|
|
273 |
group.setVisible(true);
|
|
274 |
mapControl.getMapContext().beginAtomicEvent();
|
|
275 |
try {
|
|
276 |
// checkProjection(group, mapControl.getViewPort());
|
|
277 |
try {
|
|
278 |
mapControl.getMapContext().getLayers()
|
|
279 |
.addLayer(group);
|
|
280 |
group.dispose();
|
|
281 |
} catch (CancelationException e) {
|
|
282 |
// TODO Auto-generated catch block
|
|
283 |
e.printStackTrace();
|
|
284 |
}
|
|
285 |
if (mapControl.getViewPort().getExtent() == null) {
|
|
286 |
mapControl.getViewPort().setEnvelope(env);
|
|
287 |
}
|
|
288 |
} finally {
|
|
289 |
mapControl.getMapContext().endAtomicEvent();
|
|
290 |
}
|
|
291 |
return;
|
|
292 |
}
|
|
293 |
} else
|
|
294 |
if (all_layers.size() == 1) {
|
|
295 |
layer = (FLayer) all_layers.get(0);
|
|
296 |
if (!(layer.isOk())) {
|
|
297 |
// if the layer is not okay (it has errors) process them
|
|
298 |
processErrorsOfLayer(layer, mapControl);
|
|
299 |
}
|
302 |
300 |
|
303 |
|
if (mapControl.getViewPort().getExtent() == null) {
|
304 |
|
try {
|
305 |
|
mapControl.getViewPort().setEnvelope(
|
306 |
|
layer.getFullEnvelope());
|
307 |
|
} catch (ReadException e) {
|
308 |
|
NotificationManager.addError(e);
|
309 |
|
return;
|
310 |
|
}
|
311 |
|
}
|
312 |
|
} finally {
|
|
301 |
layer.setVisible(true);
|
|
302 |
mapControl.getMapContext().beginAtomicEvent();
|
|
303 |
// checkProjection(all_layers[0], mapControl.getViewPort());
|
|
304 |
try {
|
|
305 |
try {
|
|
306 |
mapControl.getMapContext().getLayers()
|
|
307 |
.addLayer(layer);
|
|
308 |
} catch (CancelationException e) {
|
|
309 |
return;
|
|
310 |
}
|
313 |
311 |
|
314 |
|
mapControl.getMapContext().endAtomicEvent();
|
315 |
|
}
|
316 |
|
return;
|
|
312 |
if (mapControl.getViewPort().getExtent() == null) {
|
|
313 |
try {
|
|
314 |
mapControl.getViewPort().setEnvelope(
|
|
315 |
layer.getFullEnvelope());
|
|
316 |
} catch (ReadException e) {
|
|
317 |
NotificationManager.addError(e);
|
|
318 |
return;
|
|
319 |
}
|
|
320 |
}
|
|
321 |
} finally {
|
|
322 |
|
|
323 |
mapControl.getMapContext().endAtomicEvent();
|
|
324 |
}
|
|
325 |
return;
|
|
326 |
}
|
|
327 |
} finally {
|
|
328 |
// Dispose all created layers. If they have been included into
|
|
329 |
// a FLayers object, they will have been binded there.
|
|
330 |
for (int i = 0; i < all_layers.size(); i++) {
|
|
331 |
FLayer layer = (FLayer) all_layers.get(i);
|
|
332 |
layer.dispose();
|
|
333 |
}
|
317 |
334 |
}
|
318 |
335 |
}
|
319 |
336 |
|