01: /*
02: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
03: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
04: * under the terms of the GNU Lesser General Public License as published by the Free Software
05: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
06: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
07: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
08: */
09: package net.refractions.udig.project.internal.commands.selection;
10:
11: import java.util.HashMap;
12: import java.util.List;
13: import java.util.Map;
14: import java.util.Set;
15: import java.util.Map.Entry;
16:
17: import net.refractions.udig.project.command.AbstractCommand;
18: import net.refractions.udig.project.command.UndoableMapCommand;
19: import net.refractions.udig.project.internal.Layer;
20: import net.refractions.udig.project.internal.Messages;
21:
22: import org.eclipse.core.runtime.IProgressMonitor;
23: import org.geotools.filter.Filter;
24:
25: /**
26: * A command that removes all selection.
27: *
28: * @author jeichar
29: * @since 0.2
30: */
31: public class NoSelectCommand extends AbstractCommand implements
32: UndoableMapCommand {
33:
34: private Map<Layer, Filter> undoState = new HashMap<Layer, Filter>();
35:
36: /**
37: * @see net.refractions.udig.project.internal.command.MapCommand#run()
38: */
39: public void run(IProgressMonitor monitor) {
40: List<Layer> layers = getMap().getLayersInternal();
41: for (Layer layer : layers) {
42: undoState.put(layer, layer.getFilter());
43: }
44: getMap().getContextModel().select(Filter.ALL);
45: }
46:
47: /**
48: * @see net.refractions.udig.project.command.UndoableCommand#rollback()
49: */
50: public void rollback(IProgressMonitor monitor) throws Exception {
51: Set<Entry<Layer, Filter>> state = undoState.entrySet();
52: for (Entry<Layer, Filter> entry : state) {
53: entry.getKey().setFilter(entry.getValue());
54: }
55: }
56:
57: /**
58: * @see net.refractions.udig.project.command.MapCommand#getName()
59: */
60: public String getName() {
61: return Messages.NoSelectCommand_cancelSelections;
62: }
63:
64: }
|