01: package net.refractions.udig.project.internal.commands.edit;
02:
03: import net.refractions.udig.project.command.AbstractCommand;
04: import net.refractions.udig.project.command.MapCommand;
05: import net.refractions.udig.project.command.UndoableMapCommand;
06: import net.refractions.udig.project.internal.Layer;
07: import net.refractions.udig.project.internal.Messages;
08:
09: import org.eclipse.core.runtime.IProgressMonitor;
10: import org.geotools.data.FeatureStore;
11: import org.geotools.feature.Feature;
12: import org.geotools.feature.FeatureIterator;
13: import org.geotools.filter.FilterFactoryFinder;
14:
15: /**
16: * Replaces the edit feature with a new copy from the datastore. Any changes that were made to the
17: * edit feature are lost.
18: *
19: * @author jeichar
20: */
21: public class ResetEditFeatureCommand extends AbstractCommand implements
22: MapCommand, UndoableMapCommand {
23:
24: private Feature oldfeature;
25:
26: public void run(IProgressMonitor monitor) throws Exception {
27: this .oldfeature = getMap().getEditManager().getEditFeature();
28: if (oldfeature == null)
29: return;
30: if (getMap().getEditManager().getEditLayer() == null) {
31: getMap().getEditManagerInternal()
32: .setEditFeature(null, null);
33: return;
34: }
35:
36: FeatureStore store = getMap().getEditManager().getEditLayer()
37: .getResource(FeatureStore.class, monitor);
38: FeatureIterator reader = store.getFeatures(
39: FilterFactoryFinder.createFilterFactory()
40: .createFidFilter(oldfeature.getID()))
41: .features();
42: if (reader.hasNext()) {
43: Feature feature = reader.next();
44: Layer layer = getMap().getEditManagerInternal()
45: .getEditLayerInternal();
46: getMap().getEditManagerInternal().setEditFeature(feature,
47: layer);
48: } else {
49: getMap().getEditManagerInternal()
50: .setEditFeature(null, null);
51: }
52:
53: }
54:
55: public String getName() {
56: return Messages.ResetEditFeatureCommand_0;
57: }
58:
59: public void rollback(IProgressMonitor monitor) throws Exception {
60: getMap().getEditManagerInternal().setEditFeature(
61: oldfeature,
62: getMap().getEditManagerInternal()
63: .getEditLayerInternal());
64: }
65:
66: }
|