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 / BaseEditingServiceExtension.java @ 42
History | View | Annotate | Download (3.7 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; |
8 |
|
9 |
import org.gvsig.andami.PluginServices; |
10 |
import org.gvsig.andami.plugins.Extension; |
11 |
import org.gvsig.app.project.documents.view.ViewDocument; |
12 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
13 |
import org.gvsig.fmap.geom.Geometry; |
14 |
import org.gvsig.fmap.geom.GeometryLocator; |
15 |
import org.gvsig.fmap.geom.type.GeometryType; |
16 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
17 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
18 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
19 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
20 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
21 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
22 |
import org.gvsig.vectorediting.swing.api.EditingSwingLocator; |
23 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
24 |
|
25 |
public abstract class BaseEditingServiceExtension extends Extension { |
26 |
|
27 |
/**
|
28 |
*
|
29 |
*/
|
30 |
private static final long serialVersionUID = -6005105101114750889L; |
31 |
|
32 |
protected final EditingManager manager = EditingLocator.getManager(); |
33 |
protected final EditingSwingManager swingManager = EditingSwingLocator.getSwingManager(); |
34 |
|
35 |
protected DefaultViewPanel getActiveView() {
|
36 |
org.gvsig.andami.ui.mdiManager.IWindow activeWindow = PluginServices |
37 |
.getMDIManager().getActiveWindow(); |
38 |
|
39 |
if (activeWindow instanceof DefaultViewPanel) { |
40 |
return (DefaultViewPanel) activeWindow;
|
41 |
} |
42 |
|
43 |
return null; |
44 |
} |
45 |
|
46 |
protected boolean canBeEdited(FLyrVect layer) { |
47 |
if (layer != null) { |
48 |
boolean isWritable = layer.isWritable();
|
49 |
boolean isNotTransformed = layer.getFeatureStore().getTransforms().isEmpty();
|
50 |
|
51 |
return isWritable && isNotTransformed && !layer.isEditing();
|
52 |
} |
53 |
return false; |
54 |
} |
55 |
|
56 |
protected FLyrVect getActiveLayer(DefaultViewPanel vista) {
|
57 |
if (vista != null) { |
58 |
ViewDocument viewDocument = vista.getViewDocument(); |
59 |
FLayer[] actives = viewDocument.getMapContext().getLayers().getActives();
|
60 |
|
61 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
62 |
return (FLyrVect) actives[0]; |
63 |
} |
64 |
} |
65 |
return null; |
66 |
} |
67 |
|
68 |
private boolean isApplicable(GeometryType[] supportedTypes, GeometryType geometryType) { |
69 |
if (supportedTypes != null) { |
70 |
for (int i = 0; i < supportedTypes.length; i++) { |
71 |
if (supportedTypes[i].isTypeOf(geometryType)) {
|
72 |
return true; |
73 |
} |
74 |
} |
75 |
} |
76 |
return false; |
77 |
} |
78 |
|
79 |
protected boolean isApplicable(GeometryType[] supportedTypes, int shapeType) { |
80 |
GeometryType type = loadGeometryType(shapeType, Geometry.SUBTYPES.GEOM2D); |
81 |
return isApplicable(supportedTypes, type);
|
82 |
} |
83 |
|
84 |
protected GeometryType[] loadGeometryTypes(int[] types) { |
85 |
GeometryType[] supportedTypes = null; |
86 |
if (types == null) { |
87 |
supportedTypes = new GeometryType[0]; |
88 |
} |
89 |
else {
|
90 |
supportedTypes = new GeometryType[types.length];
|
91 |
for (int i = 0; i < types.length; i++) { |
92 |
supportedTypes[i] = loadGeometryType(types[i], Geometry.SUBTYPES.GEOM2D); |
93 |
} |
94 |
} |
95 |
return supportedTypes;
|
96 |
} |
97 |
|
98 |
private GeometryType loadGeometryType(int type, int subtype) { |
99 |
try {
|
100 |
return GeometryLocator.getGeometryManager()
|
101 |
.getGeometryType(type, subtype); |
102 |
} |
103 |
catch (GeometryTypeNotSupportedException e) {
|
104 |
throw new RuntimeException("Error getting the Geometry type with type = " |
105 |
+ type + ", subtype = " + subtype, e);
|
106 |
} |
107 |
catch (GeometryTypeNotValidException e) {
|
108 |
throw new RuntimeException("Error getting the Geometry type with type = " |
109 |
+ type + ", subtype = " + subtype, e);
|
110 |
} |
111 |
} |
112 |
|
113 |
} |