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 4021)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java	(revision 4023)
@@ -6,6 +6,9 @@
 import java.awt.Graphics;
 import java.util.Enumeration;
+import java.util.List;
 
-import javax.swing.*;
+import javax.swing.Icon;
+import javax.swing.JMenuItem;
+import javax.swing.JSeparator;
 import javax.swing.tree.DefaultMutableTreeNode;
 
@@ -42,5 +45,5 @@
 	 */
 	@Override public Icon getIcon() {
-		return ImageProvider.get("preferences", "validator");
+		return ImageProvider.get("layer", "validator");
 	}
 
@@ -82,5 +85,6 @@
     {
         Bag<Severity, TestError> errorTree = new Bag<Severity, TestError>();
-        for(TestError e : OSMValidatorPlugin.getPlugin().errors)
+        List<TestError> errors = OSMValidatorPlugin.getPlugin().validationDialog.tree.getErrors();
+        for(TestError e : errors)
         {
             errorTree.add(e.getSeverity(), e);
Index: applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreePanel.java
===================================================================
--- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreePanel.java	(revision 4021)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreePanel.java	(revision 4023)
@@ -34,5 +34,4 @@
     public ErrorTreePanel(List<TestError> errors) 
     {
-        this.errors = errors;
         this.setModel(treeModel);
 		this.setRootVisible(false);
@@ -42,6 +41,5 @@
 		this.setCellRenderer(new ErrorTreeRenderer());
 		this.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
-        
-        buildTree();
+        setErrorList(errors);
     }
 
@@ -152,12 +150,35 @@
 
     /**
-     * Set the errors of the tree
-     * @param errors
+     * Sets the errors list used by a data layer
+     * @param errors The error list that is used by a data layer
+     */
+    public void setErrorList(List<TestError> errors)
+    {
+    	this.errors = errors;
+        if( isVisible() )
+        	buildTree();
+    }
+
+    /**
+     * Clears the current error list and adds thiese errors to it
+     * @param errors The validation errors
      */
     public void setErrors(List<TestError> errors)
     {
-        this.errors = errors;
-    }
-    
+    	this.errors.clear();
+    	this.errors.addAll(errors);
+        if( isVisible() )
+        	buildTree();
+    }
+
+    /**
+     * Returns the errors of the tree
+     * @return  the errors of the tree
+     */
+    public List<TestError> getErrors()
+    {
+        return errors != null ? errors : Collections.<TestError>emptyList();
+    }
+
     /**
      * Expands all tree
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 4021)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java	(revision 4023)
@@ -14,4 +14,7 @@
 import org.openstreetmap.josm.actions.UploadAction.UploadHook;
 import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
 import org.openstreetmap.josm.plugins.Plugin;
@@ -25,5 +28,5 @@
  * @author Francisco R. Santos <frsantos@gmail.com>
  */
-public class OSMValidatorPlugin extends Plugin 
+public class OSMValidatorPlugin extends Plugin implements LayerChangeListener
 {
     /** The validate action */
@@ -33,7 +36,7 @@
     ValidatorDialog validationDialog;
     
-    /** The list of errors */
-    List<TestError> errors = new ArrayList<TestError>(30);
-
+    /** The list of errors per layer*/
+    Map<Layer, List<TestError>> layerErrors = new HashMap<Layer, List<TestError>>();
+    
     /** 
      * All available tests 
@@ -54,4 +57,5 @@
         CrossingSegments.class,
         SimilarNamedWays.class,
+        Coastlines.class,
     };
 
@@ -75,9 +79,11 @@
 		if (newFrame != null)
 		{
-            errors = new ArrayList<TestError>(50);
 		    validationDialog = new ValidatorDialog();
 	        newFrame.addToggleDialog(validationDialog);
             Main.main.addLayer(new ErrorLayer(tr("Validation errors")));
-		}
+            Main.map.mapView.addLayerChangeListener(this); 
+		}
+		else
+            oldFrame.mapView.removeLayerChangeListener(this); 
         
         // Add/Remove the upload hook
@@ -163,5 +169,5 @@
      * Gets the list of all available test classes
      * 
-     * @return An array of the test classes
+     * @return An array of the test classes	        validationDialog.tree.setErrorList(errors);
      */
     public static Class[] getAllAvailableTests()
@@ -197,3 +203,26 @@
 		}
 	}
+	
+	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 4021)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java	(revision 4023)
@@ -5,7 +5,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.plugins.validator.util.AgregatePrimitivesVisitor;
@@ -56,6 +58,4 @@
             return;
         
-		plugin.errors = new ArrayList<TestError>();
-		
 		Collection<Test> tests = OSMValidatorPlugin.getTests(true);
 		if( tests.isEmpty() )
@@ -86,4 +86,5 @@
 		}
 
+		List<TestError> errors = new ArrayList<TestError>();
 		for(Test test : tests) 
         {
@@ -92,13 +93,11 @@
 		    test.visit(selection);
 			test.endTest();
-			plugin.errors.addAll( test.getErrors() );
+			errors.addAll( test.getErrors() );
 		}
 		tests = null;
 		
-		plugin.validationDialog.tree.setErrors(plugin.errors);
+		plugin.validationDialog.tree.setErrors(errors);
         plugin.validationDialog.setVisible(true);
-        Main.map.repaint();
-        Main.ds.fireSelectionChanged(Main.ds.getSelected());
-        
+        DataSet.fireSelectionChanged(Main.ds.getSelected());
 	}
 }
Index: applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
===================================================================
--- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java	(revision 4021)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java	(revision 4023)
@@ -17,4 +17,5 @@
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
@@ -87,4 +88,5 @@
 			action.button.setSelected(v);
 		super.setVisible(v);
+		Main.map.repaint();
 	}
     
@@ -145,9 +147,9 @@
 			fixCommand = new SequenceCommand("Fix errors", allComands);
 		else 
-			fixCommand = (Command)allComands.get(0);
+			fixCommand = allComands.get(0);
 		
-		Main.main.editLayer().add( fixCommand );
+		Main.main.undoRedo.add( fixCommand );
 		Main.map.repaint();
-		Main.ds.fireSelectionChanged(Main.ds.getSelected());
+		DataSet.fireSelectionChanged(Main.ds.getSelected());
 		       
     	OSMValidatorPlugin.getPlugin().validateAction.doValidate(e, false);
@@ -199,14 +201,4 @@
 	}
 
-	/**
-	 * Refresh the error messages display
-	 * @param errors The errors to display
-	 */
-	public void refresh(List<TestError> errors)
-	{
-        tree.setErrors(errors);
-		tree.buildTree();
-	}
-	
     /**
      * Checks for fixes in selected element and, if needed, adds to the sel parameter all selected elements
