source: josm/trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java@ 11457

Last change on this file since 11457 was 10129, checked in by Don-vip, 8 years ago

refactor duplicated code

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.List;
7
8import org.openstreetmap.josm.data.osm.Node;
9import org.openstreetmap.josm.data.osm.OsmPrimitive;
10import org.openstreetmap.josm.data.osm.PrimitiveId;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.data.osm.Way;
13import org.openstreetmap.josm.gui.layer.OsmDataLayer;
14import org.openstreetmap.josm.gui.progress.ProgressMonitor;
15import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
16
17/**
18 * Task downloading a set of OSM primitives.
19 * @since 4081
20 */
21public class DownloadPrimitivesTask extends AbstractPrimitiveTask {
22
23 private final List<PrimitiveId> ids;
24
25 /**
26 * Constructs a new {@code DownloadPrimitivesTask}.
27 *
28 * @param layer the layer in which primitives are updated. Must not be null.
29 * @param ids a collection of primitives to update from the server. Set to
30 * the empty collection if null.
31 * @param fullRelation true if a full download is required, i.e.,
32 * a download including the immediate children of a relation.
33 * @throws IllegalArgumentException if layer is null.
34 */
35 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation) {
36 this(layer, ids, fullRelation, null);
37 }
38
39 /**
40 * Constructs a new {@code DownloadPrimitivesTask}.
41 *
42 * @param layer the layer in which primitives are updated. Must not be null.
43 * @param ids a collection of primitives to update from the server. Set to
44 * the empty collection if null.
45 * @param fullRelation true if a full download is required, i.e.,
46 * a download including the immediate children of a relation.
47 * @param progressMonitor ProgressMonitor to use or null to create a new one.
48 * @throws IllegalArgumentException if layer is null.
49 */
50 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation,
51 ProgressMonitor progressMonitor) {
52 super(tr("Download objects"), progressMonitor, layer);
53 this.ids = ids;
54 setZoom(true);
55 setDownloadRelations(true, fullRelation);
56 }
57
58 @Override
59 protected void initMultiFetchReader(MultiFetchServerObjectReader reader) {
60 getProgressMonitor().indeterminateSubTask(tr("Initializing nodes to download ..."));
61 for (PrimitiveId id : ids) {
62 OsmPrimitive osm = layer.data.getPrimitiveById(id);
63 if (osm == null) {
64 switch (id.getType()) {
65 case NODE:
66 osm = new Node(id.getUniqueId());
67 break;
68 case WAY:
69 osm = new Way(id.getUniqueId());
70 break;
71 case RELATION:
72 osm = new Relation(id.getUniqueId());
73 break;
74 default: throw new AssertionError();
75 }
76 }
77 reader.append(osm);
78 }
79 }
80}
Note: See TracBrowser for help on using the repository browser.