MovePrimitiveDataSetCommand: FIXUP: Account for deleted MapWithAI layer

Signed-off-by: Taylor Smock <tsmock@fb.com>
pull/1/head
Taylor Smock 2020-09-17 16:12:04 -06:00
rodzic 6f50f2c85f
commit 0ad2ed5c97
1 zmienionych plików z 23 dodań i 3 usunięć

Wyświetl plik

@ -27,6 +27,7 @@ import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.plugins.mapwithai.backend.GetDataRunnable; import org.openstreetmap.josm.plugins.mapwithai.backend.GetDataRunnable;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.bugreport.ReportedException;
/** /**
* Move primitives between datasets (*not* a copy) * Move primitives between datasets (*not* a copy)
@ -58,8 +59,13 @@ public class MovePrimitiveDataSetCommand extends Command {
@Override @Override
public boolean executeCommand() { public boolean executeCommand() {
if (command != null) { if (command != null) {
// DeleteCommand is used when the MapWithAI layer has been deleted.
if (command instanceof DeleteCommand) {
command.undoCommand();
} else {
command.executeCommand(); command.executeCommand();
} }
}
return true; return true;
} }
@ -134,7 +140,7 @@ public class MovePrimitiveDataSetCommand extends Command {
commands.add(delete); commands.add(delete);
commands.removeIf(Objects::isNull); commands.removeIf(Objects::isNull);
if (commands != null && !commands.isEmpty()) { if (!commands.isEmpty()) {
return SequenceCommand.wrapIfNeeded(trn("Move {0} OSM Primitive between data sets", return SequenceCommand.wrapIfNeeded(trn("Move {0} OSM Primitive between data sets",
"Move {0} OSM Primitives between data sets", selection.size(), selection.size()), commands); "Move {0} OSM Primitives between data sets", selection.size(), selection.size()), commands);
} }
@ -144,8 +150,22 @@ public class MovePrimitiveDataSetCommand extends Command {
@Override @Override
public void undoCommand() { public void undoCommand() {
if (command != null) { if (command != null) {
try {
if (command instanceof DeleteCommand) {
command.executeCommand();
} else {
command.undoCommand(); command.undoCommand();
} }
} catch (ReportedException | AssertionError e) {
if (!e.getMessage().contains("Primitive is of wrong data set for this command")) {
throw e;
}
command = DeleteCommand.delete(command.getParticipatingPrimitives());
command.executeCommand();
} catch (Exception e) {
throw e;
}
}
} }
@Override @Override