gvsig-vectorediting / 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 / PolylineExtension.java @ 89
History | View | Annotate | Download (2.74 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.app.mainplugin
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.app.mainplugin.extensions; |
8 |
|
9 |
import org.gvsig.andami.IconThemeHelper; |
10 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
11 |
import org.gvsig.fmap.dal.exception.ReadException; |
12 |
import org.gvsig.fmap.geom.type.GeometryType; |
13 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
14 |
import org.gvsig.vectorediting.app.mainplugin.BaseEditingServiceExtension; |
15 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
16 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
17 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory; |
18 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
19 |
import org.gvsig.vectorediting.swing.impl.DefaultEditingBehavior; |
20 |
import org.slf4j.Logger; |
21 |
import org.slf4j.LoggerFactory; |
22 |
|
23 |
public class PolylineExtension extends BaseEditingServiceExtension { |
24 |
|
25 |
private static final Logger logger = LoggerFactory |
26 |
.getLogger(DefaultEditingBehavior.class); |
27 |
|
28 |
public void initialize() { |
29 |
registerIcons(); |
30 |
} |
31 |
|
32 |
public void execute(String actionCommand) { |
33 |
|
34 |
if ("insert-polyline".equals(actionCommand)) { |
35 |
DefaultViewPanel view = getActiveView(); |
36 |
EditingContext editingContext = swingManager.getEditingContext(view |
37 |
.getMapControl()); |
38 |
editingContext |
39 |
.activateService(PolylineEditingProviderFactory.PROVIDER_NAME); |
40 |
} |
41 |
|
42 |
} |
43 |
|
44 |
private void registerIcons() { |
45 |
IconThemeHelper.registerIcon("action", "layer-insert-polyline", this); |
46 |
} |
47 |
|
48 |
public boolean isEnabled() { |
49 |
EditingServiceInfo polylineServiceInfo; |
50 |
FLyrVect layer = null;
|
51 |
try {
|
52 |
polylineServiceInfo = manager |
53 |
.getServiceInfo(PolylineEditingProviderFactory.PROVIDER_NAME); |
54 |
DefaultViewPanel view = getActiveView(); |
55 |
layer = getActiveLayer(view); |
56 |
|
57 |
int[] supportedTypes = polylineServiceInfo |
58 |
.getSupportedPrimitiveGeometryTypes(); |
59 |
GeometryType[] supportedGeoTypes = loadGeometryTypes(supportedTypes);
|
60 |
|
61 |
if (isApplicable(supportedGeoTypes, layer.getShapeType())) {
|
62 |
return true; |
63 |
} |
64 |
|
65 |
return false; |
66 |
|
67 |
} |
68 |
catch (ServiceInformationException e) {
|
69 |
logger.error("Cant' get service information of "
|
70 |
+ PolylineEditingProviderFactory.PROVIDER_NAME, e); |
71 |
} |
72 |
catch (ReadException e) {
|
73 |
logger.error("Can't get shape type of " + layer.getName(), e);
|
74 |
} |
75 |
return false; |
76 |
} |
77 |
|
78 |
public boolean isVisible() { |
79 |
DefaultViewPanel view = getActiveView(); |
80 |
if (view != null) { |
81 |
FLyrVect layer = getActiveLayer(view); |
82 |
if (layer != null && layer.isEditing()) { |
83 |
return true; |
84 |
} |
85 |
} |
86 |
return false; |
87 |
} |
88 |
|
89 |
} |