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