source: osm/applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DownloadParentsAction.java@ 33265

Last change on this file since 33265 was 32398, checked in by donvip, 8 years ago

checkstyle

File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package relcontext.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.ArrayList;
8import java.util.Collections;
9import java.util.HashSet;
10import java.util.List;
11import java.util.Set;
12
13import javax.swing.AbstractAction;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.data.osm.Relation;
19import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
20import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
21import org.openstreetmap.josm.tools.ImageProvider;
22
23import relcontext.ChosenRelation;
24import relcontext.ChosenRelationListener;
25
26/**
27 * Downloads parent relations for this relation and all parent objects for its members.
28 *
29 * @author Zverik
30 */
31public class DownloadParentsAction extends AbstractAction implements ChosenRelationListener {
32 private ChosenRelation rel;
33
34 public DownloadParentsAction(ChosenRelation rel) {
35 super(tr("Download referrers"));
36 putValue(SMALL_ICON, ImageProvider.get("download"));
37 putValue(SHORT_DESCRIPTION, tr("Download referrers for the chosen relation and its members."));
38 this.rel = rel;
39 rel.addChosenRelationListener(this);
40 setEnabled(rel.get() != null && Main.getLayerManager().getEditLayer() != null);
41 }
42
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 Relation relation = rel.get();
46 if (relation == null) return;
47 List<OsmPrimitive> objects = new ArrayList<>();
48 objects.add(relation);
49 objects.addAll(relation.getMemberPrimitives());
50 Main.worker.submit(new DownloadReferrersTask(Main.getLayerManager().getEditLayer(), objects));
51 }
52
53 @Override
54 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
55 setEnabled(newRelation != null && Main.getLayerManager().getEditLayer() != null);
56 }
57
58 protected void downloadMembers(Relation rel) {
59 if (!rel.isNew()) {
60 Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.getLayerManager().getEditLayer()));
61 }
62 }
63
64 protected void downloadIncomplete(Relation rel) {
65 if (rel.isNew()) return;
66 Set<OsmPrimitive> ret = new HashSet<>();
67 ret.addAll(rel.getIncompleteMembers());
68 if (ret.isEmpty()) return;
69 Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.getLayerManager().getEditLayer()));
70 }
71}
Note: See TracBrowser for help on using the repository browser.