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

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

new: MultiFetchServerObjectReader using APIs Multi Fetch method
update: now uses Multi Fetch to check for deleted primitives on the server
update: now uses Multi Fetch to update the selected primitives with the state from the server
fixed: cleaned up merging in MergeVisitor
new: conflict resolution dialog; now resolves conflicts due to different visibilities
new: replacement for realEqual() on OsmPrimitive and derived classes; realEqual now @deprecated
fixed: cleaning up OsmReader
fixed: progress indication in OsmApi

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