10 |
10 |
*
|
11 |
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
14 |
* GNU General Public License for more details.
|
15 |
15 |
*
|
16 |
16 |
* You should have received a copy of the GNU General Public License
|
17 |
17 |
* along with this program; if not, write to the Free Software
|
18 |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
|
* MA 02110-1301, USA.
|
|
19 |
* MA 02110-1301, USA.
|
20 |
20 |
*
|
21 |
21 |
* For any additional information, do not hesitate to contact us
|
22 |
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
... | ... | |
83 |
83 |
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
|
84 |
84 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
|
85 |
85 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
|
|
86 |
import org.gvsig.tools.task.RunnableWithParameters;
|
86 |
87 |
import org.slf4j.Logger;
|
87 |
88 |
import org.slf4j.LoggerFactory;
|
88 |
89 |
|
89 |
90 |
public class EditionManager implements LayerListener, LayerCollectionListener, IEditionManager {
|
90 |
91 |
|
91 |
92 |
private static final Logger logger = LoggerFactory
|
92 |
|
.getLogger(EditionManager.class);
|
|
93 |
.getLogger(EditionManager.class);
|
93 |
94 |
|
94 |
|
private List<ILayerEdited> editedLayers = new ArrayList<ILayerEdited>();
|
|
95 |
final private List<ILayerEdited> editedLayers = new ArrayList<ILayerEdited>();
|
|
96 |
final private GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
|
97 |
final private MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
|
|
98 |
|
95 |
99 |
private MapControl mapCtrl = null;
|
96 |
100 |
private ILayerEdited ile = null;
|
97 |
|
private ObservableHelper observableHelper = new ObservableHelper();
|
98 |
|
private GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
99 |
|
private MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
|
100 |
|
|
101 |
|
/* (non-Javadoc)
|
102 |
|
* @see org.gvsig.editing.IEditionManager#getLayerEdited(org.gvsig.fmap.mapcontext.layers.FLayer)
|
103 |
|
*/
|
|
101 |
|
104 |
102 |
public ILayerEdited getLayerEdited(FLayer lyr) {
|
105 |
103 |
ILayerEdited aux = null;
|
106 |
|
for (int i = 0; i < editedLayers.size(); i++) {
|
|
104 |
for ( int i = 0; i < editedLayers.size(); i++ ) {
|
107 |
105 |
aux = editedLayers.get(i);
|
108 |
|
if (aux.getLayer() == lyr)
|
|
106 |
if ( aux.getLayer() == lyr ) {
|
109 |
107 |
return aux;
|
|
108 |
}
|
110 |
109 |
}
|
111 |
110 |
return null;
|
112 |
111 |
}
|
113 |
|
|
114 |
|
/* (non-Javadoc)
|
115 |
|
* @see org.gvsig.editing.IEditionManager#editLayer(org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect, org.gvsig.app.project.documents.view.gui.DefaultViewPanel)
|
116 |
|
*/
|
|
112 |
|
117 |
113 |
public void editLayer(FLyrVect lv, DefaultViewPanel vista)
|
118 |
|
throws DataException {
|
119 |
|
|
120 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_ENTER_EDIT_LAYER, lv, null, null);
|
121 |
|
if( notification.isProcessCanceled() ) {
|
122 |
|
logger.info("Edit layer '"+ lv.getName() + "' canceled by somme observer.");
|
123 |
|
throw new CancelException("Edit layer '"+ lv.getName() + "' canceled.");
|
124 |
|
}
|
|
114 |
throws DataException {
|
125 |
115 |
|
|
116 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
126 |
117 |
|
|
118 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
119 |
this,
|
|
120 |
EditingNotification.BEFORE_ENTER_EDITING_STORE,
|
|
121 |
vista == null ? null : vista.getDocument(),
|
|
122 |
lv);
|
|
123 |
|
|
124 |
if ( notification.isCanceled() ) {
|
|
125 |
logger.info("Edit layer '" + lv.getName() + "' canceled by somme observer.");
|
|
126 |
throw new CancelException("Edit layer '" + lv.getName() + "' canceled.");
|
|
127 |
}
|
|
128 |
|
127 |
129 |
CADExtension.initFocus();
|
128 |
130 |
vista.showConsole();
|
129 |
131 |
MapControl mapControl = vista.getMapControl();
|
... | ... | |
144 |
146 |
// ----------------------------
|
145 |
147 |
// this forces a true repaint:
|
146 |
148 |
lv.drawValueChanged(LayerEvent.createDrawValuesChangedEvent(lv, ""));
|
147 |
|
|
148 |
|
notifyObservers(EditionNotifycation.AFTER_ENTER_EDIT_LAYER, lv, null, null);
|
|
149 |
|
|
150 |
editingNotificationManager.notifyObservers(
|
|
151 |
this,
|
|
152 |
EditingNotification.AFTER_ENTER_EDITING_STORE,
|
|
153 |
vista == null ? null : vista.getDocument(),
|
|
154 |
lv);
|
149 |
155 |
}
|
150 |
156 |
|
151 |
157 |
public void visibilityChanged(LayerEvent e) {
|
152 |
158 |
}
|
153 |
159 |
|
154 |
160 |
public void activationChanged(LayerEvent e) {
|
155 |
|
if (e.getSource().isActive()) {
|
|
161 |
if ( e.getSource().isActive() ) {
|
156 |
162 |
ile = getLayerEdited(e.getSource());
|
157 |
163 |
}
|
158 |
|
if (ile == null || ile.getLayer().equals(e.getSource())) {
|
|
164 |
if ( ile == null || ile.getLayer().equals(e.getSource()) ) {
|
159 |
165 |
|
160 |
|
if (ile != null && !ile.getLayer().isActive()) {
|
|
166 |
if ( ile != null && !ile.getLayer().isActive() ) {
|
161 |
167 |
VectorialLayerEdited lastVLE = (VectorialLayerEdited) ile;
|
162 |
168 |
lastVLE.activationLost(e);
|
163 |
169 |
}
|
164 |
|
if (e.getSource() instanceof FLyrVect) {
|
|
170 |
if ( e.getSource() instanceof FLyrVect ) {
|
165 |
171 |
VectorialLayerEdited vle = null;
|
166 |
172 |
vle = (VectorialLayerEdited) getLayerEdited(e.getSource());
|
167 |
173 |
ile = vle;
|
168 |
|
if (getMapControl() != null && vle != null
|
169 |
|
&& vle.getLayer().isActive()) {
|
|
174 |
if ( getMapControl() != null && vle != null
|
|
175 |
&& vle.getLayer().isActive() ) {
|
170 |
176 |
getMapControl().setTool("cadtooladapter");
|
171 |
177 |
vle.activationGained(e);
|
172 |
178 |
return;
|
173 |
179 |
}
|
174 |
180 |
}
|
175 |
|
if (getMapControl() != null) {
|
|
181 |
if ( getMapControl() != null ) {
|
176 |
182 |
getMapControl().setTool("zoomIn");
|
177 |
183 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
178 |
184 |
}
|
... | ... | |
187 |
193 |
|
188 |
194 |
// Si no est? en la lista, comprobamos que est? en edici?n
|
189 |
195 |
// y lo a?adimos
|
190 |
|
if ((lyrEdit == null) && e.getSource().isEditing()) {
|
191 |
|
lyrEdit =
|
192 |
|
FactoryLayerEdited.createLayerEdited(e.getSource(), mapCtrl);
|
|
196 |
if ( (lyrEdit == null) && e.getSource().isEditing() ) {
|
|
197 |
lyrEdit
|
|
198 |
= FactoryLayerEdited.createLayerEdited(e.getSource(), mapCtrl);
|
193 |
199 |
editedLayers.add(lyrEdit);
|
194 |
|
if (getMapControl() != null) {
|
|
200 |
if ( getMapControl() != null ) {
|
195 |
201 |
getMapControl().setTool("cadtooladapter");
|
196 |
202 |
CADExtension.setCADTool("_selection", true);
|
197 |
203 |
}
|
... | ... | |
201 |
207 |
logger.debug("NUEVA CAPA EN EDICION: {}", lyrEdit.getLayer().getName());
|
202 |
208 |
|
203 |
209 |
// Ponemos el resto de temas desactivados
|
204 |
|
if (mapCtrl != null)
|
|
210 |
if ( mapCtrl != null ) {
|
205 |
211 |
mapCtrl.getMapContext().getLayers().setActive(false);
|
|
212 |
}
|
206 |
213 |
// y activamos el nuevo.
|
207 |
214 |
e.getSource().setActive(true);
|
208 |
215 |
|
209 |
|
if (e.getSource() instanceof FLyrVect) {
|
|
216 |
if ( e.getSource() instanceof FLyrVect ) {
|
210 |
217 |
FLyrVect fLyrVect = (FLyrVect) e.getSource();
|
211 |
218 |
((VectorialLayerEdited) lyrEdit)
|
212 |
|
.setEditionChangeManager(new EditionChangeManager(fLyrVect));
|
213 |
|
|
214 |
|
addCheckRules(fLyrVect);
|
|
219 |
.setEditionChangeManager(new EditionChangeManager(fLyrVect));
|
215 |
220 |
}
|
216 |
221 |
} else {
|
217 |
|
for (int i = 0; i < editedLayers.size(); i++) {
|
218 |
|
VectorialLayerEdited vle =
|
219 |
|
(VectorialLayerEdited) editedLayers.get(i);
|
220 |
|
if (vle.equals(lyrEdit)) {
|
|
222 |
for ( int i = 0; i < editedLayers.size(); i++ ) {
|
|
223 |
VectorialLayerEdited vle
|
|
224 |
= (VectorialLayerEdited) editedLayers.get(i);
|
|
225 |
if ( vle.equals(lyrEdit) ) {
|
221 |
226 |
editedLayers.remove(i);
|
222 |
227 |
ile = null;
|
223 |
228 |
return;
|
... | ... | |
227 |
232 |
|
228 |
233 |
}
|
229 |
234 |
|
230 |
|
/* (non-Javadoc)
|
231 |
|
* @see org.gvsig.editing.IEditionManager#getActiveLayerEdited()
|
232 |
|
*/
|
233 |
235 |
public ILayerEdited getActiveLayerEdited() {
|
234 |
236 |
return ile;
|
235 |
237 |
}
|
236 |
238 |
|
237 |
|
/* (non-Javadoc)
|
238 |
|
* @see org.gvsig.editing.IEditionManager#getMapControl()
|
239 |
|
*/
|
|
239 |
|
240 |
240 |
public MapControl getMapControl() {
|
241 |
241 |
return mapCtrl;
|
242 |
242 |
}
|
243 |
243 |
|
244 |
|
/* (non-Javadoc)
|
245 |
|
* @see org.gvsig.editing.IEditionManager#setMapControl(org.gvsig.fmap.mapcontrol.MapControl)
|
246 |
|
*/
|
247 |
244 |
public void setMapControl(MapControl mapCtrl) {
|
248 |
|
if (mapCtrl != null) {
|
|
245 |
if ( mapCtrl != null ) {
|
249 |
246 |
this.mapCtrl = mapCtrl;
|
250 |
247 |
mapCtrl.getMapContext().getLayers().addLayerListener(this);
|
251 |
248 |
mapCtrl.getMapContext().getLayers()
|
252 |
|
.addLayerCollectionListener(this);
|
|
249 |
.addLayerCollectionListener(this);
|
253 |
250 |
}
|
254 |
251 |
}
|
255 |
252 |
|
... | ... | |
263 |
260 |
}
|
264 |
261 |
|
265 |
262 |
public void layerRemoved(LayerCollectionEvent e) {
|
266 |
|
VectorialLayerEdited vle =
|
267 |
|
(VectorialLayerEdited) getActiveLayerEdited();
|
268 |
|
if (vle != null && vle.getLayer().isActive()) {
|
|
263 |
VectorialLayerEdited vle
|
|
264 |
= (VectorialLayerEdited) getActiveLayerEdited();
|
|
265 |
if ( vle != null && vle.getLayer().isActive() ) {
|
269 |
266 |
try {
|
270 |
267 |
vle.clearSelection();
|
271 |
268 |
} catch (DataException e1) {
|
... | ... | |
274 |
271 |
editedLayers.remove(vle);
|
275 |
272 |
getMapControl().setTool("zoomIn");
|
276 |
273 |
FLyrVect lv = (FLyrVect) vle.getLayer();
|
277 |
|
if (e.getAffectedLayer().equals(lv)) {
|
278 |
|
IWindow window =
|
279 |
|
PluginServices.getMDIManager().getActiveWindow();
|
280 |
|
if (window instanceof DefaultViewPanel) {
|
|
274 |
if ( e.getAffectedLayer().equals(lv) ) {
|
|
275 |
IWindow window
|
|
276 |
= PluginServices.getMDIManager().getActiveWindow();
|
|
277 |
if ( window instanceof DefaultViewPanel ) {
|
281 |
278 |
DefaultViewPanel view = (DefaultViewPanel) window;
|
282 |
279 |
view.hideConsole();
|
283 |
280 |
view.validate();
|
... | ... | |
297 |
294 |
}
|
298 |
295 |
|
299 |
296 |
public void layerRemoving(LayerCollectionEvent e)
|
300 |
|
throws CancelationException {
|
|
297 |
throws CancelationException {
|
301 |
298 |
// Nothing to do
|
302 |
299 |
}
|
303 |
300 |
|
304 |
301 |
public void activationChanged(LayerCollectionEvent e)
|
305 |
|
throws CancelationException {
|
|
302 |
throws CancelationException {
|
306 |
303 |
// Nothing to do
|
307 |
304 |
}
|
308 |
305 |
|
309 |
306 |
public void visibilityChanged(LayerCollectionEvent e)
|
310 |
|
throws CancelationException {
|
|
307 |
throws CancelationException {
|
311 |
308 |
// Nothing to do
|
312 |
309 |
}
|
313 |
310 |
|
... | ... | |
315 |
312 |
// Nothing to do
|
316 |
313 |
}
|
317 |
314 |
|
318 |
|
public class DefaultCheckMandatoryAttributes extends AbstractFeatureRule
|
319 |
|
implements CheckMandatoryAttributesRule {
|
|
315 |
protected boolean validateFeature(EditableFeature feature, FeatureStore featureStore) {
|
|
316 |
// Comprobar si hay campos obligatorios y de haberlos presentamos
|
|
317 |
// el formulario
|
|
318 |
FeatureType featureType = feature.getType();
|
|
319 |
FeatureAttributeDescriptor[] attributeDescriptors = featureType.getAttributeDescriptors();
|
320 |
320 |
|
321 |
|
protected DefaultCheckMandatoryAttributes() {
|
322 |
|
super("CheckMandatoryAttributtes", "CheckMandatoryAttributtes");
|
323 |
|
}
|
324 |
|
|
325 |
|
public void validate(Feature feature, FeatureStore featureStore)
|
326 |
|
throws DataException {
|
327 |
|
// Comprobar si hay campos obligatorios y presentar formulario
|
328 |
|
FeatureType featureType = feature.getType();
|
329 |
|
FeatureAttributeDescriptor[] attributeDescriptors =
|
330 |
|
featureType.getAttributeDescriptors();
|
331 |
|
boolean showForm = false;
|
332 |
|
for (int i = 0; i < attributeDescriptors.length; i++) {
|
333 |
|
FeatureAttributeDescriptor attrDesc = attributeDescriptors[i];
|
334 |
|
if( attrDesc.isAutomatic() ) {
|
335 |
|
break;
|
336 |
|
}
|
337 |
|
if( (attrDesc.isPrimaryKey() || !attrDesc.allowNull())
|
338 |
|
&& feature.get(attrDesc.getName()) == null) {
|
339 |
|
showForm = true;
|
340 |
|
break;
|
341 |
|
}
|
|
321 |
boolean showForm = false;
|
|
322 |
for ( int i = 0; i < attributeDescriptors.length; i++ ) {
|
|
323 |
FeatureAttributeDescriptor attrDesc = attributeDescriptors[i];
|
|
324 |
if ( attrDesc.isAutomatic() ) {
|
|
325 |
break;
|
342 |
326 |
}
|
343 |
|
if (showForm) {
|
344 |
|
askRequiredAttributtes((EditableFeature) feature, featureStore);
|
|
327 |
if ( (attrDesc.isPrimaryKey() || !attrDesc.allowNull())
|
|
328 |
&& feature.get(attrDesc.getName()) == null ) {
|
|
329 |
showForm = true;
|
|
330 |
break;
|
345 |
331 |
}
|
346 |
332 |
}
|
347 |
|
|
|
333 |
if ( showForm ) {
|
|
334 |
AskRequiredAttributtes ask = new AskRequiredAttributtes();
|
|
335 |
return ask.showDialog(feature, featureStore);
|
|
336 |
}
|
|
337 |
return true;
|
348 |
338 |
}
|
349 |
339 |
|
350 |
|
private void askRequiredAttributtes(final EditableFeature feature,
|
351 |
|
final FeatureStore store)
|
352 |
|
throws FeatureRuleMandatoryAttributesException {
|
|
340 |
private class AskRequiredAttributtes {
|
353 |
341 |
|
354 |
|
// Comprobar que estamos en el thread de swing y si no excepcion
|
355 |
|
if (!SwingUtilities.isEventDispatchThread()) {
|
356 |
|
try {
|
357 |
|
SwingUtilities.invokeAndWait(new Runnable() {
|
|
342 |
private boolean returnValue = true;
|
358 |
343 |
|
359 |
|
public void run() {
|
360 |
|
askRequiredAttributtes(feature, store);
|
|
344 |
public boolean showDialog(final EditableFeature feature,
|
|
345 |
final FeatureStore store) {
|
|
346 |
|
|
347 |
if ( !SwingUtilities.isEventDispatchThread() ) {
|
|
348 |
try {
|
|
349 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
350 |
public void run() {
|
|
351 |
showDialog(feature, store);
|
|
352 |
}
|
361 |
353 |
}
|
362 |
|
});
|
363 |
|
} catch (Exception e1) {
|
364 |
|
throw new FeatureRuleMandatoryAttributesException(e1,
|
365 |
|
store.getFullName());
|
|
354 |
);
|
|
355 |
return returnValue;
|
|
356 |
} catch (Exception e1) {
|
|
357 |
returnValue = false;
|
|
358 |
return returnValue;
|
|
359 |
}
|
366 |
360 |
}
|
367 |
|
return;
|
368 |
|
}
|
369 |
|
DynObjectSwingManager dynObjectSwinManager =
|
370 |
|
ToolsSwingLocator.getDynObjectSwingManager();
|
371 |
|
final JDynObjectComponent dynObjectComponent;
|
372 |
|
try {
|
373 |
|
dynObjectComponent =
|
374 |
|
dynObjectSwinManager.createJDynObjectComponent(
|
375 |
|
feature.getAsDynObject(), true);
|
376 |
|
} catch (Exception e) {
|
377 |
|
|
378 |
|
// TODO This has to be improved
|
379 |
|
// Instead of this warning, show dialog to
|
380 |
|
// fill feature type
|
381 |
|
showBadValuesMessage(e.getMessage());
|
382 |
|
return;
|
383 |
|
|
384 |
|
}
|
385 |
|
final JPanel panel = new JPanel();
|
386 |
361 |
|
387 |
|
ButtonsPanel buttonsPanel =
|
388 |
|
new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
|
389 |
|
buttonsPanel.addButtonPressedListener(new ButtonsPanelListener() {
|
|
362 |
DynObjectSwingManager dynObjectSwinManager
|
|
363 |
= ToolsSwingLocator.getDynObjectSwingManager();
|
|
364 |
final JDynObjectComponent dynObjectComponent;
|
|
365 |
try {
|
|
366 |
dynObjectComponent
|
|
367 |
= dynObjectSwinManager.createJDynObjectComponent(
|
|
368 |
feature.getAsDynObject(), true);
|
|
369 |
} catch (Exception e) {
|
390 |
370 |
|
391 |
|
public void actionButtonPressed(ButtonsPanelEvent e) {
|
392 |
|
if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
393 |
|
dynObjectComponent.saveStatus();
|
394 |
|
panel.setVisible(false);
|
395 |
|
}
|
396 |
|
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
397 |
|
panel.setVisible(false);
|
398 |
|
throw new FeatureRuleMandatoryAttributesException(store
|
399 |
|
.getFullName());
|
400 |
|
}
|
|
371 |
// TODO This has to be improved
|
|
372 |
// Instead of this warning, show dialog to
|
|
373 |
// fill feature type
|
|
374 |
showBadValuesMessage(e.getMessage());
|
|
375 |
returnValue = false;
|
|
376 |
return returnValue;
|
|
377 |
|
401 |
378 |
}
|
|
379 |
final JPanel panel = new JPanel();
|
402 |
380 |
|
403 |
|
});
|
404 |
|
panel.setLayout(new BorderLayout());
|
405 |
|
ScrollPane scrollPanel = new ScrollPane();
|
406 |
|
scrollPanel.add(dynObjectComponent.asJComponent(), BorderLayout.CENTER);
|
407 |
|
panel.add(scrollPanel);
|
408 |
|
panel.add(buttonsPanel, BorderLayout.SOUTH);
|
409 |
|
panel.setPreferredSize(new Dimension(800, 600));
|
410 |
|
WindowManager wm = ToolsSwingLocator.getWindowManager();
|
411 |
|
wm.showWindow(panel, "Fill mandatory fields", WindowManager.MODE.DIALOG);
|
|
381 |
ButtonsPanel buttonsPanel
|
|
382 |
= new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
|
|
383 |
buttonsPanel.addButtonPressedListener(new ButtonsPanelListener() {
|
412 |
384 |
|
|
385 |
public void actionButtonPressed(ButtonsPanelEvent e) {
|
|
386 |
if ( e.getButton() == ButtonsPanel.BUTTON_ACCEPT ) {
|
|
387 |
dynObjectComponent.saveStatus();
|
|
388 |
panel.setVisible(false);
|
|
389 |
returnValue = true;
|
|
390 |
}
|
|
391 |
if ( e.getButton() == ButtonsPanel.BUTTON_CANCEL ) {
|
|
392 |
panel.setVisible(false);
|
|
393 |
returnValue = false;
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
});
|
|
398 |
panel.setLayout(new BorderLayout());
|
|
399 |
ScrollPane scrollPanel = new ScrollPane();
|
|
400 |
scrollPanel.add(dynObjectComponent.asJComponent(), BorderLayout.CENTER);
|
|
401 |
panel.add(scrollPanel);
|
|
402 |
panel.add(buttonsPanel, BorderLayout.SOUTH);
|
|
403 |
panel.setPreferredSize(new Dimension(800, 600));
|
|
404 |
WindowManager wm = ToolsSwingLocator.getWindowManager();
|
|
405 |
wm.showWindow(panel, "Fill mandatory fields", WindowManager.MODE.DIALOG);
|
|
406 |
|
|
407 |
return returnValue;
|
|
408 |
}
|
413 |
409 |
}
|
414 |
410 |
|
415 |
411 |
/**
|
416 |
412 |
* @param message
|
417 |
413 |
*/
|
418 |
414 |
private void showBadValuesMessage(String message) {
|
419 |
|
|
|
415 |
|
420 |
416 |
ApplicationLocator.getManager().message(
|
421 |
|
message,
|
422 |
|
JOptionPane.WARNING_MESSAGE);
|
423 |
|
|
424 |
|
/*
|
425 |
|
* We cannot do this because window focus
|
426 |
|
* causes exception in drawing
|
427 |
|
*
|
428 |
|
IWindow iw = PluginServices.getMDIManager().getActiveWindow();
|
429 |
|
Component pare = null;
|
430 |
|
if (iw instanceof Component) {
|
431 |
|
pare = (Component) iw;
|
432 |
|
}
|
433 |
|
|
434 |
|
String _tit = Messages.getText("editing");
|
435 |
|
String _msg = Messages.getText("_Invalid_values_in_some_fields_must_be_edited_before_end_editing");
|
436 |
|
_msg = _msg + "\n\n[" + message + "]";
|
437 |
|
|
438 |
|
JOptionPane.showMessageDialog(
|
439 |
|
pare,
|
440 |
|
_msg, _tit,
|
441 |
|
JOptionPane.WARNING_MESSAGE);
|
442 |
|
*/
|
|
417 |
message,
|
|
418 |
JOptionPane.WARNING_MESSAGE);
|
443 |
419 |
}
|
444 |
420 |
|
445 |
|
private void addCheckRules(FLyrVect layer) {
|
446 |
|
try {
|
447 |
|
FeatureType featureType =
|
448 |
|
layer.getFeatureStore().getDefaultFeatureType();
|
449 |
|
FeatureRules featureRules = featureType.getRules();
|
450 |
|
for (Iterator it = featureRules.iterator(); it.hasNext();) {
|
451 |
|
FeatureRule rule = (FeatureRule) it.next();
|
452 |
|
if (rule instanceof CheckMandatoryAttributesRule) {
|
453 |
|
return;
|
454 |
|
}
|
455 |
|
}
|
456 |
|
featureRules.add(new DefaultCheckMandatoryAttributes());
|
457 |
|
} catch (DataException e) {
|
458 |
|
throw new RuntimeException(e);
|
459 |
|
}
|
|
421 |
private VectorialLayerEdited getVLE() {
|
|
422 |
return (VectorialLayerEdited) getActiveLayerEdited();
|
460 |
423 |
}
|
461 |
424 |
|
462 |
|
public class FeatureRuleMandatoryAttributesException extends
|
463 |
|
DataRuntimeException {
|
464 |
|
|
465 |
|
private static final long serialVersionUID = -7965533441336164612L;
|
466 |
|
private final static String MESSAGE_FORMAT =
|
467 |
|
"Can't apply rule in store %(store)s.";
|
468 |
|
private final static String MESSAGE_KEY =
|
469 |
|
"_FeatureRuleMandatoryAttributesException";
|
470 |
|
|
471 |
|
public FeatureRuleMandatoryAttributesException(Throwable cause,
|
472 |
|
String store) {
|
473 |
|
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
|
474 |
|
this.setValue("store", store);
|
|
425 |
private void insertSpatialCache(Geometry geom)
|
|
426 |
throws CreateEnvelopeException {
|
|
427 |
VectorialLayerEdited vle = getVLE();
|
|
428 |
SpatialCache spatialCache = ((FLyrVect) vle.getLayer())
|
|
429 |
.getSpatialCache();
|
|
430 |
Envelope r = geom.getEnvelope();
|
|
431 |
if ( geom.getType() == Geometry.TYPES.POINT ) {
|
|
432 |
r = geomManager.createEnvelope(r.getMinimum(0), r.getMinimum(1),
|
|
433 |
r.getMinimum(0) + 1, r.getMinimum(1) + 1, SUBTYPES.GEOM2D);
|
475 |
434 |
}
|
|
435 |
spatialCache.insert(r, geom);
|
476 |
436 |
|
477 |
|
public FeatureRuleMandatoryAttributesException(String store) {
|
478 |
|
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
479 |
|
this.setValue("store", store);
|
480 |
|
}
|
481 |
437 |
}
|
482 |
438 |
|
483 |
|
private VectorialLayerEdited getVLE() {
|
484 |
|
return (VectorialLayerEdited) getActiveLayerEdited();
|
|
439 |
private void updateSpatialCache(Geometry geom) {
|
|
440 |
// TODO: no se actualizaban la cache espacial cuando se modifican las geometrias,
|
|
441 |
// habria que hacerlo.
|
|
442 |
logger.info("TODO: need update spatial cache");
|
485 |
443 |
}
|
486 |
|
|
487 |
|
private void insertSpatialCache(Geometry geom)
|
488 |
|
throws CreateEnvelopeException {
|
489 |
|
VectorialLayerEdited vle = getVLE();
|
490 |
|
SpatialCache spatialCache = ((FLyrVect) vle.getLayer())
|
491 |
|
.getSpatialCache();
|
492 |
|
Envelope r = geom.getEnvelope();
|
493 |
|
if (geom.getType() == Geometry.TYPES.POINT) {
|
494 |
|
r = geomManager.createEnvelope(r.getMinimum(0), r.getMinimum(1),
|
495 |
|
r.getMinimum(0) + 1, r.getMinimum(1) + 1, SUBTYPES.GEOM2D);
|
496 |
|
}
|
497 |
|
spatialCache.insert(r, geom);
|
498 |
444 |
|
499 |
|
}
|
|
445 |
private void removeSpatialCache(Geometry geom) {
|
|
446 |
// TODO: no se actualizaban la cache espacial cuando se modifican las geometrias,
|
|
447 |
// habria que hacerlo.
|
|
448 |
logger.info("TODO: need update spatial cache");
|
|
449 |
}
|
500 |
450 |
|
501 |
|
private void updateSpatialCache(Geometry geom) {
|
502 |
|
// TODO: no se actualizaban la cache espacial cuando se modifican las geometrias,
|
503 |
|
// habria que hacerlo.
|
504 |
|
logger.info("TODO: need update spatial cache");
|
505 |
|
}
|
506 |
|
|
507 |
|
private void removeSpatialCache(Geometry geom) {
|
508 |
|
// TODO: no se actualizaban la cache espacial cuando se modifican las geometrias,
|
509 |
|
// habria que hacerlo.
|
510 |
|
logger.info("TODO: need update spatial cache");
|
511 |
|
}
|
512 |
|
|
513 |
451 |
private void draw(Geometry geometry, Feature feature) {
|
514 |
|
if (geometry != null) {
|
|
452 |
if ( geometry != null ) {
|
515 |
453 |
getMapControl().getMapControlDrawer()
|
516 |
|
.draw(geometry, mapControlManager.getGeometrySelectionSymbol());
|
|
454 |
.draw(geometry, mapControlManager.getGeometrySelectionSymbol());
|
517 |
455 |
}
|
518 |
456 |
}
|
519 |
457 |
|
520 |
|
public Feature insertGeometry(Geometry geometry) {
|
521 |
|
VectorialLayerEdited vle = getVLE();
|
|
458 |
public Feature insertGeometry(Geometry geometry) {
|
|
459 |
VectorialLayerEdited vle = getVLE();
|
522 |
460 |
try {
|
523 |
|
FeatureStore featureStore =
|
524 |
|
((FLyrVect) vle.getLayer()).getFeatureStore();
|
|
461 |
FeatureStore featureStore
|
|
462 |
= ((FLyrVect) vle.getLayer()).getFeatureStore();
|
525 |
463 |
EditableFeature eFeature = featureStore.createNewFeature(true);
|
526 |
|
|
|
464 |
|
527 |
465 |
//Reproject the geometry
|
528 |
466 |
Geometry insertedGeometry = geometry;
|
529 |
|
if (getVLE().getLayer().getCoordTrans() != null){
|
|
467 |
if ( getVLE().getLayer().getCoordTrans() != null ) {
|
530 |
468 |
insertedGeometry = insertedGeometry.cloneGeometry();
|
531 |
469 |
insertedGeometry.reProject(getVLE().getLayer().getCoordTrans().getInverted());
|
532 |
470 |
}
|
533 |
|
|
|
471 |
|
534 |
472 |
eFeature.setGeometry(featureStore.getDefaultFeatureType()
|
535 |
|
.getDefaultGeometryAttributeName(), insertedGeometry);
|
536 |
|
|
537 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_INSERT_FEATURE, getVLE().getLayer(), featureStore, eFeature);
|
538 |
|
if( notification.isProcessCanceled() ) {
|
539 |
|
return null;
|
540 |
|
}
|
|
473 |
.getDefaultGeometryAttributeName(), insertedGeometry);
|
541 |
474 |
|
|
475 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
|
476 |
|
|
477 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
478 |
this,
|
|
479 |
EditingNotification.BEFORE_INSERT_FEATURE,
|
|
480 |
null,
|
|
481 |
vle.getLayer(),
|
|
482 |
featureStore,
|
|
483 |
eFeature
|
|
484 |
);
|
|
485 |
if ( notification.isCanceled() ) {
|
|
486 |
return null;
|
|
487 |
}
|
|
488 |
if ( !validateFeature(eFeature, featureStore) ) {
|
|
489 |
return null;
|
|
490 |
}
|
|
491 |
|
542 |
492 |
featureStore.insert(eFeature);
|
543 |
493 |
insertSpatialCache(insertedGeometry);
|
544 |
494 |
draw(insertedGeometry, eFeature);
|
545 |
|
|
546 |
|
notifyObservers(EditionNotifycation.AFTER_INSERT_FEATURE, vle.getLayer(), featureStore, eFeature);
|
547 |
495 |
|
|
496 |
editingNotificationManager.notifyObservers(
|
|
497 |
this,
|
|
498 |
EditingNotification.AFTER_INSERT_FEATURE,
|
|
499 |
null,
|
|
500 |
vle.getLayer(),
|
|
501 |
featureStore,
|
|
502 |
eFeature
|
|
503 |
);
|
|
504 |
|
548 |
505 |
return eFeature;
|
549 |
506 |
} catch (Exception e) {
|
550 |
507 |
NotificationManager.addError(e.getMessage(), e);
|
551 |
508 |
return null;
|
552 |
509 |
}
|
553 |
510 |
}
|
554 |
|
|
|
511 |
|
555 |
512 |
public Feature insertGeometry(Geometry geometry, Feature feature) {
|
556 |
513 |
VectorialLayerEdited vle = getVLE();
|
557 |
514 |
|
558 |
515 |
try {
|
559 |
|
FeatureStore featureStore =
|
560 |
|
((FLyrVect) vle.getLayer()).getFeatureStore();
|
561 |
|
EditableFeature eFeature =
|
562 |
|
featureStore.createNewFeature(
|
563 |
|
featureStore.getDefaultFeatureType(), feature);
|
|
516 |
FeatureStore featureStore
|
|
517 |
= ((FLyrVect) vle.getLayer()).getFeatureStore();
|
|
518 |
EditableFeature eFeature
|
|
519 |
= featureStore.createNewFeature(
|
|
520 |
featureStore.getDefaultFeatureType(), feature);
|
564 |
521 |
eFeature.setGeometry(featureStore.getDefaultFeatureType()
|
565 |
|
.getDefaultGeometryAttributeName(), geometry);
|
|
522 |
.getDefaultGeometryAttributeName(), geometry);
|
566 |
523 |
|
567 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_INSERT_FEATURE, getVLE().getLayer(), featureStore, feature);
|
568 |
|
if( notification.isProcessCanceled() ) {
|
569 |
|
return null;
|
570 |
|
}
|
|
524 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
571 |
525 |
|
|
526 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
527 |
this,
|
|
528 |
EditingNotification.BEFORE_INSERT_FEATURE,
|
|
529 |
null,
|
|
530 |
vle.getLayer(),
|
|
531 |
featureStore,
|
|
532 |
eFeature
|
|
533 |
);
|
|
534 |
if ( notification.isCanceled() ) {
|
|
535 |
return null;
|
|
536 |
}
|
|
537 |
if ( !validateFeature(eFeature, featureStore) ) {
|
|
538 |
return null;
|
|
539 |
}
|
|
540 |
|
572 |
541 |
featureStore.insert(eFeature);
|
573 |
542 |
insertSpatialCache(geometry);
|
574 |
543 |
draw(geometry, eFeature);
|
575 |
544 |
|
576 |
|
notifyObservers(EditionNotifycation.AFTER_INSERT_FEATURE, vle.getLayer(), featureStore, eFeature);
|
|
545 |
editingNotificationManager.notifyObservers(
|
|
546 |
this,
|
|
547 |
EditingNotification.AFTER_INSERT_FEATURE,
|
|
548 |
null,
|
|
549 |
vle.getLayer(),
|
|
550 |
featureStore,
|
|
551 |
eFeature
|
|
552 |
);
|
577 |
553 |
|
578 |
554 |
return eFeature;
|
579 |
555 |
} catch (Exception e) {
|
... | ... | |
582 |
558 |
}
|
583 |
559 |
}
|
584 |
560 |
|
585 |
|
|
586 |
561 |
public Feature insertFeature(Feature feature) {
|
587 |
562 |
VectorialLayerEdited vle = getVLE();
|
588 |
563 |
|
589 |
564 |
try {
|
590 |
|
|
591 |
|
FeatureStore featureStore =
|
592 |
|
((FLyrVect) vle.getLayer()).getFeatureStore();
|
593 |
|
EditableFeature eFeature =
|
594 |
|
featureStore.createNewFeature(
|
595 |
|
featureStore.getDefaultFeatureType(), feature);
|
|
565 |
|
|
566 |
FeatureStore featureStore
|
|
567 |
= ((FLyrVect) vle.getLayer()).getFeatureStore();
|
|
568 |
EditableFeature eFeature
|
|
569 |
= featureStore.createNewFeature(
|
|
570 |
featureStore.getDefaultFeatureType(), feature);
|
596 |
571 |
Geometry geometry = feature.getDefaultGeometry();
|
597 |
572 |
|
598 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_INSERT_FEATURE, getVLE().getLayer(), featureStore, feature);
|
599 |
|
if( notification.isProcessCanceled() ) {
|
600 |
|
return null;
|
601 |
|
}
|
|
573 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
602 |
574 |
|
603 |
|
featureStore.insert(eFeature);
|
|
575 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
576 |
this,
|
|
577 |
EditingNotification.BEFORE_INSERT_FEATURE,
|
|
578 |
null,
|
|
579 |
vle.getLayer(),
|
|
580 |
featureStore,
|
|
581 |
eFeature
|
|
582 |
);
|
|
583 |
if ( notification.isCanceled() ) {
|
|
584 |
return null;
|
|
585 |
}
|
|
586 |
if ( !validateFeature(eFeature, featureStore) ) {
|
|
587 |
return null;
|
|
588 |
}
|
|
589 |
|
|
590 |
featureStore.insert(eFeature);
|
604 |
591 |
insertSpatialCache(geometry);
|
605 |
592 |
draw(geometry, eFeature);
|
606 |
593 |
|
607 |
|
notifyObservers(EditionNotifycation.AFTER_INSERT_FEATURE, vle.getLayer(), featureStore, eFeature);
|
|
594 |
editingNotificationManager.notifyObservers(
|
|
595 |
this,
|
|
596 |
EditingNotification.AFTER_INSERT_FEATURE,
|
|
597 |
null,
|
|
598 |
vle.getLayer(),
|
|
599 |
featureStore,
|
|
600 |
eFeature
|
|
601 |
);
|
608 |
602 |
|
609 |
603 |
return eFeature;
|
610 |
604 |
} catch (Exception e) {
|
... | ... | |
619 |
613 |
FeatureStore featureStore = getVLE().getFeatureStore();
|
620 |
614 |
featureStore.beginComplexNotification();
|
621 |
615 |
featureStore.beginEditingGroup(toolName);
|
622 |
|
FeatureSelection newSelection =
|
623 |
|
featureStore.createFeatureSelection();
|
|
616 |
FeatureSelection newSelection
|
|
617 |
= featureStore.createFeatureSelection();
|
624 |
618 |
feature = insertGeometry(geometry);
|
625 |
|
if( feature != null ) {
|
626 |
|
newSelection.select(feature);
|
627 |
|
featureStore.setSelection(newSelection);
|
|
619 |
if ( feature != null ) {
|
|
620 |
newSelection.select(feature);
|
|
621 |
featureStore.setSelection(newSelection);
|
628 |
622 |
}
|
629 |
623 |
featureStore.endEditingGroup();
|
630 |
624 |
featureStore.endComplexNotification();
|
631 |
|
|
|
625 |
|
632 |
626 |
} catch (DataException e) {
|
633 |
627 |
NotificationManager.showMessageError("insertAndSelectGeoemtry", e);
|
634 |
628 |
}
|
635 |
629 |
return feature;
|
636 |
630 |
}
|
637 |
|
|
638 |
631 |
|
639 |
632 |
public EditableFeature updateGeometry(FeatureStore store, Feature feature, Geometry geometry) {
|
640 |
|
try {
|
641 |
|
EditableFeature eFeature = feature.getEditable();
|
642 |
|
eFeature.setGeometry(feature.getType()
|
643 |
|
.getDefaultGeometryAttributeName(), geometry);
|
644 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_UPDATE_FEATURE, getVLE().getLayer(), store, feature);
|
645 |
|
if( notification.isProcessCanceled() ) {
|
646 |
|
return null;
|
647 |
|
}
|
648 |
|
store.update(eFeature);
|
|
633 |
try {
|
|
634 |
EditableFeature eFeature = feature.getEditable();
|
|
635 |
eFeature.setGeometry(feature.getType()
|
|
636 |
.getDefaultGeometryAttributeName(), geometry);
|
|
637 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
|
638 |
|
|
639 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
640 |
this,
|
|
641 |
EditingNotification.BEFORE_UPDATE_FEATURE,
|
|
642 |
null,
|
|
643 |
getVLE().getLayer(),
|
|
644 |
store,
|
|
645 |
eFeature
|
|
646 |
);
|
|
647 |
if ( notification.isCanceled() ) {
|
|
648 |
return null;
|
|
649 |
}
|
|
650 |
if ( !validateFeature(eFeature, store) ) {
|
|
651 |
return null;
|
|
652 |
}
|
|
653 |
|
|
654 |
store.update(eFeature);
|
649 |
655 |
updateSpatialCache(geometry);
|
650 |
|
notifyObservers(EditionNotifycation.AFTER_UPDATE_FEATURE, getVLE().getLayer(), store, eFeature);
|
651 |
|
return eFeature;
|
652 |
|
} catch (Exception e) {
|
|
656 |
|
|
657 |
editingNotificationManager.notifyObservers(
|
|
658 |
this,
|
|
659 |
EditingNotification.AFTER_UPDATE_FEATURE,
|
|
660 |
null,
|
|
661 |
getVLE().getLayer(),
|
|
662 |
store,
|
|
663 |
eFeature
|
|
664 |
);
|
|
665 |
|
|
666 |
return eFeature;
|
|
667 |
} catch (Exception e) {
|
653 |
668 |
NotificationManager.addError(e.getMessage(), e);
|
654 |
669 |
return null;
|
655 |
|
}
|
656 |
|
|
|
670 |
}
|
|
671 |
|
657 |
672 |
}
|
658 |
673 |
|
659 |
674 |
public EditableFeature updateFeature(FeatureStore store, Feature feature) {
|
660 |
|
try {
|
661 |
|
EditableFeature eFeature = feature.getEditable();
|
662 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_UPDATE_FEATURE, getVLE().getLayer(), store, feature);
|
663 |
|
if( notification.isProcessCanceled() ) {
|
664 |
|
return null;
|
665 |
|
}
|
666 |
|
store.update(eFeature);
|
|
675 |
try {
|
|
676 |
EditableFeature eFeature = feature.getEditable();
|
|
677 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
|
678 |
|
|
679 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
680 |
this,
|
|
681 |
EditingNotification.BEFORE_UPDATE_FEATURE,
|
|
682 |
null,
|
|
683 |
getVLE().getLayer(),
|
|
684 |
store,
|
|
685 |
eFeature
|
|
686 |
);
|
|
687 |
if ( notification.isCanceled() ) {
|
|
688 |
return null;
|
|
689 |
}
|
|
690 |
if ( !validateFeature(eFeature, store) ) {
|
|
691 |
return null;
|
|
692 |
}
|
|
693 |
|
|
694 |
store.update(eFeature);
|
667 |
695 |
updateSpatialCache(feature.getDefaultGeometry());
|
668 |
|
notifyObservers(EditionNotifycation.AFTER_UPDATE_FEATURE, getVLE().getLayer(), store, eFeature);
|
669 |
|
return eFeature;
|
670 |
|
} catch (Exception e) {
|
|
696 |
editingNotificationManager.notifyObservers(
|
|
697 |
this,
|
|
698 |
EditingNotification.AFTER_UPDATE_FEATURE,
|
|
699 |
null,
|
|
700 |
getVLE().getLayer(),
|
|
701 |
store,
|
|
702 |
eFeature
|
|
703 |
);
|
|
704 |
|
|
705 |
return eFeature;
|
|
706 |
} catch (Exception e) {
|
671 |
707 |
NotificationManager.addError(e.getMessage(), e);
|
672 |
708 |
return null;
|
673 |
|
}
|
674 |
|
|
|
709 |
}
|
|
710 |
|
675 |
711 |
}
|
676 |
|
|
|
712 |
|
677 |
713 |
public void removeFeature(FeatureStore store, Feature feature) {
|
678 |
|
try {
|
679 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_REMOVE_FEATURE, getVLE().getLayer(), store, feature);
|
680 |
|
if( notification.isProcessCanceled() ) {
|
681 |
|
return;
|
682 |
|
}
|
683 |
|
store.delete(feature);
|
|
714 |
try {
|
|
715 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
|
716 |
|
|
717 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
718 |
this,
|
|
719 |
EditingNotification.BEFORE_REMOVE_FEATURE,
|
|
720 |
null,
|
|
721 |
getVLE().getLayer(),
|
|
722 |
store,
|
|
723 |
feature
|
|
724 |
);
|
|
725 |
if ( notification.isCanceled() ) {
|
|
726 |
return;
|
|
727 |
}
|
|
728 |
store.delete(feature);
|
684 |
729 |
removeSpatialCache(feature.getDefaultGeometry());
|
685 |
|
notifyObservers(EditionNotifycation.AFTER_REMOVE_FEATURE, getVLE().getLayer(), store, feature);
|
686 |
|
} catch (Exception e) {
|
|
730 |
|
|
731 |
editingNotificationManager.notifyObservers(
|
|
732 |
this,
|
|
733 |
EditingNotification.AFTER_REMOVE_FEATURE,
|
|
734 |
null,
|
|
735 |
getVLE().getLayer(),
|
|
736 |
store,
|
|
737 |
feature
|
|
738 |
);
|
|
739 |
} catch (Exception e) {
|
687 |
740 |
NotificationManager.addError(e.getMessage(), e);
|
688 |
|
}
|
689 |
|
|
|
741 |
}
|
|
742 |
|
690 |
743 |
}
|
691 |
|
|
692 |
|
public void addObserver(Observer o) {
|
693 |
|
observableHelper.addObserver(o);
|
694 |
|
}
|
695 |
744 |
|
696 |
|
public void deleteObserver(Observer o) {
|
697 |
|
observableHelper.deleteObserver(o);
|
698 |
|
}
|
|
745 |
public void stopEditLayer(DefaultViewPanel view, FLyrVect lv, int mode)
|
|
746 |
throws CancelEditingLayerException, ReadException {
|
699 |
747 |
|
700 |
|
public void deleteObservers() {
|
701 |
|
observableHelper.deleteObservers();
|
702 |
|
}
|
703 |
|
|
704 |
|
private void notifyObservers(EditionNotifycation notifycation) {
|
705 |
|
observableHelper.notifyObservers(this, notifycation);
|
706 |
|
}
|
|
748 |
EditingNotificationManager editingNotificationManager = MapControlLocator.getEditingNotificationManager();
|
707 |
749 |
|
708 |
|
private EditionNotifycation notifyObservers(int type, FLayer layer,
|
709 |
|
FeatureStore store, Feature feature) {
|
710 |
|
DefaultEditionNotifycation notifycation = new DefaultEditionNotifycation(
|
711 |
|
type, layer, store, feature);
|
712 |
|
try {
|
713 |
|
observableHelper.notifyObservers(this, notifycation);
|
714 |
|
} catch (Exception ex) {
|
715 |
|
logger.info("Can't notify observers", ex);
|
716 |
|
}
|
717 |
|
return notifycation;
|
718 |
|
}
|
719 |
|
|
720 |
|
class DefaultEditionNotifycation implements EditionNotifycation {
|
|
750 |
EditingNotification notification = editingNotificationManager.notifyObservers(
|
|
751 |
this,
|
|
752 |
EditingNotification.BEFORE_EXIT_EDITING_STORE,
|
|
753 |
view == null ? null : view.getDocument(),
|
|
754 |
lv);
|
|
755 |
if ( notification.isCanceled() ) {
|
|
756 |
logger.info("Stop edit layer '" + lv.getName() + "' canceled by somme observer.");
|
|
757 |
throw new CancelException("Stop edit layer '" + lv.getName() + "' canceled.");
|
|
758 |
}
|
721 |
759 |
|
722 |
|
private int type;
|
723 |
|
private FLayer layer;
|
724 |
|
private FeatureStore store;
|
725 |
|
private Feature feature;
|
726 |
|
private boolean processCanceled=false;
|
|
760 |
VectorialLayerEdited lyrEd = null;
|
|
761 |
FeatureStore featureStore = null;
|
727 |
762 |
|
728 |
|
DefaultEditionNotifycation(int type, FLayer layer, FeatureStore store, Feature feature) {
|
729 |
|
this.type = type;
|
730 |
|
this.layer = layer;
|
731 |
|
this.store = store;
|
732 |
|
this.feature = feature;
|
733 |
|
}
|
734 |
|
|
735 |
|
public int getNotificationType() {
|
736 |
|
return type;
|
737 |
|
}
|
|
763 |
switch (mode) {
|
738 |
764 |
|
739 |
|
public FLyrVect getLayer() {
|
740 |
|
return (FLyrVect) layer;
|
741 |
|
}
|
|
765 |
case CANCEL_EDITING:
|
|
766 |
lyrEd = (VectorialLayerEdited) this.getActiveLayerEdited();
|
|
767 |
lv.getFeatureStore().deleteObserver(lyrEd);
|
742 |
768 |
|
743 |
|
public FeatureStore getStore() {
|
744 |
|
return store;
|
745 |
|
}
|
|
769 |
try {
|
|
770 |
featureStore = lv.getFeatureStore();
|
746 |
771 |
|
747 |
|
public Feature getFeature() {
|
748 |
|
return feature;
|
749 |
|
}
|
750 |
|
|
751 |
|
public void cancelProcess() {
|
752 |
|
processCanceled = true;
|
753 |
|
}
|
754 |
|
|
755 |
|
public boolean isProcessCanceled() {
|
756 |
|
return processCanceled;
|
757 |
|
}
|
758 |
|
|
759 |
|
}
|
760 |
|
|
761 |
|
|
762 |
|
public void stopEditLayer(DefaultViewPanel view, FLyrVect lv, int mode)
|
763 |
|
throws CancelEditingLayerException, ReadException {
|
764 |
|
|
765 |
|
EditionNotifycation notification = notifyObservers(EditionNotifycation.BEFORE_EXIT_EDIT_LAYER, lv, null, null);
|
766 |
|
if( notification.isProcessCanceled() ) {
|
767 |
|
logger.info("Stop edit layer '"+ lv.getName() + "' canceled by somme observer.");
|
768 |
|
throw new CancelException("Stop edit layer '"+ lv.getName() + "' canceled.");
|
769 |
|
}
|
770 |
|
|
771 |
|
VectorialLayerEdited lyrEd = null;
|
772 |
|
FeatureStore featureStore = null;
|
773 |
|
|
774 |
|
switch (mode) {
|
775 |
|
|
776 |
|
case CANCEL_EDITING:
|
777 |
|
lyrEd = (VectorialLayerEdited) this.getActiveLayerEdited();
|
778 |
|
lv.getFeatureStore().deleteObserver(lyrEd);
|
779 |
|
|
780 |
|
try {
|
781 |
|
featureStore = lv.getFeatureStore();
|
|
772 |
featureStore.cancelEditing();
|
|
773 |
} catch (ReadException e) {
|
|
774 |
throw new CancelEditingLayerException(lv.getName(), e);
|
|
775 |
} catch (DataException e) {
|
|
776 |
throw new CancelEditingLayerException(lv.getName(), e);
|
|
777 |
}
|
|
778 |
lv.getFeatureStore().deleteObserver(view);
|
|
779 |
lv.removeLayerListener(this);
|
782 |
780 |
|
783 |
|
featureStore.cancelEditing();
|
784 |
|
} catch (ReadException e) {
|
785 |
|
throw new CancelEditingLayerException(lv.getName(), e);
|
786 |
|
} catch (DataException e) {
|
787 |
|
throw new CancelEditingLayerException(lv.getName(), e);
|
788 |
|
}
|
789 |
|
lv.getFeatureStore().deleteObserver(view);
|
790 |
|
lv.removeLayerListener(this);
|
791 |
|
|
792 |
|
if (view != null) {
|
793 |
|
view.getMapControl().getMapContext().removeLayerDrawListener(lyrEd);
|
794 |
|
}
|
795 |
|
break;
|
796 |
|
case ACCEPT_EDITING:
|
797 |
|
featureStore = lv.getFeatureStore();
|
798 |
|
try {
|
799 |
|
|
800 |
|
/*
|
801 |
|
* This will throw a WriteException
|
802 |
|
* also if the provider does not accept
|
803 |
|
* the changes (added/updated/deleted/updated featuretype)
|
804 |
|
*/
|
805 |
|
featureStore.finishEditing();
|
806 |
|
|
807 |
|
} catch (DataException e) {
|
808 |
|
throw new ReadException(lv.getName(), e);
|
809 |
|
}
|
810 |
|
lyrEd = (VectorialLayerEdited) this.getActiveLayerEdited();
|
811 |
|
featureStore.deleteObserver(lyrEd);
|
812 |
|
featureStore.deleteObserver(view);
|
813 |
|
lv.removeLayerListener(this);
|
814 |
|
if (view != null) {
|
815 |
|
view.getMapControl().getMapContext().removeLayerDrawListener(lyrEd);
|
816 |
|
}
|
|
781 |
if ( view != null ) {
|
|
782 |
view.getMapControl().getMapContext().removeLayerDrawListener(lyrEd);
|
|
783 |
}
|
|
784 |
break;
|
|
785 |
case ACCEPT_EDITING:
|
|
786 |
featureStore = lv.getFeatureStore();
|
|
787 |
try {
|
817 |
788 |
|
818 |
|
break;
|
819 |
|
case CONTINUE_EDITING:
|
820 |
|
break;
|
821 |
|
}
|
822 |
|
|
823 |
|
notifyObservers(EditionNotifycation.AFTER_EXIT_EDIT_LAYER, lv, null, null);
|
|
789 |
/*
|
|
790 |
* This will throw a WriteException
|
|
791 |
* also if the provider does not accept
|
|
792 |
* the changes (added/updated/deleted/updated featuretype)
|
|
793 |
*/
|
|
794 |
featureStore.finishEditing();
|
824 |
795 |
|
825 |
|
}
|
|
796 |
} catch (DataException e) {
|
|
797 |
throw new ReadException(lv.getName(), e);
|
|
798 |
}
|
|
799 |
lyrEd = (VectorialLayerEdited) this.getActiveLayerEdited();
|
|
800 |
featureStore.deleteObserver(lyrEd);
|
|
801 |
featureStore.deleteObserver(view);
|
|
802 |
lv.removeLayerListener(this);
|
|
803 |
if ( view != null ) {
|
|
804 |
view.getMapControl().getMapContext().removeLayerDrawListener(lyrEd);
|
|
805 |
}
|
|
806 |
|
|
807 |
break;
|
|
808 |
case CONTINUE_EDITING:
|
|
809 |
break;
|
|
810 |
}
|
|
811 |
|
|
812 |
editingNotificationManager.notifyObservers(
|
|
813 |
this,
|
|
814 |
EditingNotification.AFTER_EXIT_EDITING_STORE,
|
|
815 |
view == null ? null : view.getDocument(),
|
|
816 |
lv);
|
|
817 |
|
|
818 |
}
|
|
819 |
|
826 |
820 |
}
|