Index: trunk/src/org/openstreetmap/josm/command/AddCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 1750)
@@ -10,12 +10,8 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
 import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
-import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 
 /**
@@ -23,5 +19,5 @@
  * way.
  *
- * See {@link ChangeCommand ChangeCommand} for comments on relation back references.
+ * See {@see ChangeCommand} for comments on relation back references.
  *
  * @author imi
@@ -34,21 +30,19 @@
     private final OsmPrimitive osm;
 
-    private DataSet ds;
-
     /**
      * Create the command and specify the element to add.
      */
     public AddCommand(OsmPrimitive osm) {
+        super();
         this.osm = osm;
-        this.ds = Main.main.editLayer().data;
     }
 
     @Override public boolean executeCommand() {
-        osm.visit(new AddVisitor(ds));
+        osm.visit(new AddVisitor(getLayer().data));
         return true;
     }
 
     @Override public void undoCommand() {
-        osm.visit(new DeleteVisitor(ds));
+        osm.visit(new DeleteVisitor(getLayer().data));
     }
 
@@ -57,13 +51,9 @@
     }
 
-    // faster implementation
-    @Override public boolean invalidBecauselayerRemoved(Layer oldLayer) {
-        return oldLayer instanceof OsmDataLayer && ((OsmDataLayer)oldLayer).data == ds;
-    }
-
     @Override public MutableTreeNode description() {
         NameVisitor v = new NameVisitor();
         osm.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("Add")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(
+                new JLabel(tr("Add {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 1750)
@@ -25,4 +25,5 @@
 
     public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
+        super();
         this.osm = osm;
         this.newOsm = newOsm;
@@ -43,5 +44,5 @@
         NameVisitor v = new NameVisitor();
         osm.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("Change")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(new JLabel(tr("Change {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 1750)
@@ -40,4 +40,5 @@
 
     public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) {
+        super();
         this.objects = new LinkedList<OsmPrimitive>();
         this.key = key;
@@ -45,6 +46,7 @@
         if (value == null) {
             for (OsmPrimitive osm : objects) {
-                if(osm.get(key) != null)
+                if(osm.get(key) != null) {
                     this.objects.add(osm);
+                }
             }
         } else {
@@ -64,6 +66,7 @@
         String val = object.get(key);
         if ((value == null && val != null)
-        || (value != null && (val == null || !value.equals(val))))
+                || (value != null && (val == null || !value.equals(val)))) {
             this.objects.add(object);
+        }
     }
 
@@ -95,5 +98,5 @@
             text = value == null
             ? tr("Remove \"{0}\" for {1} ''{2}''", key, tr(v.className), v.name)
-            : tr("Set {0}={1} for {2} ''{3}''",key,value, tr(v.className), v.name);
+                    : tr("Set {0}={1} for {2} ''{3}''",key,value, tr(v.className), v.name);
         }
         else
@@ -101,5 +104,5 @@
             text = value == null
             ? tr("Remove \"{0}\" for {1} {2}", key, objects.size(), trn("object","objects",objects.size()))
-            : tr("Set {0}={1} for {2} {3}",key,value, objects.size(), trn("object","objects",objects.size()));
+                    : tr("Set {0}={1} for {2} {3}",key,value, objects.size(), trn("object","objects",objects.size()));
         }
         DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(text, ImageProvider.get("data", "key"), JLabel.HORIZONTAL));
Index: trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 1750)
@@ -13,6 +13,4 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.osm.RelationMember;
-
 import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
 
@@ -36,4 +34,5 @@
 
     public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) {
+        super();
         this.relation = relation;
         this.position = position;
@@ -67,5 +66,5 @@
         NameVisitor v = new NameVisitor();
         relation.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("ChangeRelationMemberRole")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(new JLabel(tr("ChangeRelationMemberRole {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/Command.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/Command.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/Command.java	(revision 1750)
@@ -11,5 +11,4 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -25,80 +24,74 @@
  * one atomic action on a specific dataset, such as move or delete.
  *
- * Remember that the command must be executable and undoable, even if the
- * Main.ds has changed, so the command must save the dataset it operates on
- * if necessary.
- *
+ * The command remembers the {@see OsmDataLayer} it is operating on.
+ * 
  * @author imi
  */
 abstract public class Command {
 
-   private static final class CloneVisitor extends AbstractVisitor {
-      public Map<OsmPrimitive, OsmPrimitive> orig = new HashMap<OsmPrimitive, OsmPrimitive>();
+    private static final class CloneVisitor extends AbstractVisitor {
+        public Map<OsmPrimitive, OsmPrimitive> orig = new HashMap<OsmPrimitive, OsmPrimitive>();
 
-      public void visit(Node n) {
-         orig.put(n, new Node(n));
-      }
-      public void visit(Way w) {
-         orig.put(w, new Way(w));
-      }
-      public void visit(Relation e) {
-         orig.put(e, new Relation(e));
-      }
-   }
+        public void visit(Node n) {
+            orig.put(n, new Node(n));
+        }
+        public void visit(Way w) {
+            orig.put(w, new Way(w));
+        }
+        public void visit(Relation e) {
+            orig.put(e, new Relation(e));
+        }
+    }
 
-   private CloneVisitor orig;
+    /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */
+    private Map<OsmPrimitive, OsmPrimitive> cloneMap = new HashMap<OsmPrimitive, OsmPrimitive>();
 
-   protected DataSet ds;
+    /** the layer which this command is applied to */
+    private OsmDataLayer layer;
 
-   public Command() {
-      this.ds = Main.main.editLayer().data;
-   }
-   /**
-    * Executes the command on the dataset. This implementation will remember all
-    * primitives returned by fillModifiedData for restoring them on undo.
-    */
-   public boolean did_execute = false;
-   public boolean executeCommand() {
-      did_execute = true;
-      orig = new CloneVisitor();
-      Collection<OsmPrimitive> all = new HashSet<OsmPrimitive>();
-      fillModifiedData(all, all, all);
-      for (OsmPrimitive osm : all)
-         osm.visit(orig);
-      return true;
-   }
+    public Command() {
+        this.layer = Main.main.map.mapView.getEditLayer();
+    }
+    /**
+     * Executes the command on the dataset. This implementation will remember all
+     * primitives returned by fillModifiedData for restoring them on undo.
+     */
+    public boolean executeCommand() {
+        CloneVisitor visitor = new CloneVisitor();
+        Collection<OsmPrimitive> all = new HashSet<OsmPrimitive>();
+        fillModifiedData(all, all, all);
+        for (OsmPrimitive osm : all) {
+            osm.visit(visitor);
+        }
+        cloneMap = visitor.orig;
+        return true;
+    }
 
-   /**
-    * Undoes the command.
-    * It can be assumed that all objects are in the same state they were before.
-    * It can also be assumed that executeCommand was called exactly once before.
-    *
-    * This implementation undoes all objects stored by a former call to executeCommand.
-    */
-   public void undoCommand() {
-      for (Entry<OsmPrimitive, OsmPrimitive> e : orig.orig.entrySet())
-         e.getKey().cloneFrom(e.getValue());
-   }
+    /**
+     * Undoes the command.
+     * It can be assumed that all objects are in the same state they were before.
+     * It can also be assumed that executeCommand was called exactly once before.
+     *
+     * This implementation undoes all objects stored by a former call to executeCommand.
+     */
+    public void undoCommand() {
+        for (Entry<OsmPrimitive, OsmPrimitive> e : cloneMap.entrySet()) {
+            e.getKey().cloneFrom(e.getValue());
+        }
+    }
 
-   /**
-    * Called when a layer has been removed to have the command remove itself from
-    * any buffer if it is not longer applicable to the dataset (e.g. it was part of
-    * the removed layer)
-    */
-   public boolean invalidBecauselayerRemoved(Layer oldLayer) {
-      if (!(oldLayer instanceof OsmDataLayer))
-         return false;
-      HashSet<OsmPrimitive> modified = new HashSet<OsmPrimitive>();
-      fillModifiedData(modified, modified, modified);
-      if (modified.isEmpty())
-         return false;
-
-      HashSet<OsmPrimitive> all = new HashSet<OsmPrimitive>(((OsmDataLayer)oldLayer).data.allPrimitives());
-      for (OsmPrimitive osm : all)
-         if (all.contains(osm))
-                 return true;
-
-      return false;
-   }
+    /**
+     * Called when a layer has been removed to have the command remove itself from
+     * any buffer if it is not longer applicable to the dataset (e.g. it was part of
+     * the removed layer)
+     * 
+     * @param oldLayer the old layer
+     * @return true if this command
+     */
+    public boolean invalidBecauselayerRemoved(Layer oldLayer) {
+        if (!(oldLayer instanceof OsmDataLayer))
+            return false;
+        return layer == oldLayer;
+    }
 
     /**
@@ -107,28 +100,40 @@
      */
     public OsmPrimitive getOrig(OsmPrimitive osm) {
-        OsmPrimitive o = orig.orig.get(osm);
+        OsmPrimitive o = cloneMap.get(osm);
         if (o != null)
-             return o;
+            return o;
         Main.debug("unable to find osm with id: " + osm.id + " hashCode: " + osm.hashCode());
-        for (OsmPrimitive t : orig.orig.keySet()) {
-             OsmPrimitive to = orig.orig.get(t);
-             Main.debug("now: " + t.id + " hashCode: " + t.hashCode());
-             Main.debug("orig: " + to.id + " hashCode: " + to.hashCode());
+        for (OsmPrimitive t : cloneMap.keySet()) {
+            OsmPrimitive to = cloneMap.get(t);
+            Main.debug("now: " + t.id + " hashCode: " + t.hashCode());
+            Main.debug("orig: " + to.id + " hashCode: " + to.hashCode());
         }
         return o;
     }
 
-   /**
-    * Fill in the changed data this command operates on.
-    * Add to the lists, don't clear them.
-    *
-    * @param modified The modified primitives
-    * @param deleted The deleted primitives
-    * @param added The added primitives
-    */
-   abstract public void fillModifiedData(Collection<OsmPrimitive> modified,
-         Collection<OsmPrimitive> deleted,
-         Collection<OsmPrimitive> added);
+    /**
+     * Replies the layer this command is (or was) applied to.
+     * 
+     * @return
+     */
+    protected  OsmDataLayer getLayer() {
+        return layer;
+    }
 
-   abstract public MutableTreeNode description();
+    /**
+     * Fill in the changed data this command operates on.
+     * Add to the lists, don't clear them.
+     *
+     * @param modified The modified primitives
+     * @param deleted The deleted primitives
+     * @param added The added primitives
+     */
+    abstract public void fillModifiedData(Collection<OsmPrimitive> modified,
+            Collection<OsmPrimitive> deleted,
+            Collection<OsmPrimitive> added);
+
+    abstract public MutableTreeNode description();
+
+
+
 }
Index: trunk/src/org/openstreetmap/josm/command/ConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ConflictResolveCommand.java	(revision 1750)
+++ trunk/src/org/openstreetmap/josm/command/ConflictResolveCommand.java	(revision 1750)
@@ -0,0 +1,75 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.command;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.util.logging.Logger;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.conflict.Conflict;
+import org.openstreetmap.josm.data.conflict.ConflictCollection;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+
+/**
+ * This is the common basse class for {@see Command}s which manipulate {@see Conflict}s in
+ * addition to {@see OsmPrimitive}s.
+ * 
+ * A ConflictResolverCommand can remember a collection of conflicts it resolves. Upon undoing
+ * it reconstitutes these conflicts.
+ *
+ */
+public abstract class ConflictResolveCommand extends Command {
+    private static final Logger logger = Logger.getLogger(ConflictResolveCommand.class.getName());
+
+    /** the list of resolved conflicts */
+    private ConflictCollection resolvedConflicts;
+
+    public ConflictResolveCommand() {
+        super();
+        resolvedConflicts = new ConflictCollection();
+    }
+
+    /**
+     * remembers a conflict in the internal list of remembered conflicts
+     * 
+     * @param c the remembered conflict
+     */
+    protected void rememberConflict(Conflict c) {
+        if (! resolvedConflicts.hasConflictForMy(c.getMy())) {
+            resolvedConflicts.add(c);
+        }
+    }
+
+    /**
+     * reconstitutes all remembered conflicts. Add the remembered conflicts to the
+     * set of conflicts of the {@see OsmDataLayer} this command was applied to.
+     * 
+     */
+    protected void reconstituteConflicts() {
+        OsmDataLayer editLayer = getLayer();
+        for(Conflict c : resolvedConflicts) {
+            if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
+                editLayer.getConflicts().add(c);
+            }
+        }
+    }
+
+    @Override
+    public void undoCommand() {
+        super.undoCommand();
+
+        if (! Main.map.mapView.hasLayer(getLayer())) {
+            logger.warning(tr("Can't undo command ''{0}'' because layer ''{1}'' is not present anymore",
+                    this.toString(),
+                    getLayer().toString()
+            ));
+            return;
+        }
+
+        Main.map.mapView.setActiveLayer(getLayer());
+        reconstituteConflicts();
+    }
+
+
+
+}
Index: trunk/src/org/openstreetmap/josm/command/CoordinateConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/CoordinateConflictResolveCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/CoordinateConflictResolveCommand.java	(revision 1750)
@@ -10,9 +10,7 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -22,12 +20,8 @@
  *
  */
-public class CoordinateConflictResolveCommand extends Command {
+public class CoordinateConflictResolveCommand extends ConflictResolveCommand {
 
-    /** my node (in the local dataset). merge decisions are applied to this
-     *  node
-     */
-    private final Node my;
-    /** their node (in the server dataset) */
-    private final Node their;
+    /** the conflict to resolve */
+    private Conflict<Node> conflict;
 
     /** the merge decision */
@@ -42,6 +36,5 @@
      */
     public CoordinateConflictResolveCommand(Node my, Node their, MergeDecisionType decision) {
-        this.my = my;
-        this.their = their;
+        this.conflict = new Conflict<Node>(my,their);
         this.decision = decision;
     }
@@ -52,5 +45,5 @@
         return new DefaultMutableTreeNode(
                 new JLabel(
-                        tr("Resolve conflicts in coordinates in {0}",my.id),
+                        tr("Resolve conflicts in coordinates in {0}",conflict.getMy().id),
                         ImageProvider.get("data", "object"),
                         JLabel.HORIZONTAL
@@ -69,8 +62,14 @@
             // do nothing
         } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
+            Node my = conflict.getMy();
+            Node their = conflict.getTheir();
             my.setCoor(their.getCoor());
         } else
             // should not happen
             throw new IllegalStateException(tr("cannot resolve undecided conflict"));
+
+        // remember the layer this command was applied to
+        //
+        rememberConflict(conflict);
 
         return true;
@@ -80,18 +79,5 @@
     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
-        modified.add(my);
-    }
-
-    @Override
-    public void undoCommand() {
-        // restore former state of modified primitives
-        //
-        super.undoCommand();
-
-        // restore a conflict if necessary
-        //
-        if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-            Main.map.conflictDialog.addConflict(my, their);
-        }
+        modified.add(conflict.getMy());
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 1750)
@@ -42,7 +42,7 @@
 
     /**
-     * The primitive that get deleted.
-     */
-    private final Collection<? extends OsmPrimitive> data;
+     * The primitives that get deleted.
+     */
+    private final Collection<? extends OsmPrimitive> toDelete;
 
     /**
@@ -50,5 +50,6 @@
      */
     public DeleteCommand(Collection<? extends OsmPrimitive> data) {
-        this.data = data;
+        super();
+        this.toDelete = data;
     }
 
@@ -58,10 +59,10 @@
      */
     public DeleteCommand(OsmPrimitive data) {
-        this.data = Collections.singleton(data);
+        this.toDelete = Collections.singleton(data);
     }
 
     @Override public boolean executeCommand() {
         super.executeCommand();
-        for (OsmPrimitive osm : data) {
+        for (OsmPrimitive osm : toDelete) {
             osm.delete(true);
         }
@@ -71,5 +72,5 @@
     @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
-        deleted.addAll(data);
+        deleted.addAll(toDelete);
     }
 
@@ -77,6 +78,6 @@
         NameVisitor v = new NameVisitor();
 
-        if (data.size() == 1) {
-            data.iterator().next().visit(v);
+        if (toDelete.size() == 1) {
+            toDelete.iterator().next().visit(v);
             return new DefaultMutableTreeNode(new JLabel(tr("Delete {1} {0}", v.name, tr(v.className)), v.icon,
                     JLabel.HORIZONTAL));
@@ -85,5 +86,5 @@
         String cname = null;
         String cnamem = null;
-        for (OsmPrimitive osm : data) {
+        for (OsmPrimitive osm : toDelete) {
             osm.visit(v);
             if (cname == null) {
@@ -95,7 +96,7 @@
             }
         }
-        DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(tr("Delete {0} {1}", data.size(), trn(
-                cname, cnamem, data.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
-        for (OsmPrimitive osm : data) {
+        DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(tr("Delete {0} {1}", toDelete.size(), trn(
+                cname, cnamem, toDelete.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
+        for (OsmPrimitive osm : toDelete) {
             osm.visit(v);
             root.add(new DefaultMutableTreeNode(v.toLabel()));
@@ -276,13 +277,5 @@
             Relation rel = new Relation(cur);
             for (OsmPrimitive osm : relationsToBeChanged.get(cur)) {
-                for (RelationMember rm : rel.members) {
-                    if (rm.member == osm) {
-                        RelationMember mem = new RelationMember();
-                        mem.role = rm.role;
-                        mem.member = rm.member;
-                        rel.members.remove(mem);
-                        break;
-                    }
-                }
+                rel.removeMembersFor(osm);
             }
             cmds.add(new ChangeCommand(cur, rel));
Index: trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java	(revision 1750)
@@ -10,7 +10,8 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -19,17 +20,11 @@
  *
  */
-public class DeletedStateConflictResolveCommand extends Command {
+public class DeletedStateConflictResolveCommand extends ConflictResolveCommand {
 
-    /** my primitive (in the local dataset). merge decisions are applied to this
-     *  node
-     */
-    private final OsmPrimitive my;
-    /** their primitive (in the server dataset) */
-    private final OsmPrimitive their;
+    /** the conflict to resolve */
+    private Conflict<OsmPrimitive> conflict;
 
     /** the merge decision */
     private final MergeDecisionType decision;
-
-
 
     /**
@@ -41,6 +36,5 @@
      */
     public DeletedStateConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, MergeDecisionType decision) {
-        this.my = my;
-        this.their = their;
+        this.conflict = new Conflict<OsmPrimitive>(my, their);
         this.decision = decision;
     }
@@ -51,5 +45,5 @@
         return new DefaultMutableTreeNode(
                 new JLabel(
-                        tr("Resolve conflicts in deleted state in {0}",my.id),
+                        tr("Resolve conflicts in deleted state in {0}",conflict.getMy().id),
                         ImageProvider.get("data", "object"),
                         JLabel.HORIZONTAL
@@ -65,17 +59,19 @@
         super.executeCommand();
 
+        OsmDataLayer layer = getLayer();
+
         if (decision.equals(MergeDecisionType.KEEP_MINE)) {
-            if (my.deleted) {
+            if (conflict.getMy().deleted) {
                 // because my was involved in a conflict it my still be referred
                 // to from a way or a relation. Fix this now.
                 //
-                Main.main.editLayer().data.unlinkReferencesToPrimitive(my);
+                layer.data.unlinkReferencesToPrimitive(conflict.getMy());
             }
         } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
-            if (their.deleted) {
-                Main.main.editLayer().data.unlinkReferencesToPrimitive(my);
-                my.delete(true);
+            if (conflict.getTheir().deleted) {
+                layer.data.unlinkReferencesToPrimitive(conflict.getMy());
+                conflict.getMy().delete(true);
             } else {
-                my.deleted = their.deleted;
+                conflict.getMy().deleted = conflict.getTheir().deleted;
             }
         } else
@@ -83,4 +79,5 @@
             throw new IllegalStateException(tr("cannot resolve undecided conflict"));
 
+        rememberConflict(conflict);
         return true;
     }
@@ -89,18 +86,5 @@
     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
-        modified.add(my);
-    }
-
-    @Override
-    public void undoCommand() {
-        // restore former state of modified primitives
-        //
-        super.undoCommand();
-
-        // restore a conflict if necessary
-        //
-        if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-            Main.map.conflictDialog.addConflict(my, their);
-        }
+        modified.add(conflict.getMy());
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/MoveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 1750)
@@ -15,5 +15,4 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.Node;
@@ -32,5 +31,5 @@
      * The objects that should be moved.
      */
-    public Collection<Node> objects = new LinkedList<Node>();
+    private Collection<Node> nodes = new LinkedList<Node>();
     /**
      * x difference movement. Coordinates are in northern/eastern
@@ -64,8 +63,9 @@
      */
     public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
+        super();
         this.x = x;
         this.y = y;
-        this.objects = AllNodesVisitor.getAllNodes(objects);
-        for (Node n : this.objects) {
+        this.nodes = AllNodesVisitor.getAllNodes(objects);
+        for (Node n : this.nodes) {
             OldState os = new OldState();
             os.latlon = new LatLon(n.getCoor());
@@ -84,5 +84,5 @@
      */
     public void moveAgain(double x, double y) {
-        for (Node n : objects) {
+        for (Node n : nodes) {
             n.setEastNorth(n.getEastNorth().add(x, y));
         }
@@ -92,5 +92,5 @@
 
     @Override public boolean executeCommand() {
-        for (Node n : objects) {
+        for (Node n : nodes) {
             n.setEastNorth(n.getEastNorth().add(x, y));
             n.modified = true;
@@ -101,5 +101,5 @@
     @Override public void undoCommand() {
         Iterator<OldState> it = oldState.iterator();
-        for (Node n : objects) {
+        for (Node n : nodes) {
             OldState os = it.next();
             n.setCoor(os.latlon);
@@ -109,10 +109,15 @@
 
     @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
-        for (OsmPrimitive osm : objects)
+        for (OsmPrimitive osm : nodes) {
             modified.add(osm);
+        }
     }
 
     @Override public MutableTreeNode description() {
-        return new DefaultMutableTreeNode(new JLabel(tr("Move")+" "+objects.size()+" "+trn("node","nodes",objects.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(new JLabel(tr("Move")+" "+nodes.size()+" "+trn("node","nodes",nodes.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL));
+    }
+
+    public Collection<Node> getMovedNodes() {
+        return nodes;
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java	(revision 1750)
@@ -6,7 +6,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+import java.util.logging.Logger;
 
 import javax.swing.JLabel;
@@ -15,4 +14,5 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.conflict.ConflictCollection;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
@@ -21,4 +21,5 @@
 import org.openstreetmap.josm.data.osm.RelationMember;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -34,6 +35,7 @@
  * 
  */
-public class PurgePrimitivesCommand extends Command{
-
+public class PurgePrimitivesCommand extends ConflictResolveCommand{
+
+    static private final Logger logger = Logger.getLogger(PurgePrimitivesCommand.class.getName());
 
     /**
@@ -144,5 +146,4 @@
     private ArrayList<OsmParentChildPair> pairs;
 
-    private Map<OsmPrimitive, OsmPrimitive> resolvedConflicts;
 
     /**
@@ -154,5 +155,4 @@
         purgedPrimitives = new ArrayList<OsmPrimitive>();
         pairs = new ArrayList<OsmParentChildPair>();
-        resolvedConflicts = new HashMap<OsmPrimitive, OsmPrimitive>();
     }
 
@@ -219,14 +219,15 @@
             purge(toPurge, Main.ds, hive);
             if (toPurge instanceof Node) {
-                Main.ds.nodes.remove(toPurge);
+                getLayer().data.nodes.remove(toPurge);
             } else if (primitive instanceof Way) {
-                Main.ds.ways.remove(toPurge);
+                getLayer().data.ways.remove(toPurge);
             } else if (primitive instanceof Relation) {
-                Main.ds.relations.remove(toPurge);
+                getLayer().data.relations.remove(toPurge);
             }
             purgedPrimitives.add(toPurge);
-            if (Main.map.conflictDialog.conflicts.containsKey(toPurge)) {
-                resolvedConflicts.put(toPurge, Main.map.conflictDialog.conflicts.get(toPurge));
-                Main.map.conflictDialog.removeConflictForPrimitive(toPurge);
+            ConflictCollection conflicts = getLayer().getConflicts();
+            if (conflicts.hasConflictForMy(toPurge)) {
+                rememberConflict(conflicts.getConflictForMy(toPurge));
+                conflicts.remove(toPurge);
             }
         }
@@ -246,17 +247,19 @@
     @Override
     public void undoCommand() {
+        if (! Main.map.mapView.hasLayer(getLayer())) {
+            logger.warning(tr("Can't undo command ''{0}'' because layer ''{1}'' is not present anymore",
+                    this.toString(),
+                    getLayer().toString()
+            ));
+            return;
+        }
+        Main.map.mapView.setActiveLayer(getLayer());
 
         // restore purged primitives
         //
         for (OsmPrimitive purged : purgedPrimitives) {
-            Main.ds.addPrimitive(purged);
-        }
-
-        // restore conflicts
-        //
-        for (OsmPrimitive primitive : resolvedConflicts.keySet()) {
-            Main.map.conflictDialog.addConflict(primitive, resolvedConflicts.get(primitive));
-        }
-
+            getLayer().data.addPrimitive(purged);
+        }
+        reconstituteConflicts();
         // will restore the former references to the purged nodes
         //
Index: trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java	(revision 1750)
@@ -6,4 +6,5 @@
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Logger;
 
 import javax.swing.JLabel;
@@ -15,4 +16,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -23,4 +25,5 @@
  */
 public class RelationMemberConflictResolverCommand extends Command {
+    private static final Logger logger = Logger.getLogger(RelationMemberConflictResolverCommand.class.getName());
 
     /** my relation */
@@ -32,4 +35,7 @@
      */
     private final List<RelationMember> mergedMembers;
+
+    /** the layer this conflict is resolved in */
+    private OsmDataLayer layer;
 
     /**
@@ -71,4 +77,7 @@
             my.members.add(n);
         }
+
+        // remember the layer
+        layer = Main.main.map.mapView.getEditLayer();
         return true;
     }
@@ -82,4 +91,15 @@
     @Override
     public void undoCommand() {
+        if (! Main.map.mapView.hasLayer(layer)) {
+            logger.warning(tr("Can't undo command ''{0}'' because layer ''{1}'' is not present anymore",
+                    this.toString(),
+                    layer.toString()
+            ));
+            return;
+        }
+
+        Main.map.mapView.setActiveLayer(layer);
+        OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
+
         // restore the former state
         //
@@ -88,6 +108,6 @@
         // restore a conflict if necessary
         //
-        if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-            Main.map.conflictDialog.conflicts.put(my,their);
+        if (!editLayer.getConflicts().hasConflictForMy(my)) {
+            editLayer.getConflicts().add(my,their);
         }
     }
Index: trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java	(revision 1750)
@@ -64,5 +64,5 @@
         NameVisitor v = new NameVisitor();
         relation.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("RemoveRelationMember")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(new JLabel(tr("RemoveRelationMember {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/RotateCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/RotateCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/RotateCommand.java	(revision 1750)
@@ -30,5 +30,5 @@
      * The objects to rotate.
      */
-    public Collection<Node> objects = new LinkedList<Node>();
+    private Collection<Node> nodes = new LinkedList<Node>();
 
     /**
@@ -70,8 +70,8 @@
     public RotateCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) {
 
-        this.objects = AllNodesVisitor.getAllNodes(objects);
+        this.nodes = AllNodesVisitor.getAllNodes(objects);
         pivot = new EastNorth(0,0);
 
-        for (Node n : this.objects) {
+        for (Node n : this.nodes) {
             OldState os = new OldState();
             os.latlon = new LatLon(n.getCoor());
@@ -81,5 +81,5 @@
             pivot = pivot.add(os.eastNorth.east(), os.eastNorth.north());
         }
-        pivot = new EastNorth(pivot.east()/this.objects.size(), pivot.north()/this.objects.size());
+        pivot = new EastNorth(pivot.east()/this.nodes.size(), pivot.north()/this.nodes.size());
 
         rotationAngle = Math.PI/2;
@@ -105,5 +105,5 @@
      */
     private void rotateNodes(boolean setModified) {
-        for (Node n : objects) {
+        for (Node n : nodes) {
             double cosPhi = Math.cos(rotationAngle);
             double sinPhi = Math.sin(rotationAngle);
@@ -114,6 +114,7 @@
             double ny = -cosPhi * x + sinPhi * y + pivot.north();
             n.setEastNorth(new EastNorth(nx, ny));
-            if (setModified)
+            if (setModified) {
                 n.modified = true;
+            }
         }
     }
@@ -125,5 +126,5 @@
 
     @Override public void undoCommand() {
-        for (Node n : objects) {
+        for (Node n : nodes) {
             OldState os = oldState.get(n);
             n.setCoor(os.latlon);
@@ -133,10 +134,15 @@
 
     @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
-        for (OsmPrimitive osm : objects)
+        for (OsmPrimitive osm : nodes) {
             modified.add(osm);
+        }
     }
 
     @Override public MutableTreeNode description() {
-        return new DefaultMutableTreeNode(new JLabel(tr("Rotate")+" "+objects.size()+" "+trn("node","nodes",objects.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(new JLabel(tr("Rotate {0} {1}",nodes.size(),trn("node","nodes",nodes.size())), ImageProvider.get("data", "node"), JLabel.HORIZONTAL));
+    }
+
+    public Collection<Node> getRotatedNodes() {
+        return nodes;
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/SequenceCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/SequenceCommand.java	(revision 1750)
@@ -33,4 +33,5 @@
      */
     public SequenceCommand(String name, Collection<Command> sequenz) {
+        super();
         this.name = name;
         this.sequence = new Command[sequenz.size()];
@@ -45,11 +46,11 @@
     }
 
-    public int executed_commands = 0;
     @Override public boolean executeCommand() {
         for (int i=0; i < sequence.length; i++) {
             Command c = sequence[i];
             boolean result = c.executeCommand();
-            if (!result)
+            if (!result) {
                 Main.debug("SequenceCommand, executing command[" + i + "] " +  c + " result: " + result);
+            }
             if (!result && !continueOnError) {
                 this.undoCommands(i-1);
@@ -72,6 +73,7 @@
         if (!sequence_complete)
             return;
-        for (int i = start; i >= 0; --i)
+        for (int i = start; i >= 0; --i) {
             sequence[i].undoCommand();
+        }
     }
 
@@ -81,12 +83,14 @@
 
     @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
-        for (Command c : sequence)
+        for (Command c : sequence) {
             c.fillModifiedData(modified, deleted, added);
+        }
     }
 
     @Override public MutableTreeNode description() {
         DefaultMutableTreeNode root = new DefaultMutableTreeNode(tr("Sequence")+": "+name);
-        for (Command c : sequence)
+        for (Command c : sequence) {
             root.add(c.description());
+        }
         return root;
     }
Index: trunk/src/org/openstreetmap/josm/command/TagConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/TagConflictResolveCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/TagConflictResolveCommand.java	(revision 1750)
@@ -6,4 +6,5 @@
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Logger;
 
 import javax.swing.JLabel;
@@ -11,10 +12,7 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
-import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.conflict.MergeDecisionType;
 import org.openstreetmap.josm.gui.conflict.tags.TagMergeItem;
@@ -25,15 +23,14 @@
  *
  */
-public class TagConflictResolveCommand extends Command {
+public class TagConflictResolveCommand extends ConflictResolveCommand {
+    private static final Logger logger = Logger.getLogger(TagConflictResolveCommand.class.getName());
 
-    /** my primitive (in the local dataset). merge decisions are applied to this
-     *  primitive
-     */
-    private final OsmPrimitive my;
-    /** their primitive (in the server dataset) */
-    private final OsmPrimitive their;
+
+    /** the conflict to resolve */
+    private Conflict<OsmPrimitive> conflict;
 
     /** the list of merge decisions, represented as {@see TagMergeItem}s */
     private final List<TagMergeItem> mergeItems;
+
 
     /**
@@ -60,6 +57,5 @@
      */
     public TagConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, List<TagMergeItem> mergeItems) {
-        this.my = my;
-        this.their = their;
+        this.conflict = new Conflict<OsmPrimitive>(my,their);
         this.mergeItems = mergeItems;
     }
@@ -70,5 +66,5 @@
         return new DefaultMutableTreeNode(
                 new JLabel(
-                        tr("Resolve {0} tag conflicts in {1} {2}",getNumDecidedConflicts(), OsmPrimitiveType.from(my).getLocalizedDisplayNameSingular(), my.id),
+                        tr("Resolve {0} tag conflicts in {1} {2}",getNumDecidedConflicts(), OsmPrimitiveType.from(conflict.getMy()).getLocalizedDisplayNameSingular(), conflict.getMy().id),
                         ImageProvider.get("data", "object"),
                         JLabel.HORIZONTAL
@@ -88,7 +84,8 @@
         for (TagMergeItem item: mergeItems) {
             if (! item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
-                item.applyToMyPrimitive(my);
+                item.applyToMyPrimitive(conflict.getMy());
             }
         }
+        rememberConflict(conflict);
         return true;
     }
@@ -97,18 +94,5 @@
     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
-        modified.add(my);
-    }
-
-    @Override
-    public void undoCommand() {
-        // restore former state of modified primitives
-        //
-        super.undoCommand();
-
-        // restore a conflict if necessary
-        //
-        if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-            Main.map.conflictDialog.addConflict(my, their);
-        }
+        modified.add(conflict.getMy());
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/UndeletePrimitivesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/UndeletePrimitivesCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/UndeletePrimitivesCommand.java	(revision 1750)
@@ -6,6 +6,5 @@
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.logging.Logger;
 
 import javax.swing.JLabel;
@@ -15,21 +14,21 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
- * Represents a command for undeleting a node which was deleted on the server.
+ * Represents a command for undeleting an {@see OsmPrimitive} which was deleted on the server.
  * The command remembers the former node id and sets the node id to 0. This turns
  * the node into a new node which can be uploaded to the server.
  *
  */
-public class UndeletePrimitivesCommand extends Command {
+public class UndeletePrimitivesCommand extends ConflictResolveCommand {
+    static private final Logger logger = Logger.getLogger(UndeletePrimitivesCommand.class.getName());
 
     /** the node to undelete */
     private ArrayList<OsmPrimitive> toUndelete;
-    private Map<OsmPrimitive,OsmPrimitive> resolvedConflicts;
 
     protected UndeletePrimitivesCommand() {
         toUndelete = new ArrayList<OsmPrimitive>();
-        resolvedConflicts = new HashMap<OsmPrimitive, OsmPrimitive>();
     }
     /**
@@ -77,8 +76,9 @@
     public boolean executeCommand() {
         super.executeCommand();
+
         for(OsmPrimitive primitive: toUndelete) {
-            if (Main.map.conflictDialog.conflicts.containsKey(primitive)) {
-                resolvedConflicts.put(primitive, Main.map.conflictDialog.conflicts.get(primitive));
-                Main.map.conflictDialog.removeConflictForPrimitive(primitive);
+            if(getLayer().getConflicts().hasConflictForMy(primitive)) {
+                rememberConflict(getLayer().getConflicts().getConflictForMy(primitive));
+                getLayer().getConflicts().remove(primitive);
             }
             primitive.id = 0;
@@ -92,13 +92,3 @@
         modified.addAll(toUndelete);
     }
-    @Override
-    public void undoCommand() {
-        super.undoCommand();
-
-        for (OsmPrimitive my: resolvedConflicts.keySet()) {
-            if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-                Main.map.conflictDialog.addConflict(my, resolvedConflicts.get(my));
-            }
-        }
-    }
 }
Index: trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.java	(revision 1750)
@@ -10,5 +10,5 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
@@ -20,8 +20,8 @@
  *
  */
-public class VersionConflictResolveCommand extends Command {
+public class VersionConflictResolveCommand extends ConflictResolveCommand {
 
-    private final OsmPrimitive my;
-    private final OsmPrimitive their;
+    /** the conflict to resolve */
+    private Conflict<OsmPrimitive> conflict;
 
     /**
@@ -31,6 +31,5 @@
      */
     public VersionConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) {
-        this.my = my;
-        this.their = their;
+        conflict = new Conflict<OsmPrimitive>(my, their);
     }
 
@@ -39,5 +38,5 @@
         return new DefaultMutableTreeNode(
                 new JLabel(
-                        tr("Resolve version conflicts for {0} {1}",OsmPrimitiveType.from(my).getLocalizedDisplayNameSingular(), my.id),
+                        tr("Resolve version conflicts for {0} {1}",OsmPrimitiveType.from(conflict.getMy()).getLocalizedDisplayNameSingular(),conflict.getMy().id),
                         ImageProvider.get("data", "object"),
                         JLabel.HORIZONTAL
@@ -49,6 +48,7 @@
     public boolean executeCommand() {
         super.executeCommand();
-        my.version = Math.max(my.version, their.version);
-        Main.map.conflictDialog.removeConflictForPrimitive(my);
+        conflict.getMy().version = Math.max(conflict.getMy().version, conflict.getTheir().version);
+        getLayer().getConflicts().remove(conflict);
+        rememberConflict(conflict);
         return true;
     }
@@ -57,16 +57,5 @@
     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
-        modified.add(my);
-    }
-
-    @Override
-    public void undoCommand() {
-        super.undoCommand();
-
-        // restore a conflict if necessary
-        //
-        if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-            Main.map.conflictDialog.addConflict(my, their);
-        }
+        modified.add(conflict.getMy());
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java	(revision 1728)
+++ trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java	(revision 1750)
@@ -6,4 +6,5 @@
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Logger;
 
 import javax.swing.JLabel;
@@ -11,5 +12,5 @@
 import javax.swing.tree.MutableTreeNode;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -22,14 +23,16 @@
  *
  */
-public class WayNodesConflictResolverCommand extends Command {
+public class WayNodesConflictResolverCommand extends ConflictResolveCommand {
 
-    /** my way */
-    private final Way my;
-    /** their way */
-    private final Way their;
+    static private final Logger logger = Logger.getLogger(WayNodesConflictResolverCommand.class.getName());
+
+    /** the conflict to resolve */
+    private Conflict<Way> conflict;
+
     /** the list of merged nodes. This becomes the list of news of my way after the
      *  command is executed
      */
     private final List<Node> mergedNodeList;
+
 
     /**
@@ -40,6 +43,5 @@
      */
     public WayNodesConflictResolverCommand(Way my, Way their, List<Node> mergedNodeList) {
-        this.my = my;
-        this.their = their;
+        conflict = new Conflict<Way>(my,their);
         this.mergedNodeList = mergedNodeList;
     }
@@ -50,5 +52,5 @@
         return new DefaultMutableTreeNode(
                 new JLabel(
-                        tr("Resolve conflicts in node list of of way {0}", my.id),
+                        tr("Resolve conflicts in node list of of way {0}", conflict.getMy().id),
                         ImageProvider.get("data", "object"),
                         JLabel.HORIZONTAL
@@ -66,12 +68,13 @@
         // nodes
         //
-        my.nodes.clear();
+        conflict.getMy().nodes.clear();
         for (int i=0; i<mergedNodeList.size();i++) {
             Node n = mergedNodeList.get(i);
-            my.nodes.add(n);
-            if (! Main.ds.nodes.contains(n)) {
-                System.out.println("Main.ds doesn't include node " + n.toString());
+            conflict.getMy().nodes.add(n);
+            if (! getLayer().data.nodes.contains(n)) {
+                logger.warning(tr("Main.ds doesn't include node {0}", n.toString()));
             }
         }
+        rememberConflict(conflict);
         return true;
     }
@@ -80,18 +83,5 @@
     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
-        modified.add(my);
-    }
-
-    @Override
-    public void undoCommand() {
-        // restore the former state
-        //
-        super.undoCommand();
-
-        // restore a conflict if necessary
-        //
-        if (!Main.map.conflictDialog.conflicts.containsKey(my)) {
-            Main.map.conflictDialog.addConflict(my, their);
-        }
+        modified.add(conflict.getMy());
     }
 }
