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

Last change on this file since 2026 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

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.id = 0;
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.