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

Last change on this file since 1671 was 1670, checked in by Gubaer, 16 years ago

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

File size: 2.4 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;
8
9import javax.swing.JLabel;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import 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 */
22public 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}
Note: See TracBrowser for help on using the repository browser.