01: package net.refractions.udig.project.internal.commands;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import net.refractions.udig.project.ILayer;
07: import net.refractions.udig.project.command.AbstractCommand;
08: import net.refractions.udig.project.command.UndoableMapCommand;
09: import net.refractions.udig.project.internal.Layer;
10: import net.refractions.udig.project.internal.Map;
11: import net.refractions.udig.project.internal.Messages;
12:
13: import org.eclipse.core.runtime.IProgressMonitor;
14:
15: /**
16: * Deletes specified layers from the map.
17: * <p>
18: *
19: * @author Vitalus
20: * @since UDIG 1.1.0
21: */
22: public class DeleteLayersCommand extends AbstractCommand implements
23: UndoableMapCommand {
24:
25: private List<ILayer> removedLayers = null;
26:
27: private int index;
28:
29: private Map map = null;
30:
31: private ILayer selectedLayer;;
32:
33: /**
34: * @param layers
35: */
36: public DeleteLayersCommand(ILayer[] layers) {
37:
38: removedLayers = new ArrayList<ILayer>();
39: for (int i = 0; i < layers.length; i++) {
40: removedLayers.add(layers[i]);
41: if (map == null)
42: map = ((Layer) layers[i]).getMapInternal();
43: }
44: }
45:
46: /**
47: * @see net.refractions.udig.project.command.UndoableCommand#rollback()
48: */
49: public void rollback(IProgressMonitor monitor) throws Exception {
50: map.getMapLayers().addAll(index, removedLayers);
51: if (selectedLayer != null)
52: map.getEditManagerInternal().setSelectedLayer(
53: (Layer) selectedLayer);
54: }
55:
56: /**
57: * @see net.refractions.udig.project.command.MapCommand#run()
58: */
59: public void run(IProgressMonitor monitor) throws Exception {
60:
61: selectedLayer = map.getEditManager().getSelectedLayer();
62: if (!DeleteLayerCommand.selectNewLayer(map, removedLayers))
63: selectedLayer = null;
64:
65: List<? extends ILayer> layers = map.getLayersInternal();
66: layers.removeAll(removedLayers);
67: for (ILayer layer : removedLayers) {
68: map.getColourScheme().removeItem(layer.getID().toString(),
69: ((Layer) layer).getDefaultColor()); // remove from scheme
70: }
71:
72: }
73:
74: /**
75: * @see net.refractions.udig.project.command.MapCommand#getName()
76: */
77: public String getName() {
78: // TODO Internationalization
79: return Messages.DeleteLayersCommand_name;
80: }
81: }
|