Index: trunk/src/org/openstreetmap/josm/Main.java
===================================================================
--- trunk/src/org/openstreetmap/josm/Main.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/Main.java	(revision 1814)
@@ -77,8 +77,5 @@
      */
     public static Preferences pref = new Preferences();
-    /**
-     * The global dataset.
-     */
-    public static DataSet ds = new DataSet();
+
     /**
      * The global paste buffer.
@@ -167,7 +164,4 @@
         if (map != null) {
             map.mapView.removeLayer(layer);
-            if (layer instanceof OsmDataLayer) {
-                ds = new DataSet();
-            }
             if (map.mapView.getAllLayers().isEmpty()) {
                 setMapFrame(null);
@@ -224,28 +218,38 @@
         map.mapView.addLayer(layer);
     }
-    /**
-     * Replies the current edit layer. Creates one if no {@see OsmDataLayer}
-     * exists. Replies null, if the currently active layer isn't an instance
-     * of {@see OsmDataLayer}.
+
+    /**
+     * Replies true if there is an edit layer which is currently
+     * active
      *
-     * @return the current edit layer
-     */
-    public final OsmDataLayer createOrGetEditLayer() {
-        if (map == null || map.mapView.getEditLayer() == null) {
-            menu.newAction.actionPerformed(null);
-        }
-        return map.mapView.getEditLayer();
-    }
-
-    /**
-     * Replies true if this map view has an edit layer
-     *
-     * @return true if this map view has an edit layer
-     */
-    public boolean hasEditLayer() {
+     * @return true if there is an edit layer which is currently
+     * active
+     */
+    public boolean hasActiveEditLayer() {
         if (map == null) return false;
         if (map.mapView == null) return false;
         if (map.mapView.getEditLayer() == null) return false;
         return true;
+    }
+
+    /**
+     * Replies the current edit layer
+     * 
+     * @return the current edit layer. null, if no current edit layer exists
+     */
+    public OsmDataLayer getEditLayer() {
+        if (map == null) return null;
+        if (map.mapView == null) return null;
+        return map.mapView.getEditLayer();
+    }
+
+    /**
+     * Replies the current data set.
+     *
+     * @return the current data set. null, if no current data set exists
+     */
+    public DataSet getCurrentDataSet() {
+        if (!hasActiveEditLayer()) return null;
+        return getEditLayer().data;
     }
 
@@ -495,3 +499,5 @@
         pref.put("gui.geometry", newGeometry);
     }
+
+
 }
Index: trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java	(revision 1814)
@@ -46,5 +46,5 @@
 
     protected void launchBrowser() {
-        ArrayList<OsmPrimitive> primitivesToShow = new ArrayList<OsmPrimitive>(Main.ds.getSelected());
+        ArrayList<OsmPrimitive> primitivesToShow = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected());
 
         // filter out new primitives which are not yet uploaded to the server
Index: trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java	(revision 1814)
@@ -79,5 +79,5 @@
         /* Now execute the commands to add the dupicated contents of the paste buffer to the map */
         Main.main.undoRedo.add(new AddCommand(nnew));
-        Main.ds.setSelected(nnew);
+        getCurrentDataSet().setSelected(nnew);
         Main.map.mapView.repaint();
     }
Index: trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java	(revision 1814)
@@ -79,5 +79,5 @@
 
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         Collection<Node> nodes = new LinkedList<Node>();
         Collection<Way> ways = new LinkedList<Way>();
Index: trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java	(revision 1814)
@@ -31,5 +31,5 @@
     public AlignInLineAction() {
         super(tr("Align Nodes in Line"), "alignline", tr("Move the selected nodes in to a line."),
-        Shortcut.registerShortcut("tools:alignline", tr("Tool: {0}", tr("Align Nodes in Line")), KeyEvent.VK_L, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:alignline", tr("Tool: {0}", tr("Align Nodes in Line")), KeyEvent.VK_L, Shortcut.GROUP_EDIT), true);
     }
 
@@ -40,5 +40,5 @@
      */
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         Collection<Node> nodes = new LinkedList<Node>();
         Collection<Node> itnodes = new LinkedList<Node>();
@@ -50,5 +50,5 @@
         // special case if no single nodes are selected and exactly one way is:
         // then use the way's nodes
-        if ((nodes.size() == 0) && (sel.size() == 1))
+        if ((nodes.size() == 0) && (sel.size() == 1)) {
             for (OsmPrimitive osm : sel)
                 if (osm instanceof Way) {
@@ -56,4 +56,5 @@
                     itnodes.addAll(((Way)osm).nodes);
                 }
+        }
         if (nodes.size() < 3) {
             JOptionPane.showMessageDialog(Main.parent, tr("Please select at least three nodes."));
Index: trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java	(revision 1814)
@@ -100,5 +100,5 @@
                     List<OsmPrimitive> newNodes = new LinkedList<OsmPrimitive>();
                     newNodes.add(osmPrimitive);
-                    Main.ds.setSelected(newNodes);
+                    Main.main.getCurrentDataSet().setSelected(newNodes);
                     return false;
                 }
@@ -120,5 +120,5 @@
                 newNodes.add(osmPrimitive);
 
-                Main.ds.setSelected(newNodes);
+                Main.main.getCurrentDataSet().setSelected(newNodes);
                 return false;
             }
Index: trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java	(revision 1814)
@@ -79,5 +79,5 @@
             Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>();
             if (mode.equals("selection")) {
-                sel = Main.ds.getSelected();
+                sel = getCurrentDataSet().getSelected();
             } else if (mode.equals("conflict")) {
                 if (Main.map.conflictDialog.getConflicts() != null) {
Index: trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java	(revision 1814)
@@ -52,15 +52,16 @@
     public CombineWayAction() {
         super(tr("Combine Way"), "combineway", tr("Combine several ways into one."),
-        Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true);
         DataSet.selListeners.add(this);
     }
 
     public void actionPerformed(ActionEvent event) {
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
         LinkedList<Way> selectedWays = new LinkedList<Way>();
 
         for (OsmPrimitive osm : selection)
-            if (osm instanceof Way)
+            if (osm instanceof Way) {
                 selectedWays.add((Way)osm);
+            }
 
         if (selectedWays.size() < 2) {
@@ -82,6 +83,8 @@
             new HashMap<Pair<Relation,String>, HashSet<Way>>();
         HashSet<Relation> relationsUsingWays = new HashSet<Relation>();
-        for (Relation r : Main.ds.relations) {
-            if (r.deleted || r.incomplete) continue;
+        for (Relation r : getCurrentDataSet().relations) {
+            if (r.deleted || r.incomplete) {
+                continue;
+            }
             for (RelationMember rm : r.members) {
                 if (rm.member instanceof Way) {
@@ -112,8 +115,10 @@
                         tr("Combine ways with different memberships?"),
                         tr("The selected ways have differing relation memberships.  "
-                            + "Do you still want to combine them?"),
-                        new String[] {tr("Combine Anyway"), tr("Cancel")},
-                        new String[] {"combineway.png", "cancel.png"}).getValue();
-                if (option == 1) break;
+                                + "Do you still want to combine them?"),
+                                new String[] {tr("Combine Anyway"), tr("Cancel")},
+                                new String[] {"combineway.png", "cancel.png"}).getValue();
+                if (option == 1) {
+                    break;
+                }
 
                 return;
@@ -125,6 +130,7 @@
         for (Way w : selectedWays) {
             for (Entry<String,String> e : w.entrySet()) {
-                if (!props.containsKey(e.getKey()))
+                if (!props.containsKey(e.getKey())) {
                     props.put(e.getKey(), new TreeSet<String>());
+                }
                 props.get(e.getKey()).add(e.getValue());
             }
@@ -139,9 +145,9 @@
             if (secondTry instanceof List) {
                 int option = new ExtendedDialog(Main.parent,
-                    tr("Change directions?"),
-                    tr("The ways can not be combined in their current directions.  "
-                        + "Do you want to reverse some of them?"),
-                    new String[] {tr("Reverse and Combine"), tr("Cancel")},
-                    new String[] {"wayflip.png", "cancel.png"}).getValue();
+                        tr("Change directions?"),
+                        tr("The ways can not be combined in their current directions.  "
+                                + "Do you want to reverse some of them?"),
+                                new String[] {tr("Reverse and Combine"), tr("Cancel")},
+                                new String[] {"wayflip.png", "cancel.png"}).getValue();
                 if (option != 1) return;
                 nodeList = (List<Node>) secondTry;
@@ -160,5 +166,7 @@
         for (Way w : selectedWays) {
             modifyWay = w;
-            if (w.id != 0) break;
+            if (w.id != 0) {
+                break;
+            }
         }
         Way newWay = new Way(modifyWay);
@@ -188,12 +196,13 @@
         if (!components.isEmpty()) {
             int answer = new ExtendedDialog(Main.parent,
-                tr("Enter values for all conflicts."),
-                p,
-                new String[] {tr("Solve Conflicts"), tr("Cancel")},
-                new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();
+                    tr("Enter values for all conflicts."),
+                    p,
+                    new String[] {tr("Solve Conflicts"), tr("Cancel")},
+                    new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();
             if (answer != 1) return;
 
-            for (Entry<String, JComboBox> e : components.entrySet())
+            for (Entry<String, JComboBox> e : components.entrySet()) {
                 newWay.put(e.getKey(), e.getValue().getEditor().getItem().toString());
+            }
         }
 
@@ -224,5 +233,5 @@
         }
         Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds));
-        Main.ds.setSelected(modifyWay);
+        getCurrentDataSet().setSelected(modifyWay);
     }
 
@@ -242,12 +251,12 @@
 
         HashSet<Pair<Node,Node>> chunkSet = new HashSet<Pair<Node,Node>>();
-        for (Way w : ways)
+        for (Way w : ways) {
             chunkSet.addAll(w.getNodePairs(ignoreDirection));
+        }
 
         LinkedList<Pair<Node,Node>> chunks = new LinkedList<Pair<Node,Node>>(chunkSet);
 
-        if (chunks.isEmpty()) {
+        if (chunks.isEmpty())
             return tr("All the ways were empty");
-        }
 
         List<Node> nodeList = Pair.toArrayList(chunks.poll());
@@ -273,11 +282,12 @@
                 break;
             }
-            if (!foundChunk) break;
-        }
-
-        if (!chunks.isEmpty()) {
+            if (!foundChunk) {
+                break;
+            }
+        }
+
+        if (!chunks.isEmpty())
             return tr("Could not combine ways "
-                + "(They could not be merged into a single string of nodes)");
-        }
+                    + "(They could not be merged into a single string of nodes)");
 
         return nodeList;
Index: trunk/src/org/openstreetmap/josm/actions/CopyAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/CopyAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/CopyAction.java	(revision 1814)
@@ -45,8 +45,8 @@
 
     public void actionPerformed(ActionEvent e) {
-        if(noSelection()) return;
+        if(isEmptySelection()) return;
 
         Main.pasteBuffer = copyData();
-        Main.pasteSource = Main.main.createOrGetEditLayer();
+        Main.pasteSource = getEditLayer();
         Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */
 
@@ -56,5 +56,5 @@
     }
 
-    public static DataSet copyData() {
+    public DataSet copyData() {
         /* New pasteBuffer - will be assigned to the global one at the end */
         final DataSet pasteBuffer = new DataSet();
@@ -62,5 +62,5 @@
         /* temporarily maps old nodes to new so we can do a true deep copy */
 
-        if(noSelection()) return pasteBuffer;
+        if(isEmptySelection()) return pasteBuffer;
 
         /* scan the selected objects, mapping them to copies; when copying a way or relation,
@@ -71,5 +71,6 @@
                  * or a way and a node in that way is selected, we'll see it twice, once via the
                  * way and once directly; and so on. */
-                if (map.containsKey(n)) { return; }
+                if (map.containsKey(n))
+                    return;
                 Node nnew = new Node(n);
                 map.put(n, nnew);
@@ -78,5 +79,6 @@
             public void visit(Way w) {
                 /* check if already in pasteBuffer - could have come from a relation, and directly etc. */
-                if (map.containsKey(w)) { return; }
+                if (map.containsKey(w))
+                    return;
                 Way wnew = new Way();
                 wnew.cloneFrom(w);
@@ -93,5 +95,6 @@
             }
             public void visit(Relation e) {
-                if (map.containsKey(e)) { return; }
+                if (map.containsKey(e))
+                    return;
                 Relation enew = new Relation(e);
                 List<RelationMember> members = new ArrayList<RelationMember>();
@@ -108,14 +111,18 @@
             }
             public void visitAll() {
-                for (OsmPrimitive osm : Main.ds.getSelected())
+                for (OsmPrimitive osm : getCurrentDataSet().getSelected()) {
                     osm.visit(this);
+                }
 
                 // Used internally only (in PasteTagsAction), therefore no need to translate these
-                if(Main.ds.getSelectedNodes().size() > 0)
+                if(getCurrentDataSet().getSelectedNodes().size() > 0) {
                     pasteBuffer.dataSources.add(new DataSource(null, "Copied Nodes"));
-                if(Main.ds.getSelectedWays().size() > 0)
+                }
+                if(getCurrentDataSet().getSelectedWays().size() > 0) {
                     pasteBuffer.dataSources.add(new DataSource(null, "Copied Ways"));
-                if(Main.ds.getSelectedRelations().size() > 0)
+                }
+                if(getCurrentDataSet().getSelectedRelations().size() > 0) {
                     pasteBuffer.dataSources.add(new DataSource(null, "Copied Relations"));
+                }
             }
         }.visitAll();
@@ -128,9 +135,11 @@
     }
 
-    private static boolean noSelection() {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+    private boolean isEmptySelection() {
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         if (sel.isEmpty()) {
-            JOptionPane.showMessageDialog(Main.parent,
-                    tr("Please select something to copy."));
+            JOptionPane.showMessageDialog(
+                    Main.parent,
+                    tr("Please select something to copy.")
+            );
             return true;
         }
Index: trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 1814)
@@ -80,5 +80,5 @@
         }
 
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         Collection<Node> nodes = new LinkedList<Node>();
         Way existingWay = null;
@@ -170,5 +170,5 @@
             if (a1 < 999) {
                 // if it is, delete it
-                CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(Main.ds);
+                CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(getCurrentDataSet());
                 refs.visit(n1);
                 if (refs.data.isEmpty() || ((refs.data.size() == 1) && (refs.data.contains(existingWay)))) {
Index: trunk/src/org/openstreetmap/josm/actions/DistributeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/DistributeAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/DistributeAction.java	(revision 1814)
@@ -29,5 +29,5 @@
     public DistributeAction() {
         super(tr("Distribute Nodes"), "distribute", tr("Distribute the selected nodes to equal distances along a line."),
-        Shortcut.registerShortcut("tools:distribute", tr("Tool: {0}", tr("Distribute Nodes")), KeyEvent.VK_B, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:distribute", tr("Tool: {0}", tr("Distribute Nodes")), KeyEvent.VK_B, Shortcut.GROUP_EDIT), true);
     }
 
@@ -38,5 +38,5 @@
      */
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         Collection<Node> nodes = new LinkedList<Node>();
         Collection<Node> itnodes = new LinkedList<Node>();
@@ -48,5 +48,5 @@
         // special case if no single nodes are selected and exactly one way is:
         // then use the way's nodes
-        if ((nodes.size() == 0) && (sel.size() == 1))
+        if ((nodes.size() == 0) && (sel.size() == 1)) {
             for (OsmPrimitive osm : sel)
                 if (osm instanceof Way) {
@@ -54,4 +54,5 @@
                     itnodes.addAll(((Way)osm).nodes);
                 }
+        }
 
         if (nodes.size() < 3) {
Index: trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java	(revision 1814)
@@ -9,28 +9,53 @@
 import java.util.Collection;
 
-import org.openstreetmap.josm.actions.CopyAction;
-import org.openstreetmap.josm.actions.PasteAction;
 import org.openstreetmap.josm.data.SelectionChangedListener;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
-import org.openstreetmap.josm.Main;
 
-public final class DuplicateAction extends JosmAction implements SelectionChangedListener {
+public final class DuplicateAction extends JosmAction implements SelectionChangedListener, LayerChangeListener {
 
     public DuplicateAction() {
         super(tr("Duplicate"), "duplicate",
-            tr("Duplicate selection by copy and immediate paste."),
-            Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true);
+                tr("Duplicate selection by copy and immediate paste."),
+                Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true);
         setEnabled(false);
         DataSet.selListeners.add(this);
+        Layer.listeners.add(this);
     }
 
     public void actionPerformed(ActionEvent e) {
-        PasteAction.pasteData(CopyAction.copyData(), Main.main.createOrGetEditLayer(), e);
+        new PasteAction().pasteData(new CopyAction().copyData(), getEditLayer(), e);
     }
 
+
+    protected void refreshEnabled() {
+        setEnabled(getCurrentDataSet() != null
+                && ! getCurrentDataSet().getSelected().isEmpty()
+        );
+    }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface SelectionChangeListener                                                  */
+    /* ---------------------------------------------------------------------------------- */
     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
-        setEnabled(! newSelection.isEmpty());
+        refreshEnabled();
+    }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
     }
 }
Index: trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java	(revision 1814)
@@ -84,5 +84,5 @@
     public void export(Layer layer) {
         if (layer == null)
-            throw new IllegalArgumentException(tr("paramenter ''{0'' must not be null", "layer"));
+            throw new IllegalArgumentException(tr("paramenter ''{0}'' must not be null", "layer"));
         if (! (layer instanceof OsmDataLayer) && ! (layer instanceof GpxLayer))
             throw new IllegalArgumentException(tr("expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName()));
@@ -98,5 +98,24 @@
     }
 
-    public static void exportGpx(File file, Layer layer) {
+    /**
+     * Exports a layer to a file.
+     * 
+     * <code>layer</code> must not be null. <code>layer</code> must be an instance of
+     * {@see OsmDataLayer} or {@see GpxLayer}.
+     * 
+     * @param layer the layer
+     * @exception IllegalArgumentException thrown if layer is null
+     * @exception IllegalArgumentException thrown if layer is neither an instance of {@see OsmDataLayer}
+     *  nor of {@see GpxLayer}
+     */
+
+    public void exportGpx(File file, Layer layer) {
+        if (layer == null)
+            throw new IllegalArgumentException(tr("paramenter ''{0}'' must not be null", "layer"));
+        if (! (layer instanceof OsmDataLayer) && ! (layer instanceof GpxLayer))
+            throw new IllegalArgumentException(tr("expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName()));
+        if (file == null)
+            throw new IllegalArgumentException(tr("paramenter ''{0}'' must not be null", "file"));
+
         String fn = file.getPath();
         if (fn.indexOf('.') == -1) {
@@ -172,5 +191,5 @@
             gpxData = ((GpxLayer)layer).data;
         } else {
-            gpxData = OsmDataLayer.toGpxData(Main.ds, file);
+            gpxData = OsmDataLayer.toGpxData(getCurrentDataSet(), file);
         }
 
Index: trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java	(revision 1814)
@@ -28,14 +28,14 @@
     public JoinNodeWayAction() {
         super(tr("Join Node to Way"), "joinnodeway", tr("Join a node into the nearest way segments"),
-            Shortcut.registerShortcut("tools:joinnodeway", tr("Tool: {0}", tr("Join Node to Way")), KeyEvent.VK_J, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:joinnodeway", tr("Tool: {0}", tr("Join Node to Way")), KeyEvent.VK_J, Shortcut.GROUP_EDIT), true);
     }
 
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         if (sel.size() != 1 || !(sel.iterator().next() instanceof Node)) return;
         Node node = (Node) sel.iterator().next();
 
         List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
-            Main.map.mapView.getPoint(node));
+                Main.map.mapView.getPoint(node));
         HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
         for (WaySegment ws : wss) {
@@ -60,5 +60,7 @@
             List<Integer> is = insertPoint.getValue();
             pruneSuccsAndReverse(is);
-            for (int i : is) wnew.nodes.add(i+1, node);
+            for (int i : is) {
+                wnew.nodes.add(i+1, node);
+            }
             cmds.add(new ChangeCommand(w, wnew));
         }
Index: trunk/src/org/openstreetmap/josm/actions/JosmAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JosmAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/JosmAction.java	(revision 1814)
@@ -9,4 +9,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.Destroyable;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -61,6 +62,7 @@
         putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc));
         putValue("toolbar", iconName);
-        if (register)
+        if (register) {
             Main.toolbar.register(this);
+        }
     }
 
@@ -92,7 +94,26 @@
     private void setHelpId() {
         String helpId = "Action/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1);
-        if (helpId.endsWith("Action"))
+        if (helpId.endsWith("Action")) {
             helpId = helpId.substring(0, helpId.length()-6);
+        }
         putValue("help", helpId);
     }
+
+    /**
+     * Replies the current edit layer
+     * 
+     * @return the current edit layer. null, if no edit layer exists
+     */
+    protected OsmDataLayer getEditLayer() {
+        return Main.main.getEditLayer();
+    }
+
+    /**
+     * Replies the current dataset
+     * 
+     * @return the current dataset. null, if no current dataset exists
+     */
+    protected DataSet getCurrentDataSet() {
+        return Main.main.getCurrentDataSet();
+    }
 }
Index: trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java	(revision 1814)
@@ -55,10 +55,10 @@
     public MergeNodesAction() {
         super(tr("Merge Nodes"), "mergenodes", tr("Merge nodes into the oldest one."),
-        Shortcut.registerShortcut("tools:mergenodes", tr("Tool: {0}", tr("Merge Nodes")), KeyEvent.VK_M, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:mergenodes", tr("Tool: {0}", tr("Merge Nodes")), KeyEvent.VK_M, Shortcut.GROUP_EDIT), true);
         DataSet.selListeners.add(this);
     }
 
     public void actionPerformed(ActionEvent event) {
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
         LinkedList<Node> selectedNodes = new LinkedList<Node>();
 
@@ -67,6 +67,7 @@
         // anyway as long as we have at least two nodes
         for (OsmPrimitive osm : selection)
-            if (osm instanceof Node)
+            if (osm instanceof Node) {
                 selectedNodes.add((Node)osm);
+            }
 
         if (selectedNodes.size() < 2) {
@@ -93,6 +94,7 @@
             }
         }
-        if (useNode == null)
+        if (useNode == null) {
             useNode = selectedNodes.iterator().next();
+        }
 
         mergeNodes(selectedNodes, useNode);
@@ -102,5 +104,5 @@
      * really do the merging - returns the node that is left
      */
-    public static Node mergeNodes(LinkedList<Node> allNodes, Node dest) {
+    public Node mergeNodes(LinkedList<Node> allNodes, Node dest) {
         Node newNode = new Node(dest);
 
@@ -118,6 +120,8 @@
             new HashMap<Pair<Relation,String>, HashSet<Node>>();
         HashSet<Relation> relationsUsingNodes = new HashSet<Relation>();
-        for (Relation r : Main.ds.relations) {
-            if (r.deleted || r.incomplete) continue;
+        for (Relation r : getCurrentDataSet().relations) {
+            if (r.deleted || r.incomplete) {
+                continue;
+            }
             for (RelationMember rm : r.members) {
                 if (rm.member instanceof Node) {
@@ -148,8 +152,10 @@
                         tr("Merge nodes with different memberships?"),
                         tr("The selected nodes have differing relation memberships.  "
-                            + "Do you still want to merge them?"),
-                        new String[] {tr("Merge Anyway"), tr("Cancel")},
-                        new String[] {"mergenodes.png", "cancel.png"}).getValue();
-                if (option == 1) break;
+                                + "Do you still want to merge them?"),
+                                new String[] {tr("Merge Anyway"), tr("Cancel")},
+                                new String[] {"mergenodes.png", "cancel.png"}).getValue();
+                if (option == 1) {
+                    break;
+                }
                 return null;
             }
@@ -160,6 +166,7 @@
         for (Node n : allNodes) {
             for (Entry<String,String> e : n.entrySet()) {
-                if (!props.containsKey(e.getKey()))
+                if (!props.containsKey(e.getKey())) {
                     props.put(e.getKey(), new TreeSet<String>());
+                }
                 props.get(e.getKey()).add(e.getValue());
             }
@@ -187,12 +194,13 @@
         if (!components.isEmpty()) {
             int answer = new ExtendedDialog(Main.parent,
-                tr("Enter values for all conflicts."),
-                p,
-                new String[] {tr("Solve Conflicts"), tr("Cancel")},
-                new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();
+                    tr("Enter values for all conflicts."),
+                    p,
+                    new String[] {tr("Solve Conflicts"), tr("Cancel")},
+                    new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();
             if (answer != 1)
                 return null;
-            for (Entry<String, JComboBox> e : components.entrySet())
+            for (Entry<String, JComboBox> e : components.entrySet()) {
                 newNode.put(e.getKey(), e.getValue().getEditor().getItem().toString());
+            }
         }
 
@@ -202,14 +210,20 @@
         Collection<OsmPrimitive> del = new HashSet<OsmPrimitive>();
 
-        for (Way w : Main.ds.ways) {
-            if (w.deleted || w.incomplete || w.nodes.size() < 1) continue;
+        for (Way w : getCurrentDataSet().ways) {
+            if (w.deleted || w.incomplete || w.nodes.size() < 1) {
+                continue;
+            }
             boolean modify = false;
             for (Node sn : allNodes) {
-                if (sn == dest) continue;
+                if (sn == dest) {
+                    continue;
+                }
                 if (w.nodes.contains(sn)) {
                     modify = true;
                 }
             }
-            if (!modify) continue;
+            if (!modify) {
+                continue;
+            }
             // OK - this way contains one or more nodes to change
             ArrayList<Node> nn = new ArrayList<Node>();
@@ -227,9 +241,9 @@
             if (nn.size() < 2) {
                 CollectBackReferencesVisitor backRefs =
-                    new CollectBackReferencesVisitor(Main.ds, false);
+                    new CollectBackReferencesVisitor(getCurrentDataSet(), false);
                 w.visit(backRefs);
                 if (!backRefs.data.isEmpty()) {
                     JOptionPane.showMessageDialog(Main.parent,
-                        tr("Cannot merge nodes: " +
+                            tr("Cannot merge nodes: " +
                             "Would have to delete a way that is still used."));
                     return null;
@@ -247,5 +261,7 @@
         del.addAll(allNodes);
         del.remove(dest);
-        if (!del.isEmpty()) cmds.add(new DeleteCommand(del));
+        if (!del.isEmpty()) {
+            cmds.add(new DeleteCommand(del));
+        }
 
         // modify all relations containing the now-deleted nodes
@@ -270,5 +286,5 @@
 
         Main.main.undoRedo.add(new SequenceCommand(tr("Merge {0} nodes", allNodes.size()), cmds));
-        Main.ds.setSelected(dest);
+        getCurrentDataSet().setSelected(dest);
 
         return dest;
Index: trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/MirrorAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/MirrorAction.java	(revision 1814)
@@ -14,8 +14,6 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.Command;
-import org.openstreetmap.josm.command.ChangeCommand;
 import org.openstreetmap.josm.command.MoveCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
-import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -34,10 +32,10 @@
     public MirrorAction() {
         super(tr("Mirror"), "mirror", tr("Mirror selected nodes and ways."),
-        Shortcut.registerShortcut("tools:mirror", tr("Tool: {0}", tr("Mirror")),
-            KeyEvent.VK_M, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
+                Shortcut.registerShortcut("tools:mirror", tr("Tool: {0}", tr("Mirror")),
+                        KeyEvent.VK_M, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
     }
 
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         HashSet<Node> nodes = new HashSet<Node>();
 
@@ -66,6 +64,7 @@
         Collection<Command> cmds = new LinkedList<Command>();
 
-        for (Node n : nodes)
+        for (Node n : nodes) {
             cmds.add(new MoveCommand(n, 2 * (middle - n.getEastNorth().east()), 0.0));
+        }
 
         Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds));
Index: trunk/src/org/openstreetmap/josm/actions/MoveAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/MoveAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/MoveAction.java	(revision 1814)
@@ -85,5 +85,5 @@
         }
 
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
         Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
 
Index: trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java	(revision 1814)
@@ -38,14 +38,14 @@
     public OrthogonalizeAction() {
         super(tr("Orthogonalize Shape"),
-            "ortho",
-            tr("Move nodes so all angles are 90 or 270 degree"),
-            Shortcut.registerShortcut("tools:orthogonalize", tr("Tool: {0}", tr("Orthogonalize Shape")),
-            KeyEvent.VK_Q,
-            Shortcut.GROUP_EDIT), true);
+                "ortho",
+                tr("Move nodes so all angles are 90 or 270 degree"),
+                Shortcut.registerShortcut("tools:orthogonalize", tr("Tool: {0}", tr("Orthogonalize Shape")),
+                        KeyEvent.VK_Q,
+                        Shortcut.GROUP_EDIT), true);
     }
 
     public void actionPerformed(ActionEvent e) {
 
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
 
         ArrayList<Node> dirnodes = new ArrayList<Node>();
@@ -84,5 +84,7 @@
                 double angle2 = Math.abs(way.nodes.get(i2).getEastNorth().heading(way.nodes.get(i3).getEastNorth()));
                 double delta = Math.abs(angle2 - angle1);
-                while(delta > Math.PI) delta -= Math.PI;
+                while(delta > Math.PI) {
+                    delta -= Math.PI;
+                }
                 if(delta < Math.PI/4) {
                     JOptionPane.showMessageDialog(Main.parent, tr("Please select ways with almost right angles to orthogonalize."));
@@ -96,9 +98,8 @@
                     "to undesirable results when doing rectangular alignments.<br>" +
                     "Change your projection to get rid of this warning.<br>" +
-                    "Do you want to continue?");
-
-            if (!DontShowAgainInfo.show("align_rectangular_4326", msg, false)) {
+            "Do you want to continue?");
+
+            if (!DontShowAgainInfo.show("align_rectangular_4326", msg, false))
                 return;
-            }
         }
         // Check, if selection held neither none nor two nodes
@@ -122,6 +123,7 @@
 
         for (OsmPrimitive osm : sel) {
-            if(!(osm instanceof Way))
+            if(!(osm instanceof Way)) {
                 continue;
+            }
 
             Way way = (Way)osm;
@@ -158,5 +160,7 @@
                         diff = heading_diff(headings[i], headings[i - 1]);
                     }
-                    if (diff > angle_diff_max) angle_diff_max = diff;
+                    if (diff > angle_diff_max) {
+                        angle_diff_max = diff;
+                    }
                 }
 
@@ -164,6 +168,7 @@
                     // rearrange headings: everything < 0 gets PI/2-rotated
                     for (int i=0; i < sides; i++) {
-                        if (headings[i] < 0)
+                        if (headings[i] < 0) {
                             headings[i] += Math.PI/2;
+                        }
                     }
                 }
@@ -217,5 +222,7 @@
                 // been duplicated
 
-                if (u == 0) continue;
+                if (u == 0) {
+                    continue;
+                }
 
                 // q is a number between 0 and 1
@@ -257,6 +264,10 @@
         double llimit = -Math.PI/4;
         double ulimit = Math.PI/4;
-        while (h - align_to > ulimit) h -= Math.PI/2;
-        while (h - align_to < llimit) h += Math.PI/2;
+        while (h - align_to > ulimit) {
+            h -= Math.PI/2;
+        }
+        while (h - align_to < llimit) {
+            h += Math.PI/2;
+        }
 
         return h;
Index: trunk/src/org/openstreetmap/josm/actions/PasteAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/PasteAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/PasteAction.java	(revision 1814)
@@ -31,5 +31,5 @@
     public PasteAction() {
         super(tr("Paste"), "paste", tr("Paste contents of paste buffer."),
-            Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true);
+                Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true);
         setEnabled(false);
     }
@@ -39,5 +39,5 @@
     }
 
-    public static void pasteData(DataSet pasteBuffer, Layer source, ActionEvent e) {
+    public  void pasteData(DataSet pasteBuffer, Layer source, ActionEvent e) {
         /* Find the middle of the pasteBuffer area */
         double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100;
@@ -63,5 +63,5 @@
 
         HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>();
-          /* temporarily maps old nodes to new so we can do a true deep copy */
+        /* temporarily maps old nodes to new so we can do a true deep copy */
 
         /* do the deep copy of the paste buffer contents, leaving the pasteBuffer unchanged */
@@ -69,5 +69,5 @@
             Node nnew = new Node(n);
             nnew.id = 0;
-            if (Main.main.createOrGetEditLayer() == source) {
+            if (Main.map.mapView.getEditLayer() == source) {
                 nnew.setEastNorth(nnew.getEastNorth().add(offsetEast, offsetNorth));
             }
@@ -113,5 +113,5 @@
 
         Main.main.undoRedo.add(new SequenceCommand(tr("Paste"), clist));
-        Main.ds.setSelected(osms);
+        getCurrentDataSet().setSelected(osms);
         Main.map.mapView.repaint();
     }
Index: trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java	(revision 1814)
@@ -27,6 +27,6 @@
     public PasteTagsAction(JosmAction copyAction) {
         super(tr("Paste Tags"), "pastetags",
-            tr("Apply tags of contents of paste buffer to all selected items."),
-            Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true);
+                tr("Apply tags of contents of paste buffer to all selected items."),
+                Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true);
         DataSet.selListeners.add(this);
         copyAction.addListener(this);
@@ -43,6 +43,7 @@
             OsmPrimitive osm = it.next();
             Map<String, String> m = osm.keys;
-            if(m == null)
+            if(m == null) {
                 continue;
+            }
 
             for (String key : m.keySet()) {
@@ -55,28 +56,29 @@
         Collection<Command> clist = new LinkedList<Command>();
         String pbSource = "Multiple Sources";
-        if(Main.pasteBuffer.dataSources.size() == 1)
+        if(Main.pasteBuffer.dataSources.size() == 1) {
             pbSource = ((DataSource) Main.pasteBuffer.dataSources.toArray()[0]).origin;
+        }
 
         boolean pbNodes = Main.pasteBuffer.nodes.size() > 0;
         boolean pbWays  = Main.pasteBuffer.ways.size() > 0;
 
-        boolean seNodes = Main.ds.getSelectedNodes().size() > 0;
-        boolean seWays  = Main.ds.getSelectedWays().size() > 0;
-        boolean seRels  = Main.ds.getSelectedRelations().size() > 0;
+        boolean seNodes = getCurrentDataSet().getSelectedNodes().size() > 0;
+        boolean seWays  = getCurrentDataSet().getSelectedWays().size() > 0;
+        boolean seRels  = getCurrentDataSet().getSelectedRelations().size() > 0;
 
         if(!seNodes && seWays && !seRels && pbNodes && pbSource.equals("Copied Nodes")) {
             // Copy from nodes to ways
-            pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedWays());
+            pasteKeys(clist, Main.pasteBuffer.nodes, getCurrentDataSet().getSelectedWays());
         } else if(seNodes && !seWays && !seRels && pbWays && pbSource.equals("Copied Ways")) {
             // Copy from ways to nodes
-            pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedNodes());
+            pasteKeys(clist, Main.pasteBuffer.ways, getCurrentDataSet().getSelectedNodes());
         } else {
             // Copy from equal to equal
-            pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedNodes());
-            pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedWays());
-            pasteKeys(clist, Main.pasteBuffer.relations, Main.ds.getSelectedRelations());
+            pasteKeys(clist, Main.pasteBuffer.nodes, getCurrentDataSet().getSelectedNodes());
+            pasteKeys(clist, Main.pasteBuffer.ways, getCurrentDataSet().getSelectedWays());
+            pasteKeys(clist, Main.pasteBuffer.relations, getCurrentDataSet().getSelectedRelations());
         }
         Main.main.undoRedo.add(new SequenceCommand(tr("Paste Tags"), clist));
-        Main.ds.setSelected(Main.ds.getSelected()); // to force selection listeners, in particular the tag panel, to update
+        getCurrentDataSet().setSelected(getCurrentDataSet().getSelected()); // to force selection listeners, in particular the tag panel, to update
         Main.map.mapView.repaint();
     }
@@ -86,11 +88,12 @@
         for (Iterator<? extends OsmPrimitive> it = osms.iterator(); it.hasNext();) {
             OsmPrimitive osm = it.next();
-            if (osm.keys == null || osm.keys.isEmpty())
+            if (osm.keys == null || osm.keys.isEmpty()) {
                 continue;
+            }
             for (String key : osm.keys.keySet()) {
                 String value = osm.keys.get(key);
-                if (! kvSeen.containsKey(key))
+                if (! kvSeen.containsKey(key)) {
                     kvSeen.put(key, value);
-                else if (! kvSeen.get(key).equals(value))
+                } else if (! kvSeen.get(key).equals(value))
                     return true;
             }
@@ -110,14 +113,14 @@
                 ! selection.isEmpty() &&
                 ! pasteBuffer.allPrimitives().isEmpty() &&
-                (Main.ds.getSelectedNodes().isEmpty() ||
-                    ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) &&
-                (Main.ds.getSelectedWays().isEmpty() ||
-                    ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) &&
-                (Main.ds.getSelectedRelations().isEmpty() ||
-                    ! containsSameKeysWithDifferentValues(pasteBuffer.relations)));
+                (getCurrentDataSet().getSelectedNodes().isEmpty() ||
+                        ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) &&
+                        (getCurrentDataSet().getSelectedWays().isEmpty() ||
+                                ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) &&
+                                (getCurrentDataSet().getSelectedRelations().isEmpty() ||
+                                        ! containsSameKeysWithDifferentValues(pasteBuffer.relations)));
     }
 
     @Override public void pasteBufferChanged(DataSet newPasteBuffer) {
-        possiblyEnable(Main.ds.getSelected(), newPasteBuffer);
+        possiblyEnable(getCurrentDataSet().getSelected(), newPasteBuffer);
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java	(revision 1814)
@@ -30,5 +30,5 @@
     public ReverseWayAction() {
         super(tr("Reverse Ways"), "wayflip", tr("Reverse the direction of all selected ways."),
-        Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true);
     }
 
@@ -47,6 +47,7 @@
 
             public void visitAll() {
-                for (OsmPrimitive osm : Main.ds.getSelected())
+                for (OsmPrimitive osm : getCurrentDataSet().getSelected()) {
                     osm.visit(this);
+                }
             }
         }.visitAll();
@@ -69,5 +70,5 @@
                     final Collection<Command> changePropertyCommands = reverseWayTagCorrector.execute(w, wnew);
                     propertiesUpdated = propertiesUpdated
-                        || (changePropertyCommands != null && !changePropertyCommands.isEmpty());
+                    || (changePropertyCommands != null && !changePropertyCommands.isEmpty());
                     c.addAll(changePropertyCommands);
                 }
@@ -80,6 +81,7 @@
         }
         Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
-        if (propertiesUpdated)
-            DataSet.fireSelectionChanged(Main.ds.getSelected());
+        if (propertiesUpdated) {
+            DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
+        }
         Main.map.repaint();
     }
Index: trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java	(revision 1814)
@@ -160,5 +160,5 @@
             OsmBzip2Importer osmBzip2Importer = new OsmBzip2Importer();
             if (gpxImExporter.acceptFile(file)) {
-                GpxExportAction.exportGpx(file, layer);
+                new GpxExportAction().exportGpx(file, layer);
             } else if (osmImExporter.acceptFile(file)
                     || osmGzipImporter.acceptFile(file)
Index: trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java	(revision 1814)
@@ -7,5 +7,4 @@
 import java.awt.event.KeyEvent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
@@ -24,5 +23,5 @@
         if (!isEnabled())
             return;
-        Main.ds.setSelected(Main.ds.allNonDeletedCompletePrimitives());
+        getCurrentDataSet().setSelected(getCurrentDataSet().allNonDeletedCompletePrimitives());
     }
 
@@ -32,8 +31,5 @@
      */
     protected void refreshEnabled() {
-        setEnabled(Main.map != null
-                && Main.map.mapView !=null
-                && Main.map.mapView.getEditLayer() != null
-        );
+        setEnabled(getEditLayer() != null);
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 1814)
@@ -32,6 +32,6 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
 import org.openstreetmap.josm.data.osm.visitor.Visitor;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -65,5 +65,5 @@
     public void actionPerformed(ActionEvent e) {
 
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
 
         if (!checkSelection(selection)) {
@@ -99,5 +99,5 @@
             HashMap<Way, Integer> wayOccurenceCounter = new HashMap<Way, Integer>();
             for (Node n : selectedNodes) {
-                for (Way w : Main.ds.ways) {
+                for (Way w : getCurrentDataSet().ways) {
                     if (w.deleted || w.incomplete) {
                         continue;
@@ -272,5 +272,6 @@
         Boolean warnme=false;
         // now copy all relations to new way also
-        for (Relation r : Main.ds.relations) {
+
+        for (Relation r : getCurrentDataSet().relations) {
             if (r.deleted || r.incomplete) {
                 continue;
@@ -329,11 +330,9 @@
         }
 
-        NameVisitor v = new NameVisitor();
-        v.visit(selectedWay);
         Main.main.undoRedo.add(
                 new SequenceCommand(tr("Split way {0} into {1} parts",
-                        v.name, wayChunks.size()),
+                        new PrimitiveNameFormatter().getName(selectedWay), wayChunks.size()),
                         commandList));
-        Main.ds.setSelected(newSelection);
+        getCurrentDataSet().setSelected(newSelection);
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java	(revision 1814)
@@ -50,5 +50,5 @@
     public UnGlueAction() {
         super(tr("UnGlue Ways"), "unglueways", tr("Duplicate nodes that are used by multiple ways."),
-        Shortcut.registerShortcut("tools:unglue", tr("Tool: {0}", tr("UnGlue Ways")), KeyEvent.VK_G, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("tools:unglue", tr("Tool: {0}", tr("UnGlue Ways")), KeyEvent.VK_G, Shortcut.GROUP_EDIT), true);
         //DataSet.selListeners.add(this);
     }
@@ -61,12 +61,16 @@
     public void actionPerformed(ActionEvent e) {
 
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
 
         String errMsg = null;
         if (checkSelection(selection)) {
             int count = 0;
-            for (Way w : Main.ds.ways) {
-                if (w.deleted || w.incomplete || w.nodes.size() < 1) continue;
-                if (!w.nodes.contains(selectedNode)) continue;
+            for (Way w : getCurrentDataSet().ways) {
+                if (w.deleted || w.incomplete || w.nodes.size() < 1) {
+                    continue;
+                }
+                if (!w.nodes.contains(selectedNode)) {
+                    continue;
+                }
                 count++;
             }
@@ -74,8 +78,9 @@
                 // If there aren't enough ways, maybe the user wanted to unglue the nodes
                 // (= copy tags to a new node)
-                if(checkForUnglueNode(selection))
+                if(checkForUnglueNode(selection)) {
                     unglueNode(e);
-                else
+                } else {
                     errMsg = tr("This node is not glued to anything else.");
+                }
             } else {
                 // and then do the work.
@@ -86,7 +91,11 @@
             for (Node n : selectedNodes) {
                 int count = 0;
-                for (Way w : Main.ds.ways) {
-                    if (w.deleted || w.incomplete || w.nodes.size() < 1) continue;
-                    if (!w.nodes.contains(n)) continue;
+                for (Way w : getCurrentDataSet().ways) {
+                    if (w.deleted || w.incomplete || w.nodes.size() < 1) {
+                        continue;
+                    }
+                    if (!w.nodes.contains(n)) {
+                        continue;
+                    }
                     count++;
                 }
@@ -118,10 +127,11 @@
                 "\n"+
                 tr("Note: If a way is selected, this way will get fresh copies of the unglued\n"+
-                   "nodes and the new nodes will be selected. Otherwise, all ways will get their\n"+
-                   "own copy and all nodes will be selected.");
-        }
-
-        if(errMsg != null)
+                        "nodes and the new nodes will be selected. Otherwise, all ways will get their\n"+
+                "own copy and all nodes will be selected.");
+        }
+
+        if(errMsg != null) {
             JOptionPane.showMessageDialog(Main.parent, errMsg);
+        }
 
         selectedNode = null;
@@ -156,5 +166,5 @@
 
         Main.main.undoRedo.add(new SequenceCommand(tr("Unglued Node"), cmds));
-        Main.ds.setSelected(n);
+        getCurrentDataSet().setSelected(n);
         Main.map.mapView.repaint();
     }
@@ -176,5 +186,5 @@
             return false;
         boolean isPartOfWay = false;
-        for(Way w : Main.ds.ways) {
+        for(Way w : getCurrentDataSet().ways) {
             if(w.nodes.contains(n)) {
                 isPartOfWay = true;
@@ -250,13 +260,11 @@
         for (OsmPrimitive p : selection) {
             if (p instanceof Way) {
-                if (selectedWay != null) {
+                if (selectedWay != null)
                     return false;
-                }
                 selectedWay = (Way) p;
             }
         }
-        if (selectedWay == null) {
-            return false;
-        }
+        if (selectedWay == null)
+            return false;
 
         selectedNodes = new ArrayList<Node>();
@@ -264,7 +272,6 @@
             if (p instanceof Node) {
                 Node n = (Node) p;
-                if (!selectedWay.nodes.contains(n)) {
+                if (!selectedWay.nodes.contains(n))
                     return false;
-                }
                 selectedNodes.add(n);
             }
@@ -311,6 +318,8 @@
         Relation newRel = null;
         HashSet<String> rolesToReAdd = null;
-        for (Relation r : Main.ds.relations) {
-            if (r.deleted || r.incomplete) continue;
+        for (Relation r : getCurrentDataSet().relations) {
+            if (r.deleted || r.incomplete) {
+                continue;
+            }
             newRel = null;
             rolesToReAdd = null;
@@ -330,5 +339,5 @@
                 for (RelationMember rm : r.members) {
                     //if (rm.member != selectedNode) {
-                        newRel.members.add(rm);
+                    newRel.members.add(rm);
                     //}
                 }
@@ -356,8 +365,14 @@
             boolean firstway = true;
             // modify all ways containing the nodes
-            for (Way w : Main.ds.ways) {
-                if (w.deleted || w.incomplete || w.nodes.size() < 1) continue;
-                if (!w.nodes.contains(selectedNode)) continue;
-                if (!firstway) cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes)));
+            for (Way w : getCurrentDataSet().ways) {
+                if (w.deleted || w.incomplete || w.nodes.size() < 1) {
+                    continue;
+                }
+                if (!w.nodes.contains(selectedNode)) {
+                    continue;
+                }
+                if (!firstway) {
+                    cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes)));
+                }
                 firstway = false;
             }
@@ -372,5 +387,5 @@
             newNodes.add(selectedNode);
         } // if a node and a way has been selected, new selection is only the new node that was added to the selected way
-        Main.ds.setSelected(newNodes);
+        getCurrentDataSet().setSelected(newNodes);
     }
 
@@ -393,17 +408,5 @@
 
         Main.main.undoRedo.add(new SequenceCommand(tr("Dupe {0} nodes into {1} nodes", selectedNodes.size(), selectedNodes.size()+allNewNodes.size()), cmds));
-        Main.ds.setSelected(allNewNodes);
-    }
-
-// Disabled because we have such a nice help text that would not be shown otherwise.
-//
-//  /**
-//   * Enable the menu option if the selection looks like we could use it.
-//   */
-//  public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
-//      setEnabled(checkSelection(newSelection) || checkSelection2(newSelection));
-//      selectedNode = null;
-//      selectedWay = null;
-//      selectedNodes = null;
-//  }
+        getCurrentDataSet().setSelected(allNewNodes);
+    }
 }
Index: trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java	(revision 1814)
@@ -44,5 +44,5 @@
         if (!isEnabled())
             return;
-        Main.ds.setSelected();
+        getCurrentDataSet().setSelected();
     }
     /**
@@ -51,8 +51,5 @@
      */
     protected void refreshEnabled() {
-        setEnabled(Main.map != null
-                && Main.map.mapView !=null
-                && Main.map.mapView.getEditLayer() != null
-        );
+        setEnabled(getEditLayer() != null);
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java	(revision 1814)
@@ -16,4 +16,5 @@
 import org.openstreetmap.josm.data.osm.DataSource;
 import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
@@ -38,9 +39,5 @@
      */
     protected void refreshEnabled() {
-        setEnabled(Main.main != null
-                && Main.map != null
-                && Main.map.mapView !=null
-                && Main.map.mapView.getEditLayer() != null
-        );
+        setEnabled(getEditLayer() != null);
     }
 
@@ -50,5 +47,5 @@
         int bboxCount = 0;
         List<Area> areas = new ArrayList<Area>();
-        for(DataSource ds : Main.main.createOrGetEditLayer().data.dataSources) {
+        for(DataSource ds : Main.map.mapView.getEditLayer().data.dataSources) {
             areas.add(new Area(ds.bounds.asRect()));
         }
Index: trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java	(revision 1814)
@@ -42,5 +42,5 @@
     protected void handlePrimitiveGoneException(long id) {
         MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader();
-        reader.append(Main.main.createOrGetEditLayer().data,id);
+        reader.append(getCurrentDataSet(),id);
         DataSet ds = null;
         try {
@@ -194,9 +194,6 @@
      */
     protected void refreshEnabled() {
-        setEnabled(Main.main != null
-                && Main.map != null
-                && Main.map.mapView !=null
-                && Main.map.mapView.getEditLayer() != null
-                && ! Main.map.mapView.getEditLayer().data.getSelected().isEmpty()
+        setEnabled(getCurrentDataSet() != null
+                && ! getCurrentDataSet().getSelected().isEmpty()
         );
     }
@@ -208,5 +205,5 @@
         if (! isEnabled())
             return;
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
         if (selection.size() == 0) {
             JOptionPane.showMessageDialog(
Index: trunk/src/org/openstreetmap/josm/actions/UploadAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UploadAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/UploadAction.java	(revision 1814)
@@ -178,5 +178,5 @@
         }
 
-        ConflictCollection conflicts = Main.main.createOrGetEditLayer().getConflicts();
+        ConflictCollection conflicts = Main.map.mapView.getEditLayer().getConflicts();
         if (conflicts !=null && !conflicts.isEmpty()) {
             JOptionPane.showMessageDialog(Main.parent,tr("There are unresolved conflicts. You have to resolve these first."));
@@ -189,5 +189,5 @@
         final LinkedList<OsmPrimitive> update = new LinkedList<OsmPrimitive>();
         final LinkedList<OsmPrimitive> delete = new LinkedList<OsmPrimitive>();
-        for (OsmPrimitive osm : Main.ds.allPrimitives()) {
+        for (OsmPrimitive osm : getCurrentDataSet().allPrimitives()) {
             if (osm.get("josm/ignore") != null) {
                 continue;
@@ -231,6 +231,6 @@
             @Override protected void realRun() throws SAXException, IOException {
                 try {
-                    server.uploadOsm(Main.ds.version, all, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
-                    Main.main.createOrGetEditLayer().cleanData(server.processed, !add.isEmpty());
+                    server.uploadOsm(getCurrentDataSet().version, all, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
+                    getEditLayer().cleanData(server.processed, !add.isEmpty());
                 } catch (Exception sxe) {
                     if (uploadCancelled) {
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java	(revision 1814)
@@ -77,7 +77,7 @@
         Command c;
         if (ctrl) {
-            c = DeleteCommand.deleteWithReferences(Main.ds.getSelected());
+            c = DeleteCommand.deleteWithReferences(getCurrentDataSet().getSelected());
         } else {
-            c = DeleteCommand.delete(Main.ds.getSelected(), !alt);
+            c = DeleteCommand.delete(getCurrentDataSet().getSelected(), !alt);
         }
         if (c != null) {
@@ -85,5 +85,5 @@
         }
 
-        Main.ds.setSelected();
+        getCurrentDataSet().setSelected();
         Main.map.repaint();
     }
@@ -124,5 +124,5 @@
         }
 
-        Main.ds.setSelected();
+        getCurrentDataSet().setSelected();
         Main.map.mapView.repaint();
     }
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 1814)
@@ -94,5 +94,5 @@
         // Add extra shortcut N
         Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
-            Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT).getKeyStroke(), tr("Draw"));
+                Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT).getKeyStroke(), tr("Draw"));
 
         cursorCrosshair = getCursor();
@@ -124,13 +124,13 @@
                         return;
                     switch(c) {
-                        case way:
-                            Main.map.mapView.setCursor(cursorJoinWay);
-                            break;
-                        case node:
-                            Main.map.mapView.setCursor(cursorJoinNode);
-                            break;
-                        default:
-                            Main.map.mapView.setCursor(cursorCrosshair);
-                            break;
+                    case way:
+                        Main.map.mapView.setCursor(cursorJoinWay);
+                        break;
+                    case node:
+                        Main.map.mapView.setCursor(cursorJoinNode);
+                        break;
+                    default:
+                        Main.map.mapView.setCursor(cursorCrosshair);
+                    break;
                     }
                 }
@@ -162,7 +162,8 @@
 
         // This happens when nothing is selected, but we still want to highlight the "target node"
-        if (mouseOnExistingNode == null && Main.ds.getSelected().size() == 0
-                && mousePos != null)
+        if (mouseOnExistingNode == null && getCurrentDataSet().getSelected().size() == 0
+                && mousePos != null) {
             mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos);
+        }
 
         if (mouseOnExistingNode != null) {
@@ -170,6 +171,7 @@
             // We also need this list for the statusbar help text
             oldHighlights.add(mouseOnExistingNode);
-            if(drawTargetHighlight)
+            if(drawTargetHighlight) {
                 mouseOnExistingNode.highlighted = true;
+            }
             return;
         }
@@ -259,5 +261,5 @@
 
     private void tryAgain(MouseEvent e) {
-        Main.ds.setSelected();
+        getCurrentDataSet().setSelected();
         mouseClicked(e);
     }
@@ -306,14 +308,15 @@
         mousePos = e.getPoint();
 
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
         Collection<Command> cmds = new LinkedList<Command>();
 
         ArrayList<Way> reuseWays = new ArrayList<Way>(),
-            replacedWays = new ArrayList<Way>();
+        replacedWays = new ArrayList<Way>();
         boolean newNode = false;
         Node n = null;
 
-        if (!ctrl)
+        if (!ctrl) {
             n = Main.map.mapView.getNearestNode(mousePos);
+        }
 
         if (n != null) {
@@ -323,6 +326,6 @@
                 // (this is just a convenience option so that people don't
                 // have to switch modes)
-                Main.ds.setSelected(n);
-                selection = Main.ds.getSelected();
+                getCurrentDataSet().setSelected(n);
+                selection = getCurrentDataSet().getSelected();
                 // The user explicitly selected a node, so let him continue drawing
                 wayIsFinished = false;
@@ -334,5 +337,5 @@
             if (n.getCoor().isOutSideWorld()) {
                 JOptionPane.showMessageDialog(Main.parent,
-                    tr("Cannot add a node outside of the world."));
+                        tr("Cannot add a node outside of the world."));
                 return;
             }
@@ -366,7 +369,11 @@
 
                     pruneSuccsAndReverse(is);
-                    for (int i : is) segSet.add(
-                        Pair.sort(new Pair<Node,Node>(w.nodes.get(i), w.nodes.get(i+1))));
-                    for (int i : is) wnew.addNode(i + 1, n);
+                    for (int i : is) {
+                        segSet.add(
+                                Pair.sort(new Pair<Node,Node>(w.nodes.get(i), w.nodes.get(i+1))));
+                    }
+                    for (int i : is) {
+                        wnew.addNode(i + 1, n);
+                    }
 
                     // If ALT is pressed, a new way should be created and that new way should get
@@ -375,5 +382,7 @@
                     // but pressing ALT prevents this. Therefore we must de-select the way manually
                     // here so /only/ the new way will be selected after this method finishes.
-                    if(alt) wnew.selected = false;
+                    if(alt) {
+                        wnew.selected = false;
+                    }
 
                     cmds.add(new ChangeCommand(insertPoint.getKey(), wnew));
@@ -450,6 +459,10 @@
                     int nodeCount=0;
                     for (Node p : way.nodes)
-                        if(p.equals(n0)) nodeCount++;
-                    if(nodeCount > 1) way = null;
+                        if(p.equals(n0)) {
+                            nodeCount++;
+                        }
+                    if(nodeCount > 1) {
+                        way = null;
+                    }
                 }
 
@@ -476,11 +489,12 @@
 
                 // Add new node to way
-                if (way.nodes.get(way.nodes.size() - 1) == n0)
+                if (way.nodes.get(way.nodes.size() - 1) == n0) {
                     way.addNode(n);
-                else
+                } else {
                     way.addNode(0, n);
+                }
 
                 extendedWay = true;
-                Main.ds.setSelected(way);
+                getCurrentDataSet().setSelected(way);
             }
         }
@@ -488,13 +502,15 @@
         String title;
         if (!extendedWay) {
-            if (!newNode) {
+            if (!newNode)
                 return; // We didn't do anything.
-            } else if (reuseWays.isEmpty()) {
+            else if (reuseWays.isEmpty()) {
                 title = tr("Add node");
             } else {
                 title = tr("Add node into way");
-                for (Way w : reuseWays) w.selected = false;
-            }
-            Main.ds.setSelected(n);
+                for (Way w : reuseWays) {
+                    w.selected = false;
+                }
+            }
+            getCurrentDataSet().setSelected(n);
         } else if (!newNode) {
             title = tr("Connect existing way to node");
@@ -508,5 +524,7 @@
 
         Main.main.undoRedo.add(c);
-        if(!wayIsFinished) lastUsedNode = n;
+        if(!wayIsFinished) {
+            lastUsedNode = n;
+        }
 
         computeHelperLine();
@@ -534,7 +552,7 @@
             int posn0 = selectedWay.nodes.indexOf(currentNode);
             if( posn0 != -1 && // n0 is part of way
-                (posn0 >= 1                          && targetNode.equals(selectedWay.nodes.get(posn0-1))) || // previous node
-                (posn0 < selectedWay.nodes.size()-1) && targetNode.equals(selectedWay.nodes.get(posn0+1))) {  // next node
-                Main.ds.setSelected(targetNode);
+                    (posn0 >= 1                          && targetNode.equals(selectedWay.nodes.get(posn0-1))) || // previous node
+                    (posn0 < selectedWay.nodes.size()-1) && targetNode.equals(selectedWay.nodes.get(posn0+1))) {  // next node
+                getCurrentDataSet().setSelected(targetNode);
                 lastUsedNode = targetNode;
                 return true;
@@ -618,5 +636,5 @@
         double angle = -1;
 
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
+        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
 
         Node selectedNode = null;
@@ -638,6 +656,7 @@
         if(!ctrl && currentMouseNode == null) {
             List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(mousePos);
-            for(WaySegment ws : wss)
+            for(WaySegment ws : wss) {
                 mouseOnExistingWays.add(ws.way);
+            }
         }
 
@@ -692,5 +711,7 @@
         if (previousNode != null) {
             angle = hdg - Math.toDegrees(previousNode.getCoor().heading(currentBaseNode.getCoor()));
-            if (angle < 0) angle += 360;
+            if (angle < 0) {
+                angle += 360;
+            }
         }
         Main.map.statusLine.setAngle(angle);
@@ -715,8 +736,10 @@
      *  <code>null</code> otherwise.
      */
-    public static Way getWayForNode(Node n) {
+    public Way getWayForNode(Node n) {
         Way way = null;
-        for (Way w : Main.ds.ways) {
-            if (w.deleted || w.incomplete || w.nodes.size() < 1) continue;
+        for (Way w : getCurrentDataSet().ways) {
+            if (w.deleted || w.incomplete || w.nodes.size() < 1) {
+                continue;
+            }
             Node firstNode = w.nodes.get(0);
             Node lastNode = w.nodes.get(w.nodes.size() - 1);
@@ -805,12 +828,12 @@
         default:
             EastNorth P = n.getEastNorth();
-            seg = segs.iterator().next();
-            A = seg.a.getEastNorth();
-            B = seg.b.getEastNorth();
-            double a = P.distanceSq(B);
-            double b = P.distanceSq(A);
-            double c = A.distanceSq(B);
-            q = (a - b + c) / (2*c);
-            n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())));
+        seg = segs.iterator().next();
+        A = seg.a.getEastNorth();
+        B = seg.b.getEastNorth();
+        double a = P.distanceSq(B);
+        double b = P.distanceSq(A);
+        double c = A.distanceSq(B);
+        q = (a - b + c) / (2*c);
+        n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())));
         }
     }
@@ -883,9 +906,10 @@
             // oldHighlights may store a node or way, check if it's a node
             OsmPrimitive x = oldHighlights.iterator().next();
-            if (x instanceof Node)
+            if (x instanceof Node) {
                 rv = tr("Select node under cursor.");
-            else
+            } else {
                 rv = trn("Insert new node into way.", "Insert new node into {0} ways.",
-                oldHighlights.size(), oldHighlights.size());
+                        oldHighlights.size(), oldHighlights.size());
+            }
         }
 
@@ -894,8 +918,9 @@
          */
         if (currentBaseNode != null && !wayIsFinished) {
-            if (alt)
+            if (alt) {
                 rv += " " + tr("Start new way from last node.");
-            else
+            } else {
                 rv += " " + tr("Continue way from last node.");
+            }
         }
 
@@ -904,9 +929,10 @@
          * Handle special case: Highlighted node == selected node => finish drawing
          */
-        if (n != null && Main.ds.getSelectedNodes().contains(n)) {
-            if (wayIsFinished)
+        if (n != null && getCurrentDataSet().getSelectedNodes().contains(n)) {
+            if (wayIsFinished) {
                 rv = tr("Select node under cursor.");
-            else
+            } else {
                 rv = tr("Finish drawing.");
+            }
         }
 
@@ -914,6 +940,6 @@
          * Handle special case: Self-Overlapping or closing way
          */
-        if (Main.ds.getSelectedWays().size() > 0 && !wayIsFinished && !alt) {
-            Way w = (Way) Main.ds.getSelectedWays().iterator().next();
+        if (getCurrentDataSet().getSelectedWays().size() > 0 && !wayIsFinished && !alt) {
+            Way w = (Way) getCurrentDataSet().getSelectedWays().iterator().next();
             for (Node m : w.nodes) {
                 if (m.equals(mouseOnExistingNode) || mouseOnExistingWays.contains(w)) {
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 1814)
@@ -77,6 +77,6 @@
         super(tr("Extrude"), "extrude/extrude", tr("Create areas"),
                 Shortcut.registerShortcut("mapmode:extrude", tr("Mode: {0}", tr("Extrude")), KeyEvent.VK_X, Shortcut.GROUP_EDIT),
-            mapFrame,
-            getCursor("normal", "rectangle", Cursor.DEFAULT_CURSOR));
+                mapFrame,
+                getCursor("normal", "rectangle", Cursor.DEFAULT_CURSOR));
         putValue("help", "Action/Extrude/Extrude");
         initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200);
@@ -160,9 +160,9 @@
 
             double u = ((en3.east() - en1.east()) * (en2.east() - en1.east()) +
-                        (en3.north() - en1.north()) * (en2.north() - en1.north())) /
-                       en2.distanceSq(en1);
+                    (en3.north() - en1.north()) * (en2.north() - en1.north())) /
+                    en2.distanceSq(en1);
             // the point on the segment from which the distance to mouse pos is shortest
             EastNorth base = new EastNorth(en1.east() + u * (en2.east() - en1.east()),
-                                           en1.north() + u * (en2.north() - en1.north()));
+                    en1.north() + u * (en2.north() - en1.north()));
 
             // find out the distance, in metres, between the base point and the mouse cursor
@@ -219,6 +219,7 @@
         initialMousePos = e.getPoint();
 
-        if(selectedSegment != null)
-            Main.ds.setSelected(selectedSegment.way);
+        if(selectedSegment != null) {
+            getCurrentDataSet().setSelected(selectedSegment.way);
+        }
     }
 
@@ -241,5 +242,7 @@
             wnew.addNode(selectedSegment.lowerIndex+1, n3);
             wnew.addNode(selectedSegment.lowerIndex+1, n4);
-            if (wnew.nodes.size() == 4) wnew.addNode(n1);
+            if (wnew.nodes.size() == 4) {
+                wnew.addNode(n1);
+            }
             Collection<Command> cmds = new LinkedList<Command>();
             cmds.add(new AddCommand(n4));
@@ -258,17 +261,16 @@
 
     @Override public String getModeHelpText() {
-        if (mode == Mode.select) {
+        if (mode == Mode.select)
             return tr("Release the mouse button to select the objects in the rectangle.");
-        } else if (mode == Mode.EXTRUDE) {
+        else if (mode == Mode.EXTRUDE)
             return tr("Draw a rectangle of the desired size, then release the mouse button.");
-        } else if (mode == Mode.rotate) {
+        else if (mode == Mode.rotate)
             return tr("Release the mouse button to stop rotating.");
-        } else {
+        else
             return tr("Drag a way segment to make a rectangle.");
-        }
-    }
-
-        @Override public boolean layerIsSupported(Layer l) {
-                return l instanceof OsmDataLayer;
-        }
+    }
+
+    @Override public boolean layerIsSupported(Layer l) {
+        return l instanceof OsmDataLayer;
+    }
 }
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java	(revision 1814)
@@ -207,5 +207,5 @@
             // Currently we support moving and rotating, which do not affect relations.
             // So don't add them in the first place to make handling easier
-            Collection<OsmPrimitive> selection = Main.ds.getSelectedNodesAndWays();
+            Collection<OsmPrimitive> selection = getCurrentDataSet().getSelectedNodesAndWays();
             Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
 
@@ -355,5 +355,5 @@
 
         if (ctrl && shift) {
-            if (Main.ds.getSelected().isEmpty()) {
+            if (getCurrentDataSet().getSelected().isEmpty()) {
                 selectPrims(osmColl, true, false, false, false);
             }
@@ -366,5 +366,5 @@
             // move.
             selectPrims(osmColl,
-                    shift || Main.ds.getSelected().containsAll(osmColl),
+                    shift || getCurrentDataSet().getSelected().containsAll(osmColl),
                     ctrl, false, false);
             mode = Mode.move;
@@ -403,5 +403,5 @@
 
             // Select Draw Tool if no selection has been made
-            if(Main.ds.getSelected().size() == 0 && !cancelDrawMode) {
+            if(getCurrentDataSet().getSelected().size() == 0 && !cancelDrawMode) {
                 Main.map.selectDrawTool(true);
                 return;
@@ -419,5 +419,5 @@
 
                 // If the user double-clicked a node, change to draw mode
-                List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(Main.ds.getSelected());
+                List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected());
                 if(e.getClickCount() >=2 && sel.size() == 1 && sel.get(0) instanceof Node) {
                     // We need to do it like this as otherwise drawAction will see a double
@@ -431,5 +431,5 @@
                 }
             } else {
-                Collection<OsmPrimitive> selection = Main.ds.getSelected();
+                Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
                 Collection<OsmPrimitive> s = new TreeSet<OsmPrimitive>();
                 int max = Main.pref.getInteger("warn.move.maxelements", 20);
@@ -469,5 +469,5 @@
                         if (selNodes.size() > 0) {
                             selNodes.add(n);
-                            MergeNodesAction.mergeNodes(selNodes, n);
+                            new MergeNodesAction().mergeNodes(selNodes, n);
                         }
                     }
@@ -496,5 +496,5 @@
             curSel = new LinkedList<OsmPrimitive>(); // new selection will replace the old.
         } else {
-            curSel = Main.ds.getSelected();
+            curSel = getCurrentDataSet().getSelected();
         }
 
@@ -512,5 +512,5 @@
             }
         }
-        Main.ds.setSelected(curSel);
+        getCurrentDataSet().setSelected(curSel);
         Main.map.mapView.repaint();
     }
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java	(revision 1814)
@@ -7,5 +7,4 @@
 import java.awt.event.KeyEvent;
 
-import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.MapView;
@@ -47,6 +46,6 @@
     public ZoomAction(MapFrame mapFrame) {
         super(tr("Zoom"), "zoom", tr("Zoom and move map"),
-        Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),
-        mapFrame, ImageProvider.getCursor("normal", "zoom"));
+                Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),
+                mapFrame, ImageProvider.getCursor("normal", "zoom"));
         mv = mapFrame.mapView;
         selectionManager = new SelectionManager(this, true, mv);
@@ -57,6 +56,7 @@
      */
     public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
-        if (r.width >= 3 && r.height >= 3)
+        if (r.width >= 3 && r.height >= 3) {
             mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth());
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java	(revision 1814)
@@ -164,8 +164,8 @@
         }
         try {
-            Collection<OsmPrimitive> sel = Main.ds.getSelected();
+            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
             SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive, regexSearch);
             int foundMatches = 0;
-            for (OsmPrimitive osm : Main.ds.allNonDeletedCompletePrimitives()) {
+            for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedCompletePrimitives()) {
                 if (mode == SearchMode.replace) {
                     if (matcher.match(osm)) {
@@ -183,5 +183,5 @@
                 }
             }
-            Main.ds.setSelected(sel);
+            Main.main.getCurrentDataSet().setSelected(sel);
             if (foundMatches == 0) {
                 String msg = null;
@@ -241,8 +241,5 @@
      */
     protected void refreshEnabled() {
-        setEnabled(Main.map != null
-                && Main.map.mapView !=null
-                && Main.map.mapView.getEditLayer() != null
-        );
+        setEnabled(getEditLayer() != null);
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java	(revision 1814)
@@ -133,8 +133,9 @@
                 String value = null;
 
-                if (key.equals("timestamp"))
+                if (key.equals("timestamp")) {
                     value = DateUtils.fromDate(osm.getTimestamp());
-                else
+                } else {
                     value = osm.get(key);
+                }
 
                 if (value == null)
@@ -169,7 +170,6 @@
 
         public ExactKeyValue(boolean regexp, String key, String value) throws ParseError {
-            if (key == "") {
+            if (key == "")
                 throw new ParseError(tr("Key cannot be empty when tag operator is used. Sample use: key=value"));
-            }
             this.key = key;
             this.value = value;
@@ -223,7 +223,6 @@
         public boolean match(OsmPrimitive osm) throws ParseError {
 
-            if (osm.keys == null || osm.keys.isEmpty()) {
+            if (osm.keys == null || osm.keys.isEmpty())
                 return mode == Mode.NONE;
-            }
 
             switch (mode) {
@@ -238,7 +237,6 @@
             case ANY_KEY:
                 for (String v:osm.keys.values()) {
-                    if (v.equals(value)) {
+                    if (v.equals(value))
                         return true;
-                    }
                 }
                 return false;
@@ -247,7 +245,6 @@
             case ANY_KEY_REGEXP:
                 for (String v:osm.keys.values()) {
-                    if (valuePattern.matcher(v).matches()) {
+                    if (valuePattern.matcher(v).matches())
                         return true;
-                    }
                 }
                 return false;
@@ -257,7 +254,6 @@
                     if (keyPattern.matcher(entry.getKey()).matches()) {
                         if (mode == Mode.ANY_VALUE_REGEXP
-                                || valuePattern.matcher(entry.getValue()).matches()) {
+                                || valuePattern.matcher(entry.getValue()).matches())
                             return true;
-                        }
                     }
                 }
@@ -265,7 +261,6 @@
             case MISSING_KEY_REGEXP:
                 for (String k:osm.keys.keySet()) {
-                    if (keyPattern.matcher(k).matches()) {
+                    if (keyPattern.matcher(k).matches())
                         return false;
-                    }
                 }
                 return true;
@@ -337,6 +332,7 @@
                 // is not Java 1.5
                 //String name = java.text.Normalizer.normalize(name, java.text.Normalizer.Form.NFC);
-                if (!caseSensitive)
+                if (!caseSensitive) {
                     name = name.toLowerCase();
+                }
                 if (name.indexOf(search) != -1)
                     return true;
@@ -356,8 +352,7 @@
             } else if ("relation".equals(type)) {
                 this.type = Relation.class;
-            } else {
+            } else
                 throw new ParseError(tr("Unknown primitive type: {0}. Allowed values are node, way or relation",
                         type));
-            }
         }
         @Override public boolean match(OsmPrimitive osm) {
@@ -441,14 +436,17 @@
             // "parent" (null) should mean the same as "parent()"
             // (Always). I.e. match everything
-            if (child == null)
+            if (child == null) {
                 child = new Always();
+            }
 
             if (osm instanceof Way) {
-                for (Node n : ((Way)osm).nodes)
+                for (Node n : ((Way)osm).nodes) {
                     isParent |= child.match(n);
+                }
             } else if (osm instanceof Relation) {
                 for (RelationMember member : ((Relation)osm).members) {
-                    if (member.member != null)
+                    if (member.member != null) {
                         isParent |= child.match(member.member);
+                    }
                 }
             }
@@ -464,9 +462,10 @@
             // "child" (null) should mean the same as "child()"
             // (Always). I.e. match everything
-            if (parent == null)
+            if (parent == null) {
                 parent = new Always();
+            }
 
             boolean isChild = false;
-            CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.ds);
+            CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet());
             osm.visit(backRefs);
             for (OsmPrimitive p : backRefs.data) {
@@ -485,16 +484,15 @@
 
     public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch)
-            throws ParseError {
+    throws ParseError {
         return new SearchCompiler(caseSensitive, regexSearch,
                 new PushbackTokenizer(
-                    new PushbackReader(new StringReader(searchStr))))
-            .parse();
+                        new PushbackReader(new StringReader(searchStr))))
+        .parse();
     }
 
     public Match parse() throws ParseError {
         Match m = parseJuxta();
-        if (!tokenizer.readIfEqual(null)) {
+        if (!tokenizer.readIfEqual(null))
             throw new ParseError(tr("Unexpected token: {0}", tokenizer.nextToken()));
-        }
         return m;
     }
@@ -515,7 +513,6 @@
         if (tokenizer.readIfEqual("|")) {
             Match b = parseNot();
-            if (a == null || b == null) {
+            if (a == null || b == null)
                 throw new ParseError(tr("Missing arguments for or."));
-            }
             return new Or(a, b);
         }
@@ -526,7 +523,6 @@
         if (tokenizer.readIfEqual("-")) {
             Match m = parseParens();
-            if (m == null) {
+            if (m == null)
                 throw new ParseError(tr("Missing argument for not."));
-            }
             return new Not(m);
         }
@@ -537,7 +533,6 @@
         if (tokenizer.readIfEqual("(")) {
             Match m = parseJuxta();
-            if (!tokenizer.readIfEqual(")")) {
+            if (!tokenizer.readIfEqual(")"))
                 throw new ParseError(tr("Expected closing parenthesis."));
-            }
             return m;
         }
@@ -550,6 +545,10 @@
         if (tokenizer.readIfEqual(":")) {
             String tok2 = tokenizer.readText();
-            if (tok == null) tok = "";
-            if (tok2 == null) tok2 = "";
+            if (tok == null) {
+                tok = "";
+            }
+            if (tok2 == null) {
+                tok2 = "";
+            }
             return parseKV(tok, tok2);
         }
@@ -557,43 +556,45 @@
         if (tokenizer.readIfEqual("=")) {
             String tok2 = tokenizer.readText();
-            if (tok == null) tok = "";
-            if (tok2 == null) tok2 = "";
+            if (tok == null) {
+                tok = "";
+            }
+            if (tok2 == null) {
+                tok2 = "";
+            }
             return new ExactKeyValue(regexSearch, tok, tok2);
         }
 
-        if (tok == null) {
+        if (tok == null)
             return null;
-        } else if (tok.equals("modified")) {
+        else if (tok.equals("modified"))
             return new Modified();
-        } else if (tok.equals("incomplete")) {
+        else if (tok.equals("incomplete"))
             return new Incomplete();
-        } else if (tok.equals("untagged")) {
+        else if (tok.equals("untagged"))
             return new Untagged();
-        } else if (tok.equals("selected")) {
+        else if (tok.equals("selected"))
             return new Selected();
-        } else if (tok.equals("child")) {
+        else if (tok.equals("child"))
             return new Child(parseParens());
-        } else if (tok.equals("parent")) {
+        else if (tok.equals("parent"))
             return new Parent(parseParens());
-        } else {
+        else
             return new Any(tok);
-        }
     }
 
     private Match parseKV(String key, String value) throws ParseError {
-        if (key.equals("type")) {
+        if (key.equals("type"))
             return new ExactType(value);
-        } else if (key.equals("user")) {
+        else if (key.equals("user"))
             return new UserMatch(value);
-        } else if (key.equals("nodes")) {
+        else if (key.equals("nodes")) {
             try {
                 String[] range = value.split("-");
-                if (range.length == 1) {
+                if (range.length == 1)
                     return new NodeCount(Integer.parseInt(value));
-                } else if (range.length == 2) {
+                else if (range.length == 2)
                     return new NodeCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1]));
-                } else {
+                else
                     throw new ParseError(tr("Wrong number of parameters for nodes operator."));
-                }
             } catch (NumberFormatException e) {
                 throw new ParseError(tr("Incorrect value of nodes operator: {0}. Nodes operator expects number of nodes or range, for example nodes:10-20", value));
@@ -606,7 +607,6 @@
                 throw new ParseError(tr("Incorrect value of id operator: {0}. Number is expected.", value));
             }
-        } else {
+        } else
             return new KeyValue(key, value);
-        }
     }
 
@@ -627,6 +627,7 @@
         // insensitively, but the OSM data is in Unicode. With
         // UNICODE_CASE casefolding is made Unicode-aware.
-        if (!caseSensitive)
+        if (!caseSensitive) {
             searchFlags |= (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
+        }
 
         return searchFlags;
Index: trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java	(revision 1814)
@@ -40,5 +40,5 @@
     @Override protected void realRun() {
         progressMonitor.setTicksCount(2);
-        sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives();
+        sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.main.getCurrentDataSet().allNonDeletedPrimitives();
         try {
             URLConnection con = url.openConnection();
@@ -47,5 +47,5 @@
             progressMonitor.subTask(tr("Downloading..."));
             Map<Long, String> ids = idReader.parseIds(in);
-            for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {
+            for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) {
                 if (ids.containsKey(osm.id) && osm.getClass().getName().toLowerCase().endsWith(ids.get(osm.id))) {
                     if (mode == SearchAction.SearchMode.remove) {
@@ -86,5 +86,5 @@
     @Override protected void finish() {
         if (sel != null) {
-            Main.ds.setSelected(sel);
+            Main.main.getCurrentDataSet().setSelected(sel);
         }
     }
Index: trunk/src/org/openstreetmap/josm/command/AddCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 1814)
@@ -11,7 +11,7 @@
 
 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.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
@@ -39,10 +39,10 @@
 
     @Override public boolean executeCommand() {
-        osm.visit(new AddVisitor(getLayer().data));
+        getLayer().data.addPrimitive(osm);
         return true;
     }
 
     @Override public void undoCommand() {
-        osm.visit(new DeleteVisitor(getLayer().data));
+        getLayer().data.removePrimitive(osm);
     }
 
@@ -52,8 +52,14 @@
 
     @Override public MutableTreeNode description() {
-        NameVisitor v = new NameVisitor();
-        osm.visit(v);
         return new DefaultMutableTreeNode(
-                new JLabel(tr("Add {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
+                new JLabel(
+                        tr("Add {0} {1}",
+                                OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(),
+                                new PrimitiveNameFormatter().getName(osm)
+                        ),
+                        ImageProvider.get(OsmPrimitiveType.from(osm)),
+                        JLabel.HORIZONTAL
+                )
+        );
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 1814)
@@ -11,5 +11,7 @@
 
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
@@ -42,7 +44,10 @@
 
     @Override public MutableTreeNode description() {
-        NameVisitor v = new NameVisitor();
-        osm.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("Change {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(
+                new JLabel(tr("Change {0} {1}",
+                        OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(),
+                        new PrimitiveNameFormatter().getName(osm)),
+                        ImageProvider.get(OsmPrimitiveType.from(osm)),
+                        JLabel.HORIZONTAL));
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 1814)
@@ -14,5 +14,6 @@
 
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -93,10 +94,18 @@
     @Override public MutableTreeNode description() {
         String text;
+        PrimitiveNameFormatter formatter = new PrimitiveNameFormatter();
         if (objects.size() == 1) {
-            NameVisitor v = new NameVisitor();
-            objects.iterator().next().visit(v);
+            OsmPrimitive primitive = objects.iterator().next();
+            String name = formatter.getName(primitive);
             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("Remove \"{0}\" for {1} ''{2}''", key,
+                    OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular(),
+                    name)
+                    : tr("Set {0}={1} for {2} ''{3}''",
+                            key,
+                            value,
+                            OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular(),
+                            name
+                    );
         }
         else
@@ -109,8 +118,12 @@
         if (objects.size() == 1)
             return root;
-        NameVisitor v = new NameVisitor();
         for (OsmPrimitive osm : objects) {
-            osm.visit(v);
-            root.add(new DefaultMutableTreeNode(v.toLabel()));
+            root.add(new DefaultMutableTreeNode(
+                    new JLabel(
+                            formatter.getName(osm),
+                            ImageProvider.get(OsmPrimitiveType.from(osm)),
+                            JLabel.HORIZONTAL)
+            )
+            );
         }
         return root;
Index: trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 1814)
@@ -12,6 +12,8 @@
 import org.openstreetmap.josm.Main;
 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.visitor.NameVisitor;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
@@ -64,7 +66,13 @@
 
     @Override public MutableTreeNode description() {
-        NameVisitor v = new NameVisitor();
-        relation.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("Change relation member role for {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(
+                new JLabel(
+                        tr("Change relation member role for {0} {1}",
+                                OsmPrimitiveType.from(relation),
+                                new PrimitiveNameFormatter().getName(relation)
+                        ),
+                        ImageProvider.get(OsmPrimitiveType.from(relation)),
+                        JLabel.HORIZONTAL)
+        );
     }
 }
Index: trunk/src/org/openstreetmap/josm/command/Command.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/Command.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/Command.java	(revision 1814)
@@ -51,5 +51,5 @@
 
     public Command() {
-        this.layer = Main.main.map.mapView.getEditLayer();
+        this.layer = Main.map.mapView.getEditLayer();
     }
     /**
Index: trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 1814)
@@ -25,4 +25,5 @@
 import org.openstreetmap.josm.data.osm.Node;
 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.RelationMember;
@@ -30,6 +31,6 @@
 import org.openstreetmap.josm.data.osm.WaySegment;
 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
 import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.tools.DontShowAgainInfo;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -76,10 +77,14 @@
 
     @Override public MutableTreeNode description() {
-        NameVisitor v = new NameVisitor();
-
         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));
+            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));
         }
 
@@ -87,9 +92,8 @@
         String cnamem = null;
         for (OsmPrimitive osm : toDelete) {
-            osm.visit(v);
             if (cname == null) {
-                cname = v.className;
-                cnamem = v.classNamePlural;
-            } else if (!cname.equals(v.className)) {
+                cname = OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular();
+                cnamem = OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular();
+            } else if (!cname.equals(OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular())) {
                 cname = "object";
                 cnamem = trn("object", "objects", 2);
@@ -99,6 +103,11 @@
                 cname, cnamem, toDelete.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
         for (OsmPrimitive osm : toDelete) {
-            osm.visit(v);
-            root.add(new DefaultMutableTreeNode(v.toLabel()));
+            root.add(new DefaultMutableTreeNode(
+                    new JLabel(
+                            new PrimitiveNameFormatter().getName(osm),
+                            ImageProvider.get(OsmPrimitiveType.from(osm)),
+                            JLabel.HORIZONTAL)
+            )
+            );
         }
         return root;
@@ -119,5 +128,5 @@
      */
     public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) {
-        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds);
+        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet());
         for (OsmPrimitive osm : selection) {
             osm.visit(v);
@@ -132,8 +141,5 @@
 
     private static int testRelation(Relation ref, OsmPrimitive osm) {
-        NameVisitor n = new NameVisitor();
-        ref.visit(n);
-        NameVisitor s = new NameVisitor();
-        osm.visit(s);
+        PrimitiveNameFormatter formatter = new PrimitiveNameFormatter();
         String role = new String();
         for (RelationMember m : ref.members) {
@@ -144,8 +150,9 @@
         }
         if (role.length() > 0)
-            return new ExtendedDialog(Main.parent,
+            return new ExtendedDialog(
+                    Main.parent,
                     tr("Conflicting relation"),
                     tr("Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?",
-                            s.name, n.name, role),
+                            formatter.getName(osm), formatter.getName(ref), role),
                             new String[] {tr("Delete from relation"), tr("Cancel")},
                             new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
@@ -154,5 +161,5 @@
                     tr("Conflicting relation"),
                     tr("Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?",
-                            s.name, n.name),
+                            formatter.getName(osm), formatter.getName(ref)),
                             new String[] {tr("Delete from relation"), tr("Cancel")},
                             new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
@@ -191,5 +198,5 @@
                     for (Node n : ((Way) osm).nodes) {
                         if (!n.isTagged()) {
-                            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds, false);
+                            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false);
                             n.visit(v);
                             v.data.removeAll(del);
@@ -208,5 +215,5 @@
 
         for (OsmPrimitive osm : del) {
-            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds, false);
+            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false);
             osm.visit(v);
             for (OsmPrimitive ref : v.data) {
@@ -238,5 +245,5 @@
                 del.add(w);
 
-                CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds, false);
+                CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false);
                 w.visit(v);
                 for (OsmPrimitive ref : v.data) {
@@ -366,5 +373,5 @@
      */
     private static boolean checkAndConfirmOutlyingDeletes(Collection<OsmPrimitive> del) {
-        Area a = Main.ds.getDataSourceArea();
+        Area a = Main.main.getCurrentDataSet().getDataSourceArea();
         if (a != null) {
             for (OsmPrimitive osm : del) {
Index: trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java	(revision 1814)
@@ -179,6 +179,6 @@
     protected void purge(OsmPrimitive toPurge, DataSet ds, ArrayList<OsmPrimitive> hive) {
         ArrayList<OsmPrimitive> parents = new ArrayList<OsmPrimitive>();
-        parents.addAll(Main.ds.ways);
-        parents.addAll(Main.ds.relations);
+        parents.addAll(getLayer().data.ways);
+        parents.addAll(getLayer().data.relations);
         List<OsmParentChildPair> pairs = getParentChildPairs(parents, primitive);
         hive.remove(toPurge);
@@ -217,5 +217,5 @@
         while(! hive.isEmpty()) {
             OsmPrimitive toPurge = hive.get(0);
-            purge(toPurge, Main.ds, hive);
+            purge(toPurge, getLayer().data, hive);
             if (toPurge instanceof Node) {
                 getLayer().data.nodes.remove(toPurge);
Index: trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java	(revision 1814)
@@ -12,7 +12,9 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.*;
-
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
@@ -62,7 +64,14 @@
 
     @Override public MutableTreeNode description() {
-        NameVisitor v = new NameVisitor();
-        relation.visit(v);
-        return new DefaultMutableTreeNode(new JLabel(tr("Remove relation member {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL));
+        return new DefaultMutableTreeNode(
+                new JLabel(
+                        tr("Remove relation member {0} {1}",
+                                OsmPrimitiveType.from(relation).getLocalizedDisplayNameSingular(),
+                                new PrimitiveNameFormatter().getName(relation)
+                        ),
+                        ImageProvider.get(OsmPrimitiveType.from(relation)),
+                        JLabel.HORIZONTAL
+                )
+        );
     }
 }
Index: trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
===================================================================
--- trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java	(revision 1814)
@@ -115,5 +115,5 @@
         roleCorrectionMap.put(way, new ArrayList<RoleCorrection>());
 
-        for (Relation relation : Main.ds.relations) {
+        for (Relation relation : Main.main.getCurrentDataSet().relations) {
             int position = 0;
             for (RelationMember member : relation.members) {
Index: trunk/src/org/openstreetmap/josm/corrector/RoleCorrectionTableModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/corrector/RoleCorrectionTableModel.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/corrector/RoleCorrectionTableModel.java	(revision 1814)
@@ -6,10 +6,9 @@
 import java.util.List;
 
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 
 public class RoleCorrectionTableModel extends
-        CorrectionTableModel<RoleCorrection> {
-
-    private static NameVisitor nameVisitor = new NameVisitor();
+CorrectionTableModel<RoleCorrection> {
+    private static final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
 
     public RoleCorrectionTableModel(List<RoleCorrection> roleCorrections) {
@@ -41,6 +40,5 @@
         switch (colIndex) {
         case 0:
-            roleCorrection.relation.visit(nameVisitor);
-            return nameVisitor.name;
+            return NAME_FORMATTER.getName(roleCorrection.relation);
         case 1:
             return roleCorrection.member.role;
Index: trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java
===================================================================
--- trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java	(revision 1814)
@@ -25,20 +25,22 @@
 import org.openstreetmap.josm.data.osm.Node;
 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.RelationMember;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
 import org.openstreetmap.josm.gui.JMultilineLabel;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 public abstract class TagCorrector<P extends OsmPrimitive> {
+    private static final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
 
     public abstract Collection<Command> execute(P primitive, P oldprimitive)
-        throws UserCancelException;
+    throws UserCancelException;
 
     private String[] applicationOptions = new String[] {
-        tr("Apply selected changes"),
-        tr("Don't apply changes"),
-        tr("Cancel")
+            tr("Apply selected changes"),
+            tr("Don't apply changes"),
+            tr("Cancel")
     };
 
@@ -56,5 +58,5 @@
         }
 
-        if (!hasCorrections)
+        if (!hasCorrections) {
             for (List<RoleCorrection> roleCorrectionList : roleCorrectionMap
                     .values()) {
@@ -64,4 +66,5 @@
                 }
             }
+        }
 
         if (hasCorrections) {
@@ -72,5 +75,5 @@
                 new HashMap<OsmPrimitive, RoleCorrectionTable>();
 
-            NameVisitor nameVisitor = new NameVisitor();
+            //NameVisitor nameVisitor = new NameVisitor();
 
             final JPanel p = new JPanel(new GridBagLayout());
@@ -87,10 +90,9 @@
             for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) {
                 final List<TagCorrection> tagCorrections = tagCorrectionsMap
-                        .get(primitive);
-
-                if (tagCorrections.isEmpty())
+                .get(primitive);
+
+                if (tagCorrections.isEmpty()) {
                     continue;
-
-                primitive.visit(nameVisitor);
+                }
 
                 final JLabel propertiesLabel = new JLabel(tr("Properties of "));
@@ -98,5 +100,8 @@
 
                 final JLabel primitiveLabel = new JLabel(
-                        nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT);
+                        NAME_FORMATTER.getName(primitive) + ":",
+                        ImageProvider.get(OsmPrimitiveType.from(primitive)),
+                        JLabel.LEFT
+                );
                 p.add(primitiveLabel, GBC.eol());
 
@@ -111,9 +116,8 @@
             for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
                 final List<RoleCorrection> roleCorrections = roleCorrectionMap
-                        .get(primitive);
-                if (roleCorrections.isEmpty())
+                .get(primitive);
+                if (roleCorrections.isEmpty()) {
                     continue;
-
-                primitive.visit(nameVisitor);
+                }
 
                 final JLabel rolesLabel = new JLabel(
@@ -122,5 +126,8 @@
 
                 final JLabel primitiveLabel = new JLabel(
-                        nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT);
+                        NAME_FORMATTER.getName(primitive),
+                        ImageProvider.get(OsmPrimitiveType.from(primitive)),
+                        JLabel.LEFT
+                );
                 p.add(primitiveLabel, GBC.eol());
 
@@ -145,7 +152,11 @@
                     // create the clone
                     OsmPrimitive clone = null;
-                    if (primitive instanceof Way) clone = new Way((Way)primitive);
-                    else if (primitive instanceof Node) clone = new Node((Node)primitive);
-                    else if (primitive instanceof Relation) clone = new Relation((Relation)primitive);
+                    if (primitive instanceof Way) {
+                        clone = new Way((Way)primitive);
+                    } else if (primitive instanceof Node) {
+                        clone = new Node((Node)primitive);
+                    } else if (primitive instanceof Relation) {
+                        clone = new Relation((Relation)primitive);
+                    }
 
                     // use this structure to remember keys that have been set already so that
@@ -157,5 +168,7 @@
                         if (tagTableMap.get(primitive).getCorrectionTableModel().getApply(i)) {
                             TagCorrection tagCorrection = tagCorrections.get(i);
-                            if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) clone.remove(tagCorrection.oldKey);
+                            if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) {
+                                clone.remove(tagCorrection.oldKey);
+                            }
                             clone.put(tagCorrection.newKey, tagCorrection.newValue);
                             keysChanged.add(tagCorrection.newKey);
@@ -164,9 +177,11 @@
 
                     // save the clone
-                    if (!keysChanged.isEmpty()) commands.add(new ChangeCommand(primitive, clone));
+                    if (!keysChanged.isEmpty()) {
+                        commands.add(new ChangeCommand(primitive, clone));
+                    }
                 }
                 for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
                     List<RoleCorrection> roleCorrections = roleCorrectionMap
-                            .get(primitive);
+                    .get(primitive);
 
                     for (int i = 0; i < roleCorrections.size(); i++) {
@@ -177,7 +192,6 @@
                     }
                 }
-            } else if (answer != JOptionPane.NO_OPTION) {
+            } else if (answer != JOptionPane.NO_OPTION)
                 throw new UserCancelException();
-            }
             return commands;
         }
Index: trunk/src/org/openstreetmap/josm/data/DataSetChecker.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/DataSetChecker.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/data/DataSetChecker.java	(revision 1814)
@@ -33,5 +33,5 @@
         if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) {
             OsmDataLayer l = (OsmDataLayer)Main.map.mapView.getActiveLayer();
-            if (l.data != Main.ds) {
+            if (l.data != Main.main.getCurrentDataSet()) {
                 JOptionPane.showMessageDialog(Main.parent, "Main.ds / active layer mismatch");
                 return;
Index: trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java	(revision 1814)
@@ -62,5 +62,5 @@
         }
         fireCommandsChanged();
-        Main.ds.setSelected();
+        Main.main.getCurrentDataSet().setSelected();
     }
 
@@ -84,6 +84,7 @@
 
     public void fireCommandsChanged() {
-        for (final CommandQueueListener l : listenerCommands)
+        for (final CommandQueueListener l : listenerCommands) {
             l.commandChanged(commands.size(), redoCommands.size());
+        }
     }
 
@@ -108,6 +109,7 @@
             }
         }
-        if (changed)
+        if (changed) {
             fireCommandsChanged();
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 1814)
@@ -105,11 +105,39 @@
     }
 
-    public void addPrimitive(OsmPrimitive osm) {
-        if (osm instanceof Node) {
-            nodes.add((Node) osm);
-        } else if (osm instanceof Way) {
-            ways.add((Way) osm);
-        } else if (osm instanceof Relation) {
-            relations.add((Relation) osm);
+    /**
+     * Adds a primitive to the dataset
+     * 
+     * @param primitive the primitive. Ignored if null.
+     */
+    public void addPrimitive(OsmPrimitive primitive) {
+        if (primitive == null)
+            return;
+        if (primitive instanceof Node) {
+            nodes.add((Node) primitive);
+        } else if (primitive instanceof Way) {
+            ways.add((Way) primitive);
+        } else if (primitive instanceof Relation) {
+            relations.add((Relation) primitive);
+        }
+    }
+
+    /**
+     * Removes a primitive from the dataset. This method only removes the
+     * primitive form the respective collection of primitives managed
+     * by this dataset, i.e. from {@see #nodes}, {@see #ways}, or
+     * {@see #relations}. References from other primitives to this
+     * primitive are left unchanged.
+     * 
+     * @param primitive the primitive. Ignored if null.
+     */
+    public void removePrimitive(OsmPrimitive primitive) {
+        if (primitive == null)
+            return;
+        if (primitive instanceof Node) {
+            nodes.remove(primitive);
+        } else if (primitive instanceof Way) {
+            ways.remove(primitive);
+        } else if (primitive instanceof Relation) {
+            relations.remove(primitive);
         }
     }
@@ -120,4 +148,6 @@
         return sel;
     }
+
+
     /**
      * Return a list of all selected objects. Even keys are returned.
@@ -391,3 +421,5 @@
         }
     }
+
+
 }
Index: trunk/src/org/openstreetmap/josm/data/osm/Node.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 1814)
@@ -140,4 +140,3 @@
         return name;
     }
-
 }
Index: trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java	(revision 1814)
@@ -2,4 +2,6 @@
 package org.openstreetmap.josm.data.osm;
 import static org.openstreetmap.josm.tools.I18n.tr;
+
+import javax.swing.ImageIcon;
 
 public enum OsmPrimitiveType {
Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java	(revision 1812)
+++ 	(revision )
@@ -1,33 +1,0 @@
-// License: GPL. Copyright 2007 by Immanuel Scholz and others
-package org.openstreetmap.josm.data.osm.visitor;
-
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.Way;
-
-/**
- * Visitor that adds the visited object to the dataset given at constructor.
- *
- * Is not capable of adding keys.
- *
- * @author imi
- */
-public class AddVisitor extends AbstractVisitor {
-
-    protected final DataSet ds;
-
-    public AddVisitor(DataSet ds) {
-        this.ds = ds;
-    }
-
-    public void visit(Node n) {
-        ds.nodes.add(n);
-    }
-    public void visit(Way w) {
-        ds.ways.add(w);
-    }
-    public void visit(Relation e) {
-        ds.relations.add(e);
-    }
-}
Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java	(revision 1812)
+++ 	(revision )
@@ -1,33 +1,0 @@
-// License: GPL. Copyright 2007 by Immanuel Scholz and others
-package org.openstreetmap.josm.data.osm.visitor;
-
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Relation;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.Way;
-
-/**
- * Visitor that adds the visited object to the dataset given at constructor.
- *
- * Is not capable of adding keys.
- *
- * @author imi
- */
-public class DeleteVisitor extends AbstractVisitor {
-
-    private final DataSet ds;
-
-    public DeleteVisitor(DataSet ds) {
-        this.ds = ds;
-    }
-
-    public void visit(Node n) {
-        ds.nodes.remove(n);
-    }
-    public void visit(Way w) {
-        ds.ways.remove(w);
-    }
-    public void visit(Relation e) {
-        ds.relations.remove(e);
-    }
-}
Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java	(revision 1812)
+++ 	(revision )
@@ -1,81 +1,0 @@
-// License: GPL. Copyright 2007 by Immanuel Scholz and others
-package org.openstreetmap.josm.data.osm.visitor;
-
-import static org.openstreetmap.josm.tools.I18n.tr;
-import static org.openstreetmap.josm.tools.I18n.trn;
-
-import javax.swing.Icon;
-import javax.swing.JLabel;
-
-import org.openstreetmap.josm.Main;
-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.tools.ImageProvider;
-
-/**
- * Able to create a name and an icon for each data element.
- *
- * @author imi
- */
-public class NameVisitor extends AbstractVisitor {
-
-    /**
-     * The name of the item class
-     */
-    public String className;
-    public String classNamePlural;
-    /**
-     * The name of this item.
-     */
-    public String name;
-    /**
-     * The icon of this item.
-     */
-    public Icon icon;
-
-    /**
-     * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
-     * is displayed.
-     */
-    public void visit(Node n) {
-        name = n.getName();
-        addId(n);
-        icon = ImageProvider.get("data", "node");
-        className = "node";
-        classNamePlural = trn("node", "nodes", 2);
-    }
-
-    /**
-     * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
-     * is displayed with x being the number of nodes in the way.
-     */
-    public void visit(Way w) {
-        name = w.getName();
-        addId(w);
-        icon = ImageProvider.get("data", "way");
-        className = "way";
-        classNamePlural = trn("way", "ways", 2);
-    }
-
-    /**
-     */
-    public void visit(Relation e) {
-        name = e.getName();
-        addId(e);
-        icon = ImageProvider.get("data", "relation");
-        className = "relation";
-        classNamePlural = trn("relation", "relations", 2);
-    }
-
-    public JLabel toLabel() {
-        return new JLabel(name, icon, JLabel.HORIZONTAL);
-    }
-
-
-    private void addId(OsmPrimitive osm) {
-        if (Main.pref.getBoolean("osm-primitives.showid"))
-            name += tr(" [id: {0}]", osm.id);
-    }
-}
Index: trunk/src/org/openstreetmap/josm/gui/MapStatus.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MapStatus.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/MapStatus.java	(revision 1814)
@@ -21,6 +21,6 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseListener;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Collection;
@@ -39,7 +39,7 @@
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
+import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
-import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -59,4 +59,5 @@
  */
 public class MapStatus extends JPanel implements Helpful {
+    private static final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
 
     /**
@@ -145,9 +146,11 @@
                 if (parent != Main.map)
                     return; // exit, if new parent.
-                if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null)
+                if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) {
                     continue; // freeze display when holding down ctrl
-
-                if (mv.center == null)
+                }
+
+                if (mv.center == null) {
                     continue;
+                }
 
                 // This try/catch is a hack to stop the flooding bug reports about this.
@@ -160,9 +163,8 @@
                     osmNearest = mv.getNearest(ms.mousePos);
                     if (osmNearest != null) {
-                        NameVisitor visitor = new NameVisitor();
-                        osmNearest.visit(visitor);
-                        nameText.setText(visitor.name);
-                    } else
+                        nameText.setText(NAME_FORMATTER.getName(osmNearest));
+                    } else {
                         nameText.setText(tr("(no object)"));
+                    }
 
                     // Popup Information
@@ -170,8 +172,10 @@
                         Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos);
 
-                        if (osms == null)
+                        if (osms == null) {
                             continue;
-                        if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers)
+                        }
+                        if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers) {
                             continue;
+                        }
 
                         if (popup != null) {
@@ -190,15 +194,21 @@
                         JPanel c = new JPanel(new GridBagLayout());
                         for (final OsmPrimitive osm : osms) {
-                            NameVisitor visitor = new NameVisitor();
-                            osm.visit(visitor);
                             final StringBuilder text = new StringBuilder();
-                            if (osm.id == 0 || osm.modified)
-                                visitor.name = "<i><b>"+visitor.name+"*</b></i>";
-                            text.append(visitor.name);
-                            if (osm.id != 0)
+                            String name = NAME_FORMATTER.getName(osm);
+                            if (osm.id == 0 || osm.modified) {
+                                name = "<i><b>"+ new PrimitiveNameFormatter().getName(osm)+"*</b></i>";
+                            }
+                            text.append(name);
+                            if (osm.id != 0) {
                                 text.append("<br>id="+osm.id);
-                            for (Entry<String, String> e : osm.entrySet())
+                            }
+                            for (Entry<String, String> e : osm.entrySet()) {
                                 text.append("<br>"+e.getKey()+"="+e.getValue());
-                            final JLabel l = new JLabel("<html>"+text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL);
+                            }
+                            final JLabel l = new JLabel(
+                                    "<html>"+text.toString()+"</html>",
+                                    ImageProvider.get(OsmPrimitiveType.from(osm)),
+                                    JLabel.HORIZONTAL
+                            );
                             l.setFont(l.getFont().deriveFont(Font.PLAIN));
                             l.setVerticalTextPosition(JLabel.TOP);
@@ -212,5 +222,5 @@
                                 }
                                 @Override public void mouseClicked(MouseEvent e) {
-                                    Main.ds.setSelected(osm);
+                                    Main.main.getCurrentDataSet().setSelected(osm);
                                     mv.repaint();
                                 }
@@ -306,9 +316,10 @@
                 public void eventDispatched(AWTEvent event) {
                     if (event instanceof ComponentEvent &&
-                        ((ComponentEvent)event).getComponent() == mapFrame.mapView) {
+                            ((ComponentEvent)event).getComponent() == mapFrame.mapView) {
                         synchronized (collector) {
                             mouseState.modifiers = ((InputEvent)event).getModifiersEx();
-                            if (event instanceof MouseEvent)
+                            if (event instanceof MouseEvent) {
                                 mouseState.mousePos = ((MouseEvent)event).getPoint();
+                            }
                             collector.notify();
                         }
Index: trunk/src/org/openstreetmap/josm/gui/MapView.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MapView.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/MapView.java	(revision 1814)
@@ -148,5 +148,4 @@
         if (layer instanceof OsmDataLayer) {
             OsmDataLayer editLayer = (OsmDataLayer)layer;
-            Main.ds = editLayer.data;
             editLayer.listenerModified.add(new ModifiedChangedListener(){
                 public void modifiedChanged(boolean value, OsmDataLayer source) {
@@ -181,5 +180,5 @@
 
     @Override
-    protected DataSet getData() {
+    protected DataSet getCurrentDataSet() {
         if(activeLayer != null && activeLayer instanceof OsmDataLayer)
             return ((OsmDataLayer)activeLayer).data;
@@ -211,7 +210,4 @@
     public void removeLayer(Layer layer) {
         if (layer == activeLayer) {
-            if (layer instanceof OsmDataLayer) {
-                Main.ds = null;
-            }
             activeLayer = null;
         }
@@ -351,12 +347,11 @@
     public void setActiveLayer(Layer layer) {
         if (!layers.contains(layer))
-            throw new IllegalArgumentException(tr("Layer {0} must be in list of layers", layer.toString()));
-        if (layer instanceof OsmDataLayer) {
-            OsmDataLayer editLayer = (OsmDataLayer)layer;
-            Main.ds = editLayer.data;
-        } else {
-            Main.ds.setSelected();
-        }
-        DataSet.fireSelectionChanged(Main.ds.getSelected());
+            throw new IllegalArgumentException(tr("Layer ''{0}'' must be in list of layers", layer.toString()));
+        if (! (layer instanceof OsmDataLayer)) {
+            if (getCurrentDataSet() != null) {
+                getCurrentDataSet().setSelected();
+                DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
+            }
+        }
         Layer old = activeLayer;
         activeLayer = layer;
Index: trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java	(revision 1814)
@@ -27,5 +27,4 @@
 import org.openstreetmap.josm.data.osm.WaySegment;
 import org.openstreetmap.josm.data.projection.Projection;
-import org.openstreetmap.josm.data.projection.Mercator;
 
 /**
@@ -55,7 +54,6 @@
     }
 
-    protected DataSet getData()
-    {
-        return Main.ds;
+    protected DataSet getCurrentDataSet() {
+        return Main.main.getCurrentDataSet();
     }
 
@@ -102,20 +100,20 @@
     public ProjectionBounds getProjectionBounds() {
         return new ProjectionBounds(
-        new EastNorth(
-                center.east() - getWidth()/2.0*scale,
-                center.north() - getHeight()/2.0*scale),
-        new EastNorth(
-                center.east() + getWidth()/2.0*scale,
-                center.north() + getHeight()/2.0*scale));
+                new EastNorth(
+                        center.east() - getWidth()/2.0*scale,
+                        center.north() - getHeight()/2.0*scale),
+                        new EastNorth(
+                                center.east() + getWidth()/2.0*scale,
+                                center.north() + getHeight()/2.0*scale));
     };
 
     public Bounds getRealBounds() {
         return new Bounds(
-        getProjection().eastNorth2latlon(new EastNorth(
-                center.east() - getWidth()/2.0*scale,
-                center.north() - getHeight()/2.0*scale)),
-        getProjection().eastNorth2latlon(new EastNorth(
-                center.east() + getWidth()/2.0*scale,
-                center.north() + getHeight()/2.0*scale)));
+                getProjection().eastNorth2latlon(new EastNorth(
+                        center.east() - getWidth()/2.0*scale,
+                        center.north() - getHeight()/2.0*scale)),
+                        getProjection().eastNorth2latlon(new EastNorth(
+                                center.east() + getWidth()/2.0*scale,
+                                center.north() + getHeight()/2.0*scale)));
     };
 
@@ -163,5 +161,5 @@
      */
     private void zoomTo(EastNorth newCenter, double newScale) {
-/* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */
+        /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */
         boolean rep = false;
         if (!newCenter.equals(center)) {
@@ -177,6 +175,7 @@
             firePropertyChange("scale", oldScale, newScale);
         }
-        if(rep)
+        if(rep) {
             repaint();
+        }
     }
 
@@ -186,8 +185,9 @@
 
     public void zoomTo(LatLon newCenter) {
-        if (newCenter instanceof CachedLatLon)
+        if(newCenter instanceof CachedLatLon) {
             zoomTo(((CachedLatLon)newCenter).getEastNorth(), scale);
-        else
+        } else {
             zoomTo(getProjection().latlon2eastNorth(newCenter), scale);
+        }
     }
 
@@ -197,7 +197,7 @@
         // You will get the formula by simplifying this expression: newCenter = oldCenter + mouseCoordinatesInNewZoom - mouseCoordinatesInOldZoom
         zoomTo(new EastNorth(
-        center.east() - (x - getWidth()/2.0) * (newScale - scale),
-        center.north() + (y - getHeight()/2.0) * (newScale - scale)),
-        newScale);
+                center.east() - (x - getWidth()/2.0) * (newScale - scale),
+                center.north() + (y - getHeight()/2.0) * (newScale - scale)),
+                newScale);
     }
 
@@ -213,9 +213,11 @@
         // -20 to leave some border
         int w = getWidth()-20;
-        if (w < 20)
+        if (w < 20) {
             w = 20;
+        }
         int h = getHeight()-20;
-        if (h < 20)
+        if (h < 20) {
             h = 20;
+        }
 
         double scaleX = (box.max.east()-box.min.east())/w;
@@ -228,5 +230,5 @@
     public void zoomTo(Bounds box) {
         zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.min),
-        getProjection().latlon2eastNorth(box.max)));
+                getProjection().latlon2eastNorth(box.max)));
     }
 
@@ -238,7 +240,8 @@
         double minDistanceSq = snapDistance;
         Node minPrimitive = null;
-        for (Node n : getData().nodes) {
-            if (n.deleted || n.incomplete)
+        for (Node n : getCurrentDataSet().nodes) {
+            if (n.deleted || n.incomplete) {
                 continue;
+            }
             Point sp = getPoint(n);
             double dist = p.distanceSq(sp);
@@ -249,7 +252,8 @@
             // when multiple nodes on one point, prefer new or selected nodes
             else if(dist == minDistanceSq && minPrimitive != null
-            && ((n.id == 0 && n.selected)
-            || (!minPrimitive.selected && (n.selected || n.id == 0))))
+                    && ((n.id == 0 && n.selected)
+                            || (!minPrimitive.selected && (n.selected || n.id == 0)))) {
                 minPrimitive = n;
+            }
         }
         return minPrimitive;
@@ -264,11 +268,15 @@
     public final List<WaySegment> getNearestWaySegments(Point p) {
         TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>();
-        for (Way w : getData().ways) {
-            if (w.deleted || w.incomplete) continue;
+        for (Way w : getCurrentDataSet().ways) {
+            if (w.deleted || w.incomplete) {
+                continue;
+            }
             Node lastN = null;
             int i = -2;
             for (Node n : w.nodes) {
                 i++;
-                if (n.deleted || n.incomplete) continue;
+                if (n.deleted || n.incomplete) {
+                    continue;
+                }
                 if (lastN == null) {
                     lastN = n;
@@ -283,6 +291,7 @@
                 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared
                 if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) {
-                    if(w.selected) // prefer selected ways a little bit
+                    if(w.selected) {
                         perDist -= 0.00001;
+                    }
                     List<WaySegment> l;
                     if (nearest.containsKey(perDist)) {
@@ -315,5 +324,7 @@
     public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) {
         List<WaySegment> nearest = getNearestWaySegments(p);
-        if (ignore != null) nearest.removeAll(ignore);
+        if (ignore != null) {
+            nearest.removeAll(ignore);
+        }
         return nearest.isEmpty() ? null : nearest.get(0);
     }
@@ -376,9 +387,13 @@
     public Collection<OsmPrimitive> getAllNearest(Point p) {
         Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>();
-            for (Way w : getData().ways) {
-            if (w.deleted || w.incomplete) continue;
+        for (Way w : getCurrentDataSet().ways) {
+            if (w.deleted || w.incomplete) {
+                continue;
+            }
             Node lastN = null;
             for (Node n : w.nodes) {
-                if (n.deleted || n.incomplete) continue;
+                if (n.deleted || n.incomplete) {
+                    continue;
+                }
                 if (lastN == null) {
                     lastN = n;
@@ -393,10 +408,10 @@
                 if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) {
                     nearest.add(w);
-                        break;
-                    }
+                    break;
+                }
                 lastN = n;
-                }
-            }
-        for (Node n : getData().nodes) {
+            }
+        }
+        for (Node n : getCurrentDataSet().nodes) {
             if (!n.deleted && !n.incomplete
                     && getPoint(n).distanceSq(p) < snapDistance) {
@@ -417,5 +432,5 @@
     public Collection<Node> getNearestNodes(Point p) {
         Collection<Node> nearest = new HashSet<Node>();
-        for (Node n : getData().nodes) {
+        for (Node n : getCurrentDataSet().nodes) {
             if (!n.deleted && !n.incomplete
                     && getPoint(n).distanceSq(p) < snapDistance) {
@@ -436,6 +451,8 @@
     public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore) {
         Collection<Node> nearest = getNearestNodes(p);
-                if (nearest == null) return null;
-        if (ignore != null) nearest.removeAll(ignore);
+        if (nearest == null) return null;
+        if (ignore != null) {
+            nearest.removeAll(ignore);
+        }
         return nearest.isEmpty() ? null : nearest;
     }
Index: trunk/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java	(revision 1814)
@@ -13,5 +13,6 @@
 
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
@@ -24,9 +25,5 @@
  */
 public class OsmPrimitivRenderer implements ListCellRenderer, TableCellRenderer {
-
-    /**
-     * NameVisitor provides proper names and icons for OsmPrimitives
-     */
-    private NameVisitor visitor = new NameVisitor();
+    static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
 
     /**
@@ -65,7 +62,6 @@
     private Component renderer(Component def, OsmPrimitive value) {
         if (def != null && value != null && def instanceof JLabel) {
-            (value).visit(visitor);
-            ((JLabel)def).setText(visitor.name);
-            ((JLabel)def).setIcon(visitor.icon);
+            ((JLabel)def).setText(NAME_FORMATTER.getName(value));
+            ((JLabel)def).setIcon(ImageProvider.get(OsmPrimitiveType.from(value)));
         }
         return def;
Index: trunk/src/org/openstreetmap/josm/gui/PrimitiveNameFormatter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/PrimitiveNameFormatter.java	(revision 1814)
+++ trunk/src/org/openstreetmap/josm/gui/PrimitiveNameFormatter.java	(revision 1814)
@@ -0,0 +1,17 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.gui;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+
+public class PrimitiveNameFormatter {
+    public String getName(OsmPrimitive primitive) {
+        String name = primitive.getName();
+        if (Main.pref.getBoolean("osm-primitives.showid")) {
+            name += tr(" [id: {0}]", primitive.id);
+        }
+        return name;
+    }
+}
Index: trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/SelectionManager.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/SelectionManager.java	(revision 1814)
@@ -279,5 +279,5 @@
         } else {
             // nodes
-            for (Node n : nc.getData().nodes) {
+            for (Node n : nc.getCurrentDataSet().nodes) {
                 if (!n.deleted && !n.incomplete && r.contains(nc.getPoint(n)))
                     selection.add(n);
@@ -285,5 +285,5 @@
 
             // ways
-            for (Way w : nc.getData().ways) {
+            for (Way w : nc.getCurrentDataSet().ways) {
                 if (w.deleted || w.nodes.isEmpty() || w.incomplete)
                         continue;
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java	(revision 1814)
@@ -353,5 +353,5 @@
                 sel.add((OsmPrimitive)o);
             }
-            Main.ds.setSelected(sel);
+            Main.main.getCurrentDataSet().setSelected(sel);
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java	(revision 1814)
@@ -288,5 +288,5 @@
         public void refresh() {
             data.clear();
-            for (OsmPrimitive primitive: Main.ds.getSelected()) {
+            for (OsmPrimitive primitive: Main.main.getCurrentDataSet().getSelected()) {
                 if (primitive.id == 0) {
                     continue;
@@ -398,5 +398,5 @@
         @Override
         protected void realRun() throws SAXException, IOException, OsmTransferException {
-            Collection<OsmPrimitive> selection = Main.ds.getSelected();
+            Collection<OsmPrimitive> selection = Main.main.getCurrentDataSet().getSelected();
             Iterator<OsmPrimitive> it = selection.iterator();
             try {
@@ -454,5 +454,5 @@
 
         public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
-            setEnabled(Main.ds.getSelected().size() > 0);
+            setEnabled(Main.main.getCurrentDataSet().getSelected().size() > 0);
 
         }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java	(revision 1814)
@@ -60,9 +60,12 @@
 import org.openstreetmap.josm.data.osm.RelationMember;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
 import org.openstreetmap.josm.gui.ExtendedDialog;
 import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.gui.SideButton;
 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
 import org.openstreetmap.josm.gui.tagging.TaggingPreset;
@@ -88,10 +91,6 @@
  * @author imi
  */
-public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener {
-
-    /**
-     * Used to display relation names in the membership table
-     */
-    private NameVisitor nameVisitor = new NameVisitor();
+public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener {
+    static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
 
     /**
@@ -135,5 +134,5 @@
      */
     void propertyEdit(int row) {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
         if (sel.isEmpty()) return;
 
@@ -318,5 +317,5 @@
      */
     void add() {
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
         if (sel.isEmpty()) return;
 
@@ -387,5 +386,5 @@
             boolean edit) {
         final TreeMap<String, TreeSet<String>> allData = new TreeMap<String, TreeSet<String>>();
-        for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {
+        for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) {
             for (String key : osm.keySet()) {
                 TreeSet<String> values = null;
@@ -413,5 +412,5 @@
     private void delete(int row) {
         String key = propertyData.getValueAt(row, 0).toString();
-        Collection<OsmPrimitive> sel = Main.ds.getSelected();
+        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
         Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null));
         DataSet.fireSelectionChanged(sel);
@@ -513,6 +512,5 @@
                 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
                 if (c instanceof JLabel) {
-                    nameVisitor.visit((Relation)value);
-                    ((JLabel)c).setText(nameVisitor.name);
+                    ((JLabel)c).setText(NAME_FORMATTER.getName((Relation)value));
                 }
                 return c;
@@ -576,10 +574,7 @@
                     } else if (e.getActionCommand().equals("Delete")) {
                         Relation cur = (Relation)membershipData.getValueAt(row, 0);
-                        NameVisitor n = new NameVisitor();
-                        cur.visit(n);
-
                         int result = new ExtendedDialog(Main.parent,
                                 tr("Change relation"),
-                                tr("Really delete selection from relation {0}?", n.name),
+                                tr("Really delete selection from relation {0}?", NAME_FORMATTER.getName(cur)),
                                 new String[] {tr("Delete from relation"), tr("Cancel")},
                                 new String[] {"dialogs/delete.png", "cancel.png"}).getValue();
@@ -588,5 +583,5 @@
                         {
                             Relation rel = new Relation(cur);
-                            Collection<OsmPrimitive> sel = Main.ds.getSelected();
+                            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
                             for (RelationMember rm : cur.members) {
                                 for (OsmPrimitive osm : sel) {
@@ -642,10 +637,11 @@
 
         DataSet.selListeners.add(this);
+        Layer.listeners.add(this);
     }
 
     @Override public void setVisible(boolean b) {
         super.setVisible(b);
-        if (b) {
-            selectionChanged(Main.ds.getSelected());
+        if (b && Main.main.getCurrentDataSet() != null) {
+            selectionChanged(Main.main.getCurrentDataSet().getSelected());
         }
     }
@@ -796,5 +792,5 @@
 
         Map<Relation, Collection<RelationMember>> roles = new HashMap<Relation, Collection<RelationMember>>();
-        for (Relation r : Main.ds.relations) {
+        for (Relation r : Main.main.getCurrentDataSet().relations) {
             if (!r.deleted && !r.incomplete) {
                 for (RelationMember m : r.members) {
@@ -842,3 +838,20 @@
         }
     }
+
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        if (newLayer instanceof OsmDataLayer) {
+            OsmDataLayer dataLayer = (OsmDataLayer)newLayer;
+            selectionChanged(dataLayer.data.getSelected());
+        }
+    }
+
+    public void layerAdded(Layer newLayer) {
+        // do nothing
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        // do nothing
+    }
+
+
 }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 1814)
@@ -77,5 +77,5 @@
             @Override public void mouseClicked(MouseEvent e) {
                 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
-                    Main.ds.setSelected((Relation)displaylist.getSelectedValue());
+                    Main.main.getCurrentDataSet().setSelected((Relation)displaylist.getSelectedValue());
                 }
             }
@@ -125,17 +125,23 @@
     }
 
+    protected int getNumRelations() {
+        if (Main.main.getCurrentDataSet() == null) return 0;
+        return Main.main.getCurrentDataSet().relations.size();
+    }
+
     public void updateList() {
         Relation selected = getSelected();
-        list.setSize(Main.ds.relations.size());
-        int i = 0;
-        for (OsmPrimitive e : DataSet.sort(Main.ds.relations)) {
-            if (!e.deleted && !e.incomplete) {
-                list.setElementAt(e, i++);
-            }
-        }
-        list.setSize(i);
-
-        if(Main.ds.relations.size() != 0) {
-            setTitle(tr("Relations: {0}", Main.ds.relations.size()), true);
+        list.setSize(getNumRelations());
+        if (getNumRelations() > 0 ) {
+            int i = 0;
+            for (OsmPrimitive e : DataSet.sort(Main.main.getCurrentDataSet().relations)) {
+                if (!e.deleted && !e.incomplete) {
+                    list.setElementAt(e, i++);
+                }
+            }
+            list.setSize(i);
+        }
+        if(getNumRelations() != 0) {
+            setTitle(tr("Relations: {0}", Main.main.getCurrentDataSet().relations.size()), true);
         } else {
             setTitle(tr("Relations"), false);
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java	(revision 1814)
@@ -43,4 +43,7 @@
 import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
 import org.openstreetmap.josm.gui.SideButton;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -52,5 +55,5 @@
  * @author imi
  */
-public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener {
+public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener {
 
     private static final int SELECTION_HISTORY_SIZE = 10;
@@ -80,5 +83,5 @@
     public SelectionListDialog() {
         super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."),
-        Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
+                Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
 
         selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>();
@@ -89,6 +92,7 @@
             @Override
             public void mouseClicked(MouseEvent e) {
-                if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
+                if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                     updateMap();
+                }
             }
 
@@ -112,8 +116,8 @@
                 tr("Set the selected elements on the map to the selected items in the list above."),
                 new ActionListener() {
-                    public void actionPerformed(ActionEvent e) {
-                        updateMap();
-                    }
-                });
+            public void actionPerformed(ActionEvent e) {
+                updateMap();
+            }
+        });
         buttonPanel.add(selectButton);
         BasicArrowButton selectionHistoryMenuButton = createArrowButton(selectButton);
@@ -134,8 +138,8 @@
         buttonPanel.add(new SideButton(marktr("Reload"), "refresh", "SelectionList", tr("Refresh the selection list."),
                 new ActionListener() {
-                    public void actionPerformed(ActionEvent e) {
-                        selectionChanged(Main.ds.getSelected());
-                    }
-                }));
+            public void actionPerformed(ActionEvent e) {
+                selectionChanged(Main.main.getCurrentDataSet().getSelected());
+            }
+        }));
 
         searchButton = new SideButton(marktr("Search"), "search", "SelectionList", tr("Search for objects."),
@@ -159,7 +163,10 @@
         popupMenu.add(zoomToSelection);
 
-        selectionChanged(Main.ds.getSelected());
+        if (Main.main.getCurrentDataSet() != null) {
+            selectionChanged(Main.main.getCurrentDataSet().getSelected());
+        }
 
         DataSet.selListeners.add(this);
+        Layer.listeners.add(this);
     }
 
@@ -179,6 +186,7 @@
     public void setVisible(boolean b) {
         super.setVisible(b);
-        if (b)
-            selectionChanged(Main.ds.getSelected());
+        if (b && Main.main.getCurrentDataSet() != null) {
+            selectionChanged(Main.main.getCurrentDataSet().getSelected());
+        }
     }
 
@@ -204,6 +212,7 @@
         for (int i = 0; i < selected.length; i++) {
             Object o = list.get(selected[i]);
-            if (o instanceof OsmPrimitive)
+            if (o instanceof OsmPrimitive) {
                 ((OsmPrimitive) o).visit(box);
+            }
         }
         if (box.getBounds() == null)
@@ -247,6 +256,7 @@
         list.setSize(selArr.length);
         int i = 0;
-        for (OsmPrimitive osm : selArr)
+        for (OsmPrimitive osm : selArr) {
             list.setElementAt(osm, i++);
+        }
         if (selectionHistory != null && newSelection.size() > 0 && !newSelection.equals(historyIgnoreSelection)) {
             historyIgnoreSelection = null;
@@ -259,6 +269,7 @@
             }
             selectionHistory.addFirst(newSelection);
-            while (selectionHistory.size() > SELECTION_HISTORY_SIZE)
+            while (selectionHistory.size() > SELECTION_HISTORY_SIZE) {
                 selectionHistory.removeLast();
+            }
         }
 
@@ -267,10 +278,11 @@
         int relations = 0;
         for (OsmPrimitive o : newSelection) {
-            if (o instanceof Way)
+            if (o instanceof Way) {
                 ways++;
-            else if (o instanceof Node)
+            } else if (o instanceof Node) {
                 nodes++;
-            else if (o instanceof Relation)
+            } else if (o instanceof Relation) {
                 relations++;
+            }
         }
 
@@ -288,7 +300,8 @@
         Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>();
         for (int i = 0; i < list.getSize(); ++i)
-            if (displaylist.isSelectedIndex(i))
+            if (displaylist.isSelectedIndex(i)) {
                 sel.add((OsmPrimitive) list.get(i));
-        Main.ds.setSelected(sel);
+            }
+        Main.main.getCurrentDataSet().setSelected(sel);
     }
 
@@ -308,21 +321,25 @@
             int relations = 0;
             for (OsmPrimitive o : sel) {
-                if (o instanceof Way)
+                if (o instanceof Way) {
                     ways++;
-                else if (o instanceof Node)
+                } else if (o instanceof Node) {
                     nodes++;
-                else if (o instanceof Relation)
+                } else if (o instanceof Relation) {
                     relations++;
+                }
             }
             String text = "";
-            if(ways != 0)
+            if(ways != 0) {
                 text += (text.length() > 0 ? ", " : "")
                 + trn("{0} way", "{0} ways", ways, ways);
-            if(nodes != 0)
+            }
+            if(nodes != 0) {
                 text += (text.length() > 0 ? ", " : "")
                 + trn("{0} node", "{0} nodes", nodes, nodes);
-            if(relations != 0)
+            }
+            if(relations != 0) {
                 text += (text.length() > 0 ? ", " : "")
                 + trn("{0} relation", "{0} relations", relations, relations);
+            }
             setText(tr("Selection: {0}", text));
             addActionListener(this);
@@ -331,5 +348,5 @@
         public void actionPerformed(ActionEvent e) {
             historyIgnoreSelection = sel;
-            Main.ds.setSelected(sel);
+            Main.main.getCurrentDataSet().setSelected(sel);
         }
 
@@ -355,3 +372,22 @@
 
     }
+
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        if (newLayer instanceof OsmDataLayer) {
+            OsmDataLayer dataLayer = (OsmDataLayer)newLayer;
+            selectionChanged(dataLayer.data.getSelected());
+
+        }
+
+    }
+
+    public void layerAdded(Layer newLayer) {
+        // do nothing
+
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        // do nothing
+
+    }
 }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java	(revision 1814)
@@ -24,4 +24,7 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.User;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -32,5 +35,5 @@
  * @author Frederik Ramm <frederik@remote.org>
  */
-public class UserListDialog extends ToggleDialog implements SelectionChangedListener, MouseListener{
+public class UserListDialog extends ToggleDialog implements SelectionChangedListener, MouseListener, LayerChangeListener {
 
     /**
@@ -52,18 +55,22 @@
     public UserListDialog() {
         super(tr("Authors"), "userlist", tr("Open a list of people working on the selected objects."),
-        Shortcut.registerShortcut("subwindow:authors", tr("Toggle: {0}", tr("Authors")), KeyEvent.VK_A, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
+                Shortcut.registerShortcut("subwindow:authors", tr("Toggle: {0}", tr("Authors")), KeyEvent.VK_A, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
 
         data.setColumnIdentifiers(new String[]{tr("Author"),tr("# Objects"),"%"});
         userTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         add(new JScrollPane(userTable), BorderLayout.CENTER);
-        selectionChanged(Main.ds.getSelected());
+        if (Main.main.getCurrentDataSet() != null) {
+            selectionChanged(Main.main.getCurrentDataSet().getSelected());
+        }
         userTable.addMouseListener(this);
         DataSet.selListeners.add(this);
+        Layer.listeners.add(this);
     }
 
     @Override public void setVisible(boolean b) {
         super.setVisible(b);
-        if (b)
-            selectionChanged(Main.ds.getSelected());
+        if (b && Main.main.getCurrentDataSet() != null) {
+            selectionChanged(Main.main.getCurrentDataSet().getSelected());
+        }
     }
 
@@ -91,8 +98,11 @@
         for (OsmPrimitive p : newSelection) {
             User u = p.user;
-            if (u == null) u = anonymousUser;
+            if (u == null) {
+                u = anonymousUser;
+            }
             UserCount uc = counters.get(u);
-            if (uc == null)
+            if (uc == null) {
                 counters.put(u, uc = new UserCount(u, 0));
+            }
             uc.count++;
             all++;
@@ -123,11 +133,12 @@
             if (userName==null)
                 return;
-            Collection<OsmPrimitive> selected = Main.ds.getSelected();
+            Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();
             Collection<OsmPrimitive> byUser = new LinkedList<OsmPrimitive>();
             for (OsmPrimitive p : selected) {
-                if (p.user!= null && userName.equals(p.user.name))
+                if (p.user!= null && userName.equals(p.user.name)) {
                     byUser.add(p);
+                }
             }
-            Main.ds.setSelected(byUser);
+            Main.main.getCurrentDataSet().setSelected(byUser);
         }
     }
@@ -145,3 +156,18 @@
     }
 
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        if (newLayer instanceof OsmDataLayer) {
+            OsmDataLayer dataLayer = (OsmDataLayer)newLayer;
+            selectionChanged(dataLayer.data.getSelected());
+
+        }
+    }
+
+    public void layerAdded(Layer newLayer) {
+        // do nothing
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        // do nothing
+    }
 }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java	(revision 1814)
@@ -315,5 +315,5 @@
                     }
                 }
-                Main.ds.setSelected(sel);
+                getLayer().data.setSelected(sel);
             }
         });
@@ -564,5 +564,5 @@
             memberTableModel.applyToRelation(newRelation);
             Main.main.undoRedo.add(new AddCommand(newRelation));
-            DataSet.fireSelectionChanged(Main.ds.getSelected());
+            DataSet.fireSelectionChanged(getLayer().data.getSelected());
         } else if (! memberTableModel.hasSameMembersAs(getRelation()) || tagEditorModel.isDirty()) {
             Relation editedRelation = new Relation(getRelation());
@@ -588,5 +588,5 @@
                 memberTableModel.applyToRelation(clone);
                 Main.main.undoRedo.add(new ChangeCommand(getRelation(), clone));
-                DataSet.fireSelectionChanged(Main.ds.getSelected());
+                DataSet.fireSelectionChanged(getLayer().data.getSelected());
             }
         }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableCellRenderer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableCellRenderer.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableCellRenderer.java	(revision 1814)
@@ -15,5 +15,5 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -23,4 +23,6 @@
  */
 public  class MemberTableCellRenderer extends JLabel implements TableCellRenderer {
+    static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
+
     public final static Color BGCOLOR_SELECTED = new Color(143,170,255);
     public final static Color BGCOLOR_EMPTY_ROW = new Color(234,234,234);
@@ -112,8 +114,6 @@
 
     protected void renderPrimitive(OsmPrimitive primitive) {
-        NameVisitor visitor = new NameVisitor();
-        primitive.visit(visitor);
         setIcon(icons.get(OsmPrimitiveType.from(primitive)));
-        setText(visitor.name);
+        setText(NAME_FORMATTER.getName(primitive));
         setToolTipText(buildToolTipText(primitive));
     }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableColumnModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableColumnModel.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableColumnModel.java	(revision 1814)
@@ -20,4 +20,5 @@
         col.setResizable(true);
         col.setCellRenderer(renderer);
+
         addColumn(col);
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java	(revision 1814)
@@ -15,5 +15,5 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -23,4 +23,6 @@
  */
 public  class SelectionTableCellRenderer extends JLabel implements TableCellRenderer {
+    static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
+
     public final static Color BGCOLOR_SELECTED = new Color(143,170,255);
     public final static Color BGCOLOR_DOUBLE_ENTRY = new Color(255,234,213);
@@ -115,8 +117,6 @@
 
     protected void renderPrimitive(OsmPrimitive primitive) {
-        NameVisitor visitor = new NameVisitor();
-        primitive.visit(visitor);
         setIcon(icons.get(OsmPrimitiveType.from(primitive)));
-        setText(visitor.name);
+        setText(NAME_FORMATTER.getName(primitive));
         setToolTipText(buildToolTipText(primitive));
     }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/TagEditorModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/TagEditorModel.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/TagEditorModel.java	(revision 1814)
@@ -260,20 +260,4 @@
 
     /**
-     * initializes the model with the tags in the current JOSM selection
-     */
-    public void initFromJOSMSelection() {
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
-        clear();
-        for (OsmPrimitive element : selection) {
-            for (String key : element.keySet()) {
-                String value = element.get(key);
-                add(key,value);
-            }
-        }
-        sort();
-        setDirty(false);
-    }
-
-    /**
      * initializes the model with the tags of an OSM primitive
      * 
@@ -291,5 +275,4 @@
         setDirty(false);
     }
-
 
     /**
@@ -381,35 +364,4 @@
         return command;
     }
-
-    /**
-     * updates the tags of the primitives in the current selection with the
-     * values in the current tag model
-     * 
-     */
-    public void updateJOSMSelection() {
-        ArrayList<Command> commands = new ArrayList<Command>();
-        Collection<OsmPrimitive> selection = Main.ds.getSelected();
-        if (selection == null)
-            return;
-        for (TagModel tag : tags) {
-            Command command = createUpdateTagCommand(selection,tag);
-            if (command != null) {
-                commands.add(command);
-            }
-        }
-        Command deleteCommand = createDeleteTagsCommand(selection);
-        if (deleteCommand != null) {
-            commands.add(deleteCommand);
-        }
-
-        SequenceCommand command = new SequenceCommand(
-                trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", selection.size(), selection.size()),
-                commands
-        );
-
-        // executes the commands and adds them to the undo/redo chains
-        Main.main.undoRedo.add(command);
-    }
-
 
     /**
Index: trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java	(revision 1814)
@@ -101,10 +101,12 @@
         for (OsmPrimitive s : sel) {
             String v = s.get(key);
-            if (v != null)
+            if (v != null) {
                 returnValue.values.add(v);
-            else
+            } else {
                 returnValue.hadEmpty = true;
-            if(s.keys != null && s.keys.size() > 0)
+            }
+            if(s.keys != null && s.keys.size() > 0) {
                 returnValue.hadKeys = true;
+            }
         }
         return returnValue;
@@ -149,5 +151,7 @@
                 // all objects use the same value
                 value = new JTextField();
-                for (String s : usage.values) ((JTextField) value).setText(s);
+                for (String s : usage.values) {
+                    ((JTextField) value).setText(s);
+                }
                 originalValue = ((JTextField)value).getText();
             } else {
@@ -158,6 +162,7 @@
                 originalValue = DIFFERENT;
             }
-            if(locale_text == null)
+            if(locale_text == null) {
                 locale_text = tr(text);
+            }
             p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0));
             p.add(value, GBC.eol().fill(GBC.HORIZONTAL));
@@ -169,13 +174,16 @@
             // return if unchanged
             String v = (value instanceof JComboBox) ?
-                ((JComboBox)value).getEditor().getItem().toString() :
-                ((JTextField)value).getText();
-
-            if (use_last_as_default) lastValue.put(key, v);
-            if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return;
-
-            if (delete_if_empty && v.length() == 0)
-                v = null;
-            cmds.add(new ChangePropertyCommand(sel, key, v));
+                    ((JComboBox)value).getEditor().getItem().toString() :
+                        ((JTextField)value).getText();
+
+                    if (use_last_as_default) {
+                        lastValue.put(key, v);
+                    }
+                    if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return;
+
+                    if (delete_if_empty && v.length() == 0) {
+                        v = null;
+                    }
+                    cmds.add(new ChangePropertyCommand(sel, key, v));
         }
         @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();}
@@ -200,14 +208,19 @@
             def = default_;
 
-            if(locale_text == null)
+            if(locale_text == null) {
                 locale_text = tr(text);
+            }
 
             String oneValue = null;
-            for (String s : usage.values) oneValue = s;
+            for (String s : usage.values) {
+                oneValue = s;
+            }
             if (usage.values.size() < 2 && (oneValue == null || OsmUtils.trueval.equals(oneValue) || OsmUtils.falseval.equals(oneValue))) {
                 if(def)
                 {
                     for (OsmPrimitive s : sel)
-                        if(s.keys != null && s.keys.size() > 0) def = false;
+                        if(s.keys != null && s.keys.size() > 0) {
+                            def = false;
+                        }
                 }
 
@@ -215,9 +228,9 @@
                 // we can display a standard check box.
                 initialState = OsmUtils.trueval.equals(oneValue) ?
-                            QuadStateCheckBox.State.SELECTED :
+                        QuadStateCheckBox.State.SELECTED :
                             OsmUtils.falseval.equals(oneValue) ?
-                            QuadStateCheckBox.State.NOT_SELECTED :
-                            def ? QuadStateCheckBox.State.SELECTED
-                            : QuadStateCheckBox.State.UNSET;
+                                    QuadStateCheckBox.State.NOT_SELECTED :
+                                        def ? QuadStateCheckBox.State.SELECTED
+                                                : QuadStateCheckBox.State.UNSET;
                 check = new QuadStateCheckBox(locale_text, initialState,
                         new QuadStateCheckBox.State[] {
@@ -249,6 +262,6 @@
             cmds.add(new ChangePropertyCommand(sel, key,
                     check.getState() == QuadStateCheckBox.State.SELECTED ? OsmUtils.trueval :
-                    check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? OsmUtils.falseval :
-                    null));
+                        check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? OsmUtils.falseval :
+                            null));
         }
         @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();}
@@ -280,10 +293,11 @@
             String[] value_array = values.split(",");
             String[] display_array;
-            if(locale_display_values != null)
+            if(locale_display_values != null) {
                 display_array = locale_display_values.split(",");
-            else if(display_values != null)
+            } else if(display_values != null) {
                 display_array = display_values.split(",");
-            else
+            } else {
                 display_array = value_array;
+            }
 
             lhm = new LinkedHashMap<String,String>();
@@ -294,15 +308,21 @@
             for (int i=0; i<value_array.length; i++) {
                 lhm.put(value_array[i],
-                (locale_display_values == null) ?
-                tr(display_array[i]) : display_array[i]);
+                        (locale_display_values == null) ?
+                                tr(display_array[i]) : display_array[i]);
             }
             if(!usage.unused())
             {
                 for (String s : usage.values) {
-                    if (!lhm.containsKey(s)) lhm.put(s, s);
-                }
-            }
-            if (default_ != null && !lhm.containsKey(default_)) lhm.put(default_, default_);
-            if(!lhm.containsKey("")) lhm.put("", "");
+                    if (!lhm.containsKey(s)) {
+                        lhm.put(s, s);
+                    }
+                }
+            }
+            if (default_ != null && !lhm.containsKey(default_)) {
+                lhm.put(default_, default_);
+            }
+            if(!lhm.containsKey("")) {
+                lhm.put("", "");
+            }
 
             combo = new JComboBox(lhm.values().toArray());
@@ -330,6 +350,7 @@
             }
 
-            if(locale_text == null)
+            if(locale_text == null) {
                 locale_text = tr(text);
+            }
             p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0));
             p.add(combo, GBC.eol().fill(GBC.HORIZONTAL));
@@ -340,6 +361,7 @@
             String display = (obj == null) ? null : obj.toString();
             String value = null;
-            if(display == null && combo.isEditable())
+            if(display == null && combo.isEditable()) {
                 display = combo.getEditor().getItem().toString();
+            }
 
             if (display != null)
@@ -347,17 +369,21 @@
                 for (String key : lhm.keySet()) {
                     String k = lhm.get(key);
-                    if (k != null && k.equals(display)) value=key;
-                }
-                if(value == null)
+                    if (k != null && k.equals(display)) {
+                        value=key;
+                    }
+                }
+                if(value == null) {
                     value = display;
-            }
-            else
+                }
+            } else {
                 value = "";
+            }
 
             // no change if same as before
             if (value.equals(originalValue) || (originalValue == null && (value == null || value.length() == 0))) return;
 
-            if (delete_if_empty && value != null && value.length() == 0)
+            if (delete_if_empty && value != null && value.length() == 0) {
                 value = null;
+            }
             cmds.add(new ChangePropertyCommand(sel, key, value));
         }
@@ -370,6 +396,7 @@
 
         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
-            if(locale_text == null)
+            if(locale_text == null) {
                 locale_text = tr(text);
+            }
             p.add(new JLabel(locale_text), GBC.eol());
             return false;
@@ -385,6 +412,7 @@
 
         @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
-            if(locale_text == null)
+            if(locale_text == null) {
                 locale_text = text == null ? tr("More information about this feature") : tr(text);
+            }
             String url = locale_href;
             if (url == null) {
@@ -449,11 +477,12 @@
         putValue("toolbar", "tagging_" + getRawName());
         putValue(SHORT_DESCRIPTION, (group != null ?
-        tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) :
-        tr("Use preset ''{0}''", getLocaleName())));
+                tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) :
+                    tr("Use preset ''{0}''", getLocaleName())));
     }
 
     public String getLocaleName() {
-        if(locale_name == null)
+        if(locale_name == null) {
             locale_name = tr(name);
+        }
         return locale_name;
     }
@@ -479,6 +508,7 @@
             icon = new ImageIcon(iconName);
         }
-        if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16)
+        if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16) {
             icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
+        }
         putValue(Action.SMALL_ICON, icon);
     }
@@ -488,5 +518,5 @@
      */
     private static Collection<String> allowedtypes = Arrays.asList(new String[]
-    {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")});
+                                                                              {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")});
     public void setType(String types) throws SAXException {
         this.types = Arrays.asList(types.split(","));
@@ -517,7 +547,7 @@
             if (o instanceof TaggingPresetMenu) {
                 TaggingPresetMenu tp = (TaggingPresetMenu) o;
-                if(tp == lastmenu)
+                if(tp == lastmenu) {
                     lastmenu = tp.group;
-                else
+                } else
                 {
                     tp.setDisplayName();
@@ -538,6 +568,7 @@
                 all.add(tp);
                 Main.toolbar.register(tp);
-            } else
+            } else {
                 all.getLast().data.add((Item)o);
+            }
         }
         return all;
@@ -548,6 +579,7 @@
         LinkedList<String> sources = new LinkedList<String>();
 
-        if(Main.pref.getBoolean("taggingpreset.enable-defaults", true))
+        if(Main.pref.getBoolean("taggingpreset.enable-defaults", true)) {
             sources.add("resource://presets/presets.xml");
+        }
         sources.addAll(Main.pref.getCollection("taggingpreset.sources", new LinkedList<String>()));
 
@@ -604,19 +636,21 @@
         for (Item i : data)
         {
-            if(i instanceof Link)
+            if(i instanceof Link) {
                 l.add(i);
-            else
-            {
-                if(i.addToPanel(p, selected))
+            } else
+            {
+                if(i.addToPanel(p, selected)) {
                     p.hasElements = true;
-            }
-        }
-        for(Item link : l)
+                }
+            }
+        }
+        for(Item link : l) {
             link.addToPanel(p, selected);
+        }
         return p;
     }
 
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = createSelection(Main.ds.getSelected());
+        Collection<OsmPrimitive> sel = createSelection(Main.main.getCurrentDataSet().getSelected());
         PresetPanel p = createPanel(sel);
         if (p == null)
@@ -627,8 +661,9 @@
             String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size());
             if(sel.size() == 0) {
-                if(originalSelectionEmpty)
+                if(originalSelectionEmpty) {
                     title = tr("Nothing selected!");
-                else
+                } else {
                     title = tr("Selection unsuitable!");
+                }
             }
 
@@ -651,8 +686,9 @@
         if (sel.size() != 0 && answer == 1) {
             Command cmd = createCommand(sel);
-            if (cmd != null)
+            if (cmd != null) {
                 Main.main.undoRedo.add(cmd);
-        }
-        Main.ds.setSelected(Main.ds.getSelected()); // force update
+            }
+        }
+        Main.main.getCurrentDataSet().setSelected(Main.main.getCurrentDataSet().getSelected()); // force update
     }
 
@@ -676,15 +712,20 @@
                 if(osm instanceof Relation)
                 {
-                    if(!types.contains("relation")) continue;
+                    if(!types.contains("relation")) {
+                        continue;
+                    }
                 }
                 else if(osm instanceof Node)
                 {
-                    if(!types.contains("node")) continue;
+                    if(!types.contains("node")) {
+                        continue;
+                    }
                 }
                 else if(osm instanceof Way)
                 {
                     if(!types.contains("way") &&
-                    !(types.contains("closedway") && ((Way)osm).isClosed()))
+                            !(types.contains("closedway") && ((Way)osm).isClosed())) {
                         continue;
+                    }
                 }
             }
@@ -696,6 +737,7 @@
     private Command createCommand(Collection<OsmPrimitive> sel) {
         List<Command> cmds = new LinkedList<Command>();
-        for (Item i : data)
+        for (Item i : data) {
             i.addCommands(sel, cmds);
+        }
         if (cmds.size() == 0)
             return null;
Index: trunk/src/org/openstreetmap/josm/io/GpxImporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 1814)
@@ -29,16 +29,18 @@
             GpxReader r = null;
             InputStream is;
-            if (file.getName().endsWith(".gpx.gz"))
+            if (file.getName().endsWith(".gpx.gz")) {
                 is = new GZIPInputStream(new FileInputStream(file));
-            else
+            } else {
                 is = new FileInputStream(file);
+            }
             // Workaround for SAX BOM bug
             // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206835
             if (!((is.read() == 0xef) && (is.read() == 0xbb) && (is.read() == 0xbf))) {
                 is.close();
-                if (file.getName().endsWith(".gpx.gz"))
+                if (file.getName().endsWith(".gpx.gz")) {
                     is = new GZIPInputStream(new FileInputStream(file));
-                else
+                } else {
                     is = new FileInputStream(file);
+                }
             }
             r = new GpxReader(is, file.getAbsoluteFile().getParentFile());
@@ -48,6 +50,7 @@
             if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
                 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer);
-                if (ml.data.size() > 0)
+                if (ml.data.size() > 0) {
                     Main.main.addLayer(ml);
+                }
             }
         } catch (FileNotFoundException e) {
Index: trunk/src/org/openstreetmap/josm/io/OsmReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmReader.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/io/OsmReader.java	(revision 1814)
@@ -29,5 +29,4 @@
 import org.openstreetmap.josm.data.osm.User;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.tools.DateUtils;
@@ -55,9 +54,4 @@
     private DataSet ds = new DataSet();
     public DataSet getDs() { return ds; }
-
-    /**
-     * The visitor to use to add the data to the set.
-     */
-    private AddVisitor adder = new AddVisitor(ds);
 
     /**
@@ -349,9 +343,9 @@
                 w.incomplete = true;
                 w.nodes.clear();
-                adder.visit(w);
+                ds.addPrimitive(w);
             } else {
                 e.getKey().copyTo(w);
                 w.incomplete = false;
-                adder.visit(w);
+                ds.addPrimitive(w);
             }
         }
@@ -401,5 +395,5 @@
             Relation en = new Relation();
             e.getKey().copyTo(en);
-            adder.visit(en);
+            ds.addPrimitive(en);
         }
 
@@ -421,5 +415,5 @@
                     if (em.member == null) {
                         em.member = new Node(emd.id);
-                        adder.visit((Node)em.member);
+                        ds.addPrimitive(em.member);
                     }
                 } else if (emd.type.equals("way")) {
@@ -430,5 +424,5 @@
                     if (em.member == null) {
                         em.member = new Way(emd.id);
-                        adder.visit((Way)em.member);
+                        ds.addPrimitive(em.member);
                     }
                 } else if (emd.type.equals("relation")) {
@@ -436,5 +430,5 @@
                     if (em.member == null) {
                         em.member = new Relation(emd.id);
-                        adder.visit((Relation)em.member);
+                        ds.addPrimitive(em.member);
                     }
                 } else {
@@ -458,10 +452,10 @@
 
     public static OsmReader parseDataSetOsm(InputStream source, ProgressMonitor progressMonitor) throws SAXException, IOException {
-        OsmReader osm = new OsmReader();
+        OsmReader reader = new OsmReader();
 
         // phase 1: Parse nodes and read in raw ways
         InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));
         try {
-            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, osm.new Parser());
+            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, reader.new Parser());
         } catch (ParserConfigurationException e1) {
             e1.printStackTrace(); // broken SAXException chaining
@@ -471,6 +465,6 @@
         progressMonitor.beginTask(tr("Prepare OSM data...", 2));
         try {
-            for (Node n : osm.nodes.values()) {
-                osm.adder.visit(n);
+            for (Node n : reader.nodes.values()) {
+                reader.ds.addPrimitive(n);
             }
 
@@ -478,6 +472,6 @@
 
             try {
-                osm.createWays();
-                osm.createRelations();
+                reader.createWays();
+                reader.createRelations();
             } catch (NumberFormatException e) {
                 e.printStackTrace();
@@ -486,10 +480,10 @@
 
             // clear all negative ids (new to this file)
-            for (OsmPrimitive o : osm.ds.allPrimitives())
+            for (OsmPrimitive o : reader.ds.allPrimitives())
                 if (o.id < 0) {
                     o.id = 0;
                 }
 
-            return osm;
+            return reader;
         } finally {
             progressMonitor.finishTask();
Index: trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java	(revision 1814)
@@ -4,5 +4,4 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.io.IOException;
 import java.io.InputStream;
 
@@ -11,5 +10,4 @@
 import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
-import org.xml.sax.SAXException;
 
 import sun.reflect.generics.reflectiveObjects.NotImplementedException;
Index: trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java	(revision 1814)
@@ -12,5 +12,6 @@
 import org.openstreetmap.josm.actions.UploadAction;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 
@@ -23,4 +24,5 @@
  */
 public class OsmServerWriter {
+    static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter();
     static private final Logger logger = Logger.getLogger(OsmServerWriter.class.getName());
 
@@ -123,8 +125,6 @@
                 progressMonitor.setTicksCount(primitives.size());
                 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false));
-                NameVisitor v = new NameVisitor();
                 uploadStartTime = System.currentTimeMillis();
                 for (OsmPrimitive osm : primitives) {
-                    osm.visit(v);
                     int progress = progressMonitor.getTicks();
                     String time_left_str = timeLeft(progress, primitives.size());
@@ -132,5 +132,8 @@
                             tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})",
                                     Math.round(100.0*progress/primitives.size()), progress,
-                                    primitives.size(), time_left_str, tr(v.className), v.name, osm.id));
+                                    primitives.size(), time_left_str,
+                                    OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(),
+                                    NAME_FORMATTER.getName(osm),
+                                    osm.id));
                     makeApiRequest(osm);
                     processed.add(osm);
@@ -139,4 +142,5 @@
                 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false));
             }
+
         } finally {
             progressMonitor.finishTask();
Index: trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 1812)
+++ trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 1814)
@@ -29,5 +29,7 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.io.MirroredInputStream;
+import static org.openstreetmap.josm.tools.I18n.tr;
 
 /**
@@ -95,9 +97,9 @@
                 {
                     MirroredInputStream is = new MirroredInputStream(name,
-                    new File(Main.pref.getPreferencesDir(), "images").toString());
+                            new File(Main.pref.getPreferencesDir(), "images").toString());
                     if(is != null)
                     {
-                      img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());
-                      cache.put(name, img);
+                        img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());
+                        cache.put(name, img);
                     }
                 }
@@ -107,14 +109,16 @@
             return img == null ? null : new ImageIcon(img);
         }
-        if (subdir == null)
+        if (subdir == null) {
             subdir = "";
-        else if (!subdir.equals(""))
+        } else if (!subdir.equals("")) {
             subdir += "/";
+        }
         String ext = name.indexOf('.') != -1 ? "" : ".png";
         String full_name = subdir+name+ext;
         String cache_name = full_name;
         /* cache separately */
-        if(dirs != null && dirs.size() > 0)
+        if(dirs != null && dirs.size() > 0) {
             cache_name = "id:"+id+":"+full_name;
+        }
 
         Image img = cache.get(cache_name);
@@ -198,6 +202,7 @@
     public static Cursor getCursor(String name, String overlay) {
         ImageIcon img = get("cursor",name);
-        if (overlay != null)
+        if (overlay != null) {
             img = overlay(img, "cursor/modifier/"+overlay, OverlayPosition.SOUTHEAST);
+        }
         Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(img.getImage(),
                 name.equals("crosshair") ? new Point(10,10) : new Point(3,2), "Cursor");
@@ -251,8 +256,8 @@
     }
 
-/* from: http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/
-* License: "feel free to use"
-*/
-final static double DEGREE_90 = 90.0 * Math.PI / 180.0;
+    /* from: http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/
+     * License: "feel free to use"
+     */
+    final static double DEGREE_90 = 90.0 * Math.PI / 180.0;
 
     /**
@@ -315,3 +320,14 @@
         return new ImageIcon(image);
     }
+
+    /**
+     * Replies the icon for an OSM primitive type
+     * @param type the type
+     * @return the icon
+     */
+    public static ImageIcon get(OsmPrimitiveType type) throws IllegalArgumentException {
+        if (type == null)
+            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "type"));
+        return get("data",type.getAPIName());
+    }
 }
