[25679] | 1 | package relcontext.actions;
|
---|
| 2 |
|
---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[29535] | 4 |
|
---|
[25679] | 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;
|
---|
[29535] | 11 |
|
---|
[25679] | 12 | import javax.swing.AbstractAction;
|
---|
[29535] | 13 |
|
---|
[25679] | 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;
|
---|
[29535] | 21 |
|
---|
[25679] | 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 ) {
|
---|
[25695] | 34 | super(tr("Download referrers"));
|
---|
[25679] | 35 | putValue(SMALL_ICON, ImageProvider.get("downloadreferrers"));
|
---|
[26509] | 36 | putValue(SHORT_DESCRIPTION, tr("Download referrers for the chosen relation and its members."));
|
---|
[25679] | 37 | this.rel = rel;
|
---|
| 38 | rel.addChosenRelationListener(this);
|
---|
[30145] | 39 | setEnabled(rel.get() != null && Main.main.getEditLayer() != null);
|
---|
[25679] | 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());
|
---|
[30145] | 48 | Main.worker.submit(new DownloadReferrersTask(Main.main.getEditLayer(), objects));
|
---|
[25679] | 49 | }
|
---|
| 50 |
|
---|
| 51 | public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
|
---|
[30145] | 52 | setEnabled(newRelation != null && Main.main.getEditLayer() != null);
|
---|
[25679] | 53 | }
|
---|
| 54 |
|
---|
| 55 | protected void downloadMembers( Relation rel ) {
|
---|
| 56 | if( !rel.isNew() ) {
|
---|
[30145] | 57 | Main.worker.submit(new DownloadRelationTask(Collections.singletonList(rel), Main.main.getEditLayer()));
|
---|
[25679] | 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;
|
---|
[30145] | 66 | Main.worker.submit(new DownloadRelationMemberTask(Collections.singletonList(rel), ret, Main.main.getEditLayer()));
|
---|
[25679] | 67 | }
|
---|
| 68 | }
|
---|