Ignore:
Timestamp:
2013-03-24T18:39:50+01:00 (12 years ago)
Author:
donvip
Message:

fix #josm8540 - Unglue relations not marking relations as modified

Location:
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java

    r29118 r29391  
    1919import org.openstreetmap.josm.data.osm.Node;
    2020import org.openstreetmap.josm.data.osm.OsmPrimitive;
    21 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2221import org.openstreetmap.josm.data.osm.Relation;
    23 import org.openstreetmap.josm.data.osm.RelationMember;
    2422import org.openstreetmap.josm.data.osm.Way;
    25 import org.openstreetmap.josm.gui.DefaultNameFormatter;
     23import org.openstreetmap.josm.plugins.utilsplugin2.command.ChangeRelationMemberCommand;
    2624import org.openstreetmap.josm.tools.Shortcut;
    2725
     
    8987    }
    9088
    91     /**
    92      * Change member in relation to another one
    93      */
    94     private class ChangeRelationMemberCommand extends Command {
    95 
    96         private final Relation relation;
    97         private final OsmPrimitive oldMember;
    98         private final OsmPrimitive newMember;
    99        
    100         public ChangeRelationMemberCommand(Relation relation, OsmPrimitive oldMember, OsmPrimitive newMember) {
    101             this.relation = relation;
    102             this.oldMember = oldMember;
    103             this.newMember = newMember;
    104         }
    105 
    106         private boolean replaceMembers(OsmPrimitive oldP, OsmPrimitive newP) {
    107             if (relation == null || oldMember == null || newMember == null) {
    108                 return false;
    109             }
    110             LinkedList<RelationMember> newrms = new LinkedList<RelationMember>();
    111             for (RelationMember rm : relation.getMembers()) {
    112                 if (rm.getMember() == oldP) {
    113                     newrms.add(new RelationMember(rm.getRole(), newP));
    114                 } else {
    115                     newrms.add(rm);
    116                 }
    117             }
    118             relation.setMembers(newrms);
    119             return true;
    120         }
    121        
    122         @Override
    123         public boolean executeCommand() {
    124             return replaceMembers(oldMember, newMember);
    125         }
    126 
    127         @Override
    128         public void fillModifiedData(Collection<OsmPrimitive> modified,
    129                 Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    130             modified.add(relation);
    131         }
    132 
    133         @Override
    134         public void undoCommand() {
    135             replaceMembers(newMember, oldMember);
    136         }
    137 
    138         @Override
    139         public String getDescriptionText() {
    140             return tr("Change relation member for {0} {1}",
    141                     OsmPrimitiveType.from(relation),
    142                     relation.getDisplayName(DefaultNameFormatter.getInstance()));
    143         }
    144     }
    145 
    14689    @Override
    14790    protected void updateEnabledState() {
Note: See TracChangeset for help on using the changeset viewer.