001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.command.factory;
010:
011: import java.net.URL;
012:
013: import net.refractions.udig.catalog.IGeoResource;
014: import net.refractions.udig.core.IBlockingProvider;
015: import net.refractions.udig.core.StaticBlockingProvider;
016: import net.refractions.udig.project.ILayer;
017: import net.refractions.udig.project.command.EditCommand;
018: import net.refractions.udig.project.command.MapCommand;
019: import net.refractions.udig.project.command.UndoableMapCommand;
020: import net.refractions.udig.project.internal.Layer;
021: import net.refractions.udig.project.internal.commands.DeleteLayerCommand;
022: import net.refractions.udig.project.internal.commands.DeleteLayersCommand;
023: import net.refractions.udig.project.internal.commands.edit.AddFeatureCommand;
024: import net.refractions.udig.project.internal.commands.edit.CopyFeaturesCommand;
025: import net.refractions.udig.project.internal.commands.edit.CreateFeatureCommand;
026: import net.refractions.udig.project.internal.commands.edit.CreateLayerCommand;
027: import net.refractions.udig.project.internal.commands.edit.DeleteFeatureCommand;
028: import net.refractions.udig.project.internal.commands.edit.DeleteManyFeaturesCommand;
029: import net.refractions.udig.project.internal.commands.edit.ResetEditFeatureCommand;
030: import net.refractions.udig.project.internal.commands.edit.RollbackCommand;
031: import net.refractions.udig.project.internal.commands.edit.SetAttributeCommand;
032: import net.refractions.udig.project.internal.commands.edit.SetEditFeatureCommand;
033: import net.refractions.udig.project.internal.commands.edit.SetGeometryCommand;
034: import net.refractions.udig.project.internal.commands.edit.WriteEditFeatureCommand;
035: import net.refractions.udig.project.internal.commands.selection.CommitCommand;
036:
037: import org.geotools.feature.Feature;
038: import org.geotools.filter.Filter;
039:
040: import com.vividsolutions.jts.geom.Coordinate;
041: import com.vividsolutions.jts.geom.Geometry;
042:
043: /**
044: * Creates Edit commands which must be used to modify editable feature data. API internal classes
045: * are in the returned API
046: *
047: * @author jeichar
048: * @since 0.3
049: */
050: @SuppressWarnings("deprecation")
051: public class EditCommandFactory extends
052: net.refractions.udig.project.command.EditCommandFactory {
053: /**
054: * Creates a new EditCommandFactory object
055: *
056: * @return a new EditCommandFactory object
057: */
058: public static EditCommandFactory getInstance() {
059: return instance;
060: }
061:
062: private static final EditCommandFactory instance = new EditCommandFactory();
063:
064: protected EditCommandFactory() {
065: // no op
066: }
067:
068: /**
069: * Creates a {@linkplain SetAttributeCommand}object.
070: *
071: * @param xpath xpath that identifies an attribute in the current editable Feature
072: * @param value the value that the attribute will be set to.
073: * @return a new {@linkplain SetAttributeCommand}object
074: * @see EditCommand
075: */
076: public UndoableMapCommand createSetAttributeCommand(String xpath,
077: Object value) {
078: return new SetAttributeCommand(xpath, value);
079: }
080:
081: /**
082: * Creates a {@linkplain SetGeometryCommand}object.
083: *
084: * @param xpath xpath that identifies an attribute in the current editable Feature
085: * @param geom the geom (in <b>layer </b> CRS) that the geometry will be set to.
086: * @return a new {@linkplain SetGeometryCommand}object
087: * @see EditCommand
088: * @see Geometry
089: */
090: public UndoableMapCommand createSetGeometryCommand(String xpath,
091: Geometry geom) {
092: return new SetGeometryCommand(xpath, geom);
093: }
094:
095: /**
096: * Creates a {@linkplain SetGeometryCommand}object that sets the default geometry.
097: *
098: * @param geom the geom (in <b>layer </b> CRS) that the geometry will be set to.
099: * @return a new {@linkplain SetGeometryCommand}object.
100: * @see EditCommand
101: * @see Geometry
102: */
103: public UndoableMapCommand createSetGeometryCommand(Geometry geom) {
104: return new SetGeometryCommand(SetGeometryCommand.DEFAULT, geom);
105: }
106:
107: /**
108: * Creates a {@linkplain SetAttributeCommand}object.
109: *
110: * @param xpath xpath that identifies an attribute in the current editable Feature
111: * @param value the value that the attribute will be set to.
112: * @return a new {@linkplain SetAttributeCommand}object
113: * @see EditCommand
114: */
115: public UndoableMapCommand createSetAttributeCommand(
116: Feature feature, ILayer layer, String xpath, Object value) {
117: return new SetAttributeCommand(
118: new StaticBlockingProvider<Feature>(feature),
119: new StaticBlockingProvider<ILayer>(layer), xpath, value);
120: }
121:
122: /**
123: * Creates a {@linkplain SetGeometryCommand}object.
124: *
125: * @param xpath xpath that identifies an attribute in the current editable Feature
126: * @param geom the geom (in <b>layer </b> CRS) that the geometry will be set to.
127: * @return a new {@linkplain SetGeometryCommand}object
128: * @see EditCommand
129: * @see Geometry
130: */
131: public UndoableMapCommand createSetGeomteryCommand(Feature feature,
132: ILayer layer, String xpath, Geometry geom) {
133: return new SetGeometryCommand(
134: new StaticBlockingProvider<Feature>(feature),
135: new StaticBlockingProvider<ILayer>(layer), xpath, geom);
136: }
137:
138: /**
139: * Creates a {@linkplain SetGeometryCommand}object that sets the default geometry.
140: *
141: * @param feature a feature that has a default feature type that will accept the geometry type.
142: * @param layer the layer containing the feature.
143: * @param geom the geom (in <b>layer </b> CRS) that the geometry will be set to.
144: * @return a new {@linkplain SetGeometryCommand}object.
145: * @see EditCommand
146: * @see Geometry
147: */
148: public UndoableMapCommand createSetGeomteryCommand(Feature feature,
149: ILayer layer, Geometry geom) {
150: return new SetGeometryCommand(
151: new StaticBlockingProvider<Feature>(feature),
152: new StaticBlockingProvider<ILayer>(layer),
153: SetGeometryCommand.DEFAULT, geom);
154: }
155:
156: /**
157: * Creates a {@linkplain SetGeometryCommand}object that sets the default geometry.
158: *
159: * @param featureID the id of a feature in layer.
160: * @param layer the layer containing the feature.
161: * @param geom the geom (in <b>layer </b> CRS) that the geometry will be set to.
162: * @return a new {@linkplain SetGeometryCommand}object.
163: * @see EditCommand
164: * @see Geometry
165: */
166: public UndoableMapCommand createSetGeomteryCommand(
167: String featureID, ILayer layer, Geometry geom) {
168: return new SetGeometryCommand(featureID,
169: new StaticBlockingProvider<ILayer>(layer),
170: SetGeometryCommand.DEFAULT, geom);
171: }
172:
173: /**
174: * Creates a {@linkplain SetEditFeatureCommand}object that sets the current editVictim victim.
175: *
176: * @param feature the feature that will be the new editable Feature.
177: * @param layer A victim Store that contains the editable Feature.
178: * @return a new {@linkplain SetEditFeatureCommand}object.
179: * @see Feature
180: * @see Layer
181: * @see UndoableMapCommand
182: */
183: public UndoableMapCommand createSetEditFeatureCommand(
184: Feature feature, ILayer layer) {
185: return new SetEditFeatureCommand(feature, layer);
186: }
187:
188: /**
189: * Create a Commit command
190: *
191: * @return a new {@linkplain CommitCommand} object that deletes the feature.
192: * @see CommitCommand
193: */
194: public MapCommand createCommitCommand() {
195: return new CommitCommand();
196: }
197:
198: /**
199: * Create a Commit command
200: *
201: * @return a new {@linkplain RollbackCommand} object that deletes the feature.
202: * @see RollbackCommand
203: */
204: public MapCommand createRollbackCommand() {
205: return new RollbackCommand();
206: }
207:
208: /**
209: * Creates a {@linkplain SetEditFeatureCommand}object that sets the current editable Feature.
210: *
211: * @param feature the feature that will be the new editable Feature.
212: * @return a new {@linkplain SetEditFeatureCommand}object.
213: * @see UndoableMapCommand
214: * @see Feature
215: */
216: public UndoableMapCommand createSetEditFeatureCommand(
217: Feature feature) {
218: return new SetEditFeatureCommand(feature);
219: }
220:
221: /**
222: * Creates a {@linkplain SetEditFeatureCommand}object that sets the current editable Feature
223: * to null.
224: *
225: * @return a new {@linkplain SetEditFeatureCommand}object that sets the current editable
226: * Feature to null..
227: * @see UndoableMapCommand
228: */
229: public UndoableMapCommand createNullEditFeatureCommand() {
230: return new SetEditFeatureCommand((Feature) null, (ILayer) null);
231: }
232:
233: /**
234: * @param coordinates the coordinates of the new feature in <b>Map </b> CRS.
235: * @return a new {@linkplain CreateFeatureCommand}object creates the feature.
236: * @see CreateFeatureCommand
237: */
238: public UndoableMapCommand createFeature(Coordinate[] coordinates) {
239: return new CreateFeatureCommand(coordinates);
240: }
241:
242: /**
243: * Create a delete multiple layers command
244: *
245: * @param map the map containing the layer
246: * @param evaluationObject the layer to delete
247: * @return a new {@linkplain DeleteLayerCommand}object that deletes the layer.
248: * @see DeleteLayerCommand
249: */
250: public UndoableMapCommand createDeleteLayers(ILayer[] layers) {
251: return new DeleteLayersCommand(layers);
252: }
253:
254: /**
255: * Create a delete layer command
256: *
257: * @deprecated use optimized createDeleteLayers(ILayer[]) method.
258: *
259: * @param map the map containing the layer
260: * @param layer the layer to delete
261: * @return a new {@linkplain DeleteLayerCommand}object that deletes the layer.
262: * @see DeleteLayerCommand
263: */
264: public UndoableMapCommand createDeleteLayer(ILayer layer) {
265: return new DeleteLayersCommand(new ILayer[] { layer });
266: }
267:
268: /**
269: * Create a Delete Feature command
270: *
271: * @param layer the layer containing the feature
272: * @param feature the feature to delete
273: * @return a new {@linkplain DeleteFeatureCommand}object that deletes the feature.
274: * @see DeleteFeatureCommand
275: */
276: public UndoableMapCommand createDeleteFeature(Feature feature,
277: ILayer layer) {
278: return new DeleteFeatureCommand(
279: new StaticBlockingProvider<Feature>(feature),
280: new StaticBlockingProvider<ILayer>(layer));
281: }
282:
283: /**
284: * Create a Delete Feature command
285: *
286: * @param evaluationObject the layer containing the feature
287: * @param feature the feature to delete
288: * @return a new {@linkplain DeleteFeatureCommand}object that deletes the feature.
289: * @see DeleteFeatureCommand
290: */
291: public UndoableMapCommand createDeleteFeature(
292: IBlockingProvider<Feature> provider,
293: IBlockingProvider<ILayer> layerProvider) {
294: return new DeleteFeatureCommand(provider, layerProvider);
295: }
296:
297: /**
298: * Create a {@linkplain WriteEditFeatureCommand} command
299: *
300: * @return a new {@linkplain WriteEditFeatureCommand} object that deletes the feature.
301: * @see WriteEditFeatureCommand
302: */
303: public UndoableMapCommand createWriteEditFeatureCommand() {
304: return new WriteEditFeatureCommand();
305: }
306:
307: /**
308: * Create a {@linkplain CreateLayerCommand}
309: *
310: * @see CreateLayerCommand
311: */
312: public UndoableMapCommand createCreateLayerCommand(URL resourceId) {
313: return new CreateLayerCommand(resourceId);
314: }
315:
316: /**
317: * Create a {@linkplain CreateLayerCommand}
318: *
319: * @see CreateLayerCommand
320: */
321: public UndoableMapCommand createCreateLayerCommand(
322: IGeoResource resource) {
323: return new CreateLayerCommand(resource);
324: }
325:
326: /**
327: * Create a {@linkplain ResetEditFeatureCommand} command
328: *
329: * @return a new {@linkplain ResetEditFeatureCommand} object that deletes the feature.
330: * @see ResetEditFeatureCommand
331: */
332: public UndoableMapCommand createResetEditFeatureCommand() {
333: return new ResetEditFeatureCommand();
334: }
335:
336: public MapCommand createDeleteFeatures(ILayer selectedLayer,
337: Filter filter) {
338: return new DeleteManyFeaturesCommand(selectedLayer, filter);
339: }
340:
341: public UndoableMapCommand createCopyFeaturesCommand(
342: ILayer sourceLayer, Filter filter, ILayer destinationLayer) {
343: return new CopyFeaturesCommand(sourceLayer, filter,
344: (Layer) destinationLayer);
345: }
346:
347: public UndoableMapCommand createAddFeatureCommand(Feature feature,
348: ILayer layer) {
349: return new AddFeatureCommand(feature, layer);
350: }
351:
352: }
|