001    // License: GPL. For details, see LICENSE file.
002    package org.openstreetmap.josm.command;
003    
004    import static org.openstreetmap.josm.tools.I18n.marktr;
005    import static org.openstreetmap.josm.tools.I18n.tr;
006    
007    import java.util.Collection;
008    import javax.swing.Icon;
009    
010    import javax.swing.JLabel;
011    
012    import org.openstreetmap.josm.data.conflict.Conflict;
013    import org.openstreetmap.josm.data.osm.OsmPrimitive;
014    import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
015    import org.openstreetmap.josm.tools.ImageProvider;
016    
017    /**
018     * Represents a command for to set the modified flag {@link OsmPrimitive}
019     *
020     *
021     */
022    public class ModifiedConflictResolveCommand extends ConflictResolveCommand {
023    
024        /** the conflict to resolve */
025        private Conflict<? extends OsmPrimitive> conflict;
026    
027        /**
028         * constructor
029         * @param my  my primitive (i.e. the primitive from the local dataset)
030         * @param their their primitive (i.e. the primitive from the server)
031         */
032        public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
033            this.conflict = conflict;
034        }
035    
036        @Override
037        public String getDescriptionText() {
038            String msg = "";
039            switch(OsmPrimitiveType.from(conflict.getMy())) {
040            case NODE: msg = marktr("Set the ''modified'' flag for node {0}"); break;
041            case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break;
042            case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break;
043            }
044            return tr(msg,conflict.getMy().getId());
045        }
046    
047        @Override
048        public Icon getDescriptionIcon() {
049            return ImageProvider.get("data", "object");
050        }
051    
052        @Override
053        public boolean executeCommand() {
054            super.executeCommand();
055            if (!conflict.getMy().isNew() && conflict.getMy().hasEqualSemanticAttributes(conflict.getTheir())) {
056                conflict.getMy().setModified(conflict.getTheir().isModified());
057            }
058            getLayer().getConflicts().remove(conflict);
059            rememberConflict(conflict);
060            return true;
061        }
062    
063        @Override
064        public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
065                Collection<OsmPrimitive> added) {
066            modified.add(conflict.getMy());
067        }
068    }