Revision 2109 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.java
DefaultEditingContext.java | ||
---|---|---|
31 | 31 |
import java.util.ArrayList; |
32 | 32 |
import java.util.Set; |
33 | 33 |
import java.util.Stack; |
34 |
import java.util.logging.Level; |
|
35 | 34 |
import java.util.prefs.PreferenceChangeEvent; |
36 | 35 |
import java.util.prefs.PreferenceChangeListener; |
37 | 36 |
import java.util.prefs.Preferences; |
... | ... | |
45 | 44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
46 | 45 |
import org.gvsig.fmap.geom.Geometry; |
47 | 46 |
import org.gvsig.fmap.geom.GeometryLocator; |
48 |
import org.gvsig.fmap.geom.GeometryManager; |
|
49 |
import org.gvsig.fmap.geom.primitive.Point; |
|
50 | 47 |
import org.gvsig.fmap.geom.type.GeometryType; |
51 | 48 |
import org.gvsig.fmap.mapcontext.MapContext; |
52 | 49 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
... | ... | |
104 | 101 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
105 | 102 |
import org.gvsig.temporarystorage.TemporaryStorageManager; |
106 | 103 |
import org.gvsig.tools.dataTypes.Coercion; |
107 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
108 | 104 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
109 | 105 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
110 | 106 |
|
... | ... | |
124 | 120 |
|
125 | 121 |
private Behavior[] lastAdditionalBehaviors; |
126 | 122 |
|
127 |
private ObservableHelper observableHelper; |
|
123 |
private final ObservableHelper observableHelper;
|
|
128 | 124 |
|
129 | 125 |
private EditingConsole console; |
130 | 126 |
|
... | ... | |
132 | 128 |
|
133 | 129 |
private boolean isShowConsole = false; |
134 | 130 |
|
135 |
private Stack<EditingService> serviceStack; |
|
131 |
private final Stack<EditingService> serviceStack;
|
|
136 | 132 |
|
137 | 133 |
private FLyrVect currentLayer; |
138 | 134 |
|
... | ... | |
140 | 136 |
|
141 | 137 |
private Behavior[] defaultBehaviors; |
142 | 138 |
|
143 |
private LayerListener layerListener = new LayerListener() { |
|
139 |
private final LayerListener layerListener = new LayerListener() {
|
|
144 | 140 |
|
145 | 141 |
@Override |
146 | 142 |
public void activationChanged(final LayerEvent e) { |
... | ... | |
156 | 152 |
} |
157 | 153 |
|
158 | 154 |
FLayer layer = e.getSource(); |
155 |
final MapContext mapContext = layer.getMapContext(); |
|
159 | 156 |
|
160 |
FLayer[] activeLayers = |
|
161 |
layer.getMapContext().getLayers().getActives(); |
|
157 |
if (countActiveAndEditingLayers(mapContext) > 1) { |
|
158 |
hideConsole(); |
|
159 |
return; |
|
160 |
} |
|
162 | 161 |
|
163 |
if ((activeLayers.length == 1) && (layer instanceof FLyrVect)) {
|
|
162 |
if (layer instanceof FLyrVect) {
|
|
164 | 163 |
if (layer.isActive() && layer.isEditing()) { |
165 | 164 |
getMapControl().setTool("VectorEditing"); |
166 | 165 |
setCurrentLayer((FLyrVect) layer); |
... | ... | |
169 | 168 |
} |
170 | 169 |
} |
171 | 170 |
|
171 |
FLayer[] activeLayers = |
|
172 |
layer.getMapContext().getLayers().getActives(); |
|
173 |
|
|
174 |
for (FLayer activeLayer : activeLayers) { |
|
175 |
if (activeLayer instanceof FLyrVect) { |
|
176 |
if (activeLayer.isEditing()) { |
|
177 |
getMapControl().setTool("VectorEditing"); |
|
178 |
setCurrentLayer((FLyrVect) activeLayer); |
|
179 |
showConsole(); |
|
180 |
return; |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
172 | 185 |
hideConsole(); |
173 | 186 |
if ((getMapControl().getCurrentTool() != null) |
174 | 187 |
&& getMapControl().getCurrentTool().equals("VectorEditing")) { |
... | ... | |
176 | 189 |
} |
177 | 190 |
} |
178 | 191 |
|
192 |
@Override |
|
179 | 193 |
public void drawValueChanged(LayerEvent e) { |
180 | 194 |
} |
181 | 195 |
|
... | ... | |
206 | 220 |
|
207 | 221 |
} |
208 | 222 |
|
223 |
@Override |
|
209 | 224 |
public void nameChanged(LayerEvent e) { |
210 | 225 |
} |
211 | 226 |
|
227 |
@Override |
|
212 | 228 |
public void visibilityChanged(LayerEvent e) { |
213 | 229 |
} |
214 | 230 |
}; |
231 |
|
|
232 |
private int countActiveAndEditingLayers(MapContext mapcontext){ |
|
233 |
int count = 0; |
|
234 |
|
|
235 |
FLayer[] activeLayers = |
|
236 |
mapcontext.getLayers().getActives(); |
|
237 |
|
|
238 |
for (FLayer activeLayer : activeLayers) { |
|
239 |
if (activeLayer instanceof FLyrVect) { |
|
240 |
if (activeLayer.isEditing()) { |
|
241 |
count++; |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
return count; |
|
247 |
} |
|
215 | 248 |
|
216 |
private PreferenceChangeListener preferenceChangeListener = |
|
249 |
private final PreferenceChangeListener preferenceChangeListener =
|
|
217 | 250 |
new PreferenceChangeListener() { |
218 | 251 |
|
252 |
@Override |
|
219 | 253 |
public void preferenceChange(PreferenceChangeEvent evt) { |
220 | 254 |
String key = evt.getKey(); |
221 | 255 |
if (key.equalsIgnoreCase("apply-snappers")) { |
... | ... | |
227 | 261 |
|
228 | 262 |
public DefaultEditingContext(MapControl mapControl) { |
229 | 263 |
|
230 |
this.mapControlReference = new WeakReference<MapControl>(mapControl);
|
|
264 |
this.mapControlReference = new WeakReference<>(mapControl); |
|
231 | 265 |
this.mapContextReference = |
232 |
new WeakReference<MapContext>(mapControl.getMapContext());
|
|
266 |
new WeakReference<>(mapControl.getMapContext()); |
|
233 | 267 |
this.observableHelper = new ObservableHelper(); |
234 | 268 |
|
235 |
this.serviceStack = new Stack<EditingService>();
|
|
269 |
this.serviceStack = new Stack<>(); |
|
236 | 270 |
|
237 | 271 |
addLayerListeners(); |
238 | 272 |
addPreferenceListener(); |
... | ... | |
243 | 277 |
prefs.addPreferenceChangeListener(preferenceChangeListener); |
244 | 278 |
} |
245 | 279 |
|
280 |
@Override |
|
246 | 281 |
public void activateService(String name) { |
247 | 282 |
|
248 | 283 |
if ((getMapControl() != null) |
... | ... | |
317 | 352 |
new Behavior[additionalBehavior.length + 1]; |
318 | 353 |
behaviors[0] = editingCompoundBehavior; |
319 | 354 |
|
320 |
for (int i = 0; i < additionalBehavior.length; i++) { |
|
321 |
behaviors[i + 1] = additionalBehavior[i]; |
|
322 |
} |
|
355 |
System.arraycopy(additionalBehavior, 0, behaviors, 1, additionalBehavior.length); |
|
323 | 356 |
|
324 | 357 |
getMapControl().addBehavior("VectorEditing", behaviors); |
325 | 358 |
|
... | ... | |
360 | 393 |
} |
361 | 394 |
} |
362 | 395 |
|
396 |
@Override |
|
363 | 397 |
public void layerAdded(LayerCollectionEvent e) { |
364 | 398 |
addLayer(e.getLayers()); |
365 | 399 |
} |
366 | 400 |
|
401 |
@Override |
|
367 | 402 |
public void layerAdding(LayerCollectionEvent e) |
368 | 403 |
throws CancelationException { |
369 | 404 |
} |
370 | 405 |
|
406 |
@Override |
|
371 | 407 |
public void layerMoved(LayerPositionEvent e) { |
372 | 408 |
} |
373 | 409 |
|
410 |
@Override |
|
374 | 411 |
public void layerMoving(LayerPositionEvent e) |
375 | 412 |
throws CancelationException { |
376 | 413 |
} |
... | ... | |
386 | 423 |
} |
387 | 424 |
} |
388 | 425 |
|
426 |
@Override |
|
389 | 427 |
public void layerRemoved(LayerCollectionEvent e) { |
390 | 428 |
removeLayer(e.getLayers()); |
391 | 429 |
} |
392 | 430 |
|
431 |
@Override |
|
393 | 432 |
public void layerRemoving(LayerCollectionEvent e) |
394 | 433 |
throws CancelationException { |
395 | 434 |
} |
396 | 435 |
|
436 |
@Override |
|
397 | 437 |
public void visibilityChanged(LayerCollectionEvent e) |
398 | 438 |
throws CancelationException { |
399 | 439 |
} |
400 | 440 |
}); |
401 | 441 |
} |
402 | 442 |
|
443 |
@Override |
|
403 | 444 |
public void addObserver(Observer o) { |
404 | 445 |
this.observableHelper.addObserver(o); |
405 | 446 |
} |
... | ... | |
415 | 456 |
|
416 | 457 |
if (defaultValue != null) { |
417 | 458 |
if (defaultValue instanceof String) { |
418 |
strDefaultValue = (String) defaultValue; |
|
419 | 459 |
strDefaultValue = |
420 | 460 |
i18nManager.getTranslation((String) defaultValue); |
421 | 461 |
} else { |
... | ... | |
441 | 481 |
} |
442 | 482 |
} |
443 | 483 |
|
484 |
@Override |
|
444 | 485 |
public synchronized void beginEdition(FLyrVect layer, |
445 | 486 |
Behavior[] additionalBehaviors) { |
446 | 487 |
|
... | ... | |
456 | 497 |
} catch (CreateEditingBehaviorException e1) { |
457 | 498 |
logger.info("Problems adding behaviors to editing context", e1); |
458 | 499 |
getMapControl().setTool("pan"); |
459 |
return; |
|
460 | 500 |
} |
461 | 501 |
} |
462 | 502 |
|
503 |
@Override |
|
463 | 504 |
public synchronized void beginEdition(FLyrVect layer) { |
464 | 505 |
|
465 | 506 |
EditingNotificationManager editingNotificationManager = |
... | ... | |
546 | 587 |
+ "\n"); |
547 | 588 |
} |
548 | 589 |
|
590 |
@Override |
|
549 | 591 |
public void deleteObserver(Observer o) { |
550 | 592 |
this.observableHelper.deleteObserver(o); |
551 | 593 |
} |
552 | 594 |
|
595 |
@Override |
|
553 | 596 |
public void deleteObservers() { |
554 | 597 |
this.observableHelper.deleteObservers(); |
555 | 598 |
} |
... | ... | |
598 | 641 |
logger.info(msg, e); |
599 | 642 |
dialogs.messageDialog( |
600 | 643 |
i18n.getTranslation("_There_are_problems_discarding_changes")+"\n"+ |
601 |
// i18n.getTranslation("_The_layer_is_marked_as_temporary_to_avoid_possible_problems_when_trying_to_save_the_project")+"\n"+ |
|
602 | 644 |
"\n" + i18n.getTranslation("_See_error_log_for_more_information"), |
603 | 645 |
null, |
604 | 646 |
i18n.getTranslation("_Warning"), |
... | ... | |
648 | 690 |
EditingCompoundBehavior.SELECTION_INDEX, enableSelection); |
649 | 691 |
} |
650 | 692 |
|
693 |
@Override |
|
651 | 694 |
public void endEdition(FLyrVect layer) { |
652 | 695 |
if (layer.isEditing()) { |
653 | 696 |
EditingNotificationManager editingNotificationManager = |
... | ... | |
746 | 789 |
if (console == null) { |
747 | 790 |
console = new DefaultEditingConsole(new ResponseListener() { |
748 | 791 |
|
792 |
@Override |
|
749 | 793 |
public void acceptResponse(String response) { |
750 | 794 |
textEntered(response); |
751 | 795 |
} |
... | ... | |
799 | 843 |
} |
800 | 844 |
} |
801 | 845 |
|
846 |
@Override |
|
802 | 847 |
public MapControl getMapControl() { |
803 | 848 |
return mapControlReference.get(); |
804 | 849 |
} |
... | ... | |
846 | 891 |
getDockConsole().setVisible(false); |
847 | 892 |
} |
848 | 893 |
|
894 |
@Override |
|
849 | 895 |
public boolean isServiceCompatible(String name) { |
850 | 896 |
DefaultEditingBehavior editingBehavior = getEditingBehavior(); |
851 | 897 |
|
... | ... | |
1015 | 1061 |
|
1016 | 1062 |
} |
1017 | 1063 |
|
1064 |
@Override |
|
1018 | 1065 |
public void setMapControl(MapControl mapControl) { |
1019 | 1066 |
|
1020 |
this.mapControlReference = new WeakReference<MapControl>(mapControl);
|
|
1067 |
this.mapControlReference = new WeakReference<>(mapControl); |
|
1021 | 1068 |
this.mapContextReference = |
1022 |
new WeakReference<MapContext>(mapControl.getMapContext());
|
|
1069 |
new WeakReference<>(mapControl.getMapContext()); |
|
1023 | 1070 |
|
1024 | 1071 |
// When mapControl is updated we have to add older additional behaviors |
1025 | 1072 |
// to new mapControl |
... | ... | |
1029 | 1076 |
} catch (CreateEditingBehaviorException e1) { |
1030 | 1077 |
logger.info("Problems adding behaviors to editing context", e1); |
1031 | 1078 |
getMapControl().setTool("pan"); |
1032 |
return; |
|
1033 | 1079 |
} |
1034 | 1080 |
} |
1035 | 1081 |
} |
... | ... | |
1101 | 1147 |
} catch (StopServiceException e) { |
1102 | 1148 |
logger |
1103 | 1149 |
.info("Can't stop " + activeService.getName(), e); |
1104 |
return; |
|
1105 | 1150 |
} catch (DataException e) { |
1106 | 1151 |
logger.info("Can't get selection of " |
1107 | 1152 |
+ featureStore.getFullName(), e); |
1108 |
return; |
|
1109 | 1153 |
} |
1110 | 1154 |
} |
1111 | 1155 |
} else { |
... | ... | |
1208 | 1252 |
} |
1209 | 1253 |
} |
1210 | 1254 |
|
1255 |
@Override |
|
1211 | 1256 |
public void setDefaultBehaviors(Behavior[] defaultBehaviors) { |
1212 | 1257 |
this.defaultBehaviors = defaultBehaviors; |
1213 | 1258 |
try { |
... | ... | |
1215 | 1260 |
} catch (CreateEditingBehaviorException e1) { |
1216 | 1261 |
logger.info("Problems adding behaviors to editing context", e1); |
1217 | 1262 |
getMapControl().setTool("pan"); |
1218 |
return; |
|
1219 | 1263 |
} |
1220 | 1264 |
} |
1221 | 1265 |
|
1266 |
@Override |
|
1222 | 1267 |
public Behavior[] getDefaultBehaviors() { |
1223 | 1268 |
return this.defaultBehaviors; |
1224 | 1269 |
} |
Also available in: Unified diff