Changeset 7946 in josm for trunk/src


Ignore:
Timestamp:
2015-01-09T20:44:46+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #10953 - handle "incomplete but new" relations

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r7945 r7946  
    2222
    2323import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    2425import org.openstreetmap.josm.command.AddCommand;
    2526import org.openstreetmap.josm.command.ChangeCommand;
     
    3435import org.openstreetmap.josm.data.osm.Way;
    3536import org.openstreetmap.josm.gui.Notification;
     37import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    3638import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    3739import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
     
    156158                : null;
    157159
    158         // download incomplete relation if necessary
    159         if (multipolygonRelation != null && !multipolygonRelation.isNew()
    160                 && (multipolygonRelation.isIncomplete() || multipolygonRelation.hasIncompleteMembers())) {
    161             Main.worker.submit(new DownloadRelationTask(Collections.singleton(multipolygonRelation), Main.main.getEditLayer()));
     160        // download incomplete relation or incomplete members if necessary
     161        if (multipolygonRelation != null) {
     162            if (!multipolygonRelation.isNew() && multipolygonRelation.isIncomplete()) {
     163                Main.worker.submit(new DownloadRelationTask(Collections.singleton(multipolygonRelation), Main.main.getEditLayer()));
     164            } else if (multipolygonRelation.hasIncompleteMembers()) {
     165                Main.worker.submit(new DownloadRelationMemberTask(multipolygonRelation,
     166                        DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(Collections.singleton(multipolygonRelation)),
     167                        Main.main.getEditLayer()));
     168            }
    162169        }
    163170        // create/update multipolygon relation
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r7937 r7946  
    2424public class DownloadSelectedIncompleteMembersAction extends AbstractRelationAction {
    2525
     26    private Collection<OsmPrimitive> incompleteMembers;
     27
    2628    /**
    2729     * Constructs a new <code>DownloadSelectedIncompleteMembersAction</code>.
     
    3840     * @return The set of incomplete members of the given relations.
    3941     */
    40     public Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) {
     42    public static Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) {
    4143        Set<OsmPrimitive> ret = new HashSet<>();
    4244        for (Relation r : rels) {
    43             ret.addAll(r.getIncompleteMembers());
     45            ret.addAll(Utils.filter(r.getIncompleteMembers(), new Predicate<OsmPrimitive>() {
     46                @Override
     47                public boolean evaluate(OsmPrimitive osm) {
     48                    return !osm.isNew();
     49                }
     50            }));
    4451        }
    4552        return ret;
     
    5158        Main.worker.submit(new DownloadRelationMemberTask(
    5259                relations,
    53                 buildSetOfIncompleteMembers(relations),
     60                incompleteMembers,
    5461                Main.main.getEditLayer()));
    5562    }
     
    5966        // selected relations with incomplete members
    6067        this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){
    61             @Override public boolean evaluate(Relation r) {
    62                 return !r.isNew() && r.hasIncompleteMembers();
     68            @Override
     69            public boolean evaluate(Relation r) {
     70                return r.hasIncompleteMembers();
    6371            }});
     72        this.incompleteMembers = buildSetOfIncompleteMembers(relations);
    6473        updateEnabledState();
    6574    }
     
    6776    @Override
    6877    protected void updateEnabledState() {
    69         setEnabled(!relations.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
     78        setEnabled(!relations.isEmpty() &&!incompleteMembers.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
    7079    }
    7180}
Note: See TracChangeset for help on using the changeset viewer.