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