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

Last change on this file since 2575 was 2512, checked in by stoecker, 14 years ago

i18n updated, fixed files to reduce problems when applying patches, fix #4017

File size: 2.6 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 @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
72 for(OsmPrimitive primitive: toUndelete) {
73 if(getLayer().getConflicts().hasConflictForMy(primitive)) {
74 rememberConflict(getLayer().getConflicts().getConflictForMy(primitive));
75 getLayer().getConflicts().remove(primitive);
76 }
77 primitive.clearOsmId();
78 }
79 return true;
80 }
81
82 @Override
83 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
84 Collection<OsmPrimitive> added) {
85 modified.addAll(toUndelete);
86 }
87}
Note: See TracBrowser for help on using the repository browser.