| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.command;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.util.ArrayList;
|
|---|
| 7 | import java.util.Collection;
|
|---|
| 8 | import java.util.List;
|
|---|
| 9 | import java.util.logging.Logger;
|
|---|
| 10 |
|
|---|
| 11 | import javax.swing.JLabel;
|
|---|
| 12 | import javax.swing.tree.DefaultMutableTreeNode;
|
|---|
| 13 | import javax.swing.tree.MutableTreeNode;
|
|---|
| 14 |
|
|---|
| 15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 16 | import 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 | */
|
|---|
| 24 | public 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 |
|
|---|
| 58 | @Override
|
|---|
| 59 | public MutableTreeNode description() {
|
|---|
| 60 | return new DefaultMutableTreeNode(
|
|---|
| 61 | new JLabel(
|
|---|
| 62 | tr("Undelete {0} primitives", toUndelete.size()),
|
|---|
| 63 | ImageProvider.get("data", "object"),
|
|---|
| 64 | JLabel.HORIZONTAL
|
|---|
| 65 | )
|
|---|
| 66 | );
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | @Override
|
|---|
| 70 | public boolean executeCommand() {
|
|---|
| 71 | super.executeCommand();
|
|---|
| 72 |
|
|---|
| 73 | for(OsmPrimitive primitive: toUndelete) {
|
|---|
| 74 | if(getLayer().getConflicts().hasConflictForMy(primitive)) {
|
|---|
| 75 | rememberConflict(getLayer().getConflicts().getConflictForMy(primitive));
|
|---|
| 76 | getLayer().getConflicts().remove(primitive);
|
|---|
| 77 | }
|
|---|
| 78 | primitive.clearOsmId();
|
|---|
| 79 | }
|
|---|
| 80 | return true;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | @Override
|
|---|
| 84 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
|---|
| 85 | Collection<OsmPrimitive> added) {
|
|---|
| 86 | modified.addAll(toUndelete);
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|