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 / UndoRedoViewExtension.java @ 46039
History | View | Annotate | Download (6.07 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.plugins.Extension; |
29 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
30 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
31 |
import org.gvsig.app.ApplicationLocator; |
32 |
import org.gvsig.app.ApplicationManager; |
33 |
import org.gvsig.app.gui.command.CommandStackDialog; |
34 |
import org.gvsig.app.project.documents.view.gui.IView; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 |
import org.gvsig.fmap.mapcontrol.MapControl; |
39 |
import org.gvsig.tools.undo.RedoException; |
40 |
import org.gvsig.tools.undo.UndoException; |
41 |
|
42 |
/**
|
43 |
* Extensi?n encargada de gestionar el deshacer los comandos anteriormente
|
44 |
* aplicados.
|
45 |
*
|
46 |
* @author Vicente Caballero Navarro
|
47 |
*/
|
48 |
public class UndoRedoViewExtension extends Extension { |
49 |
|
50 |
@Override
|
51 |
public void initialize() { |
52 |
IconThemeHelper.registerIcon("action", "edit-undo", this); |
53 |
IconThemeHelper.registerIcon("action", "edit-redo", this); |
54 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public void execute(String s) { |
59 |
switch (s) {
|
60 |
case "edit-undo-layer": |
61 |
undo(); |
62 |
break;
|
63 |
case "edit-redo-layer": |
64 |
redo(); |
65 |
break;
|
66 |
case "edit-undo-redo-actions-layer": |
67 |
showHistory(); |
68 |
break;
|
69 |
|
70 |
} |
71 |
} |
72 |
|
73 |
private void undo() { |
74 |
try {
|
75 |
FLyrVect layer = getActiveAndEditingLayer(); |
76 |
if (layer == null) { |
77 |
return;
|
78 |
} |
79 |
if (!layer.getFeatureStore().canUndo()) {
|
80 |
return;
|
81 |
} |
82 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
83 |
IView vista = (IView) application.getActiveWindow(); |
84 |
layer.getFeatureStore().undo(); |
85 |
vista.getMapControl().drawMap(false);
|
86 |
application.refreshMenusAndToolBars(); |
87 |
} catch (UndoException ex) {
|
88 |
logger.warn("Can't undo", ex);
|
89 |
} |
90 |
} |
91 |
|
92 |
private void showHistory() { |
93 |
FLyrVect layer = getActiveAndEditingLayer(); |
94 |
if (layer == null) { |
95 |
return;
|
96 |
} |
97 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
98 |
MDIManager uiManager = application.getUIManager(); |
99 |
FeatureStore featureStore = layer.getFeatureStore(); |
100 |
CommandStackDialog csd = new CommandStackDialog();
|
101 |
csd.setModel(featureStore); |
102 |
csd.setLabelModel(featureStore.getName()); |
103 |
uiManager.addWindow(csd); |
104 |
|
105 |
} |
106 |
|
107 |
private void redo() { |
108 |
try {
|
109 |
FLyrVect layer = getActiveAndEditingLayer(); |
110 |
if (layer == null) { |
111 |
return;
|
112 |
} |
113 |
if (!layer.getFeatureStore().canRedo()) {
|
114 |
return;
|
115 |
} |
116 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
117 |
IView vista = (IView) application.getActiveWindow(); |
118 |
layer.getFeatureStore().redo(); |
119 |
vista.getMapControl().drawMap(false);
|
120 |
application.refreshMenusAndToolBars(); |
121 |
} catch (RedoException ex) {
|
122 |
logger.warn("Can't undo", ex);
|
123 |
} |
124 |
} |
125 |
|
126 |
@Override
|
127 |
public boolean canQueryByAction() { |
128 |
return true; |
129 |
} |
130 |
|
131 |
|
132 |
@Override
|
133 |
public boolean isEnabled(String action) { |
134 |
FLyrVect layer = getActiveAndEditingLayer(); |
135 |
switch (action) {
|
136 |
case "edit-undo-layer": |
137 |
if (layer == null) { |
138 |
return false; |
139 |
} |
140 |
return layer.getFeatureStore().canUndo();
|
141 |
case "edit-redo-layer": |
142 |
if (layer == null) { |
143 |
return false; |
144 |
} |
145 |
return layer.getFeatureStore().canRedo();
|
146 |
case "edit-undo-redo-actions-layer": |
147 |
return true; |
148 |
default:
|
149 |
return false; |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
private FLyrVect getActiveAndEditingLayer() {
|
155 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
156 |
IView vista = (IView) application.getActiveWindow(); |
157 |
MapControl mapControl = vista.getMapControl(); |
158 |
FLayer[] activeLayers = mapControl.getMapContext().getLayers().getActives();
|
159 |
if (activeLayers.length != 1) { |
160 |
return null; |
161 |
} |
162 |
FLayer layer = activeLayers[0];
|
163 |
if (layer instanceof FLyrVect && ((FLyrVect) layer).getFeatureStore().isEditing()) { |
164 |
return (FLyrVect) layer;
|
165 |
} |
166 |
return null; |
167 |
|
168 |
} |
169 |
|
170 |
@Override
|
171 |
public boolean isVisible(String action) { |
172 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
173 |
if(!(application.getActiveWindow() instanceof IView)) { |
174 |
return false; |
175 |
} |
176 |
|
177 |
return getActiveAndEditingLayer()!=null; |
178 |
} |
179 |
|
180 |
@Override
|
181 |
public boolean isEnabled() { |
182 |
return true; |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public boolean isVisible() { |
187 |
return true; |
188 |
} |
189 |
} |