001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.tools.edit.commands;
016:
017: import java.util.Collections;
018:
019: import net.refractions.udig.core.IBlockingProvider;
020: import net.refractions.udig.project.command.AbstractCommand;
021: import net.refractions.udig.project.command.UndoableMapCommand;
022: import net.refractions.udig.tool.edit.internal.Messages;
023: import net.refractions.udig.tools.edit.support.EditBlackboard;
024: import net.refractions.udig.tools.edit.support.EditGeom;
025: import net.refractions.udig.tools.edit.support.EditUtils;
026: import net.refractions.udig.tools.edit.support.PrimitiveShape;
027: import net.refractions.udig.tools.edit.support.ShapeType;
028:
029: import org.eclipse.core.runtime.IProgressMonitor;
030:
031: /**
032: * Calls newGeom on the EditBlackboard.
033: *
034: * @author jones
035: * @since 1.1.0
036: */
037: public class CreateEditGeomCommand extends AbstractCommand implements
038: UndoableMapCommand, IBlockingProvider<EditGeom> {
039:
040: private String fid;
041: private EditBlackboard blackboard;
042: private EditGeom geom;
043: private ShapeType shapeType;
044:
045: /**
046: * New Instance
047: *
048: * @param blackboard the blackboard to creat the new geom on.
049: * @param fid the string to use as the feature id of the new Geom
050: */
051: public CreateEditGeomCommand(EditBlackboard blackboard, String fid) {
052: this (blackboard, fid, ShapeType.UNKNOWN);
053: }
054:
055: /**
056: * New Instance
057: *
058: * @param blackboard the blackboard to creat the new geom on.
059: * @param fid the string to use as the feature id of the new Geom
060: * @param shapeType the type of shape to create.
061: */
062: public CreateEditGeomCommand(EditBlackboard blackboard, String fid,
063: ShapeType shapeType) {
064: this .blackboard = blackboard;
065: this .fid = fid;
066: this .shapeType = shapeType;
067: }
068:
069: public void run(IProgressMonitor monitor) throws Exception {
070: this .geom = blackboard.newGeom(fid, shapeType);
071: }
072:
073: public String getName() {
074: return Messages.CreateEditGeomCommand_name;
075: }
076:
077: public void rollback(IProgressMonitor monitor) throws Exception {
078: blackboard.removeGeometries(Collections.singleton(geom));
079: }
080:
081: public EditGeom get(IProgressMonitor monitor) {
082: return geom;
083: }
084:
085: public IBlockingProvider<EditGeom> getEditGeomProvider() {
086: return new EditUtils.StaticEditGeomProvider(geom);
087: }
088:
089: public IBlockingProvider<PrimitiveShape> getShapeProvider() {
090: return new ShapeProvider();
091: }
092:
093: class ShapeProvider implements IBlockingProvider<PrimitiveShape> {
094:
095: public PrimitiveShape get(IProgressMonitor monitor) {
096: return geom.getShell();
097: }
098:
099: }
100:
101: }
|