01: package net.refractions.udig.tools.edit.commands;
02:
03: import net.refractions.udig.project.ILayer;
04: import net.refractions.udig.project.command.AbstractCommand;
05: import net.refractions.udig.project.command.UndoableMapCommand;
06: import net.refractions.udig.project.internal.Layer;
07: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
08: import net.refractions.udig.project.ui.tool.IToolContext;
09: import net.refractions.udig.tools.edit.EditToolHandler;
10: import net.refractions.udig.tools.edit.support.PrimitiveShape;
11:
12: import org.eclipse.core.runtime.IProgressMonitor;
13: import org.geotools.feature.Feature;
14: import org.geotools.feature.FeatureCollection;
15: import org.geotools.feature.FeatureIterator;
16: import org.geotools.geometry.jts.ReferencedEnvelope;
17:
18: /**
19: * Sets the feature currently being edited in the edit manager.
20: * @author chorner
21: * @since 1.1.0
22: */
23: public class SetEditFeatureCommand extends AbstractCommand implements
24: UndoableMapCommand {
25:
26: EditToolHandler handler;
27: MapMouseEvent event;
28: PrimitiveShape shape;
29: Feature oldFeature;
30: ILayer oldLayer;
31:
32: public SetEditFeatureCommand(EditToolHandler handler,
33: MapMouseEvent e, PrimitiveShape shape) {
34: this .handler = handler;
35: this .event = e;
36: this .shape = shape;
37: }
38:
39: public void run(IProgressMonitor monitor) throws Exception {
40: IToolContext context = handler.getContext();
41: ReferencedEnvelope bbox = handler.getContext().getBoundingBox(
42: event.getPoint(), 7);
43: FeatureCollection fc = context.getFeaturesInBbox(handler
44: .getEditLayer(), bbox);
45: FeatureIterator it = fc.features();
46: Feature feature = null;
47: while (it.hasNext()) {
48: Feature feat = it.next();
49: if (feat.getID().equals(
50: shape.getEditGeom().getFeatureIDRef().toString())) {
51: feature = feat;
52: break;
53: }
54: }
55: it.close();
56: oldFeature = getMap().getEditManagerInternal().getEditFeature();
57: oldLayer = getMap().getEditManagerInternal().getEditLayer();
58: getMap().getEditManagerInternal().setEditFeature(feature,
59: (Layer) handler.getEditLayer());
60: }
61:
62: public String getName() {
63: return null;
64: }
65:
66: public void rollback(IProgressMonitor monitor) throws Exception {
67: getMap().getEditManagerInternal().setEditFeature(oldFeature,
68: (Layer) oldLayer);
69: }
70:
71: }
|