| 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.logging.Logger;
|
|---|
| 9 |
|
|---|
| 10 | import javax.swing.JLabel;
|
|---|
| 11 | import javax.swing.tree.DefaultMutableTreeNode;
|
|---|
| 12 | import javax.swing.tree.MutableTreeNode;
|
|---|
| 13 |
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 15 | import 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 | */
|
|---|
| 23 | public 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 | }
|
|---|