01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.commands;
16:
17: import net.refractions.udig.core.IBlockingProvider;
18: import net.refractions.udig.project.command.AbstractCommand;
19: import net.refractions.udig.project.command.UndoableMapCommand;
20: import net.refractions.udig.project.internal.Layer;
21: import net.refractions.udig.tool.edit.internal.Messages;
22: import net.refractions.udig.tools.edit.EditToolHandler;
23: import net.refractions.udig.tools.edit.support.PrimitiveShape;
24:
25: import org.eclipse.core.runtime.IProgressMonitor;
26: import org.geotools.feature.Feature;
27:
28: /**
29: * Sets the current geometry in the handler to be the passed in geometry
30: *
31: * @author jones
32: * @since 1.1.0
33: */
34: public class SetCurrentGeomCommand extends AbstractCommand implements
35: UndoableMapCommand {
36:
37: EditToolHandler handler;
38: PrimitiveShape oldShape;
39: PrimitiveShape newShape;
40: private IBlockingProvider<PrimitiveShape> provider;
41: private Feature oldEditFeature;
42: private Layer oldEditLayer;
43:
44: /**
45: * @param handler2
46: * @param newShape2
47: */
48: public SetCurrentGeomCommand(EditToolHandler handler2,
49: PrimitiveShape newShape2) {
50: this .handler = handler2;
51: this .newShape = newShape2;
52: }
53:
54: /**
55: * @param handler2
56: * @param provider
57: */
58: public SetCurrentGeomCommand(EditToolHandler handler2,
59: IBlockingProvider<PrimitiveShape> provider) {
60: this .provider = provider;
61: this .handler = handler2;
62: }
63:
64: public void run(IProgressMonitor monitor) throws Exception {
65: oldEditFeature = getMap().getEditManager().getEditFeature();
66: oldEditLayer = getMap().getEditManagerInternal()
67: .getEditLayerInternal();
68: if (oldEditFeature != null) {
69: getMap().getEditManagerInternal()
70: .setEditFeature(null, null);
71: }
72:
73: if (oldShape == null)
74: oldShape = handler.getCurrentShape();
75: if (newShape == null && provider != null)
76: newShape = provider.get(monitor);
77: handler.setCurrentShape(newShape);
78: }
79:
80: public String getName() {
81: return Messages.SetCurrentGeomCommand_name;
82: }
83:
84: public void rollback(IProgressMonitor monitor) throws Exception {
85: handler.setCurrentShape(oldShape);
86: getMap().getEditManagerInternal().setEditFeature(
87: oldEditFeature, oldEditLayer);
88: }
89:
90: }
|