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.ui.internal.dragdrop;
16:
17: import java.util.Collection;
18:
19: import net.refractions.udig.project.internal.Layer;
20: import net.refractions.udig.project.internal.commands.AddLayersCommand;
21: import net.refractions.udig.project.internal.commands.DeleteLayersCommand;
22: import net.refractions.udig.ui.IDropAction;
23:
24: import org.eclipse.core.runtime.IProgressMonitor;
25:
26: /**
27: * Moves layers from one map to another when destination is a layer.
28: * @author Jesse
29: * @since 1.1.0
30: */
31: public class MoveLayerDropActionLayer extends IDropAction {
32:
33: public MoveLayerDropActionLayer() {
34: }
35:
36: @Override
37: public boolean accept() {
38: return MoveLayerDropAction.toLayer(this ) != null
39: && MoveLayerDropAction.toLayer(this ).getMap() != ((Layer) getDestination())
40: .getMap();
41: }
42:
43: @Override
44: public void perform(IProgressMonitor monitor) {
45: Collection<Layer> layers = MoveLayerDropAction
46: .toCollection(getData());
47:
48: Layer layer = (Layer) getDestination();
49: layer.getMap().sendCommandASync(
50: new AddLayersCommand(layers, layer.getZorder()));
51:
52: layers.iterator().next().getMap().sendCommandASync(
53: new DeleteLayersCommand(layers.toArray(new Layer[0])));
54: }
55:
56: }
|