001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.io; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.List; 007 008import org.openstreetmap.josm.data.osm.PrimitiveId; 009import org.openstreetmap.josm.gui.layer.OsmDataLayer; 010import org.openstreetmap.josm.gui.progress.ProgressMonitor; 011import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 012 013/** 014 * Task downloading a set of OSM primitives. 015 * @since 4081 016 */ 017public class DownloadPrimitivesTask extends AbstractPrimitiveTask { 018 019 private final List<PrimitiveId> ids; 020 021 /** 022 * Constructs a new {@code DownloadPrimitivesTask}. 023 * 024 * @param layer the layer in which primitives are updated. Must not be null. 025 * @param ids a collection of primitives to update from the server. Set to 026 * the empty collection if null. 027 * @param fullRelation true if a full download is required, i.e., 028 * a download including the immediate children of a relation. 029 * @throws IllegalArgumentException if layer is null. 030 */ 031 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation) { 032 this(layer, ids, fullRelation, null); 033 } 034 035 /** 036 * Constructs a new {@code DownloadPrimitivesTask}. 037 * 038 * @param layer the layer in which primitives are updated. Must not be null. 039 * @param ids a collection of primitives to update from the server. Set to 040 * the empty collection if null. 041 * @param fullRelation true if a full download is required, i.e., 042 * a download including the immediate children of a relation. 043 * @param progressMonitor ProgressMonitor to use or null to create a new one. 044 * @throws IllegalArgumentException if layer is null. 045 */ 046 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation, 047 ProgressMonitor progressMonitor) { 048 super(tr("Download objects"), progressMonitor, layer); 049 this.ids = ids; 050 setZoom(true); 051 setDownloadRelations(fullRelation); 052 } 053 054 @Override 055 protected void initMultiFetchReader(MultiFetchServerObjectReader reader) { 056 getProgressMonitor().indeterminateSubTask(tr("Initializing nodes to download ...")); 057 reader.setRecurseDownRelations(fullRelation); 058 if (ids != null) { 059 ids.forEach(reader::append); 060 } 061 } 062}