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;
16:
17: import net.refractions.udig.project.ILayer;
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.project.internal.Messages;
22:
23: import org.eclipse.core.runtime.IProgressMonitor;
24:
25: /**
26: * Command for setting the applicability of a layer.
27: *
28: * @see ILayer#isApplicable(String)
29: * @author Jesse
30: * @since 1.0.0
31: */
32: public class SetApplicabilityCommand extends AbstractCommand implements
33: UndoableMapCommand {
34:
35: private boolean newValue;
36: private String applicabilityId;
37: private ILayer layer;
38: private boolean oldValue;
39:
40: public SetApplicabilityCommand(ILayer layer,
41: String applicabilityId, boolean newValue) {
42: this .layer = layer;
43: this .applicabilityId = applicabilityId;
44: this .newValue = newValue;
45: }
46:
47: public void run(IProgressMonitor monitor) throws Exception {
48: monitor.beginTask(Messages.SetApplicabilityCommand_name, 3);
49: monitor.worked(1);
50: this .oldValue = layer.isApplicable(applicabilityId);
51: if (oldValue == newValue)
52: return;
53: ((Layer) layer).setApplicable(applicabilityId, newValue);
54: monitor.done();
55: }
56:
57: public String getName() {
58: return Messages.SetApplicabilityCommand_name;
59: }
60:
61: public void rollback(IProgressMonitor monitor) throws Exception {
62: monitor.beginTask(Messages.SetApplicabilityCommand_name, 3);
63: monitor.worked(1);
64: if (oldValue == newValue)
65: return;
66: ((Layer) layer).setApplicable(applicabilityId, oldValue);
67: monitor.done();
68: }
69:
70: }
|