kopia lustrzana https://github.com/JOSM/MapWithAI
FIXUP: Lock issues (from threading patch)
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
2a00f6aef8
commit
021de1da1f
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.openstreetmap.josm.command.Command;
|
import org.openstreetmap.josm.command.Command;
|
||||||
|
@ -34,6 +35,7 @@ public class MapWithAIAddCommand extends Command implements Runnable {
|
||||||
DataSet mapWithAI;
|
DataSet mapWithAI;
|
||||||
Collection<OsmPrimitive> primitives;
|
Collection<OsmPrimitive> primitives;
|
||||||
Command command;
|
Command command;
|
||||||
|
Lock lock;
|
||||||
final Map<OsmPrimitive, String> sources;
|
final Map<OsmPrimitive, String> sources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +48,7 @@ public class MapWithAIAddCommand extends Command implements Runnable {
|
||||||
public MapWithAIAddCommand(MapWithAILayer mapWithAILayer, OsmDataLayer editLayer,
|
public MapWithAIAddCommand(MapWithAILayer mapWithAILayer, OsmDataLayer editLayer,
|
||||||
Collection<OsmPrimitive> selection) {
|
Collection<OsmPrimitive> selection) {
|
||||||
this(mapWithAILayer.getDataSet(), editLayer.getDataSet(), selection);
|
this(mapWithAILayer.getDataSet(), editLayer.getDataSet(), selection);
|
||||||
|
lock = mapWithAILayer.getLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,16 +86,26 @@ public class MapWithAIAddCommand extends Command implements Runnable {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (command == null) {// needed for undo/redo (don't create a new command)
|
try {
|
||||||
final List<OsmPrimitive> allPrimitives = new ArrayList<>();
|
if (lock != null) {
|
||||||
MapWithAIDataUtils.addPrimitivesToCollection(allPrimitives, primitives);
|
lock.lock();
|
||||||
Collection<PrimitiveData> primitiveData = new HashSet<>();
|
}
|
||||||
final Command movePrimitivesCommand = new MovePrimitiveDataSetCommand(editable, mapWithAI, primitives,
|
if (command == null) {// needed for undo/redo (don't create a new command)
|
||||||
primitiveData);
|
final List<OsmPrimitive> allPrimitives = new ArrayList<>();
|
||||||
final Command createConnectionsCommand = createConnections(editable, primitiveData);
|
MapWithAIDataUtils.addPrimitivesToCollection(allPrimitives, primitives);
|
||||||
command = new SequenceCommand(getDescriptionText(), movePrimitivesCommand, createConnectionsCommand);
|
Collection<PrimitiveData> primitiveData = new HashSet<>();
|
||||||
|
final Command movePrimitivesCommand = new MovePrimitiveDataSetCommand(editable, mapWithAI,
|
||||||
|
primitives, primitiveData);
|
||||||
|
final Command createConnectionsCommand = createConnections(editable, primitiveData);
|
||||||
|
command = new SequenceCommand(getDescriptionText(), movePrimitivesCommand,
|
||||||
|
createConnectionsCommand);
|
||||||
|
}
|
||||||
|
GuiHelper.runInEDTAndWait(command::executeCommand);
|
||||||
|
} finally {
|
||||||
|
if (lock != null) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GuiHelper.runInEDT(command::executeCommand);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +124,19 @@ public class MapWithAIAddCommand extends Command implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undoCommand() {
|
public void undoCommand() {
|
||||||
if (command != null) {
|
try {
|
||||||
GuiHelper.runInEDT(command::undoCommand);
|
if (lock != null) {
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
if (command != null) {
|
||||||
|
GuiHelper.runInEDTAndWait(command::undoCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (lock != null) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +187,6 @@ public class MapWithAIAddCommand extends Command implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(editable, mapWithAI, primitives);
|
return Objects.hash(editable, mapWithAI, primitives, lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue