Index: trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java	(revision 1856)
@@ -13,7 +13,10 @@
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.DeleteCommand;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.WaySegment;
 import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
@@ -79,7 +82,7 @@
         Command c;
         if (ctrl) {
-            c = DeleteCommand.deleteWithReferences(getCurrentDataSet().getSelected());
+            c = DeleteCommand.deleteWithReferences(getEditLayer(),getCurrentDataSet().getSelected());
         } else {
-            c = DeleteCommand.delete(getCurrentDataSet().getSelected(), !alt);
+            c = DeleteCommand.delete(getEditLayer(),getCurrentDataSet().getSelected(), !alt);
         }
         if (c != null) {
@@ -110,15 +113,15 @@
             if (ws != null) {
                 if (shift) {
-                    c = DeleteCommand.deleteWaySegment(ws);
+                    c = DeleteCommand.deleteWaySegment(getEditLayer(),ws);
                 } else if (ctrl) {
-                    c = DeleteCommand.deleteWithReferences(Collections.singleton((OsmPrimitive)ws.way));
+                    c = DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton((OsmPrimitive)ws.way));
                 } else {
-                    c = DeleteCommand.delete(Collections.singleton((OsmPrimitive)ws.way), !alt);
+                    c = DeleteCommand.delete(getEditLayer(),Collections.singleton((OsmPrimitive)ws.way), !alt);
                 }
             }
         } else if (ctrl) {
-            c = DeleteCommand.deleteWithReferences(Collections.singleton(sel));
+            c = DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton(sel));
         } else {
-            c = DeleteCommand.delete(Collections.singleton(sel), !alt);
+            c = DeleteCommand.delete(getEditLayer(),Collections.singleton(sel), !alt);
         }
         if (c != null) {
@@ -142,3 +145,29 @@
         setEnabled(Main.map != null && Main.map.mapView != null && Main.map.mapView.isActiveLayerDrawable());
     }
+
+    /**
+     * Deletes the relation in the context of the given layer. Also notifies
+     * {@see RelationDialogManager} and {@see OsmDataLayer#fireDataChange()} events.
+     * 
+     * @param layer the layer in whose context the relation is deleted. Must not be null.
+     * @param toDelete  the relation to be deleted. Must  not be null.
+     * @exception IllegalArgumentException thrown if layer is null
+     * @exception IllegalArgumentException thrown if toDelete is nul
+     */
+    public static void deleteRelation(OsmDataLayer layer, Relation toDelete) {
+        if (layer == null)
+            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "layer"));
+        if (toDelete == null)
+            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "toDelete"));
+        if (toDelete == null)
+            return;
+        Command cmd = DeleteCommand.delete(layer, Collections.singleton(toDelete));
+        if (cmd != null) {
+            // cmd can be null if the user cancels dialogs DialogCommand displays
+            //
+            Main.main.undoRedo.add(cmd);
+            RelationDialogManager.getRelationDialogManager().close(layer, toDelete);
+            layer.fireDataChange();
+        }
+    }
 }
Index: trunk/src/org/openstreetmap/josm/command/Command.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/Command.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/command/Command.java	(revision 1856)
@@ -53,4 +53,14 @@
         this.layer = Main.map.mapView.getEditLayer();
     }
+
+    /**
+     * Creates a new command in the context of a specific data layer
+     * 
+     * @param layer the data layer
+     */
+    public Command(OsmDataLayer layer) {
+        this.layer = layer;
+    }
+
     /**
      * Executes the command on the dataset. This implementation will remember all
Index: trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 1856)
@@ -34,4 +34,5 @@
 import org.openstreetmap.josm.gui.ExtendedDialog;
 import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -63,5 +64,30 @@
     }
 
-    @Override public boolean executeCommand() {
+    /**
+     * Constructor for a single data item. Use the collection constructor to delete multiple
+     * objects.
+     * 
+     * @param layer the layer context for deleting this primitive
+     * @param data the primitive to delete
+     */
+    public DeleteCommand(OsmDataLayer layer, OsmPrimitive data) {
+        super(layer);
+        this.toDelete = Collections.singleton(data);
+    }
+
+    /**
+     * Constructor for a collection of data to be deleted in the context of
+     * a specific layer
+     * 
+     * @param layer the layer context for deleting these primitives
+     * @param data the primitives to delete
+     */
+    public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) {
+        super(layer);
+        this.toDelete = data;
+    }
+
+    @Override
+    public boolean executeCommand() {
         super.executeCommand();
         for (OsmPrimitive osm : toDelete) {
@@ -71,20 +97,17 @@
     }
 
-    @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
+    @Override
+    public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
             Collection<OsmPrimitive> added) {
         deleted.addAll(toDelete);
     }
 
-    @Override public MutableTreeNode description() {
+    @Override
+    public MutableTreeNode description() {
         if (toDelete.size() == 1) {
             OsmPrimitive primitive = toDelete.iterator().next();
-            return new DefaultMutableTreeNode(
-                    new JLabel(
-                            tr("Delete {1} {0}",
-                                    new PrimitiveNameFormatter().getName(primitive),
-                                    OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular()
-                            ),
-                            ImageProvider.get(OsmPrimitiveType.from(primitive)),
-                            JLabel.HORIZONTAL));
+            return new DefaultMutableTreeNode(new JLabel(tr("Delete {1} {0}", new PrimitiveNameFormatter()
+            .getName(primitive), OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular()),
+            ImageProvider.get(OsmPrimitiveType.from(primitive)), JLabel.HORIZONTAL));
         }
 
@@ -106,11 +129,6 @@
                 cname, cnamem, toDelete.size())), ImageProvider.get("data", apiname), JLabel.HORIZONTAL));
         for (OsmPrimitive osm : toDelete) {
-            root.add(new DefaultMutableTreeNode(
-                    new JLabel(
-                            new PrimitiveNameFormatter().getName(osm),
-                            ImageProvider.get(OsmPrimitiveType.from(osm)),
-                            JLabel.HORIZONTAL)
-            )
-            );
+            root.add(new DefaultMutableTreeNode(new JLabel(new PrimitiveNameFormatter().getName(osm), ImageProvider
+                    .get(OsmPrimitiveType.from(osm)), JLabel.HORIZONTAL)));
         }
         return root;
@@ -119,17 +137,17 @@
     /**
      * Delete the primitives and everything they reference.
-     *
+     * 
      * If a node is deleted, the node and all ways and relations the node is part of are deleted as
      * well.
-     *
+     * 
      * If a way is deleted, all relations the way is member of are also deleted.
-     *
+     * 
      * If a way is deleted, only the way and no nodes are deleted.
-     *
+     * 
      * @param selection The list of all object to be deleted.
      * @return command A command to perform the deletions, or null of there is nothing to delete.
      */
-    public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) {
-        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet());
+    public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) {
+        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data);
         for (OsmPrimitive osm : selection) {
             osm.visit(v);
@@ -138,7 +156,7 @@
         if (v.data.isEmpty())
             return null;
-        if (!checkAndConfirmOutlyingDeletes(v.data))
+        if (!checkAndConfirmOutlyingDeletes(layer,v.data))
             return null;
-        return new DeleteCommand(v.data);
+        return new DeleteCommand(layer,v.data);
     }
 
@@ -153,73 +171,89 @@
         }
         if (role.length() > 0)
-            return new ExtendedDialog(
-                    Main.parent,
-                    tr("Conflicting relation"),
-                    tr("Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?",
-                            formatter.getName(osm), formatter.getName(ref), role),
-                            new String[] {tr("Delete from relation"), tr("Cancel")},
-                            new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
+            return new ExtendedDialog(Main.parent, tr("Conflicting relation"), tr(
+                    "Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?", formatter
+                    .getName(osm), formatter.getName(ref), role), new String[] { tr("Delete from relation"),
+                tr("Cancel") }, new String[] { "dialogs/delete.png", "cancel.png" }).getValue();
         else
-            return new ExtendedDialog(Main.parent,
-                    tr("Conflicting relation"),
-                    tr("Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?",
-                            formatter.getName(osm), formatter.getName(ref)),
-                            new String[] {tr("Delete from relation"), tr("Cancel")},
-                            new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
-    }
-
-    public static Command delete(Collection<? extends OsmPrimitive> selection) {
-        return delete(selection, true);
+            return new ExtendedDialog(Main.parent, tr("Conflicting relation"), tr(
+                    "Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?", formatter.getName(osm),
+                    formatter.getName(ref)), new String[] { tr("Delete from relation"), tr("Cancel") }, new String[] {
+                "dialogs/delete.png", "cancel.png" }).getValue();
+    }
+
+    public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) {
+        return delete(layer, selection, true);
+    }
+
+    /**
+     * Replies the collection of nodes referred to by primitives in <code>primitivesToDelete</code> which
+     * can be deleted too. A node can be deleted if
+     * <ul>
+     *    <li>it is untagged (see {@see Node#isTagged()}</li>
+     *    <li>it is not referred to by other primitives outside of  <code>primitivesToDelete</code></li>
+     * <ul>
+     * @param layer  the layer in whose context primitives are deleted
+     * @param primitivesToDelete  the primitives to delete
+     * @return the collection of nodes referred to by primitives in <code>primitivesToDelete</code> which
+     * can be deleted too
+     */
+    protected static Collection<Node> computeNodesToDelete(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
+        Collection<Node> nodesToDelete = new HashSet<Node>();
+        for (OsmPrimitive osm : primitivesToDelete) {
+            if (! (osm instanceof Way) ) {
+                continue;
+            }
+            for (Node n : ((Way) osm).nodes) {
+                if (n.isTagged()) {
+                    continue;
+                }
+                CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false);
+                n.visit(v);
+                v.data.removeAll(primitivesToDelete);
+                if (v.data.isEmpty()) {
+                    nodesToDelete.add(n);
+                }
+            }
+        }
+        return nodesToDelete;
     }
 
     /**
      * Try to delete all given primitives.
-     *
+     * 
      * If a node is used by a way, it's removed from that way. If a node or a way is used by a
      * relation, inform the user and do not delete.
-     *
+     * 
      * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If
      * they are part of a relation, inform the user and do not delete.
-     *
+     * 
+     * @param layer the {@see OsmDataLayer} in whose context a primitive the primitives are deleted
      * @param selection The objects to delete.
      * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well
-     * @return command A command to perform the deletions, or null of there is nothing to delete.
-     */
-    public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) {
+     * @return command a command to perform the deletions, or null if there is nothing to delete.
+     */
+    public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) {
         if (selection.isEmpty())
             return null;
 
-        Collection<OsmPrimitive> del = new HashSet<OsmPrimitive>(selection);
+        Collection<OsmPrimitive> primitivesToDelete = new HashSet<OsmPrimitive>(selection);
         Collection<Way> waysToBeChanged = new HashSet<Way>();
         HashMap<OsmPrimitive, Collection<OsmPrimitive>> relationsToBeChanged = new HashMap<OsmPrimitive, Collection<OsmPrimitive>>();
 
         if (alsoDeleteNodesInWay) {
-            // Delete untagged nodes that are to be unreferenced.
-            Collection<OsmPrimitive> delNodes = new HashSet<OsmPrimitive>();
-            for (OsmPrimitive osm : del) {
-                if (osm instanceof Way) {
-                    for (Node n : ((Way) osm).nodes) {
-                        if (!n.isTagged()) {
-                            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false);
-                            n.visit(v);
-                            v.data.removeAll(del);
-                            if (v.data.isEmpty()) {
-                                delNodes.add(n);
-                            }
-                        }
-                    }
-                }
-            }
-            del.addAll(delNodes);
-        }
-
-        if (!checkAndConfirmOutlyingDeletes(del))
+            // delete untagged nodes only referenced by primitives in primitivesToDelete,
+            // too
+            Collection<Node> nodesToDelete = computeNodesToDelete(layer, primitivesToDelete);
+            primitivesToDelete.addAll(nodesToDelete);
+        }
+
+        if (!checkAndConfirmOutlyingDeletes(layer,primitivesToDelete))
             return null;
 
-        for (OsmPrimitive osm : del) {
-            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false);
+        for (OsmPrimitive osm : primitivesToDelete) {
+            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false);
             osm.visit(v);
             for (OsmPrimitive ref : v.data) {
-                if (del.contains(ref)) {
+                if (primitivesToDelete.contains(ref)) {
                     continue;
                 }
@@ -244,12 +278,12 @@
         for (Way w : waysToBeChanged) {
             Way wnew = new Way(w);
-            wnew.removeNodes(del);
+            wnew.removeNodes(primitivesToDelete);
             if (wnew.nodes.size() < 2) {
-                del.add(w);
-
-                CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false);
+                primitivesToDelete.add(w);
+
+                CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false);
                 w.visit(v);
                 for (OsmPrimitive ref : v.data) {
-                    if (del.contains(ref)) {
+                    if (primitivesToDelete.contains(ref)) {
                         continue;
                     }
@@ -296,19 +330,19 @@
         // deleted way is saved (or sent to the API) with a dangling reference to a node
         // Example:
-        //  <node id='2' action='delete' visible='true' version='1' ... />
-        //  <node id='1' action='delete' visible='true' version='1' ... />
-        //  <!-- missing node with id -1 because new deleted nodes are not persisted -->
-        //   <way id='3' action='delete' visible='true' version='1'>
-        //     <nd ref='1' />
-        //     <nd ref='-1' />  <!-- heres the problem -->
-        //     <nd ref='2' />
-        //   </way>
-        for (OsmPrimitive primitive : del) {
-            if (! (primitive instanceof Way)) {
+        // <node id='2' action='delete' visible='true' version='1' ... />
+        // <node id='1' action='delete' visible='true' version='1' ... />
+        // <!-- missing node with id -1 because new deleted nodes are not persisted -->
+        // <way id='3' action='delete' visible='true' version='1'>
+        // <nd ref='1' />
+        // <nd ref='-1' /> <!-- heres the problem -->
+        // <nd ref='2' />
+        // </way>
+        for (OsmPrimitive primitive : primitivesToDelete) {
+            if (!(primitive instanceof Way)) {
                 continue;
             }
-            Way w = (Way)primitive;
+            Way w = (Way) primitive;
             if (w.id == 0) { // new ways with id == 0 are fine,
-                continue;    // process existing ways only
+                continue; // process existing ways only
             }
             Way wnew = new Way(w);
@@ -317,5 +351,5 @@
             // nodes ...
             for (Node n : wnew.nodes) {
-                if (n.id == 0 && del.contains(n)) {
+                if (n.id == 0 && primitivesToDelete.contains(n)) {
                     nodesToStrip.add(n);
                 }
@@ -325,10 +359,10 @@
             wnew.nodes.removeAll(nodesToStrip);
             if (!nodesToStrip.isEmpty()) {
-                cmds.add(new ChangeCommand(w,wnew));
-            }
-        }
-
-        if (!del.isEmpty()) {
-            cmds.add(new DeleteCommand(del));
+                cmds.add(new ChangeCommand(w, wnew));
+            }
+        }
+
+        if (!primitivesToDelete.isEmpty()) {
+            cmds.add(new DeleteCommand(layer,primitivesToDelete));
         }
 
@@ -336,5 +370,5 @@
     }
 
-    public static Command deleteWaySegment(WaySegment ws) {
+    public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) {
         List<Node> n1 = new ArrayList<Node>(), n2 = new ArrayList<Node>();
 
@@ -343,5 +377,5 @@
 
         if (n1.size() < 2 && n2.size() < 2)
-            return new DeleteCommand(Collections.singleton(ws.way));
+            return new DeleteCommand(layer, Collections.singleton(ws.way));
 
         Way wnew = new Way(ws.way);
@@ -372,11 +406,15 @@
 
     /**
-     * Check whether user is about to delete data outside of the download area.
-     * Request confirmation if he is.
-     */
-    private static boolean checkAndConfirmOutlyingDeletes(Collection<OsmPrimitive> del) {
-        Area a = Main.main.getCurrentDataSet().getDataSourceArea();
+     * Check whether user is about to delete data outside of the download area. Request confirmation
+     * if he is.
+     * 
+     * @param layer the layer in whose context data is deleted
+     * @param primitivesToDelete the primitives to delete
+     * @return true, if deleting outlying primitives is OK; false, otherwise
+     */
+    private static boolean checkAndConfirmOutlyingDeletes(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
+        Area a = layer.data.getDataSourceArea();
         if (a != null) {
-            for (OsmPrimitive osm : del) {
+            for (OsmPrimitive osm : primitivesToDelete) {
                 if (osm instanceof Node && osm.id != 0) {
                     Node n = (Node) osm;
@@ -385,10 +423,10 @@
                         msg.add(new JLabel(
                                 "<html>" +
-                                // leave message in one tr() as there is a grammatical connection.
-                                tr("You are about to delete nodes outside of the area you have downloaded." +
-                                        "<br>" +
-                                        "This can cause problems because other objects (that you don't see) might use them." +
-                                        "<br>" +
-                                "Do you really want to delete?") + "</html>"));
+                                // leave message in one tr() as there is a grammatical
+                                // connection.
+                                tr("You are about to delete nodes outside of the area you have downloaded."
+                                        + "<br>"
+                                        + "This can cause problems because other objects (that you don't see) might use them."
+                                        + "<br>" + "Do you really want to delete?") + "</html>"));
                         return ConditionalOptionPaneUtil.showConfirmationDialog(
                                 "delete_outside_nodes",
Index: trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 1856)
@@ -3,4 +3,5 @@
 
 import java.awt.geom.Area;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -422,4 +423,28 @@
     }
 
-
+    /**
+     * Replies a list of parent relations which refer to the relation
+     * <code>child</code>. Replies an empty list if child is null.
+     * 
+     * @param child the child relation
+     * @return a list of parent relations which refer to the relation
+     * <code>child</code>
+     */
+    public List<Relation> getParentRelations(Relation child) {
+        ArrayList<Relation> parents = new ArrayList<Relation>();
+        if (child == null)
+            return parents;
+        for (Relation parent : relations) {
+            if (parent == child) {
+                continue;
+            }
+            for (RelationMember member: parent.members) {
+                if (member.refersTo(child)) {
+                    parents.add(parent);
+                    break;
+                }
+            }
+        }
+        return parents;
+    }
 }
Index: trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java	(revision 1856)
@@ -36,4 +36,16 @@
     }
 
+    /**
+     * Replies true, if this relation member refers to the primitive
+     * 
+     * @param primitive  the primitive to check
+     * @return true, if this relation member refers to the primitive
+     */
+    public boolean refersTo(OsmPrimitive primitive) {
+        if (primitive == null) return false;
+        if (member == null) return false;
+        return member == primitive;
+    }
+
     @Override
     public int hashCode() {
Index: trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java	(revision 1856)
@@ -65,4 +65,5 @@
         bTexts = buttonTexts;
         setupDialog(lbl, buttonIcons);
+        setAlwaysOnTop(true);
         setVisible(true);
     }
@@ -195,3 +196,11 @@
         rootPane.getActionMap().put("ESCAPE", actionListener);
     }
+
+    @Override
+    public void setVisible(boolean visible) {
+        super.setVisible(visible);
+        if (visible) {
+            toFront();
+        }
+    }
 }
Index: trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java	(revision 1856)
@@ -47,9 +47,14 @@
             public void componentShown(ComponentEvent e) {}
             public void componentResized(ComponentEvent ev) {
-               int w = getWidth();
-               if(w > 200)
-                   Main.pref.putInteger("progressdialog.size",w);
+                int w = getWidth();
+                if(w > 200) {
+                    Main.pref.putInteger("progressdialog.size",w);
+                }
             }
         });
+        // make sure this dialog is always on top of the main JOSM window
+        // and all the other windows (relation editors, detached dialogs, etc.)
+        //
+        setAlwaysOnTop(true);
     }
 
@@ -84,3 +89,14 @@
         setSize(Main.pref.getInteger("progressdialog.size", 600), 120);
     }
+
+    @Override
+    public void setVisible(boolean visible) {
+        super.setVisible(visible);
+        if (visible) {
+            // make sure this dialog is always on top of the main JOSM window
+            // and all the other windows (relation editors, detached dialogs, etc.)
+            //
+            toFront();
+        }
+    }
 }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 1856)
@@ -11,9 +11,12 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 import javax.swing.AbstractAction;
 import javax.swing.DefaultListModel;
 import javax.swing.JList;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
@@ -23,10 +26,18 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.command.ChangeCommand;
+import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.DeleteCommand;
+import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
+import org.openstreetmap.josm.gui.OptionPaneUtil;
 import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.gui.SideButton;
+import org.openstreetmap.josm.gui.dialogs.relation.ParentRelationLoadingTask;
+import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager;
 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
 import org.openstreetmap.josm.gui.layer.DataChangeListener;
@@ -34,7 +45,10 @@
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
+import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.Shortcut;
+
+import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
 
 /**
@@ -46,4 +60,5 @@
  */
 public class RelationListDialog extends ToggleDialog implements LayerChangeListener, DataChangeListener {
+    static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
 
     /**
@@ -270,4 +285,6 @@
      */
     class DeleteAction extends AbstractAction implements ListSelectionListener, Runnable {
+        class AbortException extends Exception {}
+
         public DeleteAction() {
             putValue(SHORT_DESCRIPTION,tr("Delete the selected relation"));
@@ -282,6 +299,8 @@
             if (toDelete == null)
                 return;
-            Main.main.undoRedo.add(
-                    new DeleteCommand(Collections.singleton(toDelete)));
+            org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation(
+                    Main.main.getEditLayer(),
+                    toDelete
+            );
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java	(revision 1856)
@@ -24,5 +24,4 @@
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -33,5 +32,4 @@
 import javax.swing.JButton;
 import javax.swing.JComponent;
-import javax.swing.JDialog;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
@@ -54,4 +52,5 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.DeleteAction;
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.command.ChangeCommand;
@@ -492,6 +491,12 @@
         pnl.add(new JButton(moveDownAction), gc);
 
+        // -- edit action
+        gc.gridy = 2;
+        EditAction editAction = new EditAction();
+        memberTableModel.getSelectionModel().addListSelectionListener(editAction);
+        pnl.add(new JButton(editAction),gc);
+
         // ------
-        gc.gridy = 2;
+        gc.gridy = 3;
         RemoveAction removeSelectedAction = new RemoveAction();
         memberTable.getSelectionModel().addListSelectionListener(removeSelectedAction);
@@ -499,5 +504,5 @@
 
         // ------
-        gc.gridy = 3;
+        gc.gridy = 4;
         SortAction sortAction = new SortAction();
         pnl.add(new JButton(sortAction), gc);
@@ -505,5 +510,5 @@
         // ------
         // just grab the remaining space
-        gc.gridy = 4;
+        gc.gridy = 5;
         gc.weighty = 1.0;
         gc.fill = GridBagConstraints.BOTH;
@@ -578,5 +583,9 @@
     protected JPanel buildButtonPanel() {
         JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+
+        // --- download members
         buttonPanel.add(new SideButton(new DownlaodAction()));
+
+        // --- role editing
         buttonPanel.add(new JLabel(tr("Role:")));
         tfRole = new JTextField(10);
@@ -596,8 +605,6 @@
         buttonPanel.add(new SideButton(new DuplicateRelationAction()));
 
-        // -- edit action
-        EditAction editAction = new EditAction();
-        memberTableModel.getSelectionModel().addListSelectionListener(editAction);
-        buttonPanel.add(new SideButton(editAction));
+        // --- delete relation action
+        buttonPanel.add(new SideButton(new DeleteCurrentRelationAction()));
         return buttonPanel;
     }
@@ -866,5 +873,5 @@
     class RemoveSelectedAction extends AbstractAction implements TableModelListener {
         public RemoveSelectedAction() {
-            putValue(SHORT_DESCRIPTION, tr("Remove all currently selected objects from relation"));
+            putValue(SHORT_DESCRIPTION, tr("Remove all members referring to one of the selected primitives"));
             putValue(SMALL_ICON, ImageProvider.get("dialogs", "removeselected"));
             // putValue(NAME, tr("Remove Selected"));
@@ -951,5 +958,5 @@
     class RemoveAction extends AbstractAction implements ListSelectionListener {
         public RemoveAction() {
-            putValue(SHORT_DESCRIPTION, tr("Remove the member in the current table row from this relation"));
+            putValue(SHORT_DESCRIPTION, tr("Remove the currently selected members from this relation"));
             putValue(SMALL_ICON, ImageProvider.get("dialogs", "remove"));
             // putValue(NAME, tr("Remove"));
@@ -965,4 +972,31 @@
         public void valueChanged(ListSelectionEvent e) {
             setEnabled(memberTableModel.canRemove(memberTable.getSelectedRows()));
+        }
+    }
+
+    class DeleteCurrentRelationAction extends AbstractAction {
+        public DeleteCurrentRelationAction() {
+            putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation"));
+            putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
+            putValue(NAME, tr("Delete"));
+            updateEnabledState();
+        }
+
+        public void run() {
+            Relation toDelete = getRelation();
+            if (toDelete == null)
+                return;
+            org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation(
+                    getLayer(),
+                    toDelete
+            );
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            run();
+        }
+
+        protected void updateEnabledState() {
+            setEnabled(getRelation() != null);
         }
     }
@@ -1211,5 +1245,5 @@
             putValue(SHORT_DESCRIPTION, tr("Edit the relation the currently selected relation member refers to"));
             putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit"));
-            putValue(NAME, tr("Edit"));
+            //putValue(NAME, tr("Edit"));
             refreshEnabled();
         }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java	(revision 1856)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java	(revision 1856)
@@ -0,0 +1,205 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.gui.dialogs.relation;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.DataSource;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
+import org.openstreetmap.josm.gui.OptionPaneUtil;
+import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
+import org.openstreetmap.josm.io.OsmApi;
+import org.openstreetmap.josm.io.OsmServerBackreferenceReader;
+import org.openstreetmap.josm.io.OsmTransferException;
+import org.xml.sax.SAXException;
+
+/**
+ * This is an asynchronous task for loading the parents of a given relation.
+ * 
+ * Typical usage:
+ * <pre>
+ *  final ParentRelationLoadingTask task = new ParentRelationLoadingTask(
+ *                   child,   // the child relation
+ *                   Main.main.getEditLayer(), // the edit layer
+ *                   true,  // load fully
+ *                   new PleaseWaitProgressMonitor()  // a progress monitor
+ *   );
+ *   task.setContinuation(
+ *       new Runnable() {
+ *          public void run() {
+ *              if (task.isCancelled() || task.hasError())
+ *                  return;
+ *              List<Relation> parents = task.getParents();
+ *              // do something with the parent relations
+ *       }
+ *   );
+ *
+ *   // start the task
+ *   Main.worker.submit(task);
+ * </pre>
+ *
+ */
+public class ParentRelationLoadingTask extends PleaseWaitRunnable{
+    private boolean cancelled;
+    private Exception lastException;
+    private DataSet referrers;
+    private boolean full;
+    private OsmDataLayer layer;
+    private Relation child;
+    private ArrayList<Relation> parents;
+    private Runnable continuation;
+
+    /**
+     * Creates a new task for asynchronously downloading the parents of a child relation.
+     * 
+     * @param child the child relation. Must not be null. Must have an id > 0.
+     * @param layer  the OSM data layer. Must not be null.
+     * @param full if true, parent relations are fully downloaded (i.e. with their members)
+     * @param monitor the progress monitor to be used
+     * 
+     * @exception IllegalArgumentException thrown if child is null
+     * @exception IllegalArgumentException thrown if layer is null
+     * @exception IllegalArgumentException thrown if child.id == 0
+     */
+    public ParentRelationLoadingTask(Relation child, OsmDataLayer layer, boolean full, PleaseWaitProgressMonitor monitor ) {
+        super(tr("Download referring relations"), monitor, false /* don't ignore exception */);
+        if (child == null)
+            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "child"));
+        if (layer == null)
+            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "layer"));
+        if (child.id == 0)
+            throw new IllegalArgumentException(tr("child.id >0 expected. Got {1}", child.id));
+        referrers = null;
+        this.layer = layer;
+        parents = new ArrayList<Relation>();
+        this.child = child;
+    }
+
+    /**
+     * Set a continuation which is called upon the job finished.
+     * 
+     * @param continuation the continuation
+     */
+    public void setContinuation(Runnable continuation) {
+        this.continuation = continuation;
+    }
+
+    /**
+     * Replies true if this has been cancelled by the user.
+     * 
+     * @return true if this has been cancelled by the user.
+     */
+    public boolean isCancelled() {
+        return cancelled;
+    }
+
+    /**
+     * Replies true if an exception has been caught during the execution of this task.
+     * 
+     * @return true if an exception has been caught during the execution of this task.
+     */
+    public boolean hasError() {
+        return lastException != null;
+    }
+
+
+    protected OsmDataLayer getLayer() {
+        return layer;
+    }
+
+    public List<Relation> getParents() {
+        return parents;
+    }
+
+    @Override
+    protected void cancel() {
+        cancelled = true;
+        OsmApi.getOsmApi().cancel();
+    }
+
+    protected void showLastException() {
+        String msg = lastException.getMessage();
+        if (msg == null) {
+            msg = lastException.toString();
+        }
+        OptionPaneUtil.showMessageDialog(
+                Main.parent,
+                msg,
+                tr("Error"),
+                JOptionPane.ERROR_MESSAGE
+        );
+    }
+
+    @Override
+    protected void finish() {
+        if (cancelled) return;
+        if (lastException != null) {
+            showLastException();
+            return;
+        }
+        parents.clear();
+        for (Relation parent : referrers.relations) {
+            parents.add((Relation)getLayer().data.getPrimitiveById(parent.id));
+        }
+        if (continuation != null) {
+            continuation.run();
+        }
+    }
+
+    @Override
+    protected void realRun() throws SAXException, IOException, OsmTransferException {
+        try {
+            progressMonitor.indeterminateSubTask(null);
+            OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(child, full);
+            referrers = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false));
+            if (referrers != null) {
+                final MergeVisitor visitor = new MergeVisitor(getLayer().data, referrers);
+                visitor.merge();
+
+                // copy the merged layer's data source info
+                for (DataSource src : referrers.dataSources) {
+                    getLayer().data.dataSources.add(src);
+                }
+                // FIXME: this is necessary because there are  dialogs listening
+                // for DataChangeEvents which manipulate Swing components on this
+                // thread.
+                //
+                SwingUtilities.invokeLater(
+                        new Runnable() {
+                            public void run() {
+                                getLayer().fireDataChange();
+                            }
+                        }
+                );
+
+                if (visitor.getConflicts().isEmpty())
+                    return;
+                getLayer().getConflicts().add(visitor.getConflicts());
+                OptionPaneUtil.showMessageDialog(
+                        Main.parent,
+                        tr("There were {0} conflicts during import.",
+                                visitor.getConflicts().size()),
+                                tr("Warning"),
+                                JOptionPane.WARNING_MESSAGE
+                );
+            }
+        } catch(Exception e) {
+            if (cancelled) {
+                System.out.println(tr("Warning: ignoring exception because task is cancelled. Exception: {0}", e.toString()));
+                return;
+            }
+            lastException = e;
+        }
+    }
+}
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowser.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowser.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowser.java	(revision 1856)
@@ -118,5 +118,19 @@
         public void actionPerformed(ActionEvent e) {
             boolean full = cbReadFull.isSelected();
-            ReloadTask task = new ReloadTask(full, relationEditor);
+            final ParentRelationLoadingTask task = new ParentRelationLoadingTask(
+                    model.getRelation(),
+                    getLayer(),
+                    full,
+                    new PleaseWaitProgressMonitor()
+            );
+            task.setContinuation(
+                    new Runnable() {
+                        public void run() {
+                            if (task.isCancelled() || task.hasError())
+                                return;
+                            model.populate(task.getParents());
+                        }
+                    }
+            );
             Main.worker.submit(task);
         }
@@ -177,103 +191,3 @@
         }
     }
-
-    /**
-     * Asynchronous task for loading the parent relations
-     *
-     */
-    class ReloadTask extends PleaseWaitRunnable {
-        private boolean cancelled;
-        private Exception lastException;
-        private DataSet referrers;
-        private boolean full;
-
-        public ReloadTask(boolean full, Dialog parent) {
-            super(tr("Download referring relations"), new PleaseWaitProgressMonitor(parent), false /* don't ignore exception */);
-            referrers = null;
-        }
-        @Override
-        protected void cancel() {
-            cancelled = true;
-            OsmApi.getOsmApi().cancel();
-        }
-
-        protected void showLastException() {
-            String msg = lastException.getMessage();
-            if (msg == null) {
-                msg = lastException.toString();
-            }
-            OptionPaneUtil.showMessageDialog(
-                    Main.parent,
-                    msg,
-                    tr("Error"),
-                    JOptionPane.ERROR_MESSAGE
-            );
-        }
-
-        @Override
-        protected void finish() {
-            if (cancelled) return;
-            if (lastException != null) {
-                showLastException();
-                return;
-            }
-            final ArrayList<Relation> parents = new ArrayList<Relation>();
-            for (Relation parent : referrers.relations) {
-                parents.add((Relation)getLayer().data.getPrimitiveById(parent.id));
-            }
-            SwingUtilities.invokeLater(
-                    new Runnable() {
-                        public void run() {
-                            model.populate(parents);
-                        }
-                    }
-            );
-        }
-
-        @Override
-        protected void realRun() throws SAXException, IOException, OsmTransferException {
-            try {
-                progressMonitor.indeterminateSubTask(null);
-                OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(model.getRelation(), full);
-                referrers = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false));
-                if (referrers != null) {
-                    final MergeVisitor visitor = new MergeVisitor(getLayer().data, referrers);
-                    visitor.merge();
-
-                    // copy the merged layer's data source info
-                    for (DataSource src : referrers.dataSources) {
-                        getLayer().data.dataSources.add(src);
-                    }
-                    // FIXME: this is necessary because there are  dialogs listening
-                    // for DataChangeEvents which manipulate Swing components on this
-                    // thread.
-                    //
-                    SwingUtilities.invokeLater(
-                            new Runnable() {
-                                public void run() {
-                                    getLayer().fireDataChange();
-                                }
-                            }
-                    );
-
-                    if (visitor.getConflicts().isEmpty())
-                        return;
-                    getLayer().getConflicts().add(visitor.getConflicts());
-                    OptionPaneUtil.showMessageDialog(
-                            Main.parent,
-                            tr("There were {0} conflicts during import.",
-                                    visitor.getConflicts().size()),
-                                    tr("Warning"),
-                                    JOptionPane.WARNING_MESSAGE
-                    );
-                }
-            } catch(Exception e) {
-                if (cancelled) {
-                    System.out.println(tr("Warning: ignoring exception because task is cancelled. Exception: {0}", e.toString()));
-                    return;
-                }
-                lastException = e;
-            }
-        }
-    }
 }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java	(revision 1856)
@@ -3,4 +3,5 @@
 
 import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.AbstractListModel;
@@ -55,5 +56,5 @@
     }
 
-    public void populate(ArrayList<Relation> parents) {
+    public void populate(List<Relation> parents) {
         referrers.clear();
         if (parents != null) {
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java	(revision 1855)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java	(revision 1856)
@@ -119,4 +119,18 @@
         openDialogs.put(context, editor);
         editor.addWindowListener(this);
+    }
+
+    /**
+     * Closes the editor open for a specific layer and a specific relation.
+     * 
+     * @param layer  the layer
+     * @param relation the relation
+     */
+    public void close(OsmDataLayer layer, Relation relation) {
+        DialogContext context = new DialogContext(layer, relation);
+        RelationEditor editor = openDialogs.get(context);
+        if (editor != null) {
+            editor.setVisible(false);
+        }
     }
 
