1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.Collection;
|
---|
8 |
|
---|
9 | import javax.swing.JLabel;
|
---|
10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
11 | import javax.swing.tree.MutableTreeNode;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Represents a command for undeleting a node which was deleted on the server.
|
---|
18 | * The command remembers the former node id and sets the node id to 0. This turns
|
---|
19 | * the node into a new node which can be uploaded to the server.
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class UndeletePrimitivesCommand extends Command {
|
---|
23 |
|
---|
24 | /** the node to undelete */
|
---|
25 | private ArrayList<OsmPrimitive> toUndelete;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * constructor
|
---|
29 | * @param node the node to undelete
|
---|
30 | */
|
---|
31 | public UndeletePrimitivesCommand(OsmPrimitive node) {
|
---|
32 | toUndelete = new ArrayList<OsmPrimitive>();
|
---|
33 | toUndelete.add(node);
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * constructor
|
---|
38 | * @param node the node to undelete
|
---|
39 | */
|
---|
40 | public UndeletePrimitivesCommand(OsmPrimitive ... toUndelete) {
|
---|
41 | this.toUndelete = new ArrayList<OsmPrimitive>();
|
---|
42 | for (int i=0; i < toUndelete.length; i++) {
|
---|
43 | this.toUndelete.add(toUndelete[i]);
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * constructor
|
---|
49 | * @param node the node to undelete
|
---|
50 | */
|
---|
51 | public UndeletePrimitivesCommand(Collection<OsmPrimitive> toUndelete) {
|
---|
52 | this.toUndelete = new ArrayList<OsmPrimitive>();
|
---|
53 | this.toUndelete.addAll(toUndelete);
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public MutableTreeNode description() {
|
---|
59 | return new DefaultMutableTreeNode(
|
---|
60 | new JLabel(
|
---|
61 | tr("Undelete {0} primitives", toUndelete.size()),
|
---|
62 | ImageProvider.get("data", "object"),
|
---|
63 | JLabel.HORIZONTAL
|
---|
64 | )
|
---|
65 | );
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public boolean executeCommand() {
|
---|
70 | super.executeCommand();
|
---|
71 | for(OsmPrimitive primitive: toUndelete) {
|
---|
72 | primitive.id = 0;
|
---|
73 | }
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
---|
79 | Collection<OsmPrimitive> added) {
|
---|
80 | modified.addAll(toUndelete);
|
---|
81 | }
|
---|
82 | }
|
---|