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