source: josm/trunk/src/org/openstreetmap/josm/command/UndeletePrimitivesCommand.java@ 2474

Last change on this file since 2474 was 2410, checked in by jttt, 14 years ago

Add clearId parameter to primitives copy constructor, replace some clearOsmId calls, throw exception if id is set after primitive was added to the dataset

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