Index: applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java
===================================================================
--- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java	(revision 10662)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java	(revision 10663)
@@ -29,112 +29,112 @@
  * @author frsantos
  */
-public class ErrorLayer extends Layer implements LayerChangeListener
-{
-	private OSMValidatorPlugin plugin;
+public class ErrorLayer extends Layer implements LayerChangeListener {
+    private OSMValidatorPlugin plugin;
 
-	public ErrorLayer(OSMValidatorPlugin plugin) {
-		super(tr("Validation errors"));
-		this.plugin = plugin;
-		Layer.listeners.add(this); 
-	}
+    public ErrorLayer(OSMValidatorPlugin plugin) {
+        super(tr("Validation errors"));
+        this.plugin = plugin;
+        Layer.listeners.add(this);
+    }
 
-	/**
-	 * Return a static icon.
-	 */
-	@Override public Icon getIcon() {
-		return ImageProvider.get("layer", "validator");
-	}
+    /**
+     * Return a static icon.
+     */
+    @Override
+    public Icon getIcon() {
+        return ImageProvider.get("layer", "validator");
+    }
 
-	/**
-	 * Draw all primitives in this layer but do not draw modified ones (they
-	 * are drawn by the edit layer).
-	 * Draw nodes last to overlap the ways they belong to.
-	 */
-	@SuppressWarnings("unchecked")
-	@Override 
-	public void paint(final Graphics g, final MapView mv) 
-	{
-		DefaultMutableTreeNode root = plugin.validationDialog.tree.getRoot();
-		if( root == null || root.getChildCount() == 0)
-			return;
-		
-		DefaultMutableTreeNode severity = (DefaultMutableTreeNode)root.getLastChild();
-		while( severity != null )
-		{
-			Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration();
-			while(errorMessages.hasMoreElements())
-			{
-				Object tn = errorMessages.nextElement().getUserObject();
-				if(tn instanceof TestError)
-					((TestError)tn).paint(g, mv);
-			}
-			
-			// Severities in inverse order
-			severity = severity.getPreviousSibling();
-		}
-	}
+    /**
+     * Draw all primitives in this layer but do not draw modified ones (they
+     * are drawn by the edit layer).
+     * Draw nodes last to overlap the ways they belong to.
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public void paint(final Graphics g, final MapView mv) {
+        DefaultMutableTreeNode root = plugin.validationDialog.tree.getRoot();
+        if (root == null || root.getChildCount() == 0)
+            return;
 
-	@Override 
-	public String getToolTipText() 
-	{
-		Bag<Severity, TestError> errorTree = new Bag<Severity, TestError>();
-		List<TestError> errors = plugin.validationDialog.tree.getErrors();
-		for(TestError e : errors)
-		{
-			errorTree.add(e.getSeverity(), e);
-		}
-		
-		StringBuilder b = new StringBuilder();
-		for(Severity s : Severity.values())
-		{
-			if( errorTree.containsKey(s) )
-				b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>");
-		}
-		
-		if( b.length() == 0 )
-			return "<html>"+tr("No validation errors") + "</html>";
-		else
-			return "<html>" + tr("Validation errors") + ":<br>" + b + "</html>";
-	}
+        DefaultMutableTreeNode severity = (DefaultMutableTreeNode) root.getLastChild();
+        while (severity != null) {
+            Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration();
+            while (errorMessages.hasMoreElements()) {
+                Object tn = errorMessages.nextElement().getUserObject();
+                if (tn instanceof TestError)
+                    ((TestError) tn).paint(g, mv);
+            }
 
-	@Override public void mergeFrom(Layer from) {}
+            // Severities in inverse order
+            severity = severity.getPreviousSibling();
+        }
+    }
 
-	@Override public boolean isMergable(Layer other) {
-		return false;
-	}
+    @Override
+    public String getToolTipText() {
+        Bag<Severity, TestError> errorTree = new Bag<Severity, TestError>();
+        List<TestError> errors = plugin.validationDialog.tree.getErrors();
+        for (TestError e : errors) {
+            errorTree.add(e.getSeverity(), e);
+        }
 
-	@Override public void visitBoundingBox(BoundingXYVisitor v) {}
+        StringBuilder b = new StringBuilder();
+        for (Severity s : Severity.values()) {
+            if (errorTree.containsKey(s))
+                b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>");
+        }
 
-	@Override public Object getInfoComponent() 
-	{
-		return getToolTipText();
-	}
+        if (b.length() == 0)
+            return "<html>" + tr("No validation errors") + "</html>";
+        else
+            return "<html>" + tr("Validation errors") + ":<br>" + b + "</html>";
+    }
 
-	@Override public Component[] getMenuEntries() 
-	{
-		return new Component[]{
-				new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
-				new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
-				new JSeparator(),
-				new JMenuItem(new RenameLayerAction(null, this)),
-				new JSeparator(),
-				new JMenuItem(new LayerListPopup.InfoAction(this))};
-	}
+    @Override
+    public void mergeFrom(Layer from) {
+    }
 
-	@Override public void destroy() { }
+    @Override
+    public boolean isMergable(Layer other) {
+        return false;
+    }
 
-	public void activeLayerChange(Layer oldLayer, Layer newLayer) { }
+    @Override
+    public void visitBoundingBox(BoundingXYVisitor v) {
+    }
 
-	public void layerAdded(Layer newLayer) { }
+    @Override
+    public Object getInfoComponent() {
+        return getToolTipText();
+    }
 
-	/**
-	 * If layer is the OSM Data layer, remove all errors
-	 */
-	public void layerRemoved(Layer oldLayer)
-	{
-		if(oldLayer == Main.map.mapView.editLayer ) 
-		{
-			Main.map.mapView.removeLayer(this); 
-		}
-	}
+    @Override
+    public Component[] getMenuEntries() {
+        return new Component[] { new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
+                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), new JSeparator(),
+                new JMenuItem(new RenameLayerAction(null, this)), new JSeparator(),
+                new JMenuItem(new LayerListPopup.InfoAction(this)) };
+    }
+
+    @Override
+    public void destroy() {
+    }
+
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+    }
+
+    public void layerAdded(Layer newLayer) {
+    }
+
+    /**
+     * If layer is the OSM Data layer, remove all errors
+     */
+    public void layerRemoved(Layer oldLayer) {
+        if (oldLayer == Main.map.mapView.editLayer) {
+            Main.map.mapView.removeLayer(this);
+        } else if (oldLayer == this) {
+            OSMValidatorPlugin.errorLayer = null;
+        }
+    }
 }
Index: applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
===================================================================
--- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java	(revision 10662)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java	(revision 10663)
@@ -3,5 +3,4 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.lang.reflect.InvocationTargetException;
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
@@ -10,10 +9,11 @@
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeSet;
@@ -32,5 +32,18 @@
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
 import org.openstreetmap.josm.plugins.Plugin;
-import org.openstreetmap.josm.plugins.validator.tests.*;
+import org.openstreetmap.josm.plugins.validator.tests.Coastlines;
+import org.openstreetmap.josm.plugins.validator.tests.CrossingWays;
+import org.openstreetmap.josm.plugins.validator.tests.DuplicateNode;
+import org.openstreetmap.josm.plugins.validator.tests.DuplicatedWayNodes;
+import org.openstreetmap.josm.plugins.validator.tests.NodesWithSameName;
+import org.openstreetmap.josm.plugins.validator.tests.OverlappingWays;
+import org.openstreetmap.josm.plugins.validator.tests.SelfIntersectingWay;
+import org.openstreetmap.josm.plugins.validator.tests.SimilarNamedWays;
+import org.openstreetmap.josm.plugins.validator.tests.TagChecker;
+import org.openstreetmap.josm.plugins.validator.tests.UnclosedWays;
+import org.openstreetmap.josm.plugins.validator.tests.UnconnectedWays;
+import org.openstreetmap.josm.plugins.validator.tests.UntaggedNode;
+import org.openstreetmap.josm.plugins.validator.tests.UntaggedWay;
+import org.openstreetmap.josm.plugins.validator.tests.WronglyOrderedWays;
 import org.openstreetmap.josm.plugins.validator.util.Util;
 
@@ -41,231 +54,215 @@
  * @author Francisco R. Santos <frsantos@gmail.com>
  */
-public class OSMValidatorPlugin extends Plugin implements LayerChangeListener
-{
-	/** The validate action */
-	ValidateAction validateAction = new ValidateAction(this);
-
-	/** The validation dialog */
-	ValidatorDialog validationDialog;
-
-	/** The list of errors per layer*/
-	Map<Layer, List<TestError>> layerErrors = new HashMap<Layer, List<TestError>>();
-
-	public Collection<String> ignoredErrors = new TreeSet<String>();
-
-	/**
-	 * All available tests
-	 * TODO: is there any way to find out automagically all available tests?
-	 */
-	public static Class[] allAvailableTests = new Class[]
-	{
-		DuplicateNode.class,       // ID    1 ..   99
-		OverlappingWays.class,     // ID  101 ..  199
-		UntaggedNode.class,        // ID  201 ..  299
-		UntaggedWay.class,         // ID  301 ..  399
-		SelfIntersectingWay.class, // ID  401 ..  499
-		DuplicatedWayNodes.class,  // ID  501 ..  599
-		CrossingWays.class,        // ID  601 ..  699
-		SimilarNamedWays.class,    // ID  701 ..  799
-		NodesWithSameName.class,   // ID  801 ..  899
-		Coastlines.class,          // ID  901 ..  999
-		WronglyOrderedWays.class,  // ID 1001 .. 1099
-		UnclosedWays.class,        // ID 1101 .. 1199
-		TagChecker.class,          // ID 1201 .. 1299
-		UnconnectedWays.class,     // ID 1301 .. 1399
-	};
-
-	/**
-	 * Creates the plugin, and starts the HTTP server
-	 */
-	public OSMValidatorPlugin()
-	{
-		initializeTests( getTests() );
-		loadIgnoredErrors();
-	}
-
-	private void loadIgnoredErrors() {
-		ignoredErrors.clear();
-		if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true))
-		{
-			try {
-				final BufferedReader in = new BufferedReader(new FileReader(Util.getPluginDir() + "ignorederrors"));
-				for (String line = in.readLine(); line != null; line = in.readLine()) {
-					ignoredErrors.add(line);
-				}
-			}
-			catch (final FileNotFoundException e) {}
-			catch (final IOException e) {
-				e.printStackTrace();
-			}
-		}
-	}
-
-	public void saveIgnoredErrors() {
-		try {
-			final PrintWriter out = new PrintWriter(new FileWriter(Util.getPluginDir() + "ignorederrors"), false);
-			for (String e : ignoredErrors)
-				out.println(e);
-			out.close();
-		} catch (final IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public PreferenceSetting getPreferenceSetting()
-	{
-		return new PreferenceEditor(this);
-	}
-
-	@Override
-	public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)
-	{
-		if (newFrame != null)
-		{
-			validationDialog = new ValidatorDialog(this);
-			newFrame.addToggleDialog(validationDialog);
-			if(Main.pref.getBoolean(PreferenceEditor.PREF_LAYER, true))
-				Main.main.addLayer(new ErrorLayer(this));
-			if( Main.pref.hasKey(PreferenceEditor.PREF_DEBUG + ".grid") )
-				Main.main.addLayer(new GridLayer(tr("Grid")));
-			Layer.listeners.add(this);
-		}
-		else
-			Layer.listeners.remove(this);
-
-		LinkedList<UploadHook> hooks = ((UploadAction)Main.main.menu.upload).uploadHooks;
-		Iterator<UploadHook> hooksIt = hooks.iterator();
-		while( hooksIt.hasNext() )
-		{
-			if( hooksIt.next() instanceof ValidateUploadHook )
-			{
-				if( newFrame == null )
-					hooksIt.remove();
-				break;
-			}
-		}
-		if( newFrame != null )
-			hooks.add( 0, new ValidateUploadHook(this) );
-	}
-
-	/** Gets a map from simple names to all tests. */
-	public static Map<String, Test> getAllTestsMap() {
-		Map<String, Test> tests = new HashMap<String, Test>();
-		for(Class<Test> testClass : getAllAvailableTests() )
-		{
-			try {
-				Test test = testClass.newInstance();
-				tests.put(testClass.getSimpleName(), test);
-			}
-			catch( Exception e)
-			{
-				e.printStackTrace();
-				continue;
-			}
-		}
-		applyPrefs(tests, false);
-		applyPrefs(tests, true);
-		return tests;
-	}
-
-	private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) {
-		Pattern regexp = Pattern.compile("(\\w+)=(true|false),?");
-		Matcher m = regexp.matcher(Main.pref.get(beforeUpload
-			? PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD
-			: PreferenceEditor.PREF_TESTS));
-		int pos = 0;
-		while( m.find(pos) )
-		{
-			String testName = m.group(1);
-			Test test = tests.get(testName);
-			if( test != null )
-			{
-				boolean enabled = Boolean.valueOf(m.group(2));
-				if (beforeUpload) {
-					test.testBeforeUpload = enabled;
-				} else {
-					test.enabled = enabled;
-				}
-			}
-			pos = m.end();
-		}
-	}
-
-	public static Collection<Test> getTests() {
-		return getAllTestsMap().values();
-	}
-
-	public static Collection<Test> getEnabledTests(boolean beforeUpload) {
-		Collection<Test> enabledTests = getTests();
-		for (Test t : new ArrayList<Test>(enabledTests)) {
-			if (beforeUpload ? t.testBeforeUpload : t.enabled) continue;
-			enabledTests.remove(t);
-		}
-		return enabledTests;
-	}
-
-	/**
-	 * Gets the list of all available test classes
-	 *
-	 * @return An array of the test classes
-	 */
-	public static Class[] getAllAvailableTests()
-	{
-		return allAvailableTests;
-	}
-
-	/**
-	 * Initializes all tests
-	 * @param allTests The tests to initialize
-	 */
-	public void initializeTests(Collection<Test> allTests)
-	{
-		for( Test test : allTests )
-		{
-			try
-			{
-				if( test.enabled )
-				{
-					test.getClass().getMethod("initialize", new Class[]
-					{ OSMValidatorPlugin.class} ).invoke(null, new Object[] {this});
-				}
-			}
-			catch(InvocationTargetException ite)
-			{
-				ite.getCause().printStackTrace();
-				JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}",
-				test.getClass().getSimpleName(), ite.getCause().getMessage()));
-			}
-			catch(Exception e)
-			{
-				e.printStackTrace();
-				JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}",
-				test.getClass().getSimpleName(), e));
-			}
-		}
-	}
-
-	public void activeLayerChange(Layer oldLayer, Layer newLayer)
-	{
-		if( newLayer instanceof OsmDataLayer )
-		{
-			List<TestError> errors = layerErrors.get(newLayer);
-			validationDialog.tree.setErrorList(errors);
-			Main.map.repaint();
-		}
-	}
-
-	public void layerAdded(Layer newLayer)
-	{
-		if( newLayer instanceof OsmDataLayer )
-		{
-			layerErrors.put(newLayer, new ArrayList<TestError>() );
-		}
-	}
-
-	public void layerRemoved(Layer oldLayer)
-	{
-		layerErrors.remove(oldLayer);
-	}
+public class OSMValidatorPlugin extends Plugin implements LayerChangeListener {
+
+    protected static OSMValidatorPlugin plugin;
+
+    protected static ErrorLayer errorLayer = null;
+
+    /** The validate action */
+    ValidateAction validateAction = new ValidateAction(this);
+
+    /** The validation dialog */
+    ValidatorDialog validationDialog;
+
+    /** The list of errors per layer*/
+    Map<Layer, List<TestError>> layerErrors = new HashMap<Layer, List<TestError>>();
+
+    public Collection<String> ignoredErrors = new TreeSet<String>();
+
+    /**
+     * All available tests
+     * TODO: is there any way to find out automagically all available tests?
+     */
+    @SuppressWarnings("unchecked")
+    public static Class<Test>[] allAvailableTests = new Class[] { DuplicateNode.class, // ID    1 ..   99
+            OverlappingWays.class, // ID  101 ..  199
+            UntaggedNode.class, // ID  201 ..  299
+            UntaggedWay.class, // ID  301 ..  399
+            SelfIntersectingWay.class, // ID  401 ..  499
+            DuplicatedWayNodes.class, // ID  501 ..  599
+            CrossingWays.class, // ID  601 ..  699
+            SimilarNamedWays.class, // ID  701 ..  799
+            NodesWithSameName.class, // ID  801 ..  899
+            Coastlines.class, // ID  901 ..  999
+            WronglyOrderedWays.class, // ID 1001 .. 1099
+            UnclosedWays.class, // ID 1101 .. 1199
+            TagChecker.class, // ID 1201 .. 1299
+            UnconnectedWays.class, // ID 1301 .. 1399
+    };
+
+    /**
+     * Creates the plugin
+     */
+    public OSMValidatorPlugin() {
+        plugin = this;
+        initializeTests(getTests());
+        loadIgnoredErrors();
+    }
+
+    private void loadIgnoredErrors() {
+        ignoredErrors.clear();
+        if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) {
+            try {
+                final BufferedReader in = new BufferedReader(new FileReader(Util.getPluginDir() + "ignorederrors"));
+                for (String line = in.readLine(); line != null; line = in.readLine()) {
+                    ignoredErrors.add(line);
+                }
+            } catch (final FileNotFoundException e) {
+            } catch (final IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public void saveIgnoredErrors() {
+        try {
+            final PrintWriter out = new PrintWriter(new FileWriter(Util.getPluginDir() + "ignorederrors"), false);
+            for (String e : ignoredErrors)
+                out.println(e);
+            out.close();
+        } catch (final IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public PreferenceSetting getPreferenceSetting() {
+        return new PreferenceEditor(this);
+    }
+
+    @Override
+    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
+        if (newFrame != null) {
+            validationDialog = new ValidatorDialog(this);
+            newFrame.addToggleDialog(validationDialog);
+            initializeErrorLayer();
+            if (Main.pref.hasKey(PreferenceEditor.PREF_DEBUG + ".grid"))
+                Main.main.addLayer(new GridLayer(tr("Grid")));
+            Layer.listeners.add(this);
+        } else
+            Layer.listeners.remove(this);
+
+        LinkedList<UploadHook> hooks = ((UploadAction) Main.main.menu.upload).uploadHooks;
+        Iterator<UploadHook> hooksIt = hooks.iterator();
+        while (hooksIt.hasNext()) {
+            if (hooksIt.next() instanceof ValidateUploadHook) {
+                if (newFrame == null)
+                    hooksIt.remove();
+                break;
+            }
+        }
+        if (newFrame != null)
+            hooks.add(0, new ValidateUploadHook(this));
+    }
+
+    public void initializeErrorLayer() {
+        if (!Main.pref.getBoolean(PreferenceEditor.PREF_LAYER, true))
+            return;
+        if (errorLayer == null) {
+            errorLayer = new ErrorLayer(this);
+            Main.main.addLayer(errorLayer);
+        }
+    }
+
+    /** Gets a map from simple names to all tests. */
+    public static Map<String, Test> getAllTestsMap() {
+        Map<String, Test> tests = new HashMap<String, Test>();
+        for (Class<Test> testClass : getAllAvailableTests()) {
+            try {
+                Test test = testClass.newInstance();
+                tests.put(testClass.getSimpleName(), test);
+            } catch (Exception e) {
+                e.printStackTrace();
+                continue;
+            }
+        }
+        applyPrefs(tests, false);
+        applyPrefs(tests, true);
+        return tests;
+    }
+
+    private static void applyPrefs(Map<String, Test> tests, boolean beforeUpload) {
+        Pattern regexp = Pattern.compile("(\\w+)=(true|false),?");
+        Matcher m = regexp.matcher(Main.pref.get(beforeUpload ? PreferenceEditor.PREF_TESTS_BEFORE_UPLOAD
+                : PreferenceEditor.PREF_TESTS));
+        int pos = 0;
+        while (m.find(pos)) {
+            String testName = m.group(1);
+            Test test = tests.get(testName);
+            if (test != null) {
+                boolean enabled = Boolean.valueOf(m.group(2));
+                if (beforeUpload) {
+                    test.testBeforeUpload = enabled;
+                } else {
+                    test.enabled = enabled;
+                }
+            }
+            pos = m.end();
+        }
+    }
+
+    public static Collection<Test> getTests() {
+        return getAllTestsMap().values();
+    }
+
+    public static Collection<Test> getEnabledTests(boolean beforeUpload) {
+        Collection<Test> enabledTests = getTests();
+        for (Test t : new ArrayList<Test>(enabledTests)) {
+            if (beforeUpload ? t.testBeforeUpload : t.enabled)
+                continue;
+            enabledTests.remove(t);
+        }
+        return enabledTests;
+    }
+
+    /**
+     * Gets the list of all available test classes
+     *
+     * @return An array of the test classes
+     */
+    public static Class<Test>[] getAllAvailableTests() {
+        return allAvailableTests;
+    }
+
+    /**
+     * Initializes all tests
+     * @param allTests The tests to initialize
+     */
+    public void initializeTests(Collection<Test> allTests) {
+        for (Test test : allTests) {
+            try {
+                if (test.enabled) {
+                    test.getClass().getMethod("initialize", new Class[] { OSMValidatorPlugin.class }).invoke(null,
+                            new Object[] { this });
+                }
+            } catch (InvocationTargetException ite) {
+                ite.getCause().printStackTrace();
+                JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", test.getClass()
+                        .getSimpleName(), ite.getCause().getMessage()));
+            } catch (Exception e) {
+                e.printStackTrace();
+                JOptionPane.showMessageDialog(null, tr("Error initializing test {0}:\n {1}", test.getClass()
+                        .getSimpleName(), e));
+            }
+        }
+    }
+
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        if (newLayer instanceof OsmDataLayer) {
+            List<TestError> errors = layerErrors.get(newLayer);
+            validationDialog.tree.setErrorList(errors);
+            Main.map.repaint();
+        }
+    }
+
+    public void layerAdded(Layer newLayer) {
+        if (newLayer instanceof OsmDataLayer) {
+            layerErrors.put(newLayer, new ArrayList<TestError>());
+        }
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        layerErrors.remove(oldLayer);
+    }
 }
Index: applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
===================================================================
--- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java	(revision 10662)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java	(revision 10663)
@@ -23,102 +23,90 @@
  * @author frsantos
  */
-public class ValidateAction extends JosmAction
-{
-	private OSMValidatorPlugin plugin;
+public class ValidateAction extends JosmAction {
+    private OSMValidatorPlugin plugin;
 
-	/** Serializable ID */
-	private static final long serialVersionUID = -2304521273582574603L;
+    /** Serializable ID */
+    private static final long serialVersionUID = -2304521273582574603L;
 
-	/** Last selection used to validate */
-	private Collection<OsmPrimitive> lastSelection;
+    /** Last selection used to validate */
+    private Collection<OsmPrimitive> lastSelection;
 
-	/**
-	 * Constructor
-	 */
-	public ValidateAction(OSMValidatorPlugin plugin) {
-		super(tr("Validation"), "validator", tr("Performs the data validation"),
-		KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK + KeyEvent.ALT_MASK, true);
-		this.plugin = plugin;
-	}
+    /**
+     * Constructor
+     */
+    public ValidateAction(OSMValidatorPlugin plugin) {
+        super(tr("Validation"), "validator", tr("Performs the data validation"), KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK
+                + KeyEvent.ALT_MASK, true);
+        this.plugin = plugin;
+    }
 
-	public void actionPerformed(ActionEvent ev)
-	{
-		doValidate(ev, true);
-	}
+    public void actionPerformed(ActionEvent ev) {
+        doValidate(ev, true);
+    }
 
-	/**
-	 * Does the validation.
-	 * <p>
-	 * If getSelectedItems is true, the selected items (or all items, if no one
-	 * is selected) are validated. If it is false, last selected items are
-	 * revalidated
-	 *
-	 * @param ev The event
-	 * @param getSelectedItems If selected or last selected items must be validated
-	 */
-	public void doValidate(@SuppressWarnings("unused") ActionEvent ev, boolean getSelectedItems)
-	{
-		if( plugin.validateAction == null || Main.map == null || !Main.map.isVisible() )
-			return;
+    /**
+     * Does the validation.
+     * <p>
+     * If getSelectedItems is true, the selected items (or all items, if no one
+     * is selected) are validated. If it is false, last selected items are
+     * revalidated
+     *
+     * @param ev The event
+     * @param getSelectedItems If selected or last selected items must be validated
+     */
+    public void doValidate(ActionEvent ev, boolean getSelectedItems) {
+        if (plugin.validateAction == null || Main.map == null || !Main.map.isVisible())
+            return;
 
-		Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(false);
-		if( tests.isEmpty() )
-			return;
+        OSMValidatorPlugin.plugin.initializeErrorLayer();
 
-		Collection<OsmPrimitive> selection;
-		if( getSelectedItems )
-		{
-			selection = Main.ds.getSelected();
-			if( selection.isEmpty() )
-			{
-				selection = Main.ds.allNonDeletedPrimitives();
-				lastSelection = null;
-			}
-			else
-			{
-				AgregatePrimitivesVisitor v = new AgregatePrimitivesVisitor();
-				selection = v.visit(selection);
-				lastSelection = selection;
-			}
-		}
-		else
-		{
-			if( lastSelection == null )
-				selection = Main.ds.allNonDeletedPrimitives();
-			else
-				selection = lastSelection;
-		}
+        Collection<Test> tests = OSMValidatorPlugin.getEnabledTests(false);
+        if (tests.isEmpty())
+            return;
 
-		List<TestError> errors = new ArrayList<TestError>();
-		for(Test test : tests)
-		{
-			test.setPartialSelection(lastSelection != null);
-			test.startTest();
-			test.visit(selection);
-			test.endTest();
-			errors.addAll( test.getErrors() );
-		}
-		tests = null;
-		if(Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true))
-		{
-			for(TestError error : errors)
-			{
-				List<String> s = new ArrayList<String>();
-				s.add(error.getIgnoreState());
-				s.add(error.getIgnoreGroup());
-				s.add(error.getIgnoreSubGroup());
-				for(String state : s)
-				{
-					if(state != null && plugin.ignoredErrors.contains(state))
-					{
-						error.setIgnored(true);
-					}
-				}
-			}
-		}
+        Collection<OsmPrimitive> selection;
+        if (getSelectedItems) {
+            selection = Main.ds.getSelected();
+            if (selection.isEmpty()) {
+                selection = Main.ds.allNonDeletedPrimitives();
+                lastSelection = null;
+            } else {
+                AgregatePrimitivesVisitor v = new AgregatePrimitivesVisitor();
+                selection = v.visit(selection);
+                lastSelection = selection;
+            }
+        } else {
+            if (lastSelection == null)
+                selection = Main.ds.allNonDeletedPrimitives();
+            else
+                selection = lastSelection;
+        }
 
-		plugin.validationDialog.tree.setErrors(errors);
-		plugin.validationDialog.setVisible(true);
-		DataSet.fireSelectionChanged(Main.ds.getSelected());
-	}
+        List<TestError> errors = new ArrayList<TestError>();
+        for (Test test : tests) {
+            test.setPartialSelection(lastSelection != null);
+            test.startTest();
+            test.visit(selection);
+            test.endTest();
+            errors.addAll(test.getErrors());
+        }
+        tests = null;
+        if (Main.pref.getBoolean(PreferenceEditor.PREF_USE_IGNORE, true)) {
+            for (TestError error : errors) {
+                List<String> s = new ArrayList<String>();
+                s.add(error.getIgnoreState());
+                s.add(error.getIgnoreGroup());
+                s.add(error.getIgnoreSubGroup());
+                for (String state : s) {
+                    if (state != null && plugin.ignoredErrors.contains(state)) {
+                        error.setIgnored(true);
+                    }
+                }
+            }
+        }
+
+        plugin.validationDialog.tree.setErrors(errors);
+        plugin.validationDialog.setVisible(true);
+        DataSet.fireSelectionChanged(Main.ds.getSelected());
+    }
 }
