Statistics
| Revision:

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 @ 40597

History | View | Annotate | Download (20.7 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.ApplicationLocator;
51
import org.gvsig.app.project.Project;
52
import org.gvsig.app.project.ProjectManager;
53
import org.gvsig.app.project.documents.view.DefaultViewDocument;
54
import org.gvsig.app.project.documents.view.ViewDocument;
55
import org.gvsig.app.project.documents.view.ViewManager;
56
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
57
import org.gvsig.editing.layers.VectorialLayerEdited;
58
import org.gvsig.exportto.app.extension.ExporttoLayerExtension;
59
import org.gvsig.fmap.dal.exception.DataException;
60
import org.gvsig.fmap.dal.exception.ReadException;
61
import org.gvsig.fmap.mapcontext.MapContext;
62
import org.gvsig.fmap.mapcontext.layers.FLayer;
63
import org.gvsig.fmap.mapcontext.layers.FLayers;
64
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
65
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
66
import org.gvsig.fmap.mapcontrol.MapControl;
67
import org.gvsig.i18n.Messages;
68
import org.gvsig.utils.swing.threads.IMonitorableTask;
69

    
70
/**
71
 * @author Francisco Jos?
72
 * 
73
 *         Cuando un tema se pone en edici?n, puede que su driver implemente
74
 *         ISpatialWriter. En ese caso, es capaz de guardarse sobre s? mismo. Si
75
 *         no lo implementa, esta opci?n estar? deshabilitada y la ?nica
76
 *         posibilidad de guardar este tema ser? "Guardando como..."
77
 *         
78
 */
79
public class StopEditing extends Extension {
80
    
81
    private final static Logger logger = LoggerFactory.getLogger(StopEditing.class);
82
    
83
        private DefaultViewPanel vista;
84

    
85
        /**
86
         * @see org.gvsig.andami.plugins.IExtension#initialize()
87
         */
88
        public void initialize() {
89
        }
90

    
91
        /**
92
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
93
         */
94
        public void execute(String s) {
95
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices
96
                                .getMDIManager().getActiveWindow();
97

    
98
                vista = (DefaultViewPanel) f;
99
                boolean isStop = false;
100
                ViewDocument model = vista.getModel();
101
                MapContext mapa = model.getMapContext();
102
                FLayers layers = mapa.getLayers();
103
                IEditionManager edMan = EditionLocator.getEditionManager();
104

    
105
                if (s.equals("layer-stop-editing")) {
106
                        vista.getMapControl().getCanceldraw().setCanceled(true);
107
                        FLayer[] actives = layers.getActives();
108
                        // TODO: Comprobar que solo hay una activa, o al menos
109
                        // que solo hay una en edici?n que est? activa, etc, etc
110
                        for (int i = 0; i < actives.length; i++) {
111
                                if (actives[i] instanceof FLyrVect && actives[i].isEditing()) {
112
                                        FLyrVect lv = (FLyrVect) actives[i];
113
                                        MapControl mapControl = vista.getMapControl();
114

    
115
                                        int user_opt = confirmStop(lv, mapControl);
116
                                        if (user_opt != IEditionManager.CONTINUE_EDITING) {
117
                                            isStop = true;
118
                                        }
119
                                        
120
                                        try {
121
                            edMan.stopEditLayer(vista, lv, user_opt);
122
                                        } catch (Exception ex) {
123
                                                
124
                                                /*
125
                                                 * Unable to end editing, inform user
126
                                                 * of the problem. Editing session will continue.
127
                                                 */
128
                                    showUnableToEndEditingDialog(ex);
129
                                    isStop = false;
130
                                            logger.info("While stopping layer editing.", ex);
131
                                        }
132
                                }
133
                        }
134
                        
135
                        if (isStop) {
136
                                CADExtension.clearView();
137
                        }
138
                }
139
                PluginServices.getMainFrame().enableControls();
140
        }
141

    
142

    
143
        private void showUnableToEndEditingDialog(Exception ex) {
144
                
145
                String msg = Messages.getText(
146
                                "_Invalid_values_in_some_fields_must_be_edited_before_end_editing");
147
                msg = msg + ":\n\n" + EditionUtilities.getLastMessage(ex);
148
                JOptionPane.showMessageDialog(
149
                                ApplicationLocator.getManager().getRootComponent(),
150
                                msg,
151
                                Messages.getText("_Guardar"),
152
                                JOptionPane.ERROR_MESSAGE);
153
                
154
        }
155

    
156
        /**
157
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
158
         */
159
        public boolean isEnabled() {
160
                FLayer[] lyrs = EditionUtilities.getActiveAndEditedLayers();
161
                if (lyrs == null) {
162
                        return false;
163
                }
164
                FLyrVect lyrVect = (FLyrVect) lyrs[0];
165
                if (lyrVect.isEditing()) {
166
                        return true;
167
                }
168
                return false;
169
        }
170

    
171
        /**
172
         * DOCUMENT ME!
173
         */
174
        
175
        /*
176
        public boolean stopEditing(FLyrVect layer, MapControl mapControl) {
177
                int resp = JOptionPane.CANCEL_OPTION;
178

179
                try {
180
                        if (layer.isWritable()) {
181
                                Object[] options = {
182
                                                PluginServices.getText(this, "_Guardar"),
183
                                                "       " + PluginServices.getText(this, "_Descartar") + "       ",
184
                                                PluginServices.getText(this, "_Continuar") };
185
                                
186
                                JPanel explanation_panel = getExplanationPanel(layer.getName());
187

188
                                resp = JOptionPane
189
                                                .showOptionDialog(
190
                                                                (Component) PluginServices.getMainFrame(),
191
                                                                explanation_panel,
192
                                                                PluginServices.getText(this, "stop_edition"),
193
                                                                JOptionPane.YES_NO_CANCEL_OPTION,
194
                                                                JOptionPane.QUESTION_MESSAGE, null, options,
195
                                                                options[2]);
196
                                
197
                                if (resp == JOptionPane.YES_OPTION) {
198
                                    // SAVE
199
                                        saveLayer(layer);
200
                                        // layer.setEditing(false);
201
                    return true;
202
                                } else if (resp == JOptionPane.NO_OPTION) {
203
                                    // CANCEL EDITING
204
                                        cancelEdition(layer);
205
                                        // layer.setEditing(false);
206
                                        return true;
207
                                } else if (resp == JOptionPane.CANCEL_OPTION) {
208
                                    // CONTINUE EDITING
209
                                    return false;
210
                                } else {
211
                                    // This happens when user clicks on [x]
212
                                    // to abruptly close previous JOptionPane dialog
213
                                    // We make it equivalent to CONTINUE EDITING
214
                    return false;
215
                                }
216
                                
217
                        }
218
                        // ========================================
219
                        // Layer cannot save changes:
220
                        
221
                        Object[] options = {
222
                                        PluginServices.getText(this, "export"),
223
                                        PluginServices.getText(this,
224
                                                        "finish_editing_without_saving_changes"),
225
                                        PluginServices.getText(this, "continue_editing") };
226

227
                        resp = JOptionPane
228
                                        .showOptionDialog(
229
                                                        (Component) PluginServices.getMainFrame(),
230
                                                        PluginServices
231
                                                                        .getText(
232
                                                                                        this,
233
                                                                                        "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer")
234
                                                                        + " : " + layer.getName(), PluginServices
235
                                                                        .getText(this, "stop_edition"),
236
                                                        JOptionPane.YES_NO_CANCEL_OPTION,
237
                                                        JOptionPane.QUESTION_MESSAGE, null, options,
238
                                                        options[2]);
239
                        if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING
240
                                cancelEdition(layer);
241
                                // layer.setEditing(false);
242
                                return true;
243
                        } else if (resp == JOptionPane.YES_OPTION) {
244
                                int status = exportLayer(layer);
245
                                if (status == JOptionPane.OK_OPTION) {
246
                                        cancelEdition(layer);
247
                                        // layer.setEditing(false);
248
                                }
249
                        }
250

251
                } catch (ReadException e) {
252
                        NotificationManager.addError(e);
253
                } catch (CancelEditingLayerException e) {
254
                        NotificationManager.addError(e);
255
                }
256
                return false;
257

258
        }
259
        */
260

    
261
        
262
           public int confirmStop(FLyrVect layer, MapControl mapControl) {
263
                int resp = JOptionPane.CANCEL_OPTION;
264

    
265
                try {
266
                    if (layer.isWritable()) {
267
                        Object[] options = {
268
                                PluginServices.getText(this, "_Guardar"),
269
                                "       " + PluginServices.getText(this, "_Descartar") + "       ",
270
                                PluginServices.getText(this, "_Continuar") };
271
                        
272
                        JPanel explanation_panel = getExplanationPanel(layer.getName());
273

    
274
                        resp = JOptionPane
275
                                .showOptionDialog(
276
                                        (Component) PluginServices.getMainFrame(),
277
                                        explanation_panel,
278
                                        PluginServices.getText(this, "stop_edition"),
279
                                        JOptionPane.YES_NO_CANCEL_OPTION,
280
                                        JOptionPane.QUESTION_MESSAGE, null, options,
281
                                        options[2]);
282
                        
283
                        if (resp == JOptionPane.YES_OPTION) {
284
                            return IEditionManager.ACCEPT_EDITING;
285
                        } else if (resp == JOptionPane.NO_OPTION) {
286
                        return IEditionManager.CANCEL_EDITING;
287
                        } else if (resp == JOptionPane.CANCEL_OPTION) {
288
                        return IEditionManager.CONTINUE_EDITING;
289
                        } else {
290
                            // This happens when user clicks on [x]
291
                            // to abruptly close previous JOptionPane dialog
292
                            // We make it equivalent to CONTINUE EDITING
293
                        return IEditionManager.CONTINUE_EDITING;
294
                        }
295
                        
296
                    }
297
                    // ========================================
298
                    // Layer cannot save changes:
299
                    
300
                    Object[] options = {
301
                            PluginServices.getText(this, "export"),
302
                            PluginServices.getText(this,
303
                                    "finish_editing_without_saving_changes"),
304
                            PluginServices.getText(this, "continue_editing") };
305

    
306
                    resp = JOptionPane
307
                            .showOptionDialog(
308
                                    (Component) PluginServices.getMainFrame(),
309
                                    PluginServices
310
                                            .getText(
311
                                                    this,
312
                                                    "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer")
313
                                            + " : " + layer.getName(), PluginServices
314
                                            .getText(this, "stop_edition"),
315
                                    JOptionPane.YES_NO_CANCEL_OPTION,
316
                                    JOptionPane.QUESTION_MESSAGE, null, options,
317
                                    options[2]);
318
                    if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING
319
                    return IEditionManager.CANCEL_EDITING;
320
                    } else if (resp == JOptionPane.YES_OPTION) {
321
                        int status = exportLayer(layer);
322
                        if (status == JOptionPane.OK_OPTION) {
323
                            return IEditionManager.CANCEL_EDITING;
324
                        }
325
                    }
326

    
327
                } catch (ReadException e) {
328
                    NotificationManager.addError(e);
329
                }
330
            return IEditionManager.CONTINUE_EDITING;
331

    
332

    
333
            }
334

    
335

    
336
    private JPanel getExplanationPanel(
337
        String layer_name) {
338
        
339
        JPanel resp = new JPanel(new BorderLayout(10, 10));
340
        
341
        String msg = Messages.getText("realmente_desea_guardar_la_capa");
342
        msg = msg + " '" + layer_name + "'?";
343
        JLabel topLabel = new JLabel(msg);
344
        
345
        JPanel mainPanel = new JPanel(new GridBagLayout());
346
        GridBagConstraints cc = new GridBagConstraints();
347
        
348
        cc.gridx = 0;
349
        cc.gridy = 0;
350
        cc.anchor = GridBagConstraints.WEST;
351
        
352
        cc.insets = new Insets(3, 6, 3, 6);
353
        
354
        Font boldf = mainPanel.getFont().deriveFont(Font.BOLD);
355
        
356
        JLabel lbl = new JLabel(Messages.getText("_Guardar"));
357
        lbl.setFont(boldf);
358
        mainPanel.add(lbl, cc);
359
        cc.gridx = 1;
360
        mainPanel.add(new JLabel(Messages.getText("_Save_changes_performed")), cc);
361
        
362
        cc.gridx = 0;
363
        cc.gridy = 1;
364
        lbl = new JLabel(Messages.getText("_Descartar"));
365
        lbl.setFont(boldf);
366
        mainPanel.add(lbl, cc);
367
        cc.gridx = 1;
368
        mainPanel.add(new JLabel(Messages.getText("_Discard_and_lose_changes")), cc);
369

    
370
        cc.gridx = 0;
371
        cc.gridy = 2;
372
        lbl = new JLabel(Messages.getText("_Continuar"));
373
        lbl.setFont(boldf);
374
        mainPanel.add(lbl, cc);
375
        cc.gridx = 1;
376
        mainPanel.add(new JLabel(Messages.getText("_Do_not_save_yet_Stay_in_editing_mode")), cc);
377

    
378
        resp.add(mainPanel, BorderLayout.CENTER);
379
        resp.add(topLabel, BorderLayout.NORTH);
380
        return resp;
381
    }
382
    
383

    
384
    /*
385
    private void saveLayer(FLyrVect layer) throws ReadException {
386
                FeatureStore featureStore = layer.getFeatureStore();
387
                try {
388
                        featureStore.finishEditing();
389
                } catch (WriteException e) {
390
                        throw new ReadException(featureStore.getName(), e);
391
                } catch (DataException e) {
392
                        throw new ReadException(featureStore.getName(), e);
393
                }
394
        }
395

396
        private void cancelEdition(FLyrVect layer)
397
                        throws CancelEditingLayerException {
398
                FeatureStore featureStore = null;
399
                try {
400
                        featureStore = layer.getFeatureStore();
401

402
                        featureStore.cancelEditing();
403
                } catch (ReadException e) {
404
                        throw new CancelEditingLayerException(layer.getName(), e);
405
                } catch (DataException e) {
406
                        throw new CancelEditingLayerException(layer.getName(), e);
407
                }
408
        }
409
        */
410

    
411
        private int exportLayer(FLyrVect layer) throws ReadException {
412
                ViewDocument model = vista.getModel();
413
                MapContext mapContext = model.getMapContext();
414
                IProjection projection = mapContext.getProjection();
415

    
416
                ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator
417
                                .getManager().getExtension(ExporttoLayerExtension.class);
418
                return extension.showExportto(layer, projection, mapContext);
419
        }
420

    
421
        /**
422
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
423
         */
424
        public boolean isVisible() {
425
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
426
                        return true;
427
                }
428
                return false;
429

    
430
        }
431

    
432
        public IExtensionStatus getStatus() {
433
                return new StopEditingStatus();
434
        }
435

    
436
        /**
437
         * Show the dialogs to save the layer without ask if don't like to save.
438
         * 
439
         * @param layer
440
         *            Layer to save.
441
         */
442
        public boolean executeSaveLayer(FLyrVect layer) {
443
            
444
            IEditionManager edMan = EditionLocator.getEditionManager(layer);
445

    
446
                VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan
447
                                .getLayerEdited(layer);
448
                boolean isStop = false;
449
                try {
450
                        lyrEd.clearSelection();
451

    
452
                        if (layer.isWritable()) {
453

    
454
                            try {
455
                                edMan.stopEditLayer(null, layer, IEditionManager.ACCEPT_EDITING);
456
                            } catch (Exception ex) {
457
                                logger.error("While stopping layer editing.", ex);
458
                            }
459

    
460
                                // saveLayer(layer);
461
                                // layer.setEditing(false);
462
                                // if (layer.isSpatiallyIndexed())
463
                                // {
464
                                // if(layer.getISpatialIndex() != null)
465
                                // {
466
                                // PluginServices.
467
                                // cancelableBackgroundExecution(new
468
                                // CreateSpatialIndexMonitorableTask((FLyrVect)layer));
469
                                // }
470
                                // }
471

    
472
                                isStop = true;
473
                        } else {
474
                                // Si no existe writer para la capa que tenemos en edici?n
475
                                int resp = JOptionPane
476
                                                .showConfirmDialog(
477
                                                                (Component) PluginServices.getMainFrame(),
478
                                                                PluginServices
479
                                                                                .getText(
480
                                                                                                this,
481
                                                                                                "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_no_se_guardaran_desea_continuar")
482
                                                                                + " : " + layer.getName(),
483
                                                                PluginServices
484
                                                                                .getText(this, "cancelar_edicion"),
485
                                                                JOptionPane.YES_NO_OPTION);
486
                                if (resp == JOptionPane.YES_OPTION) { // CANCEL EDITING
487

    
488
                                    try {
489
                                        edMan.stopEditLayer(null, layer, IEditionManager.CANCEL_EDITING);
490
                                    } catch (Exception ex) {
491
                                        logger.error("While stopping layer editing.", ex);
492
                                    }
493

    
494
                                                // cancelEdition(layer);
495
                                                // layer.setEditing(false);
496
                                                // if (!(layer.getSource().getDriver() instanceof
497
                                                // IndexedShpDriver)){
498
                                                // VectorialLayerEdited
499
                                                // vle=(VectorialLayerEdited)CADExtension.getEditionManager().getLayerEdited(layer);
500
                                                // layer.setLegend((IVectorLegend)vle.getLegend());
501
                                                // }
502
                                        isStop = true;
503
                                }
504

    
505
                        }
506
                        /*
507
                        if (isStop) {
508
                                layer.removeLayerListener(edMan);
509
                                // if (layer instanceof FLyrAnnotation){
510
                                // FLyrAnnotation lva=(FLyrAnnotation)layer;
511
                                // lva.setMapping(lva.getMapping());
512
                                // }
513
                                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices
514
                                                .getMDIManager().getActiveWindow();
515
                                if (f instanceof DefaultViewPanel) {
516
                                        vista = (DefaultViewPanel) f;
517
                                        FLayer auxLayer = vista.getMapControl().getMapContext()
518
                                                        .getLayers().getLayer(layer.getName());
519
                                        if (auxLayer != null && auxLayer.equals(layer)) {
520
                                                vista.getMapControl().setTool("zoomIn");
521
                                                vista.hideConsole();
522
                                                vista.repaintMap();
523
                                                CADExtension.clearView();
524
                                        }
525
                                }
526
                        }
527
                        */
528
                } catch (ReadException e1) {
529
                        NotificationManager.showMessageError(e1.getMessage(), e1);
530
                } catch (DataException e) {
531
                        NotificationManager.showMessageError(e.getMessage(), e);
532
                }
533
                return isStop;
534
        }
535

    
536
        private class UnsavedLayer extends UnsavedData {
537

    
538
                private FLayer layer;
539

    
540
                public UnsavedLayer(IExtension extension) {
541
                        super(extension);
542
                }
543

    
544
                public String getDescription() {
545
                        return PluginServices.getText(this, "editing_layer_unsaved");
546
                }
547

    
548
                public String getResourceName() {
549
                        return layer.getName();
550
                }
551

    
552
                public boolean saveData() {
553
                        return executeSaveLayer((FLyrVect) layer);
554
                }
555

    
556
                public void setLayer(FLayer layer) {
557
                        this.layer = layer;
558

    
559
                }
560

    
561
                public String getIcon() {
562
                        return layer.getTocImageIcon();
563
                }
564

    
565
        }
566

    
567
        /**
568
         * <p>
569
         * This class provides the status of extensions. If this extension has some
570
         * unsaved editing layer (and save them), and methods to check if the
571
         * extension has some associated background tasks.
572
         * 
573
         * @author Vicente Caballero Navarro
574
         * 
575
         */
576
        private class StopEditingStatus implements IExtensionStatus {
577
                /**
578
                 * This method is used to check if this extension has some unsaved
579
                 * editing layer.
580
                 * 
581
                 * @return true if the extension has some unsaved editing layer, false
582
                 *         otherwise.
583
                 */
584
                public boolean hasUnsavedData() {
585
                        Project project = ProjectManager.getInstance().getCurrentProject();
586
                        DefaultViewDocument[] views = project.getDocuments(
587
                                        ViewManager.TYPENAME).toArray(new DefaultViewDocument[0]);
588
                        for (int i = 0; i < views.length; i++) {
589
                                FLayers layers = views[i].getMapContext().getLayers();
590
                                LayersIterator iter = getEditingLayer(layers);
591
                                if (iter.hasNext()) {
592
                                        return true;
593
                                }
594
                        }
595
                        return false;
596
                }
597

    
598
                /**
599
                 * This method is used to check if the extension has some associated
600
                 * background process which is currently running.
601
                 * 
602
                 * @return true if the extension has some associated background process,
603
                 *         false otherwise.
604
                 */
605
                public boolean hasRunningProcesses() {
606
                        return false;
607
                }
608

    
609
                /**
610
                 * <p>
611
                 * Gets an array of the traceable background tasks associated with this
612
                 * extension. These tasks may be tracked, canceled, etc.
613
                 * </p>
614
                 * 
615
                 * @return An array of the associated background tasks, or null in case
616
                 *         there is no associated background tasks.
617
                 */
618
                public IMonitorableTask[] getRunningProcesses() {
619
                        return null;
620
                }
621

    
622
                /**
623
                 * <p>
624
                 * Gets an array of the UnsavedData objects, which contain information
625
                 * about the unsaved editing layers and allows to save it.
626
                 * </p>
627
                 * 
628
                 * @return An array of the associated unsaved editing layers, or null in
629
                 *         case the extension has not unsaved editing layers.
630
                 */
631
                public IUnsavedData[] getUnsavedData() {
632
                        Project project = ProjectManager.getInstance().getCurrentProject();
633
                        DefaultViewDocument[] views = project.getDocuments(
634
                                        ViewManager.TYPENAME).toArray(new DefaultViewDocument[0]);
635
                        ArrayList unsavedLayers = new ArrayList();
636
                        for (int i = 0; i < views.length; i++) {
637
                                FLayers layers = views[i].getMapContext().getLayers();
638
                                LayersIterator iter = getEditingLayer(layers);
639
                                while (iter.hasNext()) {
640
                                        UnsavedLayer ul = new UnsavedLayer(StopEditing.this);
641
                                        ul.setLayer(iter.nextLayer());
642
                                        unsavedLayers.add(ul);
643
                                }
644
                        }
645
                        return (IUnsavedData[]) unsavedLayers.toArray(new IUnsavedData[0]);
646
                }
647
        }
648

    
649
        private LayersIterator getEditingLayer(FLayers layers) {
650
                return new LayersIterator(layers) {
651
                        public boolean evaluate(FLayer layer) {
652
                                return layer.isEditing();
653
                        }
654
                };
655
        }
656
}