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.project.internal.commands.selection;
16:
17: import org.eclipse.core.runtime.IProgressMonitor;
18:
19: import net.refractions.udig.project.ILayer;
20: import net.refractions.udig.project.command.AbstractCommand;
21: import net.refractions.udig.project.command.MapCommand;
22: import net.refractions.udig.project.command.UndoableCommand;
23: import net.refractions.udig.project.command.UndoableMapCommand;
24: import net.refractions.udig.project.internal.EditManager;
25: import net.refractions.udig.project.internal.Layer;
26: import net.refractions.udig.project.internal.Messages;
27:
28: /**
29: * Command that selects the currently selected layer of a map.
30: * @author Jesse
31: * @since 1.1.0
32: */
33: public class SelectLayerCommand extends AbstractCommand implements
34: MapCommand, UndoableMapCommand {
35:
36: private Layer old;
37: private ILayer layer;
38:
39: /**
40: * new instance
41: * @param layer layer to select
42: */
43: public SelectLayerCommand(ILayer layer) {
44: super ();
45: this .layer = layer;
46: }
47:
48: public String getName() {
49: return Messages.SelectLayerCommand_name;
50: }
51:
52: public void run(IProgressMonitor monitor) throws Exception {
53: monitor.beginTask(Messages.SelectLayerCommand_selecting, 2);
54: monitor.worked(1);
55:
56: EditManager editManagerInternal = getMap()
57: .getEditManagerInternal();
58: old = editManagerInternal.getSelectedLayer();
59: editManagerInternal.setSelectedLayer((Layer) layer);
60: monitor.done();
61: }
62:
63: public void rollback(IProgressMonitor monitor) throws Exception {
64: monitor.beginTask(Messages.SelectLayerCommand_undoing, 2);
65: monitor.worked(1);
66:
67: EditManager editManagerInternal = getMap()
68: .getEditManagerInternal();
69: editManagerInternal.setSelectedLayer(old);
70: monitor.done();
71: }
72:
73: }
|