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.tool.edit;
16:
17: import java.io.IOException;
18: import java.util.Arrays;
19: import java.util.HashSet;
20:
21: import net.refractions.udig.core.IBlockingProvider;
22: import net.refractions.udig.project.IMap;
23: import net.refractions.udig.project.command.provider.EditFeatureProvider;
24: import net.refractions.udig.project.command.provider.EditLayerProvider;
25: import net.refractions.udig.project.ui.ApplicationGIS;
26: import net.refractions.udig.tools.edit.EditBlackboardUtil;
27: import net.refractions.udig.tools.edit.EditToolHandler;
28: import net.refractions.udig.tools.edit.commands.SplitLineCommand;
29: import net.refractions.udig.tools.edit.support.EditBlackboard;
30: import net.refractions.udig.tools.edit.support.Point;
31: import net.refractions.udig.tools.edit.support.PrimitiveShape;
32: import net.refractions.udig.ui.operations.IOp;
33:
34: import org.eclipse.core.runtime.IProgressMonitor;
35: import org.eclipse.swt.widgets.Display;
36:
37: /**
38: * Splits a line at the selected points.
39: *
40: * @author Jesse
41: * @since 1.1.0
42: */
43: public class SplitLineOp implements IOp {
44:
45: public void op(Display display, Object target,
46: IProgressMonitor monitor) throws Exception {
47: Point[] points = (Point[]) target;
48:
49: IMap map = ApplicationGIS.getActiveMap();
50:
51: EditBlackboard editBlackboard = EditBlackboardUtil
52: .getEditBlackboard(ApplicationGIS.createContext(map),
53: map.getEditManager().getSelectedLayer());
54:
55: ShapeProvider shapeProvider = new ShapeProvider(map);
56:
57: map.sendCommandASync(new SplitLineCommand(editBlackboard,
58: shapeProvider, new EditFeatureProvider(map),
59: new EditLayerProvider(map), new HashSet<Point>(Arrays
60: .asList(points))));
61: }
62:
63: static class ShapeProvider implements
64: IBlockingProvider<PrimitiveShape> {
65:
66: private IMap map;
67:
68: ShapeProvider(IMap map2) {
69: this .map = map2;
70: }
71:
72: public PrimitiveShape get(IProgressMonitor monitor)
73: throws IOException {
74: monitor.beginTask("", 1); //$NON-NLS-1$
75: try {
76: return (PrimitiveShape) map.getBlackboard().get(
77: EditToolHandler.CURRENT_SHAPE);
78: } finally {
79: monitor.done();
80: }
81: }
82:
83: }
84:
85: }
|