Revision 2109 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/ServiceExtension.java
ServiceExtension.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.vectorediting.app.mainplugin; |
25 | 25 |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
26 | 28 |
import org.gvsig.andami.plugins.Extension; |
27 | 29 |
import org.gvsig.app.ApplicationLocator; |
28 | 30 |
import org.gvsig.app.ApplicationManager; |
... | ... | |
36 | 38 |
|
37 | 39 |
public class ServiceExtension extends Extension { |
38 | 40 |
|
41 |
@Override |
|
39 | 42 |
public void initialize() { |
40 | 43 |
} |
41 | 44 |
|
45 |
@Override |
|
42 | 46 |
public void execute(String actionCommand) { |
43 | 47 |
IView view = getActiveView(); |
44 | 48 |
EditingSwingManager swingManager = |
... | ... | |
52 | 56 |
|
53 | 57 |
} |
54 | 58 |
|
59 |
@Override |
|
55 | 60 |
public boolean isEnabled() { |
56 | 61 |
return this.isVisible(); |
57 | 62 |
} |
... | ... | |
59 | 64 |
@Override |
60 | 65 |
public boolean isEnabled(String action) { |
61 | 66 |
IView view = getActiveView(); |
62 |
FLyrVect activeLayer = getActiveLayer(view); |
|
67 |
if(view!=null){ |
|
68 |
FLyrVect activeLayer = getActiveEditingVectLayer(view); |
|
63 | 69 |
|
64 |
if ((view != null) && (activeLayer != null) && activeLayer.isEditing() && action!=null) { |
|
65 |
EditingSwingManager swingManager = |
|
66 |
EditingSwingLocator.getSwingManager(); |
|
67 |
EditingContext editingContext = |
|
68 |
swingManager.getEditingContext(view.getMapControl()); |
|
69 |
return editingContext.isServiceCompatible(action); |
|
70 |
if (activeLayer != null && activeLayer.isEditing() && action!=null) { |
|
71 |
EditingSwingManager swingManager = |
|
72 |
EditingSwingLocator.getSwingManager(); |
|
73 |
EditingContext editingContext = |
|
74 |
swingManager.getEditingContext(view.getMapControl()); |
|
75 |
return editingContext.isServiceCompatible(action); |
|
76 |
} |
|
70 | 77 |
} |
71 | 78 |
return false; |
72 | 79 |
} |
73 | 80 |
|
81 |
@Override |
|
74 | 82 |
public boolean isVisible() { |
75 | 83 |
IView view = getActiveView(); |
76 |
FLyrVect activeLayer = getActiveLayer(view); |
|
77 |
return ((view != null) && (activeLayer != null) && activeLayer |
|
78 |
.isEditing()); |
|
84 |
if(view!=null){ |
|
85 |
FLyrVect activeLayer = getActiveEditingVectLayer(view); |
|
86 |
return (activeLayer != null && activeLayer.isEditing()); |
|
87 |
} |
|
88 |
return false; |
|
79 | 89 |
} |
80 | 90 |
|
81 | 91 |
@Override |
... | ... | |
95 | 105 |
return view; |
96 | 106 |
} |
97 | 107 |
|
98 |
private FLyrVect getActiveLayer(IView view) { |
|
108 |
private FLyrVect getActiveEditingVectLayer(IView view) { |
|
109 |
List<FLyrVect> activeEditingVectLayers = new ArrayList<>(); |
|
99 | 110 |
if (view != null) { |
100 | 111 |
ViewDocument viewDocument = view.getViewDocument(); |
101 |
FLayer[] actives = |
|
112 |
FLayer[] activeLayers =
|
|
102 | 113 |
viewDocument.getMapContext().getLayers().getActives(); |
114 |
for (FLayer activeLayer : activeLayers) { |
|
115 |
if(activeLayer instanceof FLyrVect){ |
|
116 |
FLyrVect activeVectLayer = (FLyrVect) activeLayer; |
|
117 |
if(activeVectLayer.isEditing()){ |
|
118 |
activeEditingVectLayers.add(activeVectLayer); |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
103 | 122 |
|
104 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) {
|
|
105 |
return (FLyrVect) actives[0];
|
|
123 |
if ((activeEditingVectLayers.size() == 1)) {
|
|
124 |
return (FLyrVect) activeEditingVectLayers.get(0);
|
|
106 | 125 |
} |
107 | 126 |
} |
108 | 127 |
return null; |
Also available in: Unified diff