Ignore:
Timestamp:
2017-07-10T11:27:18+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm14977 - download incomplete relation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SortPTStopsAction.java

    r33433 r33434  
    33package org.openstreetmap.josm.plugins.pt_assistant.actions;
    44
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
    57import java.awt.event.ActionEvent;
    68import java.util.ArrayList;
    79import java.util.Collection;
     10import java.util.Collections;
    811import java.util.HashMap;
    912import java.util.List;
    1013import java.util.Map;
     14import java.util.concurrent.ExecutionException;
     15import java.util.concurrent.Future;
    1116
     17import javax.swing.JOptionPane;
     18
     19import org.openstreetmap.josm.Main;
    1220import org.openstreetmap.josm.actions.JosmAction;
     21import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    1322import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1423import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    1625import org.openstreetmap.josm.data.osm.RelationMember;
    1726import org.openstreetmap.josm.data.osm.Way;
     27import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    1828import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
    1929import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
     
    3848
    3949        Relation rel = (Relation) getLayerManager().getEditDataSet().getSelected().iterator().next();
     50
     51        if (rel.hasIncompleteMembers()) {
     52            if (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(Main.parent,
     53                tr("The relation has incomplete members. Do you want to download them and continue with the sorting?"),
     54                tr("Incomplete Members"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
     55                null, null, null)) {
     56
     57                List<Relation> incomplete = Collections.singletonList(rel);
     58                Future<?> future = Main.worker.submit(new DownloadRelationMemberTask(
     59                        incomplete,
     60                        DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(incomplete),
     61                        Main.getLayerManager().getEditLayer()));
     62
     63                    Main.worker.submit(() -> {
     64                        try {
     65                            future.get();
     66                            continueAfterDownload(rel);
     67                        } catch (InterruptedException | ExecutionException e1) {
     68                             Main.error(e1);
     69                            return;
     70                        }
     71                    });
     72            } else
     73                return;
     74        } else
     75            continueAfterDownload(rel);
     76    }
     77
     78    private void continueAfterDownload(Relation rel) {
    4079        List<RelationMember> members = rel.getMembers();
    4180
Note: See TracChangeset for help on using the changeset viewer.