Revision 98 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/extensions/EditingExtension.java
EditingExtension.java | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
package org.gvsig.vectorediting.app.mainplugin.extensions; |
8 | 8 |
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.List; |
|
11 |
|
|
9 | 12 |
import org.gvsig.andami.IconThemeHelper; |
13 |
import org.gvsig.andami.PluginServices; |
|
14 |
import org.gvsig.andami.plugins.Extension; |
|
10 | 15 |
import org.gvsig.app.ApplicationLocator; |
16 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
11 | 17 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
12 | 18 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
19 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
13 | 20 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
14 | 21 |
import org.gvsig.fmap.mapcontrol.MapControl; |
15 | 22 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
16 | 23 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
17 |
import org.gvsig.vectorediting.app.mainplugin.BaseEditingServiceExtension; |
|
24 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
|
25 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
|
26 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
27 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
|
18 | 28 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
29 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
|
30 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
|
31 |
import org.gvsig.vectorediting.swing.impl.DefaultEditingBehavior; |
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
19 | 34 |
|
20 |
public class EditingExtension extends BaseEditingServiceExtension {
|
|
35 |
public class EditingExtension extends Extension { |
|
21 | 36 |
|
22 |
public void execute(String actionCommand) { |
|
37 |
private static final Logger logger = LoggerFactory |
|
38 |
.getLogger(DefaultEditingBehavior.class); |
|
23 | 39 |
|
24 |
if ("start-edit".equals(actionCommand)) { |
|
25 |
DefaultViewPanel view = getActiveView(); |
|
40 |
private List<String> serviceNames; |
|
26 | 41 |
|
27 |
if (view != null) { |
|
28 |
FLyrVect layer = getActiveLayer(view); |
|
42 |
public void execute(String actionCommand) { |
|
29 | 43 |
|
44 |
DefaultViewPanel view = getActiveView(); |
|
45 |
EditingSwingManager swingManager = EditingSwingLocator.getSwingManager(); |
|
46 |
if (view != null) { |
|
47 |
FLyrVect layer = getActiveLayer(view); |
|
48 |
EditingContext editingContext = swingManager.getEditingContext(view |
|
49 |
.getMapControl()); |
|
50 |
if ("start-editing".equals(actionCommand)) { |
|
30 | 51 |
if (canBeEdited(layer)) { |
31 |
EditingContext editingContext = swingManager.getEditingContext(view |
|
32 |
.getMapControl()); |
|
33 | 52 |
MapControl mapControl = view.getMapControl(); |
34 | 53 |
StatusBarListener sbl = new StatusBarListener(mapControl); |
35 | 54 |
editingContext.beginEdition(layer, |
... | ... | |
37 | 56 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
38 | 57 |
} |
39 | 58 |
} |
59 |
else if ("end-editing".equals(actionCommand)) { |
|
60 |
if (layer != null && layer.isEditing()) { |
|
61 |
editingContext.endEdition(layer); |
|
62 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
|
63 |
} |
|
64 |
} |
|
65 |
else if (serviceNames.contains(actionCommand)) { |
|
66 |
editingContext.activateService(actionCommand); |
|
67 |
} |
|
40 | 68 |
} |
41 | 69 |
} |
42 | 70 |
|
43 | 71 |
public void initialize() { |
44 |
|
|
72 |
buildServiceNames(); |
|
45 | 73 |
registerIcons(); |
46 | 74 |
} |
47 | 75 |
|
76 |
private void buildServiceNames() { |
|
77 |
serviceNames = new ArrayList<String>(); |
|
78 |
serviceNames.add("insert-point"); |
|
79 |
serviceNames.add("insert-circle-cr"); |
|
80 |
serviceNames.add("insert-circumference-cr"); |
|
81 |
serviceNames.add("insert-polyline"); |
|
82 |
serviceNames.add("insert-polygon"); |
|
83 |
serviceNames.add("modify-symmetry"); |
|
84 |
serviceNames.add("modify-internal-polygon"); |
|
85 |
} |
|
86 |
|
|
48 | 87 |
private void registerIcons() { |
49 | 88 |
IconThemeHelper.registerIcon("action", "vector-editing", this); |
89 |
IconThemeHelper.registerIcon("action", "insert-point", this); |
|
90 |
IconThemeHelper.registerIcon("action", "insert-circle-cr", this); |
|
91 |
IconThemeHelper.registerIcon("action", "insert-circumference-cr", this); |
|
92 |
IconThemeHelper.registerIcon("action", "insert-polyline", this); |
|
93 |
IconThemeHelper.registerIcon("action", "insert-polygon", this); |
|
94 |
IconThemeHelper.registerIcon("action", "modify-symmetry", this); |
|
95 |
IconThemeHelper.registerIcon("action", "modify-internal-polygon", this); |
|
50 | 96 |
} |
51 | 97 |
|
52 | 98 |
public boolean isEnabled() { |
53 |
DefaultViewPanel vista = getActiveView();
|
|
54 |
FLyrVect activeLayer = getActiveLayer(vista);
|
|
99 |
return true;
|
|
100 |
}
|
|
55 | 101 |
|
56 |
return (canBeEdited(activeLayer)); |
|
102 |
public boolean isVisible() { |
|
103 |
return true; |
|
104 |
} |
|
57 | 105 |
|
106 |
@Override |
|
107 |
public boolean isVisible(String action) { |
|
108 |
DefaultViewPanel view = getActiveView(); |
|
109 |
FLyrVect activeLayer = getActiveLayer(view); |
|
110 |
if ("start-editing".equals(action)) { |
|
111 |
return (view != null && activeLayer != null && !activeLayer.isEditing()); |
|
112 |
} |
|
113 |
else if ("end-editing".equals(action) || serviceNames.contains(action)) { |
|
114 |
return (view != null && activeLayer != null && activeLayer.isEditing()); |
|
115 |
} |
|
116 |
return false; |
|
58 | 117 |
} |
59 | 118 |
|
60 |
public boolean isVisible() { |
|
119 |
@Override |
|
120 |
public boolean isEnabled(String action) { |
|
121 |
EditingManager manager = EditingLocator.getManager(); |
|
61 | 122 |
DefaultViewPanel vista = getActiveView(); |
62 | 123 |
FLyrVect activeLayer = getActiveLayer(vista); |
63 | 124 |
|
64 |
return (vista != null && activeLayer != null && !activeLayer.isEditing()); |
|
125 |
if ("start-editing".equals(action)) { |
|
126 |
return (canBeEdited(activeLayer)); |
|
127 |
} |
|
128 |
else if ("end-editing".equals(action)) { |
|
129 |
return activeLayer.isEditing(); |
|
130 |
} |
|
131 |
else if(serviceNames.contains(action)){ |
|
132 |
EditingServiceInfo serviceInfo = null; |
|
133 |
try { |
|
134 |
serviceInfo = manager.getServiceInfo(action); |
|
135 |
return serviceInfo.isCompatibleWith(activeLayer.getFeatureStore()); |
|
136 |
} |
|
137 |
catch (ServiceInformationException e) { |
|
138 |
logger.error("Can't get service information of " + action, e); |
|
139 |
} |
|
140 |
} |
|
141 |
return false; |
|
65 | 142 |
} |
66 | 143 |
|
144 |
public boolean canQueryByAction() { |
|
145 |
return true; |
|
146 |
} |
|
147 |
|
|
148 |
private DefaultViewPanel getActiveView() { |
|
149 |
org.gvsig.andami.ui.mdiManager.IWindow activeWindow = PluginServices |
|
150 |
.getMDIManager().getActiveWindow(); |
|
151 |
|
|
152 |
if (activeWindow instanceof DefaultViewPanel) { |
|
153 |
return (DefaultViewPanel) activeWindow; |
|
154 |
} |
|
155 |
|
|
156 |
return null; |
|
157 |
} |
|
158 |
|
|
159 |
private boolean canBeEdited(FLyrVect layer) { |
|
160 |
if (layer != null) { |
|
161 |
boolean isWritable = layer.isWritable(); |
|
162 |
boolean isNotTransformed = layer.getFeatureStore().getTransforms() |
|
163 |
.isEmpty(); |
|
164 |
|
|
165 |
return isWritable && isNotTransformed && !layer.isEditing(); |
|
166 |
} |
|
167 |
return false; |
|
168 |
} |
|
169 |
|
|
170 |
private FLyrVect getActiveLayer(DefaultViewPanel vista) { |
|
171 |
if (vista != null) { |
|
172 |
ViewDocument viewDocument = vista.getViewDocument(); |
|
173 |
FLayer[] actives = viewDocument.getMapContext().getLayers().getActives(); |
|
174 |
|
|
175 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
|
176 |
return (FLyrVect) actives[0]; |
|
177 |
} |
|
178 |
} |
|
179 |
return null; |
|
180 |
} |
|
67 | 181 |
} |
Also available in: Unified diff