Revision 38872 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/StopEditing.java
StopEditing.java | ||
---|---|---|
13 | 13 |
import javax.swing.JPanel; |
14 | 14 |
|
15 | 15 |
import org.cresques.cts.IProjection; |
16 |
import org.slf4j.Logger; |
|
17 |
import org.slf4j.LoggerFactory; |
|
18 |
|
|
19 | 16 |
import org.gvsig.andami.PluginServices; |
20 | 17 |
import org.gvsig.andami.PluginsLocator; |
21 | 18 |
import org.gvsig.andami.messages.NotificationManager; |
... | ... | |
24 | 21 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
25 | 22 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
26 | 23 |
import org.gvsig.andami.plugins.status.UnsavedData; |
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
28 |
import org.gvsig.app.ApplicationLocator; |
|
29 |
import org.gvsig.app.ApplicationManager; |
|
30 | 24 |
import org.gvsig.app.project.Project; |
31 | 25 |
import org.gvsig.app.project.ProjectManager; |
32 | 26 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
27 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
33 | 28 |
import org.gvsig.app.project.documents.view.ViewManager; |
34 | 29 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
35 | 30 |
import org.gvsig.editing.gui.cad.CADToolAdapter; |
... | ... | |
57 | 52 |
* ISpatialWriter. En ese caso, es capaz de guardarse sobre s? mismo. Si |
58 | 53 |
* no lo implementa, esta opci?n estar? deshabilitada y la ?nica |
59 | 54 |
* posibilidad de guardar este tema ser? "Guardando como..." |
55 |
* |
|
60 | 56 |
*/ |
61 | 57 |
public class StopEditing extends Extension { |
62 |
|
|
63 |
private static Logger logger = LoggerFactory.getLogger(StopEditing.class); |
|
58 |
private DefaultViewPanel vista; |
|
64 | 59 |
|
65 | 60 |
/** |
66 | 61 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
... | ... | |
72 | 67 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
73 | 68 |
*/ |
74 | 69 |
public void execute(String s) { |
75 |
|
|
70 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices |
|
71 |
.getMDIManager().getActiveWindow(); |
|
72 |
|
|
73 |
vista = (DefaultViewPanel) f; |
|
76 | 74 |
boolean isStop = false; |
75 |
ViewDocument model = vista.getModel(); |
|
76 |
MapContext mapa = model.getMapContext(); |
|
77 |
FLayers layers = mapa.getLayers(); |
|
77 | 78 |
EditionManager edMan = CADExtension.getEditionManager(); |
78 |
VectorialLayerEdited ile = (VectorialLayerEdited) edMan.getActiveLayerEdited(); |
|
79 |
FLayer _layer = ile.getLayer(); |
|
80 |
if (!(_layer instanceof FLyrVect)) { |
|
81 |
logger.error("Editing layer is not of class FLyrVect (?)"); |
|
82 |
return; |
|
83 |
} |
|
84 |
|
|
85 |
FLyrVect edit_layer = (FLyrVect) _layer; |
|
86 |
MapControl mco = edMan.getMapControl(); |
|
87 | 79 |
|
88 | 80 |
if (s.equals("layer-stop-editing")) { |
89 |
mco.getCanceldraw().setCanceled(true); |
|
81 |
vista.getMapControl().getCanceldraw().setCanceled(true); |
|
82 |
FLayer[] actives = layers.getActives(); |
|
83 |
// TODO: Comprobar que solo hay una activa, o al menos |
|
84 |
// que solo hay una en edici?n que est? activa, etc, etc |
|
85 |
for (int i = 0; i < actives.length; i++) { |
|
86 |
if (actives[i] instanceof FLyrVect && actives[i].isEditing()) { |
|
87 |
FLyrVect lv = (FLyrVect) actives[i]; |
|
88 |
MapControl mapControl = vista.getMapControl(); |
|
89 |
VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan |
|
90 |
.getActiveLayerEdited(); |
|
91 |
lv.getFeatureStore().deleteObserver(lyrEd); |
|
92 |
isStop = stopEditing(lv, mapControl); |
|
93 |
if (isStop) { |
|
94 |
lv.removeLayerListener(edMan); |
|
95 |
mapControl.getMapContext().removeLayerDrawListener( |
|
96 |
lyrEd); |
|
97 |
// if (lv instanceof FLyrAnnotation){ |
|
98 |
// FLyrAnnotation lva=(FLyrAnnotation)lv; |
|
99 |
// lva.setMapping(lva.getMapping()); |
|
100 |
// } |
|
101 |
} else { |
|
102 |
lv.getFeatureStore().addObserver(lyrEd); |
|
90 | 103 |
|
91 |
edit_layer.getFeatureStore().deleteObserver(ile);
|
|
92 |
isStop = stopEditing(edit_layer, mco);
|
|
93 |
if (isStop) {
|
|
94 |
edit_layer.removeLayerListener(edMan);
|
|
95 |
mco.getMapContext().removeLayerDrawListener(ile);
|
|
96 |
hideEditingConsole("zoomIn", edit_layer);
|
|
97 |
CADExtension.clearView();
|
|
98 |
} else {
|
|
99 |
edit_layer.getFeatureStore().addObserver(ile); |
|
100 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
}
|
|
107 |
if (isStop) {
|
|
108 |
vista.getMapControl().setTool("zoomIn");
|
|
109 |
vista.hideConsole();
|
|
110 |
vista.repaintMap();
|
|
111 |
CADExtension.clearView();
|
|
112 |
|
|
113 |
}
|
|
101 | 114 |
} |
102 | 115 |
PluginServices.getMainFrame().enableControls(); |
103 | 116 |
} |
... | ... | |
188 | 201 |
layer.setEditing(false); |
189 | 202 |
return true; |
190 | 203 |
} else if (resp == JOptionPane.YES_OPTION) { |
191 |
int status = exportLayer(layer, mapControl.getMapContext());
|
|
204 |
int status = exportLayer(layer); |
|
192 | 205 |
if (status == JOptionPane.OK_OPTION) { |
193 | 206 |
cancelEdition(layer); |
194 | 207 |
layer.setEditing(false); |
... | ... | |
280 | 293 |
} |
281 | 294 |
} |
282 | 295 |
|
283 |
private int exportLayer(FLyrVect layer, MapContext mctxt) throws ReadException { |
|
296 |
private int exportLayer(FLyrVect layer) throws ReadException { |
|
297 |
ViewDocument model = vista.getModel(); |
|
298 |
MapContext mapContext = model.getMapContext(); |
|
299 |
IProjection projection = mapContext.getProjection(); |
|
284 | 300 |
|
285 |
IProjection projection = mctxt.getProjection(); |
|
301 |
ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator |
|
302 |
.getManager().getExtension(ExporttoLayerExtension.class); |
|
303 |
return extension.showExportto(layer, projection, mapContext); |
|
304 |
} |
|
286 | 305 |
|
287 |
ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator |
|
288 |
.getManager().getExtension(ExporttoLayerExtension.class); |
|
289 |
return extension.showExportto(layer, projection, mctxt); |
|
290 |
} |
|
291 |
|
|
292 | 306 |
/** |
293 | 307 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
294 | 308 |
*/ |
... | ... | |
370 | 384 |
// FLyrAnnotation lva=(FLyrAnnotation)layer; |
371 | 385 |
// lva.setMapping(lva.getMapping()); |
372 | 386 |
// } |
373 |
CADExtension.clearView(); |
|
374 |
hideEditingConsole("zoomIn", layer); |
|
387 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices |
|
388 |
.getMDIManager().getActiveWindow(); |
|
389 |
if (f instanceof DefaultViewPanel) { |
|
390 |
vista = (DefaultViewPanel) f; |
|
391 |
FLayer auxLayer = vista.getMapControl().getMapContext() |
|
392 |
.getLayers().getLayer(layer.getName()); |
|
393 |
if (auxLayer != null && auxLayer.equals(layer)) { |
|
394 |
vista.getMapControl().setTool("zoomIn"); |
|
395 |
vista.hideConsole(); |
|
396 |
vista.repaintMap(); |
|
397 |
CADExtension.clearView(); |
|
398 |
} |
|
399 |
} |
|
375 | 400 |
} |
376 | 401 |
} catch (ReadException e1) { |
377 | 402 |
NotificationManager.showMessageError(e1.getMessage(), e1); |
... | ... | |
503 | 528 |
} |
504 | 529 |
}; |
505 | 530 |
} |
506 |
|
|
507 |
private void hideEditingConsole(String new_tool, FLayer edit_layer) { |
|
508 |
|
|
509 |
ApplicationManager appm = ApplicationLocator.getManager(); |
|
510 |
IWindow[] ww = appm.getUIManager().getAllWindows(); |
|
511 |
DefaultViewPanel view = null; |
|
512 |
for (int i=0; i<ww.length; i++) { |
|
513 |
if (ww[i] instanceof DefaultViewPanel) { |
|
514 |
view = (DefaultViewPanel) ww[i]; |
|
515 |
MapContext ctxt = view.getMapControl().getMapContext(); |
|
516 |
if (isItsMapContext(edit_layer, ctxt)) { |
|
517 |
view.hideConsole(); |
|
518 |
if (new_tool != null) { |
|
519 |
view.getMapControl().setTool(new_tool); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
|
|
526 |
/** |
|
527 |
* Tells whether the layer is in the mapContext or not |
|
528 |
* @param lyr |
|
529 |
* @param mco |
|
530 |
* @return |
|
531 |
*/ |
|
532 |
private boolean isItsMapContext(FLayer lyr, MapContext mco) { |
|
533 |
|
|
534 |
if (lyr == null || mco == null) { |
|
535 |
return false; |
|
536 |
} |
|
537 |
|
|
538 |
FLayers prnt = null; |
|
539 |
if (lyr instanceof FLayers) { |
|
540 |
prnt = (FLayers) lyr; |
|
541 |
} else { |
|
542 |
prnt = lyr.getParentLayer(); |
|
543 |
} |
|
544 |
|
|
545 |
if (prnt == null) { |
|
546 |
return false; |
|
547 |
} |
|
548 |
|
|
549 |
while (prnt.getParentLayer() != null) { |
|
550 |
prnt = prnt.getParentLayer(); |
|
551 |
} |
|
552 |
|
|
553 |
return prnt == mco.getLayers(); |
|
554 |
} |
|
555 | 531 |
} |
Also available in: Unified diff