svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / StopEditing.java @ 40557
History | View | Annotate | Download (20.1 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Component; |
28 |
import java.awt.Font; |
29 |
import java.awt.GridBagConstraints; |
30 |
import java.awt.GridBagLayout; |
31 |
import java.awt.Insets; |
32 |
import java.util.ArrayList; |
33 |
|
34 |
import javax.swing.JLabel; |
35 |
import javax.swing.JOptionPane; |
36 |
import javax.swing.JPanel; |
37 |
|
38 |
import org.cresques.cts.IProjection; |
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.PluginsLocator; |
44 |
import org.gvsig.andami.messages.NotificationManager; |
45 |
import org.gvsig.andami.plugins.Extension; |
46 |
import org.gvsig.andami.plugins.IExtension; |
47 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
48 |
import org.gvsig.andami.plugins.status.IUnsavedData; |
49 |
import org.gvsig.andami.plugins.status.UnsavedData; |
50 |
import org.gvsig.app.project.Project; |
51 |
import org.gvsig.app.project.ProjectManager; |
52 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
53 |
import org.gvsig.app.project.documents.view.ViewDocument; |
54 |
import org.gvsig.app.project.documents.view.ViewManager; |
55 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
56 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
57 |
import org.gvsig.exportto.app.extension.ExporttoLayerExtension; |
58 |
import org.gvsig.fmap.dal.exception.DataException; |
59 |
import org.gvsig.fmap.dal.exception.ReadException; |
60 |
import org.gvsig.fmap.mapcontext.MapContext; |
61 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
62 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
63 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
65 |
import org.gvsig.fmap.mapcontrol.MapControl; |
66 |
import org.gvsig.i18n.Messages; |
67 |
import org.gvsig.utils.swing.threads.IMonitorableTask; |
68 |
|
69 |
/**
|
70 |
* @author Francisco Jos?
|
71 |
*
|
72 |
* Cuando un tema se pone en edici?n, puede que su driver implemente
|
73 |
* ISpatialWriter. En ese caso, es capaz de guardarse sobre s? mismo. Si
|
74 |
* no lo implementa, esta opci?n estar? deshabilitada y la ?nica
|
75 |
* posibilidad de guardar este tema ser? "Guardando como..."
|
76 |
*
|
77 |
*/
|
78 |
public class StopEditing extends Extension { |
79 |
|
80 |
private final static Logger logger = LoggerFactory.getLogger(StopEditing.class); |
81 |
|
82 |
private DefaultViewPanel vista;
|
83 |
|
84 |
/**
|
85 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
86 |
*/
|
87 |
public void initialize() { |
88 |
} |
89 |
|
90 |
/**
|
91 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
92 |
*/
|
93 |
public void execute(String s) { |
94 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices |
95 |
.getMDIManager().getActiveWindow(); |
96 |
|
97 |
vista = (DefaultViewPanel) f; |
98 |
boolean isStop = false; |
99 |
ViewDocument model = vista.getModel(); |
100 |
MapContext mapa = model.getMapContext(); |
101 |
FLayers layers = mapa.getLayers(); |
102 |
IEditionManager edMan = EditionLocator.getEditionManager(); |
103 |
|
104 |
if (s.equals("layer-stop-editing")) { |
105 |
vista.getMapControl().getCanceldraw().setCanceled(true);
|
106 |
FLayer[] actives = layers.getActives();
|
107 |
// TODO: Comprobar que solo hay una activa, o al menos
|
108 |
// que solo hay una en edici?n que est? activa, etc, etc
|
109 |
for (int i = 0; i < actives.length; i++) { |
110 |
if (actives[i] instanceof FLyrVect && actives[i].isEditing()) { |
111 |
FLyrVect lv = (FLyrVect) actives[i]; |
112 |
MapControl mapControl = vista.getMapControl(); |
113 |
|
114 |
int user_opt = confirmStop(lv, mapControl);
|
115 |
if (user_opt != IEditionManager.CONTINUE_EDITING) {
|
116 |
isStop = true;
|
117 |
} |
118 |
|
119 |
try {
|
120 |
edMan.stopEditLayer(vista, lv, user_opt); |
121 |
} catch (Exception ex) { |
122 |
logger.error("While stopping layer editing.", ex);
|
123 |
} |
124 |
} |
125 |
} |
126 |
|
127 |
if (isStop) {
|
128 |
CADExtension.clearView(); |
129 |
} |
130 |
} |
131 |
PluginServices.getMainFrame().enableControls(); |
132 |
} |
133 |
|
134 |
|
135 |
/**
|
136 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
137 |
*/
|
138 |
public boolean isEnabled() { |
139 |
FLayer[] lyrs = EditionUtilities.getActiveAndEditedLayers();
|
140 |
if (lyrs == null) { |
141 |
return false; |
142 |
} |
143 |
FLyrVect lyrVect = (FLyrVect) lyrs[0];
|
144 |
if (lyrVect.isEditing()) {
|
145 |
return true; |
146 |
} |
147 |
return false; |
148 |
} |
149 |
|
150 |
/**
|
151 |
* DOCUMENT ME!
|
152 |
*/
|
153 |
|
154 |
/*
|
155 |
public boolean stopEditing(FLyrVect layer, MapControl mapControl) {
|
156 |
int resp = JOptionPane.CANCEL_OPTION;
|
157 |
|
158 |
try {
|
159 |
if (layer.isWritable()) {
|
160 |
Object[] options = {
|
161 |
PluginServices.getText(this, "_Guardar"),
|
162 |
" " + PluginServices.getText(this, "_Descartar") + " ",
|
163 |
PluginServices.getText(this, "_Continuar") };
|
164 |
|
165 |
JPanel explanation_panel = getExplanationPanel(layer.getName());
|
166 |
|
167 |
resp = JOptionPane
|
168 |
.showOptionDialog(
|
169 |
(Component) PluginServices.getMainFrame(),
|
170 |
explanation_panel,
|
171 |
PluginServices.getText(this, "stop_edition"),
|
172 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
173 |
JOptionPane.QUESTION_MESSAGE, null, options,
|
174 |
options[2]);
|
175 |
|
176 |
if (resp == JOptionPane.YES_OPTION) {
|
177 |
// SAVE
|
178 |
saveLayer(layer);
|
179 |
// layer.setEditing(false);
|
180 |
return true;
|
181 |
} else if (resp == JOptionPane.NO_OPTION) {
|
182 |
// CANCEL EDITING
|
183 |
cancelEdition(layer);
|
184 |
// layer.setEditing(false);
|
185 |
return true;
|
186 |
} else if (resp == JOptionPane.CANCEL_OPTION) {
|
187 |
// CONTINUE EDITING
|
188 |
return false;
|
189 |
} else {
|
190 |
// This happens when user clicks on [x]
|
191 |
// to abruptly close previous JOptionPane dialog
|
192 |
// We make it equivalent to CONTINUE EDITING
|
193 |
return false;
|
194 |
}
|
195 |
|
196 |
}
|
197 |
// ========================================
|
198 |
// Layer cannot save changes:
|
199 |
|
200 |
Object[] options = {
|
201 |
PluginServices.getText(this, "export"),
|
202 |
PluginServices.getText(this,
|
203 |
"finish_editing_without_saving_changes"),
|
204 |
PluginServices.getText(this, "continue_editing") };
|
205 |
|
206 |
resp = JOptionPane
|
207 |
.showOptionDialog(
|
208 |
(Component) PluginServices.getMainFrame(),
|
209 |
PluginServices
|
210 |
.getText(
|
211 |
this,
|
212 |
"no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer")
|
213 |
+ " : " + layer.getName(), PluginServices
|
214 |
.getText(this, "stop_edition"),
|
215 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
216 |
JOptionPane.QUESTION_MESSAGE, null, options,
|
217 |
options[2]);
|
218 |
if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING
|
219 |
cancelEdition(layer);
|
220 |
// layer.setEditing(false);
|
221 |
return true;
|
222 |
} else if (resp == JOptionPane.YES_OPTION) {
|
223 |
int status = exportLayer(layer);
|
224 |
if (status == JOptionPane.OK_OPTION) {
|
225 |
cancelEdition(layer);
|
226 |
// layer.setEditing(false);
|
227 |
}
|
228 |
}
|
229 |
|
230 |
} catch (ReadException e) {
|
231 |
NotificationManager.addError(e);
|
232 |
} catch (CancelEditingLayerException e) {
|
233 |
NotificationManager.addError(e);
|
234 |
}
|
235 |
return false;
|
236 |
|
237 |
}
|
238 |
*/
|
239 |
|
240 |
|
241 |
public int confirmStop(FLyrVect layer, MapControl mapControl) { |
242 |
int resp = JOptionPane.CANCEL_OPTION; |
243 |
|
244 |
try {
|
245 |
if (layer.isWritable()) {
|
246 |
Object[] options = { |
247 |
PluginServices.getText(this, "_Guardar"), |
248 |
" " + PluginServices.getText(this, "_Descartar") + " ", |
249 |
PluginServices.getText(this, "_Continuar") }; |
250 |
|
251 |
JPanel explanation_panel = getExplanationPanel(layer.getName());
|
252 |
|
253 |
resp = JOptionPane
|
254 |
.showOptionDialog( |
255 |
(Component) PluginServices.getMainFrame(),
|
256 |
explanation_panel, |
257 |
PluginServices.getText(this, "stop_edition"), |
258 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
259 |
JOptionPane.QUESTION_MESSAGE, null, options, |
260 |
options[2]);
|
261 |
|
262 |
if (resp == JOptionPane.YES_OPTION) { |
263 |
return IEditionManager.ACCEPT_EDITING;
|
264 |
} else if (resp == JOptionPane.NO_OPTION) { |
265 |
return IEditionManager.CANCEL_EDITING;
|
266 |
} else if (resp == JOptionPane.CANCEL_OPTION) { |
267 |
return IEditionManager.CONTINUE_EDITING;
|
268 |
} else {
|
269 |
// This happens when user clicks on [x]
|
270 |
// to abruptly close previous JOptionPane dialog
|
271 |
// We make it equivalent to CONTINUE EDITING
|
272 |
return IEditionManager.CONTINUE_EDITING;
|
273 |
} |
274 |
|
275 |
} |
276 |
// ========================================
|
277 |
// Layer cannot save changes:
|
278 |
|
279 |
Object[] options = { |
280 |
PluginServices.getText(this, "export"), |
281 |
PluginServices.getText(this,
|
282 |
"finish_editing_without_saving_changes"),
|
283 |
PluginServices.getText(this, "continue_editing") }; |
284 |
|
285 |
resp = JOptionPane
|
286 |
.showOptionDialog( |
287 |
(Component) PluginServices.getMainFrame(),
|
288 |
PluginServices |
289 |
.getText( |
290 |
this,
|
291 |
"no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer")
|
292 |
+ " : " + layer.getName(), PluginServices
|
293 |
.getText(this, "stop_edition"), |
294 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
295 |
JOptionPane.QUESTION_MESSAGE, null, options, |
296 |
options[2]);
|
297 |
if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING |
298 |
return IEditionManager.CANCEL_EDITING;
|
299 |
} else if (resp == JOptionPane.YES_OPTION) { |
300 |
int status = exportLayer(layer);
|
301 |
if (status == JOptionPane.OK_OPTION) { |
302 |
return IEditionManager.CANCEL_EDITING;
|
303 |
} |
304 |
} |
305 |
|
306 |
} catch (ReadException e) {
|
307 |
NotificationManager.addError(e); |
308 |
} |
309 |
return IEditionManager.CONTINUE_EDITING;
|
310 |
|
311 |
|
312 |
} |
313 |
|
314 |
|
315 |
private JPanel getExplanationPanel( |
316 |
String layer_name) {
|
317 |
|
318 |
JPanel resp = new JPanel(new BorderLayout(10, 10)); |
319 |
|
320 |
String msg = Messages.getText("realmente_desea_guardar_la_capa"); |
321 |
msg = msg + " '" + layer_name + "'?"; |
322 |
JLabel topLabel = new JLabel(msg); |
323 |
|
324 |
JPanel mainPanel = new JPanel(new GridBagLayout()); |
325 |
GridBagConstraints cc = new GridBagConstraints(); |
326 |
|
327 |
cc.gridx = 0;
|
328 |
cc.gridy = 0;
|
329 |
cc.anchor = GridBagConstraints.WEST;
|
330 |
|
331 |
cc.insets = new Insets(3, 6, 3, 6); |
332 |
|
333 |
Font boldf = mainPanel.getFont().deriveFont(Font.BOLD); |
334 |
|
335 |
JLabel lbl = new JLabel(Messages.getText("_Guardar")); |
336 |
lbl.setFont(boldf); |
337 |
mainPanel.add(lbl, cc); |
338 |
cc.gridx = 1;
|
339 |
mainPanel.add(new JLabel(Messages.getText("_Save_changes_performed")), cc); |
340 |
|
341 |
cc.gridx = 0;
|
342 |
cc.gridy = 1;
|
343 |
lbl = new JLabel(Messages.getText("_Descartar")); |
344 |
lbl.setFont(boldf); |
345 |
mainPanel.add(lbl, cc); |
346 |
cc.gridx = 1;
|
347 |
mainPanel.add(new JLabel(Messages.getText("_Discard_and_lose_changes")), cc); |
348 |
|
349 |
cc.gridx = 0;
|
350 |
cc.gridy = 2;
|
351 |
lbl = new JLabel(Messages.getText("_Continuar")); |
352 |
lbl.setFont(boldf); |
353 |
mainPanel.add(lbl, cc); |
354 |
cc.gridx = 1;
|
355 |
mainPanel.add(new JLabel(Messages.getText("_Do_not_save_yet_Stay_in_editing_mode")), cc); |
356 |
|
357 |
resp.add(mainPanel, BorderLayout.CENTER);
|
358 |
resp.add(topLabel, BorderLayout.NORTH);
|
359 |
return resp;
|
360 |
} |
361 |
|
362 |
|
363 |
/*
|
364 |
private void saveLayer(FLyrVect layer) throws ReadException {
|
365 |
FeatureStore featureStore = layer.getFeatureStore();
|
366 |
try {
|
367 |
featureStore.finishEditing();
|
368 |
} catch (WriteException e) {
|
369 |
throw new ReadException(featureStore.getName(), e);
|
370 |
} catch (DataException e) {
|
371 |
throw new ReadException(featureStore.getName(), e);
|
372 |
}
|
373 |
}
|
374 |
|
375 |
private void cancelEdition(FLyrVect layer)
|
376 |
throws CancelEditingLayerException {
|
377 |
FeatureStore featureStore = null;
|
378 |
try {
|
379 |
featureStore = layer.getFeatureStore();
|
380 |
|
381 |
featureStore.cancelEditing();
|
382 |
} catch (ReadException e) {
|
383 |
throw new CancelEditingLayerException(layer.getName(), e);
|
384 |
} catch (DataException e) {
|
385 |
throw new CancelEditingLayerException(layer.getName(), e);
|
386 |
}
|
387 |
}
|
388 |
*/
|
389 |
|
390 |
private int exportLayer(FLyrVect layer) throws ReadException { |
391 |
ViewDocument model = vista.getModel(); |
392 |
MapContext mapContext = model.getMapContext(); |
393 |
IProjection projection = mapContext.getProjection(); |
394 |
|
395 |
ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator |
396 |
.getManager().getExtension(ExporttoLayerExtension.class); |
397 |
return extension.showExportto(layer, projection, mapContext);
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
402 |
*/
|
403 |
public boolean isVisible() { |
404 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
|
405 |
return true; |
406 |
} |
407 |
return false; |
408 |
|
409 |
} |
410 |
|
411 |
public IExtensionStatus getStatus() {
|
412 |
return new StopEditingStatus(); |
413 |
} |
414 |
|
415 |
/**
|
416 |
* Show the dialogs to save the layer without ask if don't like to save.
|
417 |
*
|
418 |
* @param layer
|
419 |
* Layer to save.
|
420 |
*/
|
421 |
public boolean executeSaveLayer(FLyrVect layer) { |
422 |
|
423 |
IEditionManager edMan = EditionLocator.getEditionManager(layer); |
424 |
|
425 |
VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan |
426 |
.getLayerEdited(layer); |
427 |
boolean isStop = false; |
428 |
try {
|
429 |
lyrEd.clearSelection(); |
430 |
|
431 |
if (layer.isWritable()) {
|
432 |
|
433 |
try {
|
434 |
edMan.stopEditLayer(null, layer, IEditionManager.ACCEPT_EDITING);
|
435 |
} catch (Exception ex) { |
436 |
logger.error("While stopping layer editing.", ex);
|
437 |
} |
438 |
|
439 |
// saveLayer(layer);
|
440 |
// layer.setEditing(false);
|
441 |
// if (layer.isSpatiallyIndexed())
|
442 |
// {
|
443 |
// if(layer.getISpatialIndex() != null)
|
444 |
// {
|
445 |
// PluginServices.
|
446 |
// cancelableBackgroundExecution(new
|
447 |
// CreateSpatialIndexMonitorableTask((FLyrVect)layer));
|
448 |
// }
|
449 |
// }
|
450 |
|
451 |
isStop = true;
|
452 |
} else {
|
453 |
// Si no existe writer para la capa que tenemos en edici?n
|
454 |
int resp = JOptionPane |
455 |
.showConfirmDialog( |
456 |
(Component) PluginServices.getMainFrame(),
|
457 |
PluginServices |
458 |
.getText( |
459 |
this,
|
460 |
"no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_no_se_guardaran_desea_continuar")
|
461 |
+ " : " + layer.getName(),
|
462 |
PluginServices |
463 |
.getText(this, "cancelar_edicion"), |
464 |
JOptionPane.YES_NO_OPTION);
|
465 |
if (resp == JOptionPane.YES_OPTION) { // CANCEL EDITING |
466 |
|
467 |
try {
|
468 |
edMan.stopEditLayer(null, layer, IEditionManager.CANCEL_EDITING);
|
469 |
} catch (Exception ex) { |
470 |
logger.error("While stopping layer editing.", ex);
|
471 |
} |
472 |
|
473 |
// cancelEdition(layer);
|
474 |
// layer.setEditing(false);
|
475 |
// if (!(layer.getSource().getDriver() instanceof
|
476 |
// IndexedShpDriver)){
|
477 |
// VectorialLayerEdited
|
478 |
// vle=(VectorialLayerEdited)CADExtension.getEditionManager().getLayerEdited(layer);
|
479 |
// layer.setLegend((IVectorLegend)vle.getLegend());
|
480 |
// }
|
481 |
isStop = true;
|
482 |
} |
483 |
|
484 |
} |
485 |
/*
|
486 |
if (isStop) {
|
487 |
layer.removeLayerListener(edMan);
|
488 |
// if (layer instanceof FLyrAnnotation){
|
489 |
// FLyrAnnotation lva=(FLyrAnnotation)layer;
|
490 |
// lva.setMapping(lva.getMapping());
|
491 |
// }
|
492 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices
|
493 |
.getMDIManager().getActiveWindow();
|
494 |
if (f instanceof DefaultViewPanel) {
|
495 |
vista = (DefaultViewPanel) f;
|
496 |
FLayer auxLayer = vista.getMapControl().getMapContext()
|
497 |
.getLayers().getLayer(layer.getName());
|
498 |
if (auxLayer != null && auxLayer.equals(layer)) {
|
499 |
vista.getMapControl().setTool("zoomIn");
|
500 |
vista.hideConsole();
|
501 |
vista.repaintMap();
|
502 |
CADExtension.clearView();
|
503 |
}
|
504 |
}
|
505 |
}
|
506 |
*/
|
507 |
} catch (ReadException e1) {
|
508 |
NotificationManager.showMessageError(e1.getMessage(), e1); |
509 |
} catch (DataException e) {
|
510 |
NotificationManager.showMessageError(e.getMessage(), e); |
511 |
} |
512 |
return isStop;
|
513 |
} |
514 |
|
515 |
private class UnsavedLayer extends UnsavedData { |
516 |
|
517 |
private FLayer layer;
|
518 |
|
519 |
public UnsavedLayer(IExtension extension) {
|
520 |
super(extension);
|
521 |
} |
522 |
|
523 |
public String getDescription() { |
524 |
return PluginServices.getText(this, "editing_layer_unsaved"); |
525 |
} |
526 |
|
527 |
public String getResourceName() { |
528 |
return layer.getName();
|
529 |
} |
530 |
|
531 |
public boolean saveData() { |
532 |
return executeSaveLayer((FLyrVect) layer);
|
533 |
} |
534 |
|
535 |
public void setLayer(FLayer layer) { |
536 |
this.layer = layer;
|
537 |
|
538 |
} |
539 |
|
540 |
public String getIcon() { |
541 |
return layer.getTocImageIcon();
|
542 |
} |
543 |
|
544 |
} |
545 |
|
546 |
/**
|
547 |
* <p>
|
548 |
* This class provides the status of extensions. If this extension has some
|
549 |
* unsaved editing layer (and save them), and methods to check if the
|
550 |
* extension has some associated background tasks.
|
551 |
*
|
552 |
* @author Vicente Caballero Navarro
|
553 |
*
|
554 |
*/
|
555 |
private class StopEditingStatus implements IExtensionStatus { |
556 |
/**
|
557 |
* This method is used to check if this extension has some unsaved
|
558 |
* editing layer.
|
559 |
*
|
560 |
* @return true if the extension has some unsaved editing layer, false
|
561 |
* otherwise.
|
562 |
*/
|
563 |
public boolean hasUnsavedData() { |
564 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
565 |
DefaultViewDocument[] views = project.getDocuments(
|
566 |
ViewManager.TYPENAME).toArray(new DefaultViewDocument[0]); |
567 |
for (int i = 0; i < views.length; i++) { |
568 |
FLayers layers = views[i].getMapContext().getLayers(); |
569 |
LayersIterator iter = getEditingLayer(layers); |
570 |
if (iter.hasNext()) {
|
571 |
return true; |
572 |
} |
573 |
} |
574 |
return false; |
575 |
} |
576 |
|
577 |
/**
|
578 |
* This method is used to check if the extension has some associated
|
579 |
* background process which is currently running.
|
580 |
*
|
581 |
* @return true if the extension has some associated background process,
|
582 |
* false otherwise.
|
583 |
*/
|
584 |
public boolean hasRunningProcesses() { |
585 |
return false; |
586 |
} |
587 |
|
588 |
/**
|
589 |
* <p>
|
590 |
* Gets an array of the traceable background tasks associated with this
|
591 |
* extension. These tasks may be tracked, canceled, etc.
|
592 |
* </p>
|
593 |
*
|
594 |
* @return An array of the associated background tasks, or null in case
|
595 |
* there is no associated background tasks.
|
596 |
*/
|
597 |
public IMonitorableTask[] getRunningProcesses() { |
598 |
return null; |
599 |
} |
600 |
|
601 |
/**
|
602 |
* <p>
|
603 |
* Gets an array of the UnsavedData objects, which contain information
|
604 |
* about the unsaved editing layers and allows to save it.
|
605 |
* </p>
|
606 |
*
|
607 |
* @return An array of the associated unsaved editing layers, or null in
|
608 |
* case the extension has not unsaved editing layers.
|
609 |
*/
|
610 |
public IUnsavedData[] getUnsavedData() { |
611 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
612 |
DefaultViewDocument[] views = project.getDocuments(
|
613 |
ViewManager.TYPENAME).toArray(new DefaultViewDocument[0]); |
614 |
ArrayList unsavedLayers = new ArrayList(); |
615 |
for (int i = 0; i < views.length; i++) { |
616 |
FLayers layers = views[i].getMapContext().getLayers(); |
617 |
LayersIterator iter = getEditingLayer(layers); |
618 |
while (iter.hasNext()) {
|
619 |
UnsavedLayer ul = new UnsavedLayer(StopEditing.this);
|
620 |
ul.setLayer(iter.nextLayer()); |
621 |
unsavedLayers.add(ul); |
622 |
} |
623 |
} |
624 |
return (IUnsavedData[]) unsavedLayers.toArray(new IUnsavedData[0]); |
625 |
} |
626 |
} |
627 |
|
628 |
private LayersIterator getEditingLayer(FLayers layers) {
|
629 |
return new LayersIterator(layers) { |
630 |
public boolean evaluate(FLayer layer) { |
631 |
return layer.isEditing();
|
632 |
} |
633 |
}; |
634 |
} |
635 |
} |