svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / UndoViewExtension.java @ 37534
History | View | Annotate | Download (5.27 KB)
1 | 4024 | caballero | /* 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 | 29616 | jpiera | package org.gvsig.editing; |
42 | 4024 | caballero | |
43 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
44 | import org.gvsig.andami.messages.NotificationManager; |
||
45 | import org.gvsig.andami.plugins.Extension; |
||
46 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
47 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
48 | import org.gvsig.fmap.dal.exception.ReadException; |
||
49 | 26215 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayer; |
50 | 21666 | vcaballero | import org.gvsig.fmap.mapcontext.layers.FLayers; |
51 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
52 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
53 | 25069 | vcaballero | import org.gvsig.tools.undo.UndoException; |
54 | 21666 | vcaballero | |
55 | 4024 | caballero | |
56 | |||
57 | /**
|
||
58 | * Extensi?n encargada de gestionar el deshacer los comandos anteriormente
|
||
59 | * aplicados.
|
||
60 | *
|
||
61 | * @author Vicente Caballero Navarro
|
||
62 | */
|
||
63 | 5005 | jorpiell | public class UndoViewExtension extends Extension { |
64 | 4024 | caballero | /**
|
65 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
66 | 4024 | caballero | */
|
67 | 5005 | jorpiell | public void initialize() { |
68 | 15637 | jmvivo | PluginServices.getIconTheme().registerDefault( |
69 | 14810 | jmvivo | "view-undo",
|
70 | this.getClass().getClassLoader().getResource("images/Undo.png") |
||
71 | ); |
||
72 | 4024 | caballero | } |
73 | |||
74 | /**
|
||
75 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
76 | 4024 | caballero | */
|
77 | public void execute(String s) { |
||
78 | 31496 | jjdelcerro | DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
79 | 4024 | caballero | |
80 | |||
81 | if (s.compareTo("UNDO") == 0) { |
||
82 | undo(vista); |
||
83 | 4637 | caballero | |
84 | 4024 | caballero | } |
85 | } |
||
86 | |||
87 | 31496 | jjdelcerro | private void undo(DefaultViewPanel vista) { |
88 | 6604 | caballero | MapControl mapControl = vista.getMapControl(); |
89 | 4024 | caballero | try {
|
90 | FLayers layers=mapControl.getMapContext().getLayers(); |
||
91 | for (int i=0;i<layers.getLayersCount();i++){ |
||
92 | 4058 | caballero | if (layers.getLayer(i) instanceof FLyrVect && layers.getLayer(i).isEditing() && layers.getLayer(i).isActive()){ |
93 | 24429 | vcaballero | ((FLyrVect)layers.getLayer(i)).getFeatureStore().undo(); |
94 | // CommandsRecord commandsRecord=((FLyrVect)layers.getLayer(i)).getFeatureStore().getCommandsRecord();
|
||
95 | // commandsRecord.undo();
|
||
96 | 23535 | vcaballero | mapControl.drawMap(false);
|
97 | 22986 | vcaballero | // VectorialEditableAdapter vea=(VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource();
|
98 | // vea.undo();
|
||
99 | // vea.getCommandRecord().fireCommandsRepaint(null);
|
||
100 | // CADExtension.getCADTool().clearSelection();
|
||
101 | 4024 | caballero | } |
102 | } |
||
103 | 30050 | cordinyana | // } catch (ReadException e) {
|
104 | // NotificationManager.addError(e.getMessage(),e);
|
||
105 | // } catch (DataException e) {
|
||
106 | // NotificationManager.addError(e.getMessage(),e);
|
||
107 | 25069 | vcaballero | } catch (UndoException e) {
|
108 | NotificationManager.addError(e.getMessage(),e); |
||
109 | 4024 | caballero | } |
110 | 4118 | caballero | |
111 | 4024 | caballero | } |
112 | |||
113 | /**
|
||
114 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
115 | 4024 | caballero | */
|
116 | public boolean isEnabled() { |
||
117 | 31496 | jjdelcerro | DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
118 | 6604 | caballero | MapControl mapControl = vista.getMapControl(); |
119 | 4024 | caballero | FLayers layers=mapControl.getMapContext().getLayers(); |
120 | for (int i=0;i<layers.getLayersCount();i++){ |
||
121 | 30050 | cordinyana | // try {
|
122 | 22986 | vcaballero | if (layers.getLayer(i) instanceof FLyrVect && ((FLyrVect)layers.getLayer(i)).getFeatureStore().isEditing() && layers.getLayer(i).isActive()){ |
123 | 25069 | vcaballero | return ((FLyrVect)layers.getLayer(i)).getFeatureStore().canUndo();
|
124 | 22986 | vcaballero | // VectorialEditableAdapter vea=(VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource();
|
125 | // if (vea==null)return false;
|
||
126 | // return vea.getCommandRecord().moreUndoCommands();
|
||
127 | } |
||
128 | 30050 | cordinyana | // } catch (ReadException e) {
|
129 | // // TODO Auto-generated catch block
|
||
130 | // e.printStackTrace();
|
||
131 | // } catch (DataException e) {
|
||
132 | // // TODO Auto-generated catch block
|
||
133 | // e.printStackTrace();
|
||
134 | // }
|
||
135 | 4024 | caballero | |
136 | } |
||
137 | return false; |
||
138 | } |
||
139 | |||
140 | /**
|
||
141 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isVisible()
|
142 | 4024 | caballero | */
|
143 | public boolean isVisible() { |
||
144 | 29616 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
145 | 6880 | cesar | .getActiveWindow(); |
146 | 4024 | caballero | |
147 | if (f == null) { |
||
148 | return false; |
||
149 | } |
||
150 | |||
151 | 31496 | jjdelcerro | if (f instanceof DefaultViewPanel) { |
152 | MapControl mapControl = ((DefaultViewPanel)f).getMapControl(); |
||
153 | 26215 | jmvivo | FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
|
154 | FLayer layer; |
||
155 | for (int i=0;i<layers.length;i++){ |
||
156 | layer = layers[i]; |
||
157 | if (!layer.isAvailable()){
|
||
158 | continue;
|
||
159 | } |
||
160 | 30050 | cordinyana | // try {
|
161 | 26215 | jmvivo | if (layer instanceof FLyrVect && ((FLyrVect)layer).getFeatureStore().isEditing()){ |
162 | 22986 | vcaballero | return true; |
163 | } |
||
164 | 30050 | cordinyana | // } catch (ReadException e) {
|
165 | // // TODO Auto-generated catch block
|
||
166 | // e.printStackTrace();
|
||
167 | // }
|
||
168 | 6604 | caballero | } |
169 | 4024 | caballero | } |
170 | 6604 | caballero | return false; |
171 | 4024 | caballero | } |
172 | } |