Index: trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java	(revision 14138)
+++ trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java	(revision 14143)
@@ -7,7 +7,7 @@
 import java.util.Objects;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.OsmDataManager;
 import org.openstreetmap.josm.spi.preferences.Config;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
@@ -291,5 +291,5 @@
         if (commands.isEmpty())
             return;
-        DataSet ds = Main.main.getEditDataSet();
+        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
         if (ds != null) {
             ds.beginUpdate();
Index: trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java	(revision 14138)
+++ trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java	(revision 14143)
@@ -98,5 +98,5 @@
      */
     public void executeFilters() {
-        DataSet ds = Main.main.getActiveDataSet();
+        DataSet ds = OsmDataManager.getInstance().getActiveDataSet();
         changed = false;
         if (ds == null) {
@@ -150,5 +150,5 @@
      */
     public void executeFilters(Collection<? extends OsmPrimitive> primitives) {
-        DataSet ds = Main.main.getEditDataSet();
+        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
         if (ds == null)
             return;
@@ -209,5 +209,5 @@
      */
     public void clearFilterFlags() {
-        DataSet ds = Main.main.getEditDataSet();
+        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
         if (ds != null) {
             FilterWorker.clearFilterFlags(ds.allPrimitives());
Index: trunk/src/org/openstreetmap/josm/data/osm/IOsmDataManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/IOsmDataManager.java	(revision 14143)
+++ trunk/src/org/openstreetmap/josm/data/osm/IOsmDataManager.java	(revision 14143)
@@ -0,0 +1,52 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import java.util.Collection;
+
+/**
+ * Global OSM dataset registry.
+ * @since 14143
+ */
+public interface IOsmDataManager {
+
+    /**
+     * Replies the current selected OSM primitives, from a end-user point of view.
+     * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
+     * @return The current selected OSM primitives, from a end-user point of view. Can be {@code null}.
+     */
+    Collection<OsmPrimitive> getInProgressSelection();
+
+    /**
+     * Replies the current selected primitives, from a end-user point of view.
+     * It is not always technically the same collection of primitives than {@link OsmData#getSelected()}.
+     * @return The current selected primitives, from a end-user point of view. Can be {@code null}.
+     */
+    Collection<? extends IPrimitive> getInProgressISelection();
+
+    /**
+     * Gets the active edit data set (not read-only).
+     * @return That data set, <code>null</code>.
+     * @see #getActiveDataSet
+     */
+    DataSet getEditDataSet();
+
+    /**
+     * Gets the active data set (can be read-only).
+     * @return That data set, <code>null</code>.
+     * @see #getEditDataSet
+     */
+    DataSet getActiveDataSet();
+
+    /**
+     * Sets the active data set (and also edit data set if not read-only).
+     * @param ds New data set, or <code>null</code>
+     */
+    void setActiveDataSet(DataSet ds);
+
+    /**
+     * Determines if the list of data sets managed by JOSM contains {@code ds}.
+     * @param ds the data set to look for
+     * @return {@code true} if the list of data sets managed by JOSM contains {@code ds}
+     */
+    boolean containsDataSet(DataSet ds);
+}
Index: trunk/src/org/openstreetmap/josm/data/osm/OsmDataManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/OsmDataManager.java	(revision 14143)
+++ trunk/src/org/openstreetmap/josm/data/osm/OsmDataManager.java	(revision 14143)
@@ -0,0 +1,82 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+import org.openstreetmap.josm.actions.mapmode.DrawAction;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+
+/**
+ * Global OSM dataset registry.
+ * @since 14143
+ */
+public final class OsmDataManager implements IOsmDataManager {
+
+    private OsmDataManager() {
+        // hide constructor
+    }
+
+    private static class InstanceHolder {
+        static final OsmDataManager INSTANCE = new OsmDataManager();
+    }
+
+    /**
+     * Returns the unique instance.
+     * @return the unique instance
+     */
+    public static OsmDataManager getInstance() {
+        return InstanceHolder.INSTANCE;
+    }
+
+    @Override
+    public Collection<OsmPrimitive> getInProgressSelection() {
+        MapFrame map = MainApplication.getMap();
+        if (map != null && map.mapMode instanceof DrawAction) {
+            return ((DrawAction) map.mapMode).getInProgressSelection();
+        } else {
+            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
+            if (ds == null) return Collections.emptyList();
+            return ds.getSelected();
+        }
+    }
+
+    @Override
+    public Collection<? extends IPrimitive> getInProgressISelection() {
+        MapFrame map = MainApplication.getMap();
+        if (map != null && map.mapMode instanceof DrawAction) {
+            return ((DrawAction) map.mapMode).getInProgressSelection();
+        } else {
+            OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
+            if (ds == null) return Collections.emptyList();
+            return ds.getSelected();
+        }
+    }
+
+    @Override
+    public DataSet getEditDataSet() {
+        return MainApplication.getLayerManager().getEditDataSet();
+    }
+
+    @Override
+    public DataSet getActiveDataSet() {
+        return MainApplication.getLayerManager().getActiveDataSet();
+    }
+
+    @Override
+    public void setActiveDataSet(DataSet ds) {
+        Optional<OsmDataLayer> layer = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
+                .filter(l -> l.data.equals(ds)).findFirst();
+        if (layer.isPresent()) {
+            MainApplication.getLayerManager().setActiveLayer(layer.get());
+        }
+    }
+
+    @Override
+    public boolean containsDataSet(DataSet ds) {
+        return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream().anyMatch(l -> l.data.equals(ds));
+    }
+}
Index: trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 14138)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 14143)
@@ -18,5 +18,4 @@
 import java.util.Set;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
@@ -24,4 +23,5 @@
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmDataManager;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.QuadBuckets;
@@ -169,5 +169,5 @@
         mindist = Config.getPref().getDouble(PREFIX + ".node_way_distance", 10.0);
         minmiddledist = Config.getPref().getDouble(PREFIX + ".way_way_distance", 0.0);
-        DataSet dataSet = Main.main != null ? Main.main.getEditDataSet() : null;
+        DataSet dataSet = OsmDataManager.getInstance().getEditDataSet();
         dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
     }
Index: trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java	(revision 14138)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java	(revision 14143)
@@ -9,7 +9,7 @@
 import java.util.Set;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.OsmDataManager;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
@@ -142,5 +142,5 @@
     public void startTest(ProgressMonitor monitor) {
         super.startTest(monitor);
-        DataSet ds = Main.main.getEditDataSet();
+        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
         if (ds == null)
             return;
