01: /*
02: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
03: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
04: * under the terms of the GNU Lesser General Public License as published by the Free Software
05: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
06: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
07: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
08: */
09: package net.refractions.udig.project.internal.commands.selection;
10:
11: import net.refractions.udig.project.ILayer;
12: import net.refractions.udig.project.command.AbstractCommand;
13: import net.refractions.udig.project.command.UndoableMapCommand;
14: import net.refractions.udig.project.internal.Layer;
15: import net.refractions.udig.project.internal.Messages;
16:
17: import org.eclipse.core.runtime.IProgressMonitor;
18: import org.geotools.feature.Feature;
19: import org.geotools.filter.Filter;
20: import org.geotools.filter.FilterFactoryFinder;
21:
22: /**
23: * TODO Purpose of net.refractions.udig.project.internal.commands.selection
24: * <p>
25: * </p>
26: *
27: * @author Jesse
28: * @since 1.0.0
29: */
30: public class FIDSelectCommand extends AbstractCommand implements
31: UndoableMapCommand {
32:
33: private Layer layer;
34: private String id;
35: private Filter oldFilter;
36:
37: /**
38: * Set the select of a layer to be a single feature as specified by the FID
39: *
40: * @param layer
41: * @param featureID
42: */
43: public FIDSelectCommand(ILayer layer, String featureID) {
44: this .layer = (Layer) layer;
45: this .id = featureID;
46: }
47:
48: /**
49: * Set the select of a layer to be a single feature as specified by the feature
50: *
51: * @param layer
52: * @param featureID
53: */
54: public FIDSelectCommand(ILayer layer, Feature feature) {
55: this .layer = (Layer) layer;
56: this .id = feature.getID();
57: }
58:
59: /**
60: * @see net.refractions.udig.project.internal.command.UndoableCommand#rollback()
61: */
62: public void rollback(IProgressMonitor monitor) {
63: if (oldFilter != null)
64: layer.setFilter(oldFilter);
65: }
66:
67: /**
68: * @see net.refractions.udig.project.internal.command.MapCommand#run()
69: */
70: public void run(IProgressMonitor monitor) {
71: oldFilter = layer.getFilter();
72: Filter filter = FilterFactoryFinder.createFilterFactory()
73: .createFidFilter(id);
74: layer.setFilter(filter);
75: }
76:
77: /**
78: * @see net.refractions.udig.project.command.MapCommand#getName()
79: */
80: public String getName() {
81: return Messages.FIDSelectCommand_featureSelection;
82: }
83:
84: }
|