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

Last change on this file since 26174 was 25711, checked in by zverik, 14 years ago

context menu for relations, selected relations in relation list (reltoolbox plugin)

File size: 2.6 KB
Line 
1package relcontext.actions;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4import java.awt.event.ActionEvent;
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.HashSet;
8import java.util.List;
9import java.util.Set;
10import javax.swing.AbstractAction;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.Relation;
15import org.openstreetmap.josm.data.osm.RelationMember;
16import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
17import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
18import org.openstreetmap.josm.tools.ImageProvider;
19import relcontext.ChosenRelation;
20import relcontext.ChosenRelationListener;
21
22/**
23 * Downloads parent relations for this relation and all parent objects for its members.
24 *
25 * @author Zverik
26 */
27public 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}
Note: See TracBrowser for help on using the repository browser.