Operations¶
The operation extension point is one of the most useful (and used) facilities of the uDig SDK. It allows you to contribute functionality to the user interface based on what is selected, regardless of which view it is displayed in.
Related:
- Export Shapefile tutorial
IOp¶
The IOp interface is used to define user interface needs. This represents a suitable compromise that can be maintained both by uDig and Toolkit providers.
<extension
point="org.locationtech.udig.ui.operation">
<operation
class="org.locationtech.udig.tool.edit.DifferenceOp"
enablesFor="2"
id="org.locationtech.udig.tool.edit.difference"
name="%difference.name"
targetClass="org.locationtech.udig.project.ILayer"/>
<operation
class="org.locationtech.udig.tool.edit.SplitLineOp"
enablesFor="+"
id="org.locationtech.udig.tool.edit.operation1"
menuPath="edit/add.ext"
name="%operation.splitLine.name"
targetClass="org.locationtech.udig.tools.edit.support.Point">
<enablement>
<and>
<property propertyId="org.locationtech.udig.tools.edit.CurrentShape.ShapeType" expectedValue="LINE"/>
<property propertyId="org.locationtech.udig.project.ui.OpenMap" expectedValue="java.lang.Object"/>
</and>
</enablement>
</operation>
</extension>
The above example (from org.locationtech.udig.tool.edit) contributes two “operations” to the system:
- DifferenceOp which is available whenever the user is working with a ILayer (or even something that can adapt to an ILayer)
- SplitLineOp which is available whenever the user has selected a point using the edit tool and the enablement conditions are met.
All operations are available in the Edit > Operations... menu in accordance with the Eclipse House Rules.
Implementation of an Operation¶
The targetClass mentioned in the extension point is an actual API contract; the system will make sure the user has supplied you with an actual object of the requested Class before you are called. So performing a cast to the expected targetClass is expected.
Here is an example from the Export Shapefile tutorial:
public class ShpExportOp implements IOp {
public void op(Display display, Object target, IProgressMonitor monitor)
throws Exception {
FeatureSource source = (FeatureSource) target;
SimpleFeatureType featureType = source.getSchema();
GeometryDescriptor geometryType = featureType.getGeometryDescriptor();
CoordinateReferenceSystem crs = geometryType.getCoordinateReferenceSystem();
String typeName = featureType.getTypeName();
...
}
}
The system will contribute this operation to the user interface whenever the conditions can be met. So this operation will work on both GeoResources that can adapt to FeatureSource; and on ILayers used to render a FeatureSource.