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

History | View | Annotate | Download (22.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
import java.util.Iterator;
34
import java.util.List;
35
import java.util.prefs.Preferences;
36

    
37
import javax.swing.JLabel;
38
import javax.swing.JOptionPane;
39
import javax.swing.JPanel;
40

    
41
import org.cresques.cts.IProjection;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44
import org.gvsig.andami.PluginServices;
45
import org.gvsig.andami.PluginsLocator;
46
import org.gvsig.andami.messages.NotificationManager;
47
import org.gvsig.andami.plugins.Extension;
48
import org.gvsig.andami.plugins.IExtension;
49
import org.gvsig.andami.plugins.IExtensionExecuteWithArgs;
50
import org.gvsig.andami.plugins.status.IExtensionStatus;
51
import org.gvsig.andami.plugins.status.IUnsavedData;
52
import org.gvsig.andami.plugins.status.UnsavedData;
53
import org.gvsig.app.ApplicationLocator;
54
import org.gvsig.app.gui.preferencespage.GridPage;
55
import org.gvsig.app.project.Project;
56
import org.gvsig.app.project.ProjectManager;
57
import org.gvsig.app.project.documents.view.DefaultViewDocument;
58
import org.gvsig.app.project.documents.view.ViewDocument;
59
import org.gvsig.app.project.documents.view.ViewManager;
60
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
61
import org.gvsig.editing.gui.preferences.EditingPage;
62
import org.gvsig.editing.layers.ILayerEdited;
63
import org.gvsig.editing.layers.VectorialLayerEdited;
64
import org.gvsig.exportto.app.extension.ExporttoLayerExtension;
65
import org.gvsig.fmap.dal.exception.DataException;
66
import org.gvsig.fmap.dal.exception.ReadException;
67
import org.gvsig.fmap.mapcontext.MapContext;
68
import org.gvsig.fmap.mapcontext.layers.FLayer;
69
import org.gvsig.fmap.mapcontext.layers.FLayers;
70
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
71
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
72
import org.gvsig.fmap.mapcontrol.MapControl;
73
import org.gvsig.fmap.mapcontrol.MapControlLocator;
74
import org.gvsig.fmap.mapcontrol.MapControlManager;
75
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper;
76
import org.gvsig.i18n.Messages;
77
import org.gvsig.utils.swing.threads.IMonitorableTask;
78

    
79
/**
80
 * @author Francisco Jos?
81
 * 
82
 *         Cuando un tema se pone en edici?n, puede que su driver implemente
83
 *         ISpatialWriter. En ese caso, es capaz de guardarse sobre s? mismo. Si
84
 *         no lo implementa, esta opci?n estar? deshabilitada y la ?nica
85
 *         posibilidad de guardar este tema ser? "Guardando como..."
86
 *         
87
 */
88
public class StopEditing extends Extension implements IExtensionExecuteWithArgs {
89
    
90
    private final static Logger logger = LoggerFactory.getLogger(StopEditing.class);
91
    
92
        private DefaultViewPanel vista;
93

    
94
        /**
95
         * @see org.gvsig.andami.plugins.IExtension#initialize()
96
         */
97
        public void initialize() {
98
        }
99

    
100
        public void execute(String s) {
101
                super.execute(s, null);
102
        }
103

    
104
        public void execute(String s, Object[] args) {
105
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices
106
                                .getMDIManager().getActiveWindow();
107

    
108
                vista = (DefaultViewPanel) f;
109
                boolean isStop = false;
110
                ViewDocument model = vista.getModel();
111
                MapContext mapa = model.getMapContext();
112
                FLayers layers = mapa.getLayers();
113
                IEditionManager edMan = EditionLocator.getEditionManager();
114

    
115
                if (s.equals("layer-stop-editing")) {
116
                        
117
                FLayer[] selectedItems = null;
118
                    // Desde el menu contextual del TOC se le pasan las capas seleccionadas como primer argumento.
119
                if( args!=null && args.length>0 && args[0] instanceof FLayer[] ) {
120
                        selectedItems = (FLayer[]) args[0];
121
                }
122

    
123
                        vista.getMapControl().getCanceldraw().setCanceled(true);
124
                        FLayer[] actives = layers.getActives();
125
                        // TODO: Comprobar que solo hay una activa, o al menos
126
                        // que solo hay una en edici?n que est? activa, etc, etc
127
                        for (int i = 0; i < actives.length; i++) {
128
                                if (actives[i] instanceof FLyrVect && actives[i].isEditing()) {
129
                                        FLyrVect lv = (FLyrVect) actives[i];
130
                                        MapControl mapControl = vista.getMapControl();
131

    
132
                                        int user_opt = confirmStop(lv, mapControl);
133
                                        if (user_opt != IEditionManager.CONTINUE_EDITING) {
134
                                            isStop = true;
135
                                        }
136
                                        
137
                                        try {
138
                            edMan.stopEditLayer(vista, lv, user_opt);
139
                                        } catch (CancelException ex) {
140
                                                // Do nothing
141
                                    isStop = false;
142
                                        } catch (Exception ex) {
143
                                                
144
                                                /*
145
                                                 * Unable to end editing, inform user
146
                                                 * of the problem. Editing session will continue.
147
                                                 */
148
                                    showUnableToEndEditingDialog(ex);
149
                                    isStop = false;
150
                                            logger.info("While stopping layer editing.", ex);
151
                                        }
152
                                }
153
                        }
154
                        
155
                        if (isStop) {
156
                                CADExtension.clearView();
157
                                /*
158
                                 * Make grid not visible and remove snapping to grid
159
                                 * and disable snappers
160
                                 */
161
                                disableGridAndSnappers(vista.getMapControl());
162
                        }
163
                }
164
                PluginServices.getMainFrame().enableControls();
165
        }
166
        
167
        
168
        private void disableGridAndSnappers(MapControl mco) {
169
                mco.setGridVisibility(false);
170
                mco.setAdjustGrid(false);
171
        Preferences prefs = GridPage.prefs;
172
        prefs.putBoolean("grid.showgrid", false);
173
        prefs.getBoolean("grid.adjustgrid", false);
174
        // Snapping to geometries disabled
175
        mco.setRefentEnabled(false);
176
        /*
177
         * Remove all layers to snap to (unless they are being edited).
178
         * If we don't do this, geometries will still be added
179
         * to the spatial cache of those layers when editing session ends 
180
         */
181
        List removelist = new ArrayList();
182
        FLyrVect item = null;
183
        Iterator snapiter = mco.getMapContext().getLayersToSnap().iterator();
184
        while (snapiter.hasNext()) {
185
                item = (FLyrVect) snapiter.next();
186
                if (!item.isEditing()) {
187
                        /*
188
                         * Get list of layers to be removed from the list
189
                         */
190
                        removelist.add(item);
191
                }
192
        }
193
        /*
194
         * Remove layers from list
195
         */
196
        mco.getMapContext().getLayersToSnap().removeAll(removelist);
197
        
198
        
199
        }
200

    
201
        
202

    
203
        private void showUnableToEndEditingDialog(Exception ex) {
204
                
205
                String msg = Messages.getText(
206
                                "_Unable_to_save_edits_The_cause_is");
207
                msg = msg + ":\n\n" + EditionUtilities.getLastMessage(ex);
208
                JOptionPane.showMessageDialog(
209
                                ApplicationLocator.getManager().getRootComponent(),
210
                                msg,
211
                                Messages.getText("_Guardar"),
212
                                JOptionPane.ERROR_MESSAGE);
213
                
214
        }
215

    
216
        /**
217
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
218
         */
219
        public boolean isEnabled() {
220
                FLayer[] lyrs = EditionUtilities.getActiveAndEditedLayers();
221
                if (lyrs == null) {
222
                        return false;
223
                }
224
                FLyrVect lyrVect = (FLyrVect) lyrs[0];
225
                if (lyrVect.isEditing()) {
226
                        return true;
227
                }
228
                return false;
229
        }
230

    
231
        /**
232
         * DOCUMENT ME!
233
         */
234
        
235
        /*
236
        public boolean stopEditing(FLyrVect layer, MapControl mapControl) {
237
                int resp = JOptionPane.CANCEL_OPTION;
238

239
                try {
240
                        if (layer.isWritable()) {
241
                                Object[] options = {
242
                                                PluginServices.getText(this, "_Guardar"),
243
                                                "       " + PluginServices.getText(this, "_Descartar") + "       ",
244
                                                PluginServices.getText(this, "_Continuar") };
245
                                
246
                                JPanel explanation_panel = getExplanationPanel(layer.getName());
247

248
                                resp = JOptionPane
249
                                                .showOptionDialog(
250
                                                                (Component) PluginServices.getMainFrame(),
251
                                                                explanation_panel,
252
                                                                PluginServices.getText(this, "stop_edition"),
253
                                                                JOptionPane.YES_NO_CANCEL_OPTION,
254
                                                                JOptionPane.QUESTION_MESSAGE, null, options,
255
                                                                options[2]);
256
                                
257
                                if (resp == JOptionPane.YES_OPTION) {
258
                                    // SAVE
259
                                        saveLayer(layer);
260
                                        // layer.setEditing(false);
261
                    return true;
262
                                } else if (resp == JOptionPane.NO_OPTION) {
263
                                    // CANCEL EDITING
264
                                        cancelEdition(layer);
265
                                        // layer.setEditing(false);
266
                                        return true;
267
                                } else if (resp == JOptionPane.CANCEL_OPTION) {
268
                                    // CONTINUE EDITING
269
                                    return false;
270
                                } else {
271
                                    // This happens when user clicks on [x]
272
                                    // to abruptly close previous JOptionPane dialog
273
                                    // We make it equivalent to CONTINUE EDITING
274
                    return false;
275
                                }
276
                                
277
                        }
278
                        // ========================================
279
                        // Layer cannot save changes:
280
                        
281
                        Object[] options = {
282
                                        PluginServices.getText(this, "export"),
283
                                        PluginServices.getText(this,
284
                                                        "finish_editing_without_saving_changes"),
285
                                        PluginServices.getText(this, "continue_editing") };
286

287
                        resp = JOptionPane
288
                                        .showOptionDialog(
289
                                                        (Component) PluginServices.getMainFrame(),
290
                                                        PluginServices
291
                                                                        .getText(
292
                                                                                        this,
293
                                                                                        "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer")
294
                                                                        + " : " + layer.getName(), PluginServices
295
                                                                        .getText(this, "stop_edition"),
296
                                                        JOptionPane.YES_NO_CANCEL_OPTION,
297
                                                        JOptionPane.QUESTION_MESSAGE, null, options,
298
                                                        options[2]);
299
                        if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING
300
                                cancelEdition(layer);
301
                                // layer.setEditing(false);
302
                                return true;
303
                        } else if (resp == JOptionPane.YES_OPTION) {
304
                                int status = exportLayer(layer);
305
                                if (status == JOptionPane.OK_OPTION) {
306
                                        cancelEdition(layer);
307
                                        // layer.setEditing(false);
308
                                }
309
                        }
310

311
                } catch (ReadException e) {
312
                        NotificationManager.addError(e);
313
                } catch (CancelEditingLayerException e) {
314
                        NotificationManager.addError(e);
315
                }
316
                return false;
317

318
        }
319
        */
320

    
321
        
322
           public int confirmStop(FLyrVect layer, MapControl mapControl) {
323
                int resp = JOptionPane.CANCEL_OPTION;
324

    
325
                try {
326
                    if (layer.isWritable()) {
327
                        Object[] options = {
328
                                PluginServices.getText(this, "_Guardar"),
329
                                "       " + PluginServices.getText(this, "_Descartar") + "       ",
330
                                PluginServices.getText(this, "_Continuar") };
331
                        
332
                        
333
                        String question = Messages.getText("realmente_desea_guardar_la_capa");
334
                        question = question + " '" + layer.getName() + "'?";
335
                        String firstLabel = Messages.getText("_Guardar");
336
                        String firstDesc = Messages.getText("_Save_changes_performed");
337
                        
338
                        JPanel explanation_panel = getExplanationPanel(
339
                            question, firstLabel, firstDesc);
340

    
341
                        resp = JOptionPane
342
                                .showOptionDialog(
343
                                        (Component) PluginServices.getMainFrame(),
344
                                        explanation_panel,
345
                                        PluginServices.getText(this, "stop_edition"),
346
                                        JOptionPane.YES_NO_CANCEL_OPTION,
347
                                        JOptionPane.QUESTION_MESSAGE, null, options,
348
                                        options[2]);
349
                        
350
                        if (resp == JOptionPane.YES_OPTION) {
351
                            return IEditionManager.ACCEPT_EDITING;
352
                        } else if (resp == JOptionPane.NO_OPTION) {
353
                        return IEditionManager.CANCEL_EDITING;
354
                        } else if (resp == JOptionPane.CANCEL_OPTION) {
355
                        return IEditionManager.CONTINUE_EDITING;
356
                        } else {
357
                            // This happens when user clicks on [x]
358
                            // to abruptly close previous JOptionPane dialog
359
                            // We make it equivalent to CONTINUE EDITING
360
                        return IEditionManager.CONTINUE_EDITING;
361
                        }
362
                        
363
                    }
364
                    // ========================================
365
                    // Layer cannot save changes:
366
                    
367
                Object[] options = {
368
                    PluginServices.getText(this, "export"),
369
                    "       " + PluginServices.getText(this, "_Descartar") + "       ",
370
                    PluginServices.getText(this, "_Continuar") };
371
                
372
                String question = Messages.getText(
373
                    "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer");
374
                String firstLabel = Messages.getText("export");
375
                String firstDesc = Messages.getText("_Export_to_another_format");
376
                
377
                JPanel explanation_panel = getExplanationPanel(
378
                    question, firstLabel, firstDesc);
379

    
380
                    resp = JOptionPane
381
                            .showOptionDialog(
382
                                    (Component) PluginServices.getMainFrame(),
383
                                    explanation_panel,
384
                                    PluginServices.getText(this, "stop_edition"),
385
                                    JOptionPane.YES_NO_CANCEL_OPTION,
386
                                    JOptionPane.QUESTION_MESSAGE, null, options,
387
                                    options[2]);
388
                    if (resp == JOptionPane.NO_OPTION) { // CANCEL EDITING
389
                    return IEditionManager.CANCEL_EDITING;
390
                    } else if (resp == JOptionPane.YES_OPTION) {
391
                        int status = exportLayer(layer);
392
                        if (status == JOptionPane.OK_OPTION) {
393
                            return IEditionManager.CANCEL_EDITING;
394
                        }
395
                    }
396

    
397
                } catch (ReadException e) {
398
                    NotificationManager.addError(e);
399
                }
400
            return IEditionManager.CONTINUE_EDITING;
401

    
402

    
403
            }
404

    
405

    
406
    private JPanel getExplanationPanel(
407
        String translatedQuestion,
408
        String translatedFirstTag,
409
        String translatedFirstDescription) {
410
        
411
        JPanel resp = new JPanel(new BorderLayout(10, 10));
412
        
413
        JLabel topLabel = new JLabel(translatedQuestion);
414
        
415
        JPanel mainPanel = new JPanel(new GridBagLayout());
416
        GridBagConstraints cc = new GridBagConstraints();
417
        
418
        cc.gridx = 0;
419
        cc.gridy = 0;
420
        cc.anchor = GridBagConstraints.WEST;
421
        
422
        cc.insets = new Insets(3, 6, 3, 6);
423
        
424
        Font boldf = mainPanel.getFont().deriveFont(Font.BOLD);
425
        
426
        JLabel lbl = new JLabel(translatedFirstTag);
427
        lbl.setFont(boldf);
428
        mainPanel.add(lbl, cc);
429
        cc.gridx = 1;
430
        mainPanel.add(new JLabel(translatedFirstDescription), cc);
431
        
432
        cc.gridx = 0;
433
        cc.gridy = 1;
434
        lbl = new JLabel(Messages.getText("_Descartar"));
435
        lbl.setFont(boldf);
436
        mainPanel.add(lbl, cc);
437
        cc.gridx = 1;
438
        mainPanel.add(new JLabel(Messages.getText("_Discard_and_lose_changes")), cc);
439

    
440
        cc.gridx = 0;
441
        cc.gridy = 2;
442
        lbl = new JLabel(Messages.getText("_Continuar"));
443
        lbl.setFont(boldf);
444
        mainPanel.add(lbl, cc);
445
        cc.gridx = 1;
446
        mainPanel.add(new JLabel(Messages.getText("_Do_not_save_yet_Stay_in_editing_mode")), cc);
447

    
448
        resp.add(mainPanel, BorderLayout.CENTER);
449
        resp.add(topLabel, BorderLayout.NORTH);
450
        return resp;
451
    }
452
    
453

    
454
    /*
455
    private void saveLayer(FLyrVect layer) throws ReadException {
456
                FeatureStore featureStore = layer.getFeatureStore();
457
                try {
458
                        featureStore.finishEditing();
459
                } catch (WriteException e) {
460
                        throw new ReadException(featureStore.getName(), e);
461
                } catch (DataException e) {
462
                        throw new ReadException(featureStore.getName(), e);
463
                }
464
        }
465

466
        private void cancelEdition(FLyrVect layer)
467
                        throws CancelEditingLayerException {
468
                FeatureStore featureStore = null;
469
                try {
470
                        featureStore = layer.getFeatureStore();
471

472
                        featureStore.cancelEditing();
473
                } catch (ReadException e) {
474
                        throw new CancelEditingLayerException(layer.getName(), e);
475
                } catch (DataException e) {
476
                        throw new CancelEditingLayerException(layer.getName(), e);
477
                }
478
        }
479
        */
480

    
481
        private int exportLayer(FLyrVect layer) throws ReadException {
482
                ViewDocument model = vista.getModel();
483
                MapContext mapContext = model.getMapContext();
484
                IProjection projection = mapContext.getProjection();
485

    
486
                ExporttoLayerExtension extension = (ExporttoLayerExtension) PluginsLocator
487
                                .getManager().getExtension(ExporttoLayerExtension.class);
488
                return extension.showExportto(layer, projection, mapContext);
489
        }
490

    
491
        /**
492
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
493
         */
494
        public boolean isVisible() {
495
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
496
                        return true;
497
                }
498
                return false;
499

    
500
        }
501

    
502
        public IExtensionStatus getStatus() {
503
                return new StopEditingStatus();
504
        }
505

    
506
        /**
507
         * Show the dialogs to save the layer without ask if don't like to save.
508
         * 
509
         * @param layer
510
         *            Layer to save.
511
         */
512
        public boolean executeSaveLayer(FLyrVect layer) {
513
            
514
            IEditionManager edMan = EditionLocator.getEditionManager(layer);
515

    
516
                VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan
517
                                .getLayerEdited(layer);
518
                boolean isStop = false;
519
                try {
520
                        lyrEd.clearSelection();
521

    
522
                        if (layer.isWritable()) {
523

    
524
                            try {
525
                                edMan.stopEditLayer(null, layer, IEditionManager.ACCEPT_EDITING);
526
                                        isStop = true;
527
                            } catch (CancelException ex) {
528
                                        isStop = false;
529
                                    
530
                            } catch (Exception ex) {
531
                                logger.error("While stopping layer editing.", ex);
532
                                        isStop = false;
533
                            }
534

    
535
                        } else {
536
                                // Si no existe writer para la capa que tenemos en edici?n
537
                                int resp = JOptionPane
538
                                                .showConfirmDialog(
539
                                                                (Component) PluginServices.getMainFrame(),
540
                                                                PluginServices
541
                                                                                .getText(
542
                                                                                                this,
543
                                                                                                "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_no_se_guardaran_desea_continuar")
544
                                                                                + " : " + layer.getName(),
545
                                                                PluginServices
546
                                                                                .getText(this, "cancelar_edicion"),
547
                                                                JOptionPane.YES_NO_OPTION);
548
                                if (resp == JOptionPane.YES_OPTION) { // CANCEL EDITING
549

    
550
                                    try {
551
                                        edMan.stopEditLayer(null, layer, IEditionManager.CANCEL_EDITING);
552
                                                isStop = true;
553
                                    } catch(CancelException ex) {
554
                                                isStop = false;
555
                                            
556
                                    } catch (Exception ex) {
557
                                                isStop = false;
558
                                        logger.error("While stopping layer editing.", ex);
559
                                    }
560

    
561
                                }
562

    
563
                        }
564
                } catch (ReadException e1) {
565
                        NotificationManager.showMessageError(e1.getMessage(), e1);
566
                } catch (DataException e) {
567
                        NotificationManager.showMessageError(e.getMessage(), e);
568
                }
569
                return isStop;
570
        }
571

    
572
        private class UnsavedLayer extends UnsavedData {
573

    
574
                private FLayer layer;
575

    
576
                public UnsavedLayer(IExtension extension) {
577
                        super(extension);
578
                }
579

    
580
                public String getDescription() {
581
                        return PluginServices.getText(this, "editing_layer_unsaved");
582
                }
583

    
584
                public String getResourceName() {
585
                        return layer.getName();
586
                }
587

    
588
                public boolean saveData() {
589
                        return executeSaveLayer((FLyrVect) layer);
590
                }
591

    
592
                public void setLayer(FLayer layer) {
593
                        this.layer = layer;
594

    
595
                }
596

    
597
                public String getIcon() {
598
                        return layer.getTocImageIcon();
599
                }
600

    
601
        }
602

    
603
        /**
604
         * <p>
605
         * This class provides the status of extensions. If this extension has some
606
         * unsaved editing layer (and save them), and methods to check if the
607
         * extension has some associated background tasks.
608
         * 
609
         * @author Vicente Caballero Navarro
610
         * 
611
         */
612
        private class StopEditingStatus implements IExtensionStatus {
613
                /**
614
                 * This method is used to check if this extension has some unsaved
615
                 * editing layer.
616
                 * 
617
                 * @return true if the extension has some unsaved editing layer, false
618
                 *         otherwise.
619
                 */
620
                public boolean hasUnsavedData() {
621
                        Project project = ProjectManager.getInstance().getCurrentProject();
622
                        DefaultViewDocument[] views = project.getDocuments(
623
                                        ViewManager.TYPENAME).toArray(new DefaultViewDocument[0]);
624
                        for (int i = 0; i < views.length; i++) {
625
                                FLayers layers = views[i].getMapContext().getLayers();
626
                                LayersIterator iter = getEditingLayer(layers);
627
                                if (iter.hasNext()) {
628
                                        return true;
629
                                }
630
                        }
631
                        return false;
632
                }
633

    
634
                /**
635
                 * This method is used to check if the extension has some associated
636
                 * background process which is currently running.
637
                 * 
638
                 * @return true if the extension has some associated background process,
639
                 *         false otherwise.
640
                 */
641
                public boolean hasRunningProcesses() {
642
                        return false;
643
                }
644

    
645
                /**
646
                 * <p>
647
                 * Gets an array of the traceable background tasks associated with this
648
                 * extension. These tasks may be tracked, canceled, etc.
649
                 * </p>
650
                 * 
651
                 * @return An array of the associated background tasks, or null in case
652
                 *         there is no associated background tasks.
653
                 */
654
                public IMonitorableTask[] getRunningProcesses() {
655
                        return null;
656
                }
657

    
658
                /**
659
                 * <p>
660
                 * Gets an array of the UnsavedData objects, which contain information
661
                 * about the unsaved editing layers and allows to save it.
662
                 * </p>
663
                 * 
664
                 * @return An array of the associated unsaved editing layers, or null in
665
                 *         case the extension has not unsaved editing layers.
666
                 */
667
                public IUnsavedData[] getUnsavedData() {
668
                        Project project = ProjectManager.getInstance().getCurrentProject();
669
                        DefaultViewDocument[] views = project.getDocuments(
670
                                        ViewManager.TYPENAME).toArray(new DefaultViewDocument[0]);
671
                        ArrayList unsavedLayers = new ArrayList();
672
                        for (int i = 0; i < views.length; i++) {
673
                                FLayers layers = views[i].getMapContext().getLayers();
674
                                LayersIterator iter = getEditingLayer(layers);
675
                                while (iter.hasNext()) {
676
                                        UnsavedLayer ul = new UnsavedLayer(StopEditing.this);
677
                                        ul.setLayer(iter.nextLayer());
678
                                        unsavedLayers.add(ul);
679
                                }
680
                        }
681
                        return (IUnsavedData[]) unsavedLayers.toArray(new IUnsavedData[0]);
682
                }
683
        }
684

    
685
        private LayersIterator getEditingLayer(FLayers layers) {
686
                return new LayersIterator(layers) {
687
                        public boolean evaluate(FLayer layer) {
688
                                return layer.isEditing();
689
                        }
690
                };
691
        }
692
}