From 6677610a8f5f21024fdb7b5498b6b33e2a91009f Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Mon, 6 Apr 2020 18:32:25 -0600 Subject: [PATCH] Attempt to fix an issue where an empty selection is attempted to be changed Signed-off-by: Taylor Smock --- .../commands/MovePrimitiveDataSetCommand.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MovePrimitiveDataSetCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MovePrimitiveDataSetCommand.java index e3dda2d..a1811fd 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MovePrimitiveDataSetCommand.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MovePrimitiveDataSetCommand.java @@ -110,19 +110,25 @@ public class MovePrimitiveDataSetCommand extends Command { List removeKeyCommand = new ArrayList<>(); Set fullSelection = new HashSet<>(); MapWithAIDataUtils.addPrimitivesToCollection(fullSelection, selection); - CreateConnectionsCommand.getConflationCommands().forEach(clazz -> { - try { - removeKeyCommand.add(new ChangePropertyCommand(fullSelection, - clazz.getConstructor(DataSet.class).newInstance(from).getKey(), null)); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - Logging.error(e); - } - }); - SequenceCommand sequence = new SequenceCommand("Temporary Command", removeKeyCommand); - sequence.executeCommand(); // This *must* be executed for the delete command to get everything. - commands.add(DeleteCommand.delete(selection, true, true)); - sequence.undoCommand(); + if (!fullSelection.isEmpty()) { + CreateConnectionsCommand.getConflationCommands().forEach(clazz -> { + try { + removeKeyCommand.add(new ChangePropertyCommand(fullSelection, + clazz.getConstructor(DataSet.class).newInstance(from).getKey(), null)); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + Logging.error(e); + } + }); + } + if (!removeKeyCommand.isEmpty()) { + SequenceCommand sequence = new SequenceCommand("Temporary Command", removeKeyCommand); + sequence.executeCommand(); // This *must* be executed for the delete command to get everything. + commands.add(DeleteCommand.delete(selection, true, true)); + sequence.undoCommand(); + } else { + commands.add(DeleteCommand.delete(selection, true, true)); + } return new SequenceCommand(trn("Move {0} OSM Primitive between data sets", "Move {0} OSM Primitives between data sets", selection.size(), selection.size()), commands);