kopia lustrzana https://github.com/JOSM/MapWithAI
Fix #23529: JSON downloads may wait on EDT while EDT is waiting on downloads to finish
Signed-off-by: Taylor Smock <tsmock@meta.com>pull/46/head
rodzic
fbd3f10541
commit
f7c1d3d8b0
|
@ -84,10 +84,17 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (!isEnabled()) {
|
if (isEnabled()) {
|
||||||
return;
|
MainApplication.worker.execute(() -> realRun(this.info));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the download tasks. This should be run off of the EDT, see #23529.
|
||||||
|
*
|
||||||
|
* @param info The external data to download
|
||||||
|
*/
|
||||||
|
private static void realRun(MapWithAIInfo info) {
|
||||||
MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
|
MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
|
||||||
final DataSet ds;
|
final DataSet ds;
|
||||||
final OsmData<?, ?, ?, ?> boundsSource;
|
final OsmData<?, ?, ?, ?> boundsSource;
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Optional;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.ForkJoinTask;
|
import java.util.concurrent.ForkJoinTask;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.Bounds;
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
|
@ -213,37 +214,26 @@ public final class MapWithAIDataUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean confirmBigDownload(List<Bounds> realBounds) {
|
/**
|
||||||
final var confirmation = new ConfirmBigDownload(realBounds);
|
* Confirm a large download
|
||||||
GuiHelper.runInEDTAndWait(confirmation);
|
*
|
||||||
return confirmation.confirmed();
|
* @param realBounds The list of bounds that will be downloaded
|
||||||
}
|
* @return {@code true} if the user still wants to download data
|
||||||
|
*/
|
||||||
private static class ConfirmBigDownload implements Runnable {
|
private static synchronized boolean confirmBigDownload(List<Bounds> realBounds) {
|
||||||
Boolean bool;
|
final var confirmation = new AtomicBoolean(false);
|
||||||
final List<?> realBounds;
|
// This is not a separate class since we don't want to show multiple
|
||||||
|
// confirmation dialogs
|
||||||
public ConfirmBigDownload(List<?> realBounds) {
|
// which is why this method is synchronized.
|
||||||
this.realBounds = realBounds;
|
GuiHelper.runInEDTAndWait(() -> {
|
||||||
}
|
final var confirmed = ConditionalOptionPaneUtil.showConfirmationDialog(
|
||||||
|
MapWithAIPlugin.NAME.concat(".alwaysdownload"), null,
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
bool = ConditionalOptionPaneUtil.showConfirmationDialog(MapWithAIPlugin.NAME.concat(".alwaysdownload"),
|
|
||||||
null,
|
|
||||||
tr("You are going to make {0} requests to the MapWithAI server. This may take some time. <br /> Continue?",
|
tr("You are going to make {0} requests to the MapWithAI server. This may take some time. <br /> Continue?",
|
||||||
realBounds.size()),
|
realBounds.size()),
|
||||||
null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION);
|
null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION);
|
||||||
}
|
confirmation.set(confirmed);
|
||||||
|
});
|
||||||
/**
|
return confirmation.get();
|
||||||
* Check if the user confirmed the download
|
|
||||||
*
|
|
||||||
* @return {@code true} if the user wants to continue
|
|
||||||
*/
|
|
||||||
public boolean confirmed() {
|
|
||||||
return bool;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Ładowanie…
Reference in New Issue