Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / RedoViewExtension.java @ 39212

History | View | Annotate | Download (4.38 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.ApplicationLocator;
47
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
48
import org.gvsig.fmap.mapcontext.layers.FLayer;
49
import org.gvsig.fmap.mapcontext.layers.FLayers;
50
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
51
import org.gvsig.fmap.mapcontrol.MapControl;
52
import org.gvsig.tools.undo.RedoException;
53

    
54

    
55

    
56
/**
57
 * Extensi?n encargada de gestionar el rehacer un comando anteriormente
58
 * deshecho.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class RedoViewExtension extends Extension {
63
        /**
64
         * @see org.gvsig.andami.plugins.IExtension#initialize()
65
         */
66
        public void initialize() {
67
        }
68

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

    
76
                if (s.compareTo("edit-redo-layer") == 0) {
77
                        try {
78
                                        FLayers layers=mapControl.getMapContext().getLayers();
79
                                        for (int i=0;i<layers.getLayersCount();i++){
80
                                                if (layers.getLayer(i) instanceof FLyrVect && layers.getLayer(i).isEditing() && layers.getLayer(i).isActive()){
81
                                                        ((FLyrVect)layers.getLayer(i)).getFeatureStore().redo();
82
                                                        mapControl.drawMap(false);
83
                                                        ApplicationLocator.getManager().refreshMenusAndToolBars();
84
                                                }
85

    
86
                                        }
87
                        } catch (RedoException e) {
88
                                NotificationManager.addError(e.getMessage(),e);
89
                        }
90
                }
91
        }
92

    
93
        /**
94
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
95
         */
96
        public boolean isEnabled() {
97
                DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
98
                MapControl mapControl = vista.getMapControl();
99
                FLayers layers=mapControl.getMapContext().getLayers();
100
                for (int i=0;i<layers.getLayersCount();i++){
101
//                        try {
102
                                if (layers.getLayer(i) instanceof FLyrVect && ((FLyrVect)layers.getLayer(i)).getFeatureStore().isEditing() && layers.getLayer(i).isActive()){
103
                                        return ((FLyrVect)layers.getLayer(i)).getFeatureStore().canRedo();
104
                                }
105
//                        } catch (ReadException e) {
106
//                                // TODO Auto-generated catch block
107
//                                e.printStackTrace();
108
//                        } catch (DataException e) {
109
//                                // TODO Auto-generated catch block
110
//                                e.printStackTrace();
111
//                        }
112

    
113
                }
114
                return false;
115
        }
116

    
117
        /**
118
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
119
         */
120
        public boolean isVisible() {
121
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
122
                                                                                                                         .getActiveWindow();
123

    
124
                if (f == null) {
125
                        return false;
126
                }
127

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