Index: trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java	(revision 4694)
+++ trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java	(revision 4695)
@@ -127,7 +127,7 @@
                 cancel();
                 throw e;
-            } catch (Throwable t) {
+            } catch (Error e) {
                 cancel();
-                throw new RuntimeException(t);
+                throw e;
             }
         }
Index: trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java	(revision 4694)
+++ trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java	(revision 4695)
@@ -4,4 +4,6 @@
 import java.awt.Component;
 import java.awt.Container;
+
+import javax.swing.SwingUtilities;
 
 /**
@@ -24,3 +26,11 @@
     }
 
+    public static void runInEDT(Runnable task) {
+        if (SwingUtilities.isEventDispatchThread()) {
+            task.run();
+        } else {
+            SwingUtilities.invokeLater(task);
+        }
+    }
+
 }
Index: trunk/src/org/openstreetmap/josm/io/GpxImporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 4694)
+++ trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 4695)
@@ -19,7 +19,12 @@
 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.xml.sax.SAXException;
 
 public class GpxImporter extends FileImporter {
+
+    protected GpxLayer gpxLayer;
+    protected MarkerLayer markerLayer;
+    protected Runnable postLayerTask;
 
     public GpxImporter() {
@@ -27,49 +32,75 @@
     }
 
-    @Override public void importData(final File file, ProgressMonitor progressMonitor) throws IOException {
-        final String fn = file.getName();
+    @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
+        InputStream is;
+        if (file.getName().endsWith(".gpx.gz")) {
+            is = new GZIPInputStream(new FileInputStream(file));
+        } else {
+            is = new FileInputStream(file);
+        }
+        String fileName = file.getName();
+        loadLayers(is, file, fileName, tr("Markers from {0}", fileName), progressMonitor);
 
+        // FIXME: remove UI stuff from the IO subsystem
+        GuiHelper.runInEDT(new Runnable() {
+            public void run() {
+                if (markerLayer != null) {
+                    Main.main.addLayer(markerLayer);
+                }
+                if (gpxLayer != null) {
+                    Main.main.addLayer(gpxLayer);
+                }
+                postLayerTask.run();
+            }
+        });
+    }
+
+    public void loadLayers(InputStream is, final File associatedFile,
+                    final String gpxLayerName, String markerLayerName, ProgressMonitor progressMonitor) throws IOException {
         try {
-            InputStream is;
-            if (file.getName().endsWith(".gpx.gz")) {
-                is = new GZIPInputStream(new FileInputStream(file));
-            } else {
-                is = new FileInputStream(file);
-            }
             final GpxReader r = new GpxReader(is);
             final boolean parsedProperly = r.parse(true);
-            r.data.storageFile = file;
-            final GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
-
-            // FIXME: remove UI stuff from the IO subsystem
-            //
-            Runnable task = new Runnable() {
+            r.data.storageFile = associatedFile;
+            if (r.data.hasRoutePoints() || r.data.hasTrackPoints()) {
+                gpxLayer = new GpxLayer(r.data, gpxLayerName, associatedFile != null);
+            }
+            if (Main.pref.getBoolean("marker.makeautomarkers", true) && !r.data.waypoints.isEmpty()) {
+                markerLayer = new MarkerLayer(r.data, markerLayerName, associatedFile, gpxLayer);
+                if (markerLayer.data.size() == 0) {
+                    markerLayer = null;
+                }
+            }
+            postLayerTask = new Runnable() {
+                @Override
                 public void run() {
-                    if (r.data.hasRoutePoints() || r.data.hasTrackPoints()) {
-                        Main.main.addLayer(gpxLayer);
-                    }
-                    if (Main.pref.getBoolean("marker.makeautomarkers", true) && !r.data.waypoints.isEmpty()) {
-                        MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer);
-                        if (ml.data.size() > 0) {
-                            Main.main.addLayer(ml);
+                    if (!parsedProperly) {
+                        String msg;
+                        if (associatedFile == null) {
+                            msg = tr("Error occurred while parsing gpx data for layer ''{0}''. Only a part of the file will be available.",
+                                    gpxLayerName);
+                        } else {
+                            msg = tr("Error occurred while parsing gpx file ''{0}''. Only a part of the file will be available.",
+                                    associatedFile.getPath());
                         }
-                    }
-                    if (!parsedProperly) {
-                        JOptionPane.showMessageDialog(null, tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", file.getName()));
+                        JOptionPane.showMessageDialog(null, msg);
                     }
                 }
             };
-            if (SwingUtilities.isEventDispatchThread()) {
-                task.run();
-            } else {
-                SwingUtilities.invokeLater(task);
-            }
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-            throw new IOException(tr("File \"{0}\" does not exist", file.getName()));
         } catch (SAXException e) {
             e.printStackTrace();
-            throw new IOException(tr("Parsing file \"{0}\" failed", file.getName()));
+            throw new IOException(tr("Parsing data for layer ''{0}'' failed", gpxLayerName));
         }
     }
+
+    public GpxLayer getGpxLayer() {
+        return gpxLayer;
+    }
+
+    public MarkerLayer getMarkerLayer() {
+        return markerLayer;
+    }
+
+    public Runnable getPostLayerTask() {
+        return postLayerTask;
+    }
 }
Index: trunk/src/org/openstreetmap/josm/io/OsmImporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmImporter.java	(revision 4694)
+++ trunk/src/org/openstreetmap/josm/io/OsmImporter.java	(revision 4695)
@@ -19,9 +19,10 @@
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.gui.util.GuiHelper;
 
 public class OsmImporter extends FileImporter {
 
-    private OsmDataLayer layer;
-    private Runnable postLayerTask;
+    protected OsmDataLayer layer;
+    protected Runnable postLayerTask;
 
     public OsmImporter() {
@@ -47,5 +48,5 @@
         loadLayer(in, associatedFile, associatedFile == null ? OsmDataLayer.createNewName() : associatedFile.getName(), NullProgressMonitor.INSTANCE);
         // FIXME: remove UI stuff from IO subsystem
-        Runnable uiStuff = new Runnable() {
+        GuiHelper.runInEDT(new Runnable() {
             @Override
             public void run() {
@@ -54,10 +55,5 @@
                 layer.onPostLoadFromFile();
             }
-        };
-        if (SwingUtilities.isEventDispatchThread()) {
-            uiStuff.run();
-        } else {
-            SwingUtilities.invokeLater(uiStuff);
-        }
+        });
     }
 
