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

Last change on this file since 2349 was 2070, checked in by Gubaer, 15 years ago

new: rewrite of CombineWay action
new: conflict resolution dialog for CombineWay, including conflicts for different relation memberships
cleanup: cleanup in OsmReader, reduces memory footprint and reduces parsing time
cleanup: made most of the public fields in OsmPrimitive @deprecated, added accessors and changed the code
cleanup: replaced usages of @deprecated constructors for ExtendedDialog
fixed #3208: Combine ways brokes relation order

WARNING: this changeset touches a lot of code all over the code base. "latest" might become slightly unstable in the next days. Also experience incompatibility issues with plugins in the next few days.

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