8 |
8 |
|
9 |
9 |
import java.awt.BorderLayout;
|
10 |
10 |
import java.awt.Component;
|
|
11 |
import java.lang.ref.WeakReference;
|
11 |
12 |
|
12 |
13 |
import org.slf4j.Logger;
|
13 |
14 |
import org.slf4j.LoggerFactory;
|
... | ... | |
48 |
49 |
private static final Logger logger = LoggerFactory
|
49 |
50 |
.getLogger(EditingManager.class);
|
50 |
51 |
|
51 |
|
private MapControl mapControl;
|
|
52 |
private WeakReference<MapControl> mapControlReference;
|
52 |
53 |
|
|
54 |
private MapContext mapContext;
|
|
55 |
|
53 |
56 |
private EditingCompoundBehavior editingCompoundBehavior;
|
54 |
57 |
|
|
58 |
private Behavior[] olderAdditionalBehaviors;
|
|
59 |
|
55 |
60 |
private JConsole console;
|
56 |
61 |
|
57 |
62 |
private JDockPanel dockConsole = null;
|
... | ... | |
93 |
98 |
};
|
94 |
99 |
|
95 |
100 |
public DefaultEditingContext(MapControl mapControl) {
|
96 |
|
this.mapControl = mapControl;
|
|
101 |
this.mapControlReference = new WeakReference<MapControl>(mapControl);
|
|
102 |
this.mapContext = mapControl.getMapContext();
|
97 |
103 |
|
98 |
104 |
addConsolePanelListeners(getConsolePanel());
|
99 |
105 |
}
|
... | ... | |
141 |
147 |
layer.getFeatureStore().edit();
|
142 |
148 |
} catch (Exception e) {
|
143 |
149 |
String msg =
|
144 |
|
String.format("Can't set %1$s in edit mode",
|
145 |
|
layer.getFeatureStore().getName());
|
|
150 |
String.format("Can't set %1$s in edit mode", layer
|
|
151 |
.getFeatureStore().getName());
|
146 |
152 |
logger.info(msg, new VectorEditingException(e));
|
147 |
153 |
getEditingBehavior().cleanBehavior();
|
148 |
154 |
return;
|
... | ... | |
154 |
160 |
|
155 |
161 |
editingNotificationManager.notifyObservers(this,
|
156 |
162 |
EditingNotification.AFTER_ENTER_EDITING_STORE, null, layer);
|
|
163 |
|
|
164 |
getMapControl().setTool("VectorEditing");
|
|
165 |
showConsole();
|
157 |
166 |
}
|
158 |
167 |
|
159 |
168 |
private void addBehaviors(Behavior[] additionalBehavior)
|
... | ... | |
181 |
190 |
|
182 |
191 |
getMapControl().addBehavior("VectorEditing", behaviors);
|
183 |
192 |
|
|
193 |
olderAdditionalBehaviors = additionalBehavior;
|
|
194 |
|
184 |
195 |
} else {
|
185 |
|
getMapControl()
|
186 |
|
.addBehavior("VectorEditing", editingCompoundBehavior);
|
|
196 |
getMapControl().addBehavior("VectorEditing",
|
|
197 |
editingCompoundBehavior);
|
187 |
198 |
}
|
188 |
199 |
|
189 |
200 |
} else {
|
... | ... | |
195 |
206 |
editingBehavior.cleanBehavior();
|
196 |
207 |
}
|
197 |
208 |
|
198 |
|
getMapControl().setTool("VectorEditing");
|
199 |
|
showConsole();
|
200 |
209 |
}
|
201 |
210 |
|
202 |
211 |
public MapControl getMapControl() {
|
203 |
|
return mapControl;
|
|
212 |
MapControl mapControl = mapControlReference.get();
|
|
213 |
if (mapControl != null) {
|
|
214 |
return mapControl;
|
|
215 |
}
|
|
216 |
return null;
|
204 |
217 |
}
|
205 |
218 |
|
206 |
219 |
private void discardChanges(FLyrVect layer) throws EndEditingException {
|
... | ... | |
374 |
387 |
|
375 |
388 |
private void addLayerListeners() {
|
376 |
389 |
|
377 |
|
MapContext context = getMapControl().getMapContext();
|
378 |
|
FLayers layers = context.getLayers();
|
|
390 |
FLayers layers = mapContext.getLayers();
|
379 |
391 |
|
380 |
|
// Add LayerListener to existing layers.
|
381 |
|
for (int i = 0; i < layers.getLayersCount(); i++) {
|
382 |
|
FLayer layer = layers.getLayer(i);
|
383 |
|
if (layer instanceof FLyrVect) {
|
384 |
|
((FLyrVect) layer).addLayerListener(layerListener);
|
385 |
|
}
|
386 |
|
}
|
|
392 |
layers.addLayerListener(layerListener);
|
387 |
393 |
|
388 |
394 |
layers.addLayerCollectionListener(new LayerCollectionListener() {
|
389 |
395 |
|
... | ... | |
462 |
468 |
public void showConsoleMessage(String text) {
|
463 |
469 |
getConsolePanel().addText(text, JConsole.MESSAGE);
|
464 |
470 |
}
|
|
471 |
|
|
472 |
public void setMapControl(MapControl mapControl) {
|
|
473 |
|
|
474 |
this.mapControlReference = new WeakReference<MapControl>(mapControl);
|
|
475 |
this.mapContext = mapControl.getMapContext();
|
|
476 |
|
|
477 |
// When mapControl is updated we have to add older additional behaviors
|
|
478 |
// to new mapControl
|
|
479 |
try {
|
|
480 |
addBehaviors(olderAdditionalBehaviors);
|
|
481 |
} catch (CreateEditingBehaviorException e1) {
|
|
482 |
logger.info("Problems adding behaviors to editing context", e1);
|
|
483 |
getMapControl().setTool("pan");
|
|
484 |
return;
|
|
485 |
}
|
|
486 |
}
|
465 |
487 |
}
|