Skip to content

Commit de21668

Browse files
author
stoecker
committed
warn about downloading old data - patch by taylor.smock, fix #21904
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19550 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 69fe547 commit de21668

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/org/openstreetmap/josm/actions/OpenLocationAction.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
3737
import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
3838
import org.openstreetmap.josm.data.preferences.BooleanProperty;
39+
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
3940
import org.openstreetmap.josm.gui.ExtendedDialog;
4041
import org.openstreetmap.josm.gui.HelpAwareOptionPane;
4142
import org.openstreetmap.josm.gui.MainApplication;
@@ -278,9 +279,13 @@ public List<Future<?>> openUrl(DownloadParams settings, boolean zoomToData, Stri
278279

279280
List<Future<?>> result = new ArrayList<>();
280281
for (final DownloadTask task : tasks) {
282+
DownloadParams currentParams = settings;
283+
if (task.providesOldData() && !settings.isNewLayer()) {
284+
currentParams = GuiHelper.runInEDTAndWaitAndReturn(() -> confirmNoNewLayer(settings, url));
285+
}
281286
try {
282287
task.setZoomAfterDownload(zoomToData);
283-
result.add(MainApplication.worker.submit(new PostDownloadHandler(task, task.loadUrl(settings, url,
288+
result.add(MainApplication.worker.submit(new PostDownloadHandler(task, task.loadUrl(currentParams, url,
284289
new PleaseWaitProgressMonitor(tr("Download data"))))));
285290
} catch (IllegalArgumentException e) {
286291
Logging.error(e);
@@ -289,6 +294,17 @@ public List<Future<?>> openUrl(DownloadParams settings, boolean zoomToData, Stri
289294
return Collections.unmodifiableList(result);
290295
}
291296

297+
private static DownloadParams confirmNoNewLayer(DownloadParams originalParams, String url) {
298+
if (ConditionalOptionPaneUtil.showConfirmationDialog("open-location-action.confirm-no-new-layer",
299+
MainApplication.getMainFrame(),
300+
tr("Do you want to create a new layer for {0}?<br>You may be mixing old and new data otherwise!", url),
301+
tr("No new layer"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION)
302+
) {
303+
return new DownloadParams(originalParams).withNewLayer(true);
304+
}
305+
return originalParams;
306+
}
307+
292308
/**
293309
* Asks the user which of the possible tasks to perform.
294310
* @param tasks a list of possible tasks

src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public Future<?> loadUrl(DownloadParams settings, final String url, ProgressMoni
8686
return MainApplication.worker.submit(downloadTask);
8787
}
8888

89+
@Override
90+
public boolean providesOldData() {
91+
return true;
92+
}
93+
8994
/**
9095
* OsmChange download task.
9196
*/

src/org/openstreetmap/josm/actions/downloadtasks/DownloadParams.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ public class DownloadParams {
1616
private DownloadPolicy downloadPolicy;
1717
private UploadPolicy uploadPolicy;
1818

19+
public DownloadParams() {
20+
// Do nothing -- just make this constructor visible
21+
}
22+
23+
/**
24+
* Clone another {@link DownloadParams}
25+
* @param other The download parameters to clone
26+
*/
27+
public DownloadParams(DownloadParams other) {
28+
this.newLayer = other.newLayer;
29+
this.layerName = other.layerName;
30+
this.locked = other.locked;
31+
this.downloadPolicy = other.downloadPolicy;
32+
this.uploadPolicy = other.uploadPolicy;
33+
}
34+
1935
/**
2036
* Determines if the data is to be downloaded into a new layer.
2137
* @return true, if the data is to be downloaded into a new layer. If false, the task

src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ default List<String> getErrorMessages() {
153153
}).filter(Objects::nonNull).collect(Collectors.toList());
154154
}
155155

156+
/**
157+
* If this task provides potentially old data, this should return {@code true}. If so, it would be a good decision
158+
* to prompt users to verify if they want the data to be downloaded to the current layer.
159+
* @return {@code true} if the data could be old.
160+
* @since xxx
161+
*/
162+
default boolean providesOldData() {
163+
return false;
164+
}
165+
156166
/**
157167
* Cancels the asynchronous download task.
158168
*

0 commit comments

Comments
 (0)