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 / CircleCRExtension.java @ 91
History | View | Annotate | Download (3.19 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.mapcontext.layers.vectorial.FLyrVect; |
12 |
import org.gvsig.fmap.mapcontrol.MapControl; |
13 |
import org.gvsig.vectorediting.app.mainplugin.BaseEditingServiceExtension; |
14 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
15 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
16 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProviderFactory; |
17 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircumferenceCREditingProviderFactory; |
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 CircleCRExtension 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 arg0) { |
33 |
MapControl mapControl = getActiveView().getMapControl(); |
34 |
EditingContext editingContext = swingManager.getEditingContext(mapControl); |
35 |
if ("insert-circle-cr".equalsIgnoreCase(arg0)) { |
36 |
editingContext |
37 |
.activateService(CircleCREditingProviderFactory.PROVIDER_NAME); |
38 |
} |
39 |
else if ("insert-circumference-cr".equalsIgnoreCase(arg0)) { |
40 |
editingContext |
41 |
.activateService(CircumferenceCREditingProviderFactory.PROVIDER_NAME); |
42 |
} |
43 |
} |
44 |
|
45 |
private void registerIcons() { |
46 |
IconThemeHelper |
47 |
.registerIcon("action", "layer-insert-circumferencecr", this); |
48 |
IconThemeHelper.registerIcon("action", "layer-insert-circlecr", this); |
49 |
} |
50 |
|
51 |
public boolean isEnabled() { |
52 |
return true; |
53 |
} |
54 |
|
55 |
public boolean isVisible() { |
56 |
DefaultViewPanel view = getActiveView(); |
57 |
if (view != null) { |
58 |
FLyrVect layer = getActiveLayer(view); |
59 |
if (layer != null && layer.isEditing()) { |
60 |
return true; |
61 |
} |
62 |
} |
63 |
return false; |
64 |
} |
65 |
|
66 |
@Override
|
67 |
public boolean isVisible(String action) { |
68 |
return isVisible();
|
69 |
} |
70 |
|
71 |
@Override
|
72 |
public boolean isEnabled(String action) { |
73 |
EditingServiceInfo circleCRInfo; |
74 |
FLyrVect layer = null;
|
75 |
try {
|
76 |
if (action.equalsIgnoreCase("insert-circle-cr")) { |
77 |
circleCRInfo = manager |
78 |
.getServiceInfo(CircleCREditingProviderFactory.PROVIDER_NAME); |
79 |
} |
80 |
else if (action.equalsIgnoreCase("insert-circumference-cr")) { |
81 |
circleCRInfo = manager |
82 |
.getServiceInfo(CircumferenceCREditingProviderFactory.PROVIDER_NAME); |
83 |
} |
84 |
else {
|
85 |
return false; |
86 |
} |
87 |
DefaultViewPanel view = getActiveView(); |
88 |
layer = getActiveLayer(view); |
89 |
|
90 |
return circleCRInfo.isCompatibleWith(layer.getFeatureStore());
|
91 |
|
92 |
} |
93 |
catch (ServiceInformationException e) {
|
94 |
logger.error("Cant' get service information of "
|
95 |
+ CircleCREditingProviderFactory.PROVIDER_NAME, e); |
96 |
return false; |
97 |
} |
98 |
} |
99 |
|
100 |
public boolean canQueryByAction() { |
101 |
return true; |
102 |
} |
103 |
|
104 |
} |