Revision 78 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingSwingManager.java
DefaultEditingSwingManager.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
3 |
*
|
|
4 |
* Project : DiSiD org.gvsig.vectorediting.swing.impl
|
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.swing.impl |
|
5 | 5 |
* SVN Id : $Id$ |
6 | 6 |
*/ |
7 | 7 |
package org.gvsig.vectorediting.swing.impl; |
... | ... | |
18 | 18 |
import javax.swing.JPanel; |
19 | 19 |
|
20 | 20 |
import org.gvsig.andami.PluginServices; |
21 |
import org.gvsig.andami.messages.NotificationManager; |
|
21 | 22 |
import org.gvsig.editing.EditingNotification; |
22 | 23 |
import org.gvsig.editing.EditingNotificationManager; |
23 | 24 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
24 | 25 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
25 | 26 |
import org.gvsig.fmap.mapcontrol.MapControl; |
26 | 27 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
28 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
|
27 | 29 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
28 | 30 |
import org.gvsig.tools.ToolsLocator; |
29 | 31 |
import org.gvsig.tools.dynobject.DynObject; |
... | ... | |
32 | 34 |
import org.gvsig.tools.service.Service; |
33 | 35 |
import org.gvsig.tools.service.ServiceException; |
34 | 36 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
37 |
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException; |
|
35 | 38 |
import org.gvsig.vectorediting.lib.api.exceptions.EndEditingException; |
36 | 39 |
import org.gvsig.vectorediting.lib.api.exceptions.StartEditingException; |
37 | 40 |
import org.gvsig.vectorediting.lib.api.exceptions.VectorEditingException; |
... | ... | |
64 | 67 |
|
65 | 68 |
public void activateService(String name, MapControl mapControl) { |
66 | 69 |
if (mapControl != null && mapControl.hasTool("VectorEditing")) { |
67 |
EditingBehavior behavior = (EditingBehavior) mapControl |
|
68 |
.getMapTool("VectorEditing"); |
|
70 |
CompoundBehavior behavior = (CompoundBehavior) mapControl.getMapTool("VectorEditing"); |
|
69 | 71 |
mapControl.setTool("VectorEditing"); |
70 |
behavior.activateService(name); |
|
72 |
EditingBehavior editingBehavior = (EditingBehavior) behavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX); |
|
73 |
behavior.setDrawnBehavior(EditingCompoundBehavior.EDITING_INDEX, true); |
|
74 |
editingBehavior.activateService(name); |
|
71 | 75 |
} |
72 | 76 |
} |
73 | 77 |
|
... | ... | |
87 | 91 |
|
88 | 92 |
} |
89 | 93 |
|
90 |
initFocus(mapControl); |
|
94 |
try { |
|
95 |
initFocus(mapControl); |
|
96 |
} catch (CreateEditingBehaviorException e1) { |
|
97 |
NotificationManager.addError(e1.getMessage(), e1); |
|
98 |
} |
|
91 | 99 |
|
92 | 100 |
try { |
93 | 101 |
layer.getFeatureStore().edit(); |
94 | 102 |
} |
95 | 103 |
catch (Exception e) { |
96 |
logger.error("Can't set featureStore in edit mode", |
|
97 |
new VectorEditingException(e)); |
|
98 |
} |
|
104 |
logger.error("Can't set featureStore in edit mode", |
|
105 |
new VectorEditingException(e)); } |
|
99 | 106 |
|
100 | 107 |
// layer.getFeatureStore().addObserver(view); |
101 | 108 |
layer.getFeatureStore().addObserver(mapControl); |
... | ... | |
114 | 121 |
FeatureStore featureStore = layer.getFeatureStore(); |
115 | 122 |
try { |
116 | 123 |
featureStore.cancelEditing(); |
117 |
EditingBehavior editingBehavior = (EditingBehavior) mapControl |
|
118 |
.getMapTool("VectorEditing"); |
|
124 |
EditingCompoundBehavior editingCompoundBehavior = (EditingCompoundBehavior) mapControl.getMapTool("VectorEditing"); |
|
125 |
EditingBehavior editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX); |
|
126 |
//FIXME: ?habr?a que poner el editingCompoundBehavior en modo editing? No, ya lo hace el cleanBehavior |
|
127 |
// editingCompoundBehavior.setDrawnBehavior(EditingCompoundBehavior.EDITING_INDEX, true); |
|
119 | 128 |
editingBehavior.cleanBehavior(); |
120 | 129 |
editingBehavior.hideConsole(); |
121 | 130 |
} |
... | ... | |
265 | 274 |
|
266 | 275 |
/** |
267 | 276 |
* @param mapControl |
277 |
* @throws CreateEditingBehaviorException |
|
268 | 278 |
*/ |
269 |
private void initFocus(MapControl mapControl) { |
|
279 |
private void initFocus(MapControl mapControl) throws CreateEditingBehaviorException {
|
|
270 | 280 |
|
271 | 281 |
EditingBehavior editingBehavior; |
282 |
EditingCompoundBehavior editingCompoundBehavior; |
|
272 | 283 |
if (!mapControl.hasTool("VectorEditing")) { |
273 | 284 |
editingBehavior = new DefaultEditingBehavior(mapControl); |
274 |
mapControl.addBehavior("VectorEditing", (Behavior) editingBehavior); |
|
285 |
editingCompoundBehavior = new EditingCompoundBehavior(editingBehavior); |
|
286 |
((DefaultEditingBehavior)editingBehavior).setCompoundBehavior(editingCompoundBehavior); |
|
287 |
mapControl.addBehavior("VectorEditing",editingCompoundBehavior); |
|
275 | 288 |
|
289 |
|
|
276 | 290 |
} |
277 | 291 |
else { |
278 |
editingBehavior = (EditingBehavior) mapControl
|
|
279 |
.getMapTool("VectorEditing");
|
|
280 |
editingBehavior.cleanBehavior();
|
|
292 |
editingCompoundBehavior = (EditingCompoundBehavior) mapControl.getMapTool("VectorEditing");
|
|
293 |
editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX);
|
|
294 |
editingBehavior.cleanBehavior();
|
|
281 | 295 |
} |
282 | 296 |
|
283 | 297 |
mapControl.setTool("VectorEditing"); |
... | ... | |
294 | 308 |
FeatureStore featureStore = layer.getFeatureStore(); |
295 | 309 |
try { |
296 | 310 |
featureStore.finishEditing(); |
297 |
EditingBehavior editingBehavior = (EditingBehavior) mapControl |
|
298 |
.getMapTool("VectorEditing"); |
|
311 |
EditingBehavior editingBehavior; |
|
312 |
EditingCompoundBehavior editingCompoundBehavior; |
|
313 |
editingCompoundBehavior = (EditingCompoundBehavior) mapControl.getMapTool("VectorEditing"); |
|
314 |
editingBehavior = (EditingBehavior) editingCompoundBehavior.getBehavior(EditingCompoundBehavior.EDITING_INDEX); |
|
315 |
|
|
299 | 316 |
editingBehavior.cleanBehavior(); |
300 | 317 |
editingBehavior.hideConsole(); |
301 | 318 |
} |
Also available in: Unified diff