Revision 38871 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 |
|
|
16 | 19 |
import org.gvsig.andami.PluginServices; |
17 | 20 |
import org.gvsig.andami.PluginsLocator; |
18 | 21 |
import org.gvsig.andami.messages.NotificationManager; |
... | ... | |
21 | 24 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
22 | 25 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
23 | 26 |
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; |
|
24 | 30 |
import org.gvsig.app.project.Project; |
25 | 31 |
import org.gvsig.app.project.ProjectManager; |
26 | 32 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
27 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
28 | 33 |
import org.gvsig.app.project.documents.view.ViewManager; |
29 | 34 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
30 | 35 |
import org.gvsig.editing.gui.cad.CADToolAdapter; |
... | ... | |
54 | 59 |
* posibilidad de guardar este tema ser? "Guardando como..." |
55 | 60 |
*/ |
56 | 61 |
public class StopEditing extends Extension { |
57 |
private DefaultViewPanel vista; |
|
62 |
|
|
63 |
private static Logger logger = LoggerFactory.getLogger(StopEditing.class); |
|
58 | 64 |
|
59 | 65 |
/** |
60 | 66 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
... | ... | |
66 | 72 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
67 | 73 |
*/ |
68 | 74 |
public void execute(String s) { |
69 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices |
|
70 |
.getMDIManager().getActiveWindow(); |
|
71 |
|
|
72 |
vista = (DefaultViewPanel) f; |
|
75 |
|
|
73 | 76 |
boolean isStop = false; |
74 |
ViewDocument model = vista.getModel(); |
|
75 |
MapContext mapa = model.getMapContext(); |
|
76 |
FLayers layers = mapa.getLayers(); |
|
77 | 77 |
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(); |
|
78 | 87 |
|
79 | 88 |
if (s.equals("layer-stop-editing")) { |
80 |
vista.getMapControl().getCanceldraw().setCanceled(true); |
|
81 |
FLayer[] actives = layers.getActives(); |
|
82 |
// TODO: Comprobar que solo hay una activa, o al menos |
|
83 |
// que solo hay una en edici?n que est? activa, etc, etc |
|
84 |
for (int i = 0; i < actives.length; i++) { |
|
85 |
if (actives[i] instanceof FLyrVect && actives[i].isEditing()) { |
|
86 |
FLyrVect lv = (FLyrVect) actives[i]; |
|
87 |
MapControl mapControl = vista.getMapControl(); |
|
88 |
VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan |
|
89 |
.getActiveLayerEdited(); |
|
90 |
lv.getFeatureStore().deleteObserver(lyrEd); |
|
91 |
isStop = stopEditing(lv, mapControl); |
|
92 |
if (isStop) { |
|
93 |
lv.removeLayerListener(edMan); |
|
94 |
mapControl.getMapContext().removeLayerDrawListener( |
|
95 |
lyrEd); |
|
96 |
// if (lv instanceof FLyrAnnotation){ |
|
97 |
// FLyrAnnotation lva=(FLyrAnnotation)lv; |
|
98 |
// lva.setMapping(lva.getMapping()); |
|
99 |
// } |
|
100 |
} else { |
|
101 |
lv.getFeatureStore().addObserver(lyrEd); |
|
89 |
mco.getCanceldraw().setCanceled(true); |
|
102 | 90 |
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
if (isStop) {
|
|
107 |
vista.getMapControl().setTool("zoomIn");
|
|
108 |
vista.hideConsole();
|
|
109 |
vista.repaintMap();
|
|
110 |
CADExtension.clearView();
|
|
111 |
|
|
112 |
}
|
|
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 |
}
|
|
113 | 101 |
} |
114 | 102 |
PluginServices.getMainFrame().enableControls(); |
115 | 103 |
} |
... | ... | |
200 | 188 |
layer.setEditing(false); |
201 | 189 |
return true; |
202 | 190 |
} else if (resp == JOptionPane.YES_OPTION) { |
203 |
int status = exportLayer(layer); |
|
191 |
int status = exportLayer(layer, mapControl.getMapContext());
|
|
204 | 192 |
if (status == JOptionPane.OK_OPTION) { |
205 | 193 |
cancelEdition(layer); |
206 | 194 |
layer.setEditing(false); |
... | ... | |
292 | 280 |
} |
293 | 281 |
} |
294 | 282 |
|
295 |
private int exportLayer(FLyrVect layer) throws ReadException { |
|
296 |
ViewDocument model = vista.getModel(); |
|
297 |
MapContext mapContext = model.getMapContext(); |
|
298 |
IProjection projection = mapContext.getProjection(); |
|
283 |
private int exportLayer(FLyrVect layer, MapContext mctxt) throws ReadException { |
|
299 | 284 |
|
300 |
ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator |
|
301 |
.getManager().getExtension(ExporttoLayerExtension.class); |
|
302 |
return extension.showExportto(layer, projection, mapContext); |
|
303 |
} |
|
285 |
IProjection projection = mctxt.getProjection(); |
|
304 | 286 |
|
287 |
ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator |
|
288 |
.getManager().getExtension(ExporttoLayerExtension.class); |
|
289 |
return extension.showExportto(layer, projection, mctxt); |
|
290 |
} |
|
291 |
|
|
305 | 292 |
/** |
306 | 293 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
307 | 294 |
*/ |
... | ... | |
383 | 370 |
// FLyrAnnotation lva=(FLyrAnnotation)layer; |
384 | 371 |
// lva.setMapping(lva.getMapping()); |
385 | 372 |
// } |
386 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices |
|
387 |
.getMDIManager().getActiveWindow(); |
|
388 |
if (f instanceof DefaultViewPanel) { |
|
389 |
vista = (DefaultViewPanel) f; |
|
390 |
FLayer auxLayer = vista.getMapControl().getMapContext() |
|
391 |
.getLayers().getLayer(layer.getName()); |
|
392 |
if (auxLayer != null && auxLayer.equals(layer)) { |
|
393 |
vista.getMapControl().setTool("zoomIn"); |
|
394 |
vista.hideConsole(); |
|
395 |
vista.repaintMap(); |
|
396 |
CADExtension.clearView(); |
|
397 |
} |
|
398 |
} |
|
373 |
CADExtension.clearView(); |
|
374 |
hideEditingConsole("zoomIn", layer); |
|
399 | 375 |
} |
400 | 376 |
} catch (ReadException e1) { |
401 | 377 |
NotificationManager.showMessageError(e1.getMessage(), e1); |
... | ... | |
527 | 503 |
} |
528 | 504 |
}; |
529 | 505 |
} |
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 |
} |
|
530 | 555 |
} |
Also available in: Unified diff