Revision 43359
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/WizardVectorialDB.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.Window; |
27 | 27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
|
29 | 28 |
import java.util.List; |
30 | 29 |
|
31 | 30 |
import org.cresques.cts.IProjection; |
... | ... | |
35 | 34 |
import org.gvsig.andami.PluginServices; |
36 | 35 |
import org.gvsig.andami.messages.NotificationManager; |
37 | 36 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
38 |
import org.gvsig.app.ApplicationLocator; |
|
39 |
import org.gvsig.app.ApplicationManager; |
|
40 | 37 |
import org.gvsig.app.prepareAction.PrepareContext; |
41 | 38 |
import org.gvsig.app.prepareAction.PrepareContextView; |
42 | 39 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
... | ... | |
44 | 41 |
import org.gvsig.fmap.dal.DataManager; |
45 | 42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
46 | 43 |
import org.gvsig.fmap.dal.exception.DataException; |
47 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
48 | 44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
49 | 45 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer; |
50 | 46 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
51 | 47 |
import org.gvsig.fmap.geom.primitive.Envelope; |
52 | 48 |
import org.gvsig.fmap.mapcontext.MapContext; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
50 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
53 | 51 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
54 | 52 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
55 | 53 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
56 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
|
57 | 54 |
import org.gvsig.fmap.mapcontrol.MapControl; |
58 | 55 |
|
59 | 56 |
|
... | ... | |
68 | 65 |
public class WizardVectorialDB extends WizardDB { |
69 | 66 |
private static final long serialVersionUID = -5002685263220038989L; |
70 | 67 |
|
71 |
private static Logger logger = LoggerFactory |
|
72 |
.getLogger(WizardVectorialDB.class.getName()); |
|
68 |
private static final Logger logger = LoggerFactory.getLogger(WizardVectorialDB.class); |
|
73 | 69 |
|
74 | 70 |
private static final String GEODB_WIZARD_TAB_NAME = "GeoDB"; |
75 | 71 |
private DefaultViewPanel view = null; |
... | ... | |
79 | 75 |
/** |
80 | 76 |
* This method initializes this |
81 | 77 |
* |
82 |
* @return void |
|
83 | 78 |
*/ |
79 |
@Override |
|
84 | 80 |
protected void initialize() { |
85 | 81 |
super.initialize(); |
86 | 82 |
setTabName(GEODB_WIZARD_TAB_NAME); |
... | ... | |
99 | 95 |
} |
100 | 96 |
} |
101 | 97 |
|
102 |
|
|
103 |
|
|
98 |
@Override |
|
104 | 99 |
protected List getTableList(DBServerExplorer explorer) throws DataException { |
105 | 100 |
return explorer.list(DBServerExplorer.MODE_GEOMETRY); |
106 | 101 |
} |
107 | 102 |
|
108 |
|
|
103 |
@Override |
|
109 | 104 |
protected TablesListItem createTabeListItem(DBStoreParameters param) { |
110 | 105 |
return new TablesListItemVectorial(param, getMapCtrl(),this); |
111 | 106 |
} |
112 | 107 |
|
108 |
@Override |
|
113 | 109 |
public void setSettingsPanels(TablesListItem actTable) { |
114 | 110 |
super.setSettingsPanels(actTable); |
115 | 111 |
} |
116 | 112 |
|
113 |
@Override |
|
117 | 114 |
protected UserTableSettingsPanel createSettingsPanel( |
118 | 115 |
TablesListItem actTable) { |
119 | 116 |
if (actTable == null) { |
... | ... | |
129 | 126 |
.getUserTableSettingsPanel(abrev); |
130 | 127 |
} |
131 | 128 |
|
132 |
|
|
129 |
@Override |
|
133 | 130 |
public DataStoreParameters[] getParameters() { |
134 | 131 |
try { |
135 | 132 |
TablesListItem[] selected = getSelectedTables(); |
... | ... | |
146 | 143 |
dbParameters[i] = getParameterForTable(item); |
147 | 144 |
} |
148 | 145 |
|
149 |
return dbParameters;// layerArrayToGroup(all_layers, groupName);
|
|
146 |
return dbParameters; |
|
150 | 147 |
} catch (Exception e) { |
151 |
logger.info("Error while creating jdbc layer: " + e.getMessage(), e); |
|
152 |
NotificationManager.addError( |
|
153 |
"Error while loading layer: " |
|
154 |
+ e.getMessage(), e); |
|
148 |
logger.warn("Error while creating jdbc layer: " + e.getMessage(), e); |
|
155 | 149 |
} |
156 | 150 |
|
157 | 151 |
return null; |
158 | 152 |
} |
159 | 153 |
|
154 |
@Override |
|
160 | 155 |
public void execute() { |
161 | 156 |
MapControl mapControl = this.getMapCtrl(); |
162 |
IProjection proj = null; |
|
157 |
MapContext mc = mapControl.getMapContext(); |
|
158 |
MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
|
163 | 159 |
TablesListItem[] tables = getSelectedTables(); |
164 | 160 |
|
165 |
|
|
166 |
List all_layers = new ArrayList(); |
|
167 |
String strEPSG = mapControl.getViewPort().getProjection().getAbrev(); |
|
168 |
LayerFactory layerFactory = LayerFactory.getInstance(); |
|
161 |
List<FLayer> all_layers = new ArrayList(); |
|
169 | 162 |
String groupName = null; |
163 |
Boolean needCalculateEnvelope = mc.getViewPort().getEnvelope() == null; |
|
170 | 164 |
Envelope env = null; |
171 | 165 |
DBStoreParameters parameter; |
172 | 166 |
TablesListItem table; |
173 |
FeatureStore store, storeToAdd;
|
|
167 |
FeatureStore store; |
|
174 | 168 |
|
175 | 169 |
DataManager man = DALLocator.getDataManager(); |
176 | 170 |
|
177 |
ApplicationManager appGvSIGMan = ApplicationLocator.getManager(); |
|
178 |
PrepareContext context = this.getPrepareDataStoreContext(); |
|
179 |
|
|
180 |
|
|
181 | 171 |
try { |
182 | 172 |
|
183 | 173 |
FLayer layer; |
184 | 174 |
for (int i = 0; i < tables.length; i++) { |
185 | 175 |
table = tables[i]; |
186 |
UserTableSettingsVectorialPanel userTableSettingsPanel = |
|
187 |
(UserTableSettingsVectorialPanel) table |
|
188 |
.getUserTableSettingsPanel(); |
|
176 |
UserTableSettingsPanel userTableSettingsPanel = table.getUserTableSettingsPanel(); |
|
189 | 177 |
parameter = getParameterForTable(table); |
190 | 178 |
if (i == 0) { |
191 |
groupName = |
|
192 |
parameter.getDBName() + " (" + parameter.getHost() |
|
193 |
+ ")"; |
|
179 |
groupName = parameter.getDBName() + " (" + parameter.getHost() + ")"; |
|
194 | 180 |
} |
195 | 181 |
try { |
196 |
parameter = |
|
197 |
(DBStoreParameters) appGvSIGMan |
|
198 |
.prepareOpenDataStoreParameters(parameter, context); |
|
199 |
|
|
200 |
} catch (Exception e2) { |
|
201 |
NotificationManager.addError(e2); |
|
202 |
continue; |
|
203 |
} |
|
204 |
|
|
205 |
try { |
|
206 | 182 |
store = (FeatureStore) man.openStore( |
207 | 183 |
parameter.getDataStoreName(), |
208 | 184 |
parameter); |
209 | 185 |
} catch (Exception e) { |
210 |
logger.error("While opening DB store.", e);
|
|
186 |
logger.warn("While opening DB store.", e);
|
|
211 | 187 |
return; |
212 | 188 |
} |
213 |
|
|
214 | 189 |
try { |
215 |
storeToAdd = |
|
216 |
(FeatureStore) appGvSIGMan.pepareOpenDataSource(store, |
|
217 |
context); |
|
218 |
} catch (Exception e) { |
|
219 |
NotificationManager.addError(e); |
|
220 |
store.dispose(); |
|
221 |
continue; |
|
222 |
} |
|
223 | 190 |
|
224 |
try { |
|
225 |
|
|
226 |
layer = |
|
227 |
layerFactory.createLayer( |
|
228 |
userTableSettingsPanel.getUserLayerName(), |
|
229 |
storeToAdd); |
|
191 |
layer = mapContextManager.createLayer( |
|
192 |
userTableSettingsPanel.getUserLayerName(), |
|
193 |
store |
|
194 |
); |
|
230 | 195 |
all_layers.add(layer); |
231 |
if (env == null) { |
|
232 |
env = layer.getFullEnvelope(); |
|
233 |
} else { |
|
234 |
env.add(layer.getFullEnvelope()); |
|
196 |
if( needCalculateEnvelope ) { |
|
197 |
if (env == null) { |
|
198 |
env = layer.getFullEnvelope(); |
|
199 |
} else { |
|
200 |
env.add(layer.getFullEnvelope()); |
|
201 |
} |
|
235 | 202 |
} |
236 |
storeToAdd.dispose(); |
|
237 | 203 |
} catch (Exception e) { |
238 |
storeToAdd.dispose(); |
|
239 |
NotificationManager.addError(e); |
|
204 |
logger.warn("Can't create layer '"+userTableSettingsPanel.getUserLayerName()+"'.",e); |
|
240 | 205 |
} |
241 | 206 |
} |
242 | 207 |
|
243 |
MapContext mc = mapControl.getMapContext(); |
|
244 |
FLayers root = mapControl.getMapContext().getLayers(); |
|
245 | 208 |
if (all_layers.size() > 1) { |
246 |
FLayers group = new FLayers();// (mc,root);
|
|
209 |
FLayers group = new FLayers(); |
|
247 | 210 |
group.setMapContext(mc); |
248 |
group.setParentLayer(root);
|
|
211 |
group.setParentLayer(mc.getLayers());
|
|
249 | 212 |
group.setName(groupName); |
250 | 213 |
|
251 |
Iterator iter = all_layers.iterator(); |
|
252 |
while (iter.hasNext()) { |
|
253 |
group.addLayer((FLayer) iter.next()); |
|
214 |
for( FLayer aLayer : all_layers) { |
|
215 |
group.addLayer(aLayer); |
|
254 | 216 |
} |
255 |
|
|
256 |
if ((group != null) && !(group.isOk())) { |
|
217 |
if ( !(group.isOk())) { |
|
257 | 218 |
// if the layer is not okay (it has errors) process them |
258 | 219 |
processErrorsOfLayer(group, mapControl); |
259 | 220 |
} |
260 | 221 |
|
261 |
if (group != null) {
|
|
262 |
group.setVisible(true);
|
|
263 |
mapControl.getMapContext().beginAtomicEvent();
|
|
222 |
group.setVisible(true);
|
|
223 |
mc.beginAtomicEvent();
|
|
224 |
try {
|
|
264 | 225 |
try { |
265 |
// checkProjection(group, mapControl.getViewPort()); |
|
266 |
try { |
|
267 |
mapControl.getMapContext().getLayers() |
|
268 |
.addLayer(group); |
|
269 |
group.dispose(); |
|
270 |
} catch (CancelationException e) { |
|
271 |
// TODO Auto-generated catch block |
|
272 |
e.printStackTrace(); |
|
273 |
} |
|
274 |
if (mapControl.getViewPort().getExtent() == null) { |
|
275 |
mapControl.getViewPort().setEnvelope(env); |
|
276 |
} |
|
277 |
} finally { |
|
278 |
mapControl.getMapContext().endAtomicEvent(); |
|
226 |
mc.getLayers().addLayer(group); |
|
227 |
group.dispose(); |
|
228 |
} catch (CancelationException e) { |
|
229 |
logger.warn("Can't add group to mapcontext layers.",e); |
|
279 | 230 |
} |
280 |
return; |
|
231 |
if ( needCalculateEnvelope && env!=null ) { |
|
232 |
mapControl.getViewPort().setEnvelope(env); |
|
233 |
} |
|
234 |
} finally { |
|
235 |
mc.endAtomicEvent(); |
|
281 | 236 |
} |
282 |
} else |
|
237 |
return; |
|
238 |
} else { |
|
283 | 239 |
if (all_layers.size() == 1) { |
284 | 240 |
layer = (FLayer) all_layers.get(0); |
285 | 241 |
if (!(layer.isOk())) { |
... | ... | |
288 | 244 |
} |
289 | 245 |
|
290 | 246 |
layer.setVisible(true); |
291 |
mapControl.getMapContext().beginAtomicEvent(); |
|
292 |
// checkProjection(all_layers[0], mapControl.getViewPort()); |
|
247 |
mc.beginAtomicEvent(); |
|
293 | 248 |
try { |
294 | 249 |
try { |
295 |
mapControl.getMapContext().getLayers() |
|
296 |
.addLayer(layer); |
|
250 |
mc.getLayers().addLayer(layer); |
|
297 | 251 |
} catch (CancelationException e) { |
298 | 252 |
return; |
299 | 253 |
} |
300 | 254 |
|
301 |
if (mapControl.getViewPort().getExtent() == null) { |
|
302 |
try { |
|
303 |
mapControl.getViewPort().setEnvelope( |
|
304 |
layer.getFullEnvelope()); |
|
305 |
} catch (ReadException e) { |
|
306 |
NotificationManager.addError(e); |
|
307 |
return; |
|
308 |
} |
|
255 |
if ( needCalculateEnvelope && env!=null ) { |
|
256 |
mapControl.getViewPort().setEnvelope(env); |
|
309 | 257 |
} |
310 | 258 |
} finally { |
311 |
|
|
312 |
mapControl.getMapContext().endAtomicEvent(); |
|
259 |
mc.endAtomicEvent(); |
|
313 | 260 |
} |
314 | 261 |
return; |
315 | 262 |
} |
263 |
} |
|
316 | 264 |
} finally { |
317 | 265 |
// Dispose all created layers. If they have been included into |
318 | 266 |
// a FLayers object, they will have been binded there. |
... | ... | |
323 | 271 |
} |
324 | 272 |
} |
325 | 273 |
|
274 |
@Override |
|
326 | 275 |
protected PrepareContext getPrepareDataStoreContext() { |
327 | 276 |
if (this.prepareContext == null) { |
328 | 277 |
this.prepareContext = new PrepareContextView() { |
278 |
@Override |
|
329 | 279 |
public Window getOwnerWindow() { |
330 | 280 |
return null; |
331 | 281 |
} |
332 | 282 |
|
283 |
@Override |
|
333 | 284 |
public MapControl getMapControl() { |
334 | 285 |
return WizardVectorialDB.this |
335 | 286 |
.getMapCtrl(); |
336 | 287 |
} |
337 | 288 |
|
289 |
@Override |
|
338 | 290 |
public IProjection getViewProjection() { |
339 | 291 |
MapControl mapControl = getMapControl(); |
340 | 292 |
if (mapControl!=null){ |
... | ... | |
348 | 300 |
return this.prepareContext; |
349 | 301 |
} |
350 | 302 |
|
303 |
@Override |
|
351 | 304 |
protected DBStoreParameters getParameterForTable(TablesListItem table) { |
352 | 305 |
DBStoreParameters parameters = table.getParameters(); |
353 | 306 |
|
Also available in: Unified diff