svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / UndoViewExtension.java @ 44535
History | View | Annotate | Download (4.48 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.app.extension; |
25 |
|
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.messages.NotificationManager; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.app.ApplicationLocator; |
31 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
32 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
33 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
34 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
35 |
import org.gvsig.fmap.mapcontrol.MapControl; |
36 |
import org.gvsig.tools.undo.UndoException; |
37 |
|
38 |
|
39 |
|
40 |
/**
|
41 |
* Extensi?n encargada de gestionar el deshacer los comandos anteriormente
|
42 |
* aplicados.
|
43 |
*
|
44 |
* @author Vicente Caballero Navarro
|
45 |
*/
|
46 |
public class UndoViewExtension extends Extension { |
47 |
/**
|
48 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
49 |
*/
|
50 |
public void initialize() { |
51 |
IconThemeHelper.registerIcon("action", "edit-undo", this); |
52 |
} |
53 |
|
54 |
/**
|
55 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
56 |
*/
|
57 |
public void execute(String s) { |
58 |
DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
59 |
|
60 |
|
61 |
if (s.compareTo("edit-undo-layer") == 0) { |
62 |
undo(vista); |
63 |
|
64 |
} |
65 |
} |
66 |
|
67 |
private void undo(DefaultViewPanel vista) { |
68 |
MapControl mapControl = vista.getMapControl(); |
69 |
try {
|
70 |
FLayers layers=mapControl.getMapContext().getLayers(); |
71 |
for (int i=0;i<layers.getLayersCount();i++){ |
72 |
if (layers.getLayer(i) instanceof FLyrVect && layers.getLayer(i).isEditing() && layers.getLayer(i).isActive()){ |
73 |
((FLyrVect)layers.getLayer(i)).getFeatureStore().undo(); |
74 |
mapControl.drawMap(false);
|
75 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
76 |
} |
77 |
} |
78 |
} catch (UndoException e) {
|
79 |
NotificationManager.addError(e.getMessage(),e); |
80 |
} |
81 |
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
86 |
*/
|
87 |
public boolean isEnabled() { |
88 |
DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
89 |
MapControl mapControl = vista.getMapControl(); |
90 |
FLayers layers=mapControl.getMapContext().getLayers(); |
91 |
for (int i=0;i<layers.getLayersCount();i++){ |
92 |
// try {
|
93 |
if (layers.getLayer(i) instanceof FLyrVect && ((FLyrVect)layers.getLayer(i)).getFeatureStore().isEditing() && layers.getLayer(i).isActive()){ |
94 |
return ((FLyrVect)layers.getLayer(i)).getFeatureStore().canUndo();
|
95 |
// VectorialEditableAdapter vea=(VectorialEditableAdapter)((FLyrVect)layers.getLayer(i)).getSource();
|
96 |
// if (vea==null)return false;
|
97 |
// return vea.getCommandRecord().moreUndoCommands();
|
98 |
} |
99 |
// } catch (ReadException e) {
|
100 |
// // TODO Auto-generated catch block
|
101 |
// e.printStackTrace();
|
102 |
// } catch (DataException e) {
|
103 |
// // TODO Auto-generated catch block
|
104 |
// e.printStackTrace();
|
105 |
// }
|
106 |
|
107 |
} |
108 |
return false; |
109 |
} |
110 |
|
111 |
/**
|
112 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
113 |
*/
|
114 |
public boolean isVisible() { |
115 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
116 |
.getActiveWindow(); |
117 |
|
118 |
if (f == null) { |
119 |
return false; |
120 |
} |
121 |
|
122 |
if (f instanceof DefaultViewPanel) { |
123 |
MapControl mapControl = ((DefaultViewPanel)f).getMapControl(); |
124 |
FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
|
125 |
FLayer layer; |
126 |
for (int i=0;i<layers.length;i++){ |
127 |
layer = layers[i]; |
128 |
if (!layer.isAvailable()){
|
129 |
continue;
|
130 |
} |
131 |
// try {
|
132 |
if (layer instanceof FLyrVect && ((FLyrVect)layer).getFeatureStore().isEditing()){ |
133 |
return true; |
134 |
} |
135 |
// } catch (ReadException e) {
|
136 |
// // TODO Auto-generated catch block
|
137 |
// e.printStackTrace();
|
138 |
// }
|
139 |
} |
140 |
} |
141 |
return false; |
142 |
} |
143 |
} |