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 / UndoViewExtension.java @ 40557

History | View | Annotate | Download (4.36 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 org.gvsig.andami.PluginServices;
27
import org.gvsig.andami.messages.NotificationManager;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.fmap.mapcontext.layers.FLayers;
33
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
34
import org.gvsig.fmap.mapcontrol.MapControl;
35
import org.gvsig.tools.undo.UndoException;
36

    
37

    
38

    
39
/**
40
 * Extensi?n encargada de gestionar el deshacer los comandos anteriormente
41
 * aplicados.
42
 *
43
 * @author Vicente Caballero Navarro
44
 */
45
public class UndoViewExtension extends Extension {
46
        /**
47
         * @see org.gvsig.andami.plugins.IExtension#initialize()
48
         */
49
        public void initialize() {
50
        }
51

    
52
        /**
53
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
54
         */
55
        public void execute(String s) {
56
                DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
57

    
58

    
59
                if (s.compareTo("edit-undo-layer") == 0) {
60
                        undo(vista);
61

    
62
                }
63
        }
64

    
65
        private void undo(DefaultViewPanel vista) {
66
                MapControl mapControl = vista.getMapControl();
67
                try {
68
                        FLayers layers=mapControl.getMapContext().getLayers();
69
                        for (int i=0;i<layers.getLayersCount();i++){
70
                                if (layers.getLayer(i) instanceof FLyrVect && layers.getLayer(i).isEditing() && layers.getLayer(i).isActive()){
71
                                        ((FLyrVect)layers.getLayer(i)).getFeatureStore().undo();
72
                                        mapControl.drawMap(false);
73
                                        ApplicationLocator.getManager().refreshMenusAndToolBars();
74
                                }
75
                        }
76
                } catch (UndoException e) {
77
                        NotificationManager.addError(e.getMessage(),e);
78
                }
79

    
80
        }
81

    
82
        /**
83
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
84
         */
85
        public boolean isEnabled() {
86
                DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
87
                MapControl mapControl = vista.getMapControl();
88
                FLayers layers=mapControl.getMapContext().getLayers();
89
                for (int i=0;i<layers.getLayersCount();i++){
90
//                        try {
91
                                if (layers.getLayer(i) instanceof FLyrVect && ((FLyrVect)layers.getLayer(i)).getFeatureStore().isEditing() && layers.getLayer(i).isActive()){
92
                                        return ((FLyrVect)layers.getLayer(i)).getFeatureStore().canUndo();
93
//                                VectorialEditableAdapter vea=(VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource();
94
//                                if (vea==null)return false;
95
//                                return vea.getCommandRecord().moreUndoCommands();
96
                                }
97
//                        } catch (ReadException e) {
98
//                                // TODO Auto-generated catch block
99
//                                e.printStackTrace();
100
//                        } catch (DataException e) {
101
//                                // TODO Auto-generated catch block
102
//                                e.printStackTrace();
103
//                        }
104

    
105
                }
106
                return false;
107
        }
108

    
109
        /**
110
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
111
         */
112
        public boolean isVisible() {
113
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
114
                                                                                                                         .getActiveWindow();
115

    
116
                if (f == null) {
117
                        return false;
118
                }
119

    
120
                if (f instanceof DefaultViewPanel) {
121
                        MapControl mapControl = ((DefaultViewPanel)f).getMapControl();
122
                        FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
123
                        FLayer layer;
124
                        for (int i=0;i<layers.length;i++){
125
                                layer = layers[i];
126
                                if (!layer.isAvailable()){
127
                                        continue;
128
                                }
129
//                                try {
130
                                        if (layer instanceof FLyrVect && ((FLyrVect)layer).getFeatureStore().isEditing()){
131
                                                return true;
132
                                        }
133
//                                } catch (ReadException e) {
134
//                                        // TODO Auto-generated catch block
135
//                                        e.printStackTrace();
136
//                                }
137
                        }
138
                }
139
                return false;
140
        }
141
}