Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2056 / extensions / extEditing / src / org / gvsig / editing / UndoViewExtension.java @ 39004

History | View | Annotate | Download (5.04 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.editing;
42

    
43
import org.gvsig.andami.PluginServices;
44
import org.gvsig.andami.messages.NotificationManager;
45
import org.gvsig.andami.plugins.Extension;
46
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
47
import org.gvsig.fmap.mapcontext.layers.FLayer;
48
import org.gvsig.fmap.mapcontext.layers.FLayers;
49
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
50
import org.gvsig.fmap.mapcontrol.MapControl;
51
import org.gvsig.tools.undo.UndoException;
52

    
53

    
54

    
55
/**
56
 * Extensi?n encargada de gestionar el deshacer los comandos anteriormente
57
 * aplicados.
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class UndoViewExtension extends Extension {
62
        /**
63
         * @see org.gvsig.andami.plugins.IExtension#initialize()
64
         */
65
        public void initialize() {
66
        }
67

    
68
        /**
69
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
70
         */
71
        public void execute(String s) {
72
                DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
73

    
74

    
75
                if (s.compareTo("edit-undo-layer") == 0) {
76
                        undo(vista);
77

    
78
                }
79
        }
80

    
81
        private void undo(DefaultViewPanel vista) {
82
                MapControl mapControl = vista.getMapControl();
83
                try {
84
                        FLayers layers=mapControl.getMapContext().getLayers();
85
                        for (int i=0;i<layers.getLayersCount();i++){
86
                                if (layers.getLayer(i) instanceof FLyrVect && layers.getLayer(i).isEditing() && layers.getLayer(i).isActive()){
87
                                        ((FLyrVect)layers.getLayer(i)).getFeatureStore().undo();
88
//                                        CommandsRecord commandsRecord=((FLyrVect)layers.getLayer(i)).getFeatureStore().getCommandsRecord();
89
//                                        commandsRecord.undo();
90
                                        mapControl.drawMap(false);
91
//                                        VectorialEditableAdapter vea=(VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource();
92
//                                        vea.undo();
93
//                                        vea.getCommandRecord().fireCommandsRepaint(null);
94
//                                        CADExtension.getCADTool().clearSelection();
95
                                }
96
                        }
97
//                } catch (ReadException e) {
98
//                        NotificationManager.addError(e.getMessage(),e);
99
//                } catch (DataException e) {
100
//                        NotificationManager.addError(e.getMessage(),e);
101
                } catch (UndoException e) {
102
                        NotificationManager.addError(e.getMessage(),e);
103
                }
104

    
105
        }
106

    
107
        /**
108
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
109
         */
110
        public boolean isEnabled() {
111
                DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
112
                MapControl mapControl = vista.getMapControl();
113
                FLayers layers=mapControl.getMapContext().getLayers();
114
                for (int i=0;i<layers.getLayersCount();i++){
115
//                        try {
116
                                if (layers.getLayer(i) instanceof FLyrVect && ((FLyrVect)layers.getLayer(i)).getFeatureStore().isEditing() && layers.getLayer(i).isActive()){
117
                                        return ((FLyrVect)layers.getLayer(i)).getFeatureStore().canUndo();
118
//                                VectorialEditableAdapter vea=(VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource();
119
//                                if (vea==null)return false;
120
//                                return vea.getCommandRecord().moreUndoCommands();
121
                                }
122
//                        } catch (ReadException e) {
123
//                                // TODO Auto-generated catch block
124
//                                e.printStackTrace();
125
//                        } catch (DataException e) {
126
//                                // TODO Auto-generated catch block
127
//                                e.printStackTrace();
128
//                        }
129

    
130
                }
131
                return false;
132
        }
133

    
134
        /**
135
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
136
         */
137
        public boolean isVisible() {
138
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
139
                                                                                                                         .getActiveWindow();
140

    
141
                if (f == null) {
142
                        return false;
143
                }
144

    
145
                if (f instanceof DefaultViewPanel) {
146
                        MapControl mapControl = ((DefaultViewPanel)f).getMapControl();
147
                        FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
148
                        FLayer layer;
149
                        for (int i=0;i<layers.length;i++){
150
                                layer = layers[i];
151
                                if (!layer.isAvailable()){
152
                                        continue;
153
                                }
154
//                                try {
155
                                        if (layer instanceof FLyrVect && ((FLyrVect)layer).getFeatureStore().isEditing()){
156
                                                return true;
157
                                        }
158
//                                } catch (ReadException e) {
159
//                                        // TODO Auto-generated catch block
160
//                                        e.printStackTrace();
161
//                                }
162
                        }
163
                }
164
                return false;
165
        }
166
}