Index: applications/editors/josm/plugins/turnrestrictions/build.xml
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/build.xml	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/build.xml	(revision 23571)
@@ -39,12 +39,12 @@
       ** should not be necessary to change the following properties
      -->
-	<property name="josm"                   location="../../core/dist/josm-custom.jar"/>
-	<property name="plugin.build.dir"       value="build"/>
-	<property name="plugin.src.dir"         value="src"/>
+	<property name="josm" location="../../core/dist/josm-custom.jar" />
+	<property name="plugin.build.dir" value="build" />
+	<property name="plugin.src.dir" value="src" />
 	<!-- this is the directory where the plugin jar is copied to -->
-	<property name="plugin.dist.dir"        value="dist"/>
-	<property name="ant.build.javac.target" value="1.6"/>
-	<property name="plugin.jar"             value="../../dist/${ant.project.name}.jar"/>
-    <property name="test.build.dir" 	    value="test/build" />
+	<property name="plugin.dist.dir" value="dist" />
+	<property name="ant.build.javac.target" value="1.6" />
+	<property name="plugin.jar" value="../../dist/${ant.project.name}.jar" />
+	<property name="test.build.dir" value="test/build" />
 	<!--
     **********************************************************
@@ -53,6 +53,6 @@
     -->
 	<target name="init">
-		<mkdir dir="${plugin.build.dir}"/>
-		<mkdir dir="${test.build.dir}"/>
+		<mkdir dir="${plugin.build.dir}" />
+		<mkdir dir="${test.build.dir}" />
 	</target>
 
@@ -63,8 +63,8 @@
     -->
 	<target name="compile" depends="init">
-		<echo message="compiling sources for  ${plugin.jar} ... "/>
+		<echo message="compiling sources for  ${plugin.jar} ... " />
 		<javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}">
-			<compilerarg value="-Xlint:deprecation"/>
-			<compilerarg value="-Xlint:unchecked"/>
+			<compilerarg value="-Xlint:deprecation" />
+			<compilerarg value="-Xlint:unchecked" />
 		</javac>
 	</target>
@@ -76,10 +76,10 @@
     -->
 	<target name="dist" depends="compile,revision">
-		<echo message="creating ${ant.project.name}.jar ... "/>
+		<echo message="creating ${ant.project.name}.jar ... " />
 		<copy todir="${plugin.build.dir}/resources">
-			<fileset dir="resources"/>
+			<fileset dir="resources" />
 		</copy>
 		<copy todir="${plugin.build.dir}/images">
-			<fileset dir="images"/>
+			<fileset dir="images" />
 		</copy>
 		<copy todir="${plugin.build.dir}">
@@ -99,12 +99,12 @@
     -->
 			<manifest>
-				<attribute name="Author" value="Karl Guggisberg"/>
-				<attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionsPlugin"/>
-				<attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
-				<attribute name="Plugin-Description" value="The turnrestrictions plugin allows to enter maintain information about turn restrictions in the OpenStreetMap database."/>
-				<attribute name="Plugin-Icon" value="images/preferences/turnrestrictions.png"/>
-				<attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/turnrestrictions"/>
-				<attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
-				<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
+				<attribute name="Author" value="Karl Guggisberg" />
+				<attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionsPlugin" />
+				<attribute name="Plugin-Date" value="${version.entry.commit.date}" />
+				<attribute name="Plugin-Description" value="The turnrestrictions plugin allows to enter maintain information about turn restrictions in the OpenStreetMap database." />
+				<attribute name="Plugin-Icon" value="images/preferences/turnrestrictions.png" />
+				<attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/turnrestrictions" />
+				<attribute name="Plugin-Mainversion" value="${plugin.main.version}" />
+				<attribute name="Plugin-Version" value="${version.entry.commit.revision}" />
 			</manifest>
 		</jar>
@@ -121,11 +121,11 @@
 
 		<exec append="false" output="REVISION" executable="svn" failifexecutionfails="false">
-			<env key="LANG" value="C"/>
-			<arg value="info"/>
-			<arg value="--xml"/>
-			<arg value="."/>
-		</exec>
-		<xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/>
-		<delete file="REVISION"/>
+			<env key="LANG" value="C" />
+			<arg value="info" />
+			<arg value="--xml" />
+			<arg value="." />
+		</exec>
+		<xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true" />
+		<delete file="REVISION" />
 	</target>
 
@@ -136,6 +136,6 @@
     -->
 	<target name="clean">
-		<delete dir="${plugin.build.dir}"/>
-		<delete file="${plugin.jar}"/>
+		<delete dir="${plugin.build.dir}" />
+		<delete file="${plugin.jar}" />
 	</target>
 
@@ -146,11 +146,11 @@
     -->
 	<target name="install" depends="dist">
-		<property environment="env"/>
+		<property environment="env" />
 		<condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
 			<and>
-				<os family="windows"/>
+				<os family="windows" />
 			</and>
 		</condition>
-		<copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
+		<copy file="${plugin.jar}" todir="${josm.plugins.dir}" />
 	</target>
 
@@ -165,10 +165,10 @@
 	<target name="core-info">
 		<exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
-			<env key="LANG" value="C"/>
-			<arg value="info"/>
-			<arg value="--xml"/>
-			<arg value="../../core"/>
-		</exec>
-		<xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
+			<env key="LANG" value="C" />
+			<arg value="info" />
+			<arg value="--xml" />
+			<arg value="../../core" />
+		</exec>
+		<xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true" />
 		<echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
 		<echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
@@ -182,8 +182,8 @@
 		<echo>Commiting the plugin source with message '${commit.message}' ...</echo>
 		<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
-			<env key="LANG" value="C"/>
-			<arg value="commit"/>
-			<arg value="-m '${commit.message}'"/>
-			<arg value="."/>
+			<env key="LANG" value="C" />
+			<arg value="commit" />
+			<arg value="-m '${commit.message}'" />
+			<arg value="." />
 		</exec>
 	</target>
@@ -195,13 +195,13 @@
 		<echo>Updating plugin source ...</echo>
 		<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
-			<env key="LANG" value="C"/>
-			<arg value="up"/>
-			<arg value="."/>
+			<env key="LANG" value="C" />
+			<arg value="up" />
+			<arg value="." />
 		</exec>
 		<echo>Updating ${plugin.jar} ...</echo>
 		<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
-			<env key="LANG" value="C"/>
-			<arg value="up"/>
-			<arg value="../dist/${plugin.jar}"/>
+			<env key="LANG" value="C" />
+			<arg value="up" />
+			<arg value="../dist/${plugin.jar}" />
 		</exec>
 	</target>
@@ -222,8 +222,8 @@
 	</echo>
 		<exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
-			<env key="LANG" value="C"/>
-			<arg value="-m '${commit.message}'"/>
-			<arg value="commit"/>
-			<arg value="${plugin.jar}"/>
+			<env key="LANG" value="C" />
+			<arg value="-m '${commit.message}'" />
+			<arg value="commit" />
+			<arg value="${plugin.jar}" />
 		</exec>
 	</target>
@@ -261,5 +261,5 @@
 
 	<path id="groovy.path">
-		<pathelement location="${eclipse.plugin.dir}/org.codehaus.groovy_1.7.5.xx-20100926-2000-e36-RC1\lib\groovy-all-1.7.5.jar"/>
+		<pathelement location="${eclipse.plugin.dir}/org.codehaus.groovy_1.7.5.xx-20100926-2000-e36-RC1\lib\groovy-all-1.7.5.jar" />
 	</path>
 
@@ -269,8 +269,8 @@
 
 	<path id="test.class.path">
-		<pathelement location="${josm}"/>
+		<pathelement location="${josm}" />
 		<pathelement location="${plugin.build.dir}" />
-		<path refid="groovy.path"/>
-		<path refid="junit.path"/>
+		<path refid="groovy.path" />
+		<path refid="junit.path" />
 	</path>
 
@@ -287,37 +287,45 @@
 
 	<target name="test-clean">
-		<delete dir="${test.build.dir}"/>
-		<mkdir dir="${test.build.dir}"/>
-    </target>
+		<delete dir="${test.build.dir}" />
+		<mkdir dir="${test.build.dir}" />
+	</target>
 
 	<target name="test-compile" depends="compile,test-clean" description="Compiles the test files">
 
-		<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.path"/>
-
-		<echo message="compiling java test cases for ${plugin.jar} ... "/>
-			<javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}">
-				<compilerarg value="-Xlint:deprecation"/>
-				<compilerarg value="-Xlint:unchecked"/>
-			</javac>
-
-		<echo message="compiling groovy test cases for ${plugin.jar} ... "/>
+		<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.path" />
+
+		<echo message="compiling test infrastructor for ${plugin.jar} ... " />
+		<javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}" includes="org/openstreetmap/josm/plugins/turnrestrictions/fixtures/**/*">
+			<compilerarg value="-Xlint:deprecation" />
+			<compilerarg value="-Xlint:unchecked" />
+		</javac>
+
+		<echo message="compiling groovy test cases for ${plugin.jar} ... " />
 		<groovyc srcdir="test/src" destdir="${test.build.dir}" classpathref="groovyc.path">
 		</groovyc>
+
+		<echo message="compiling java test cases for ${plugin.jar} ... " />
+		<javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}">
+			<compilerarg value="-Xlint:deprecation" />
+			<compilerarg value="-Xlint:unchecked" />
+		</javac>
 	</target>
 
 	<target name="test-run" depends="test-compile" description="Runs the junit tests">
-		<delete dir="test/output"/>
-		<mkdir dir="test/output"/>
+		<delete dir="test/output" />
+		<mkdir dir="test/output" />
 
 		<junit printsummary="true" failureproperty="junit.failure">
-		      <classpath>
-		      	<path refid="groovyc.path" />
-		      	<pathelement location="test/config"/> <!-- required for test config file -->
-		      	<pathelement location="."/> <!-- required to load images from subdir 'images/' -->
-		      </classpath>
-
-			  <test todir="test/output" name='org.openstreetmap.josm.plugins.turnrestrictions.AllUnitTests'>
-		        <formatter type="xml"/>
-			  </test>
+			<classpath>
+				<path refid="groovyc.path" />
+				<pathelement location="test/config" />
+				<!-- required for test config file -->
+				<pathelement location="." />
+				<!-- required to load images from subdir 'images/' -->
+			</classpath>
+
+			<test todir="test/output" name='org.openstreetmap.josm.plugins.turnrestrictions.AllUnitTests'>
+				<formatter type="xml" />
+			</test>
 		</junit>
 	</target>
Index: applications/editors/josm/plugins/turnrestrictions/images/accept.svg
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/images/accept.svg	(revision 23571)
+++ applications/editors/josm/plugins/turnrestrictions/images/accept.svg	(revision 23571)
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="24"
+   height="24"
+   id="svg2"
+   sodipodi:version="0.32"
+   inkscape:version="0.47 r22583"
+   version="1.0"
+   sodipodi:docname="copyaftercurrentright.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
+   inkscape:export-filename="C:\data\projekte\eclipse-3.4.1-ws\JOSM\images\dialogs\conflict\copybeforecurrentleft.png"
+   inkscape:export-xdpi="90"
+   inkscape:export-ydpi="90">
+  <defs
+     id="defs4">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective10" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="16"
+     inkscape:cx="21.982894"
+     inkscape:cy="13.089584"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     showborder="true"
+     inkscape:window-width="1348"
+     inkscape:window-height="669"
+     inkscape:window-x="169"
+     inkscape:window-y="85"
+     inkscape:window-maximized="0" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Ebene 1"
+     inkscape:groupmode="layer"
+     id="layer1">
+    <rect
+       style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#646464;stroke-width:1.01156402;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+       id="rect2383"
+       width="11.335931"
+       height="19.273432"
+       x="11.019533"
+       y="2.2070346" />
+    <path
+       style="fill:none"
+       d="m 10.8125,4.125 6.75,-0.0625"
+       id="path3157" />
+    <path
+       style="fill:none;stroke:#646464;stroke-width:0.62002015;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+       d="M 11.57251,9.29126 22.17749,9.33374"
+       id="path3167" />
+    <rect
+       style="fill:#8faaff;fill-opacity:1;fill-rule:nonzero;stroke:#8faaff;stroke-width:0.38590878;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+       id="rect3173"
+       width="9.8710909"
+       height="2.6210914"
+       x="11.751954"
+       y="9.8144541" />
+    <path
+       style="fill:none;stroke:#646464;stroke-width:0.62002015;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+       d="m 11.51001,12.85376 10.60498,0.04248"
+       id="path3219" />
+    <path
+       style="fill:#c8c8c8;fill-opacity:1;fill-rule:evenodd;stroke:#c8c8c8;stroke-width:1.98654306;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+       d="m 8.225474,19.725473 0,-14.075946 -5.950948,7.022916 5.950948,7.05303 z"
+       id="path3221"
+       sodipodi:nodetypes="cccc" />
+    <path
+       style="fill:#000080;fill-rule:evenodd;stroke:#000080;stroke-width:1.98654306;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+       d="m 7.881724,18.631723 0,-14.0759461 -5.950948,7.0229161 5.950948,7.05303 z"
+       id="path3171"
+       sodipodi:nodetypes="cccc" />
+  </g>
+</svg>
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilder.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilder.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilder.java	(revision 23571)
@@ -2,4 +2,5 @@
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -11,4 +12,5 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
 
@@ -20,94 +22,6 @@
  */
 public class TurnRestrictionBuilder {
-
-    private Way from;
-    private Way to;
-    private final ArrayList<OsmPrimitive> vias = new ArrayList<OsmPrimitive>();
     
     public TurnRestrictionBuilder(){
-    }
-    
-    /**
-     * Initializes the 'from' leg. Proposes the  first element
-     * in {@code primitives} as 'from' leg if this element is a
-     * non-deleted, visible way.
-     * 
-     * @param primitives
-     */
-    protected void initFromLeg(List<OsmPrimitive> primitives){
-        if (primitives == null || primitives.isEmpty()) return;
-        OsmPrimitive p = primitives.get(0);
-        if (! (p instanceof Way)) return;
-        Way fromLeg = (Way)p;
-        if (fromLeg.isDeleted() || ! fromLeg.isVisible()) return;
-        this.from = fromLeg;
-    }
-
-    /**
-     * Initializes the 'to' leg. Proposes the last element 
-     * in {@code primitives} as 'to' leg if this element is a
-     * non-deleted, visible way.
-     *
-     * @param primitives
-     */
-    protected void initToLeg(List<OsmPrimitive> primitives){
-        if (primitives == null || primitives.isEmpty()) return;
-        if (primitives.size() < 2) return;
-        OsmPrimitive p = primitives.get(primitives.size()-1);
-        if (! (p instanceof Way)) return;
-        Way toLeg = (Way)p;
-        if (toLeg.isDeleted() || ! toLeg.isVisible()) return;
-        this.to = toLeg;
-    }
-    
-    /**
-     * Initializes the vias from the two turn restriction legs. The two
-     * legs have to be defined, otherwise no via is proposed. This methods
-     * proposes exactly one node as via, if the two turn restriction
-     * legs intersect at exactly one node. 
-     */
-    protected void initViaFromLegs(){
-        if (from == null || to == null) return;     
-        // check whether 'from' and 'to' have exactly one intersecting 
-        // node. This node is proposed as via node. The turn restriction
-        // node will also provide functionality to split either or both
-        // of 'from' and 'to' way if they aren't connected from tail to
-        // head
-        //
-        HashSet<Node> nodes = new HashSet<Node>();
-        nodes.addAll(from.getNodes());
-        nodes.retainAll(to.getNodes());
-        if (nodes.size() == 1){
-            vias.add(nodes.iterator().next());
-        }       
-    }
-    
-    /**
-     * Initializes the vias with the primitives (1..size-2), provided
-     * these primitives aren't relations and they are visible and non-deleted.
-     * 
-     * @param primitives
-     */
-    protected void initViasFromPrimitives(List<OsmPrimitive> primitives) {
-        if (primitives == null || primitives.size() <=2) return;
-        // if we didn't find a from or a to way, we don't propose via objects
-        // either
-        if (from == null || to == null) return;
-        for(int i=1; i< primitives.size() -2;i++){
-            OsmPrimitive p = primitives.get(i);
-            if (p == null) continue;
-            if (p instanceof Relation) continue;
-            if (p.isDeleted() || ! p.isVisible()) continue;
-            vias.add(p);
-        }
-    }
-    
-    /**
-     * Resets the builder 
-     */
-    protected void reset() {
-        this.from = null;
-        this.to = null;
-        this.vias.clear();
     }
     
@@ -128,4 +42,250 @@
 
     /**
+     * Tries to initialize a No-U-Turn restriction from the primitives in 
+     * <code>primitives</code>. If successful, replies true, otherwise false.
+     * 
+     * @param primitives the primitives 
+     * @return true, if we can propose a U-turn restriction for the primitives
+     * in <code>primitives</code>
+     */
+    protected Relation initNoUTurnRestriction(List<OsmPrimitive> primitives) {
+    	if (primitives.size() != 2) return null;
+    	    	
+    	// we need exactly one node and one way in the selection ...
+    	List<Node> nodes = OsmPrimitive.getFilteredList(primitives, Node.class);
+    	List<Way> ways = OsmPrimitive.getFilteredList(primitives, Way.class);
+    	if (nodes.size() != 1 || ways.size() != 1) return null;
+    	
+    	// .. and the node has to be the start or the node of the way
+    	Way way = ways.get(0);
+    	Node node = nodes.get(0);
+    	List<Node> wayNodes = way.getNodes();
+    	if (wayNodes.size() < 2) return null; // shouldn't happen - just in case
+    	if (! (wayNodes.get(0).equals(node) ||wayNodes.get(wayNodes.size()-1).equals(node))) return null;
+
+    	Relation tr = new Relation();
+    	tr.put("type", "restriction");
+    	tr.addMember(new RelationMember("from", way));
+    	tr.addMember(new RelationMember("to", way));
+    	tr.addMember(new RelationMember("via", node));
+    	tr.put("restriction", TurnRestrictionType.NO_U_TURN.getTagValue());
+    	return tr;    	
+    }
+
+    /**
+     * Replies the unique common node of two ways, or null, if either no
+     * such node or multiple common nodes exist.
+     * 
+     * @param w1 the first way
+     * @param w2 the second way
+     * @return the common node
+     */
+    protected Node getUniqueCommonNode(Way w1, Way w2){
+    	List<Node> w1Nodes = w1.getNodes();
+    	w1Nodes.retainAll(w2.getNodes());
+    	if (w1Nodes.size() != 1) return null;
+    	return w1Nodes.get(0);
+    }    
+    
+    /**
+     * Replies true, if {@code n} is the start node of the way {@code w}.
+     * 
+     * @param w the way 
+     * @param n the node 
+     * @return true, if {@code n} is the start node of the way {@code w}.
+     */
+    protected boolean isStartNode(Way w, Node n) {
+    	if (w.getNodesCount() == 0) return false;
+    	return w.getNode(0).equals(n);
+    }
+    
+    
+    /**
+     * Replies true, if {@code n} is the end node of the way {@code w}.
+     * 
+     * @param w the way 
+     * @param n the node 
+     * @return true, if {@code n} is the end node of the way {@code w}.
+     */
+    protected boolean isEndNode(Way w, Node n){
+    	if (w.getNodesCount() == 0) return false;
+    	return w.getNode(w.getNodesCount()-1).equals(n);
+    }
+    
+    /**
+     * <p>Replies true, if the ways {@code w1} and {@code w2} are connected
+     * at the node {@code n}.</p>
+     * 
+     * <p>If {@code w1} and {@code w2} <em>intersect</em> at the node {@code n},
+     * this method replies false.</p>
+     * 
+     * @param w1 the first way
+     * @param w2 the second way 
+     * @param n the node 
+     * @return
+     */
+    protected boolean isConnectingNode(Way w1, Way w2, Node n){
+    	if (isStartNode(w1, n)) {
+    		return isStartNode(w2, n)  | isEndNode(w2, n);
+    	} else if (isEndNode(w1, n)){
+    		return isStartNode(w2, n)  | isEndNode(w2, n);
+    	}
+    	return false;
+    }
+    
+    /**
+     * Replies true, if the way {@code w} is closed at the node {@code n}.
+     * 
+     * @param w the way
+     * @param n the node 
+     * @return true, if the way {@code w} is closed at the node {@code n}.
+     */
+    protected boolean isClosedAt(Way w, Node n){
+    	List<Node> nodes = w.getNodes();
+    	nodes.retainAll(Collections.singletonList(n));
+    	return nodes.size() >= 2;
+    }
+    
+    protected double phi(Way w) {
+    	return phi(w, false /* not inverse */);
+    }
+    
+    protected double phi(Way w, boolean doInvert) {
+    	double x1 = w.getNode(0).getCoor().getX();
+    	double y1 = w.getNode(0).getCoor().getY();
+    	double x2 = w.getNode(w.getNodesCount()-1).getCoor().getX();
+    	double y2 = w.getNode(w.getNodesCount()-1).getCoor().getY();
+    	if (doInvert){
+    		double t = x1; x1 = x2; x2 = t;
+    		t = y1; y1 = y2; y2 = t;
+    	}
+    	x2-=x1;
+    	y2-=y1;
+    	return phi(x2,y2);    	
+    }
+    
+    protected double phi(double x, double y) {
+    	return Math.atan2(y, x);
+    }   
+    
+    /**
+     * <p>Determines the standard turn restriction between from way {@code w1} to
+     * way {@code w2}.</p>
+     * 
+     * <p>Replies {@link TurnRestrictionType#NO_LEFT_TURN no_left_turn} or 
+     * {@link TurnRestrictionType#NO_RIGHT_TURN no_right_turn}, if applicable. Or
+     * null, if neither of these restrictions is applicable, for instance because
+     * the passed in via node {@code via} isn't a node where the two ways are
+     * connected.</p>
+     * 
+     * @param w1 the "from"-way
+     * @param w2 the "to"-way
+     * @param via the via node
+     * @return an applicable turn restriction, or null, if no turn restriction is
+     * applicable
+     */
+    protected String determineRestriction(Way w1, Way w2, Node via){
+    	if (via == null) return null;
+    	if (!isConnectingNode(w1, w2, via)) return null;
+    	// if either w1 or w2 are closed at the via node, we can't determine automatically
+    	// whether the connection at "via" is a "left turn" or a "right turn"
+    	if (isClosedAt(w1, via)) return null;
+    	if (isClosedAt(w2, via)) return null;
+    	
+    	double phi1 = 0, phi2 = 0;
+    	if (isEndNode(w1, via)){
+    		if (isStartNode(w2, via)) {
+	    		phi1 = phi(w1);
+	    		phi2 = phi(w2);
+    		} else if (isEndNode(w2, via)){
+    			phi1 = phi(w1);
+    			phi2 = phi(w2, true /* reverse it */);
+    		} else {
+    			assert false: "Unexpected state: via node is expected to be a start or and end node";
+    		}	    		
+    	} else if (isStartNode(w1,via)) {
+    		if (isStartNode(w2, via)) {
+	    		phi1 = phi(w1, true /* reverse it */);
+	    		phi2 = phi(w2);
+    		} else if (isEndNode(w2, via)){
+    			phi1 = phi(w1, true /* reverse it */);
+    			phi2 = phi(w2, true /* reverse it */);
+    		} else {
+    			assert false: "Unexpected state: via node is expected to be a start or and end node";
+    		}	    
+    	} else {
+    		assert false: "Unexpected state: via node is expected to be a start or and end node of w1";    		
+    	}
+    	
+    	double phi = phi1-phi2;
+    	if (phi >=0 && phi <= Math.PI) {
+    		// looks like a right turn  
+    		return TurnRestrictionType.NO_RIGHT_TURN.getTagValue();
+    	} else {
+    		// looks like a left turn 
+    		return TurnRestrictionType.NO_LEFT_TURN.getTagValue();
+    	} 
+    }
+    
+    protected Relation initTurnRestrictionFromTwoWays(List<OsmPrimitive> primitives) {
+    	Way w1 = null;
+    	Way w2 = null;
+    	Node via = null;
+    	if (primitives.size() == 2) {
+    		// if we have exactly two selected primitives, we expect two ways. 
+    		// See initNoUTurnRestriction() for the case where we have a selected way
+    		// and a selected node
+    		List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class);
+    		if (selWays.size() != 2) return null;
+    		w1 = selWays.get(0);
+    		w2 = selWays.get(1);
+    		via = getUniqueCommonNode(w1, w2);    		
+    	} else if (primitives.size() == 3){
+    		// if we have exactly three selected primitives, we need two ways and a 
+    		// node, which should be an acceptable via node 
+    		List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class);
+    		List<Node> selNodes = OsmPrimitive.getFilteredList(primitives, Node.class);
+    		if (selWays.size() != 2) return null;
+    		if (selNodes.size() != 1) return null;
+    		w1 = selWays.get(0);
+    		w2 = selWays.get(1);
+    		via = selNodes.get(0);
+    		if (! w1.getNodes().contains(via) || ! w2.getNodes().contains(via)){
+    			// the selected node is not an acceptable via node
+    			via = null;
+    		}
+    	} else {
+    		// the selection doesn't consists of primitives for which we can build
+    		// a turn restriction 
+    		return null;
+    	}
+    	
+    	// if we get here, we know the two "legs" of the turn restriction. We may
+    	// or may not know a via node, though
+    	assert w1 != null;
+    	assert w2 != null;
+    	
+    	Relation tr = new Relation();
+    	tr.put("type", "restriction");
+    	tr.addMember(new RelationMember("from", w1));
+    	tr.addMember(new RelationMember("to", w2));
+    	
+    	if (via != null){
+    		tr.addMember(new RelationMember("via", via));
+    		String restriction = determineRestriction(w1, w2, via); 
+    		if (restriction != null){
+    			tr.put("restriction", restriction);
+    		}
+    	}
+    	return tr;
+    }
+       
+    protected Relation initEmptyTurnRestriction() {
+	   Relation tr = new Relation();
+       tr.put("type", "restriction");
+       return tr;
+    }
+    
+    /**
      * Creates and initializes a new turn restriction based on primitives 
      * in {@code primitives}.
@@ -136,27 +296,31 @@
      */
     public synchronized Relation build(List<OsmPrimitive> primitives){
-        Relation tr = new Relation();
-        tr.put("type", "restriction");
-        if (primitives == null || primitives.isEmpty()) return tr;
-        if (primitives.size() <=2){
-            initFromLeg(primitives);
-            initToLeg(primitives);
-            initViaFromLegs();
-        } else if (primitives.size() > 2) {
-            initFromLeg(primitives);
-            initToLeg(primitives);
-            initViasFromPrimitives(primitives);
+        if (primitives == null || primitives.isEmpty()) {
+        	return initEmptyTurnRestriction();
         }
-        
-        if (from != null){
-            tr.addMember(new RelationMember("from", from));
+        Relation tr;
+        switch(primitives.size()){
+        // case 0 already handled 
+        case 1: 
+        	tr = initEmptyTurnRestriction();
+        	if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) {     
+        		// we have exactly one selected way? -> init the "from" leg
+        		// of the turn restriction with it
+        		tr.addMember(new RelationMember("from", primitives.get(0)));
+        	}
+        	return tr;
+        	
+        case 2:
+        	tr = initNoUTurnRestriction(primitives);
+        	if (tr != null) return tr;
+        	tr = initTurnRestrictionFromTwoWays(primitives);
+        	if (tr != null) return tr;
+        	return initEmptyTurnRestriction();       
+        	
+        default:        	
+        	tr = initTurnRestrictionFromTwoWays(primitives);
+        	if (tr != null) return tr;
+        	return initEmptyTurnRestriction();       
         }
-        if (to != null){
-            tr.addMember(new RelationMember("to", to));
-        }
-        for(OsmPrimitive via: vias){
-            tr.addMember(new RelationMember("via", via));
-        }
-        return tr;
     }       
 }
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java	(revision 23571)
@@ -10,4 +10,5 @@
 import javax.swing.AbstractListModel;
 import javax.swing.DefaultListSelectionModel;
+import javax.swing.ListSelectionModel;
 
 import org.openstreetmap.josm.Main;
@@ -38,5 +39,5 @@
     
     private final List<OsmPrimitive> selection = new ArrayList<OsmPrimitive>();
-    private DefaultListSelectionModel selectionModel;
+    private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
     private OsmDataLayer layer;
 
@@ -46,12 +47,9 @@
      * @param selectionModel the selection model used in the list. Must not be null.
      * @param layer the layer this model is displaying the selection from. Must not be null.
-     * @throws IllegalArgumentException thrown if {@code selectionModel} is null
      * @throws IllegalArgumentException thrown if {@code layer} is null
      */
-    public JosmSelectionListModel(OsmDataLayer layer, DefaultListSelectionModel selectionModel) {
-        CheckParameterUtil.ensureParameterNotNull(selectionModel, "selectionModel");
+    public JosmSelectionListModel(OsmDataLayer layer) throws IllegalArgumentException{
         CheckParameterUtil.ensureParameterNotNull(layer, "layer");
         this.layer = layer;
-        this.selectionModel = selectionModel;
         setJOSMSelection(layer.data.getSelected());
     }
@@ -118,5 +116,10 @@
         this.selection.addAll(selection);
         fireContentsChanged(this, 0, getSize());       
-        setSelected(sel);
+        setSelected(sel);       
+        // if the user selects exactly one primitive (i.e. a way), we automatically
+        // select it in the list of selected JOSM objects too. 
+        if (getSelected().isEmpty() && this.selection.size() == 1) {
+        	setSelected(this.selection);
+        }
     }
 
@@ -138,4 +141,8 @@
         }
         setSelected(sel);
+    }
+        
+    public ListSelectionModel getListSelectionModel() {
+    	return selectionModel;
     }
 
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java	(revision 23571)
@@ -54,9 +54,7 @@
     protected void build(OsmDataLayer layer) {
         setLayout(new BorderLayout());
-        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
-        model = new JosmSelectionListModel(layer,selectionModel);
         lstSelection = new JList(model);
         lstSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
-        lstSelection.setSelectionModel(selectionModel);
+        lstSelection.setSelectionModel(model.getListSelectionModel());
         lstSelection.setCellRenderer(new OsmPrimitivRenderer());
         lstSelection.setTransferHandler(transferHandler = new JosmSelectionTransferHandler(model));
@@ -77,6 +75,7 @@
      * @exception IllegalArgumentException thrown if {@code layer} is null
      */
-    public JosmSelectionPanel(OsmDataLayer layer) throws IllegalArgumentException{
+    public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException{
         CheckParameterUtil.ensureParameterNotNull(layer, "layer");
+        this.model = model;
         build(layer); 
     }
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java	(revision 23571)
@@ -114,10 +114,10 @@
      */
     protected JPanel buildJOSMSelectionPanel() {
-        pnlJosmSelection = new JosmSelectionPanel(layer);
+        pnlJosmSelection = new JosmSelectionPanel(layer,editorModel.getJosmSelectionListModel());
         return pnlJosmSelection;
     }
     
     /**
-     * Builds the panel with the editor masks (the left panel in the split pane of 
+     * Builds the panel with the editor forms (the left panel in the split pane of 
      * this dialog)
      * 
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java	(revision 23571)
@@ -69,4 +69,5 @@
     private  IssuesModel issuesModel;
     private NavigationControler navigationControler;
+    private JosmSelectionListModel selectionModel;
     
     /**
@@ -87,4 +88,12 @@
         addObserver(issuesModel);
         tagEditorModel.addTableModelListener(new TagEditorModelObserver());
+        selectionModel = new JosmSelectionListModel(layer);
+    }
+    
+    /**
+     * Replies the model for the currently selected JOSM primitives
+     */
+    public JosmSelectionListModel getJosmSelectionListModel() {
+    	return selectionModel;
     }
     
@@ -211,4 +220,5 @@
         CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");      
         TagCollection tags = tagEditorModel.getTagCollection();
+        logger.info(tags.toString());
         turnRestriction.removeAll();
         tags.applyTo(turnRestriction);
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java	(revision 23571)
@@ -4,4 +4,5 @@
 
 import java.awt.BorderLayout;
+import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.Toolkit;
@@ -38,8 +39,11 @@
 import javax.swing.TransferHandler;
 import javax.swing.UIManager;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.data.osm.PrimitiveId;
+import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.DefaultNameFormatter;
 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
@@ -64,4 +68,5 @@
     private CopyAction actCopy;
     private PasteAction actPaste;
+    private AcceptAction actAccept;
     private TransferHandler transferHandler;
     
@@ -81,10 +86,19 @@
         );
         
+        JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
+        pnlButtons.setBorder(null);
         JButton btn;
         actDelete = new DeleteAction();
-        add(btn = new JButton(actDelete), BorderLayout.EAST);
+        pnlButtons.add(btn = new JButton(actDelete));
         btn.setFocusable(false);
         btn.setText(null);
         btn.setBorder(BorderFactory.createRaisedBevelBorder());
+        
+        actAccept = new AcceptAction();
+        pnlButtons.add(btn = new JButton(actAccept));
+        btn.setFocusable(false);
+        btn.setText(null);
+        btn.setBorder(BorderFactory.createRaisedBevelBorder());
+        add(pnlButtons, BorderLayout.EAST);
                 
         // focus handling
@@ -260,4 +274,35 @@
     
     /**
+     * Accepts the currently selected way as turn restriction leg. Only enabled,
+     * if there is exactly one way selected 
+     */
+    class AcceptAction extends AbstractAction implements ListSelectionListener {
+    	
+    	public AcceptAction() {
+			 putValue(SHORT_DESCRIPTION, tr("Accept the currently selected way"));
+	         putValue(NAME, tr("Accept"));
+	         putValue(SMALL_ICON, ImageProvider.get("accept"));
+	         model.getJosmSelectionListModel().getListSelectionModel().addListSelectionListener(this);
+	         updateEnabledState();	         
+    	}
+    	
+    	 public void actionPerformed(ActionEvent e) {
+    		 List<Way> selWays = OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class);
+    		 if (selWays.size() != 1) return;
+    		 Way w = selWays.get(0);    		 
+             model.setTurnRestrictionLeg(role, w);            
+         }       
+         
+         public void updateEnabledState() {
+        	setEnabled(OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class).size() == 1);
+         }
+
+		@Override
+		public void valueChanged(ListSelectionEvent e) {
+			updateEnabledState();
+		}
+    }
+    
+    /**
      * The transfer handler for Drag-and-Drop. 
      */
@@ -366,3 +411,5 @@
         }
     }
+    
+     
 }
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java	(revision 23571)
@@ -51,4 +51,6 @@
     private ExceptValueModel exceptValue = new ExceptValueModel();
     
+    private StandardVehicleTypeChangeListener svtChangeListener;
+    
     private JPanel buildMessagePanel() {
         JPanel pnl = new JPanel(new BorderLayout());
@@ -67,5 +69,5 @@
             return pnlStandard;
         
-        StandardVehicleTypeChangeListener changeHandler = new StandardVehicleTypeChangeListener();
+        svtChangeListener = new StandardVehicleTypeChangeListener();
         
         GridBagConstraints gc = new GridBagConstraints();
@@ -78,5 +80,5 @@
         JLabel lbl;
         cbPsv = new JCheckBox();
-        cbPsv.addItemListener(changeHandler);
+        cbPsv.addItemListener(svtChangeListener);
         lbl = new JLabel();
         lbl.setText(tr("Public Service Vehicles"));
@@ -91,5 +93,5 @@
         
         cbHgv = new JCheckBox();
-        cbHgv.addItemListener(changeHandler);
+        cbHgv.addItemListener(svtChangeListener);
         lbl = new JLabel();
         lbl.setText(tr("Heavy Goods Vehicles"));
@@ -104,5 +106,5 @@
 
         cbMotorcar = new JCheckBox();
-        cbMotorcar.addItemListener(changeHandler);
+        cbMotorcar.addItemListener(svtChangeListener);
         lbl = new JLabel();
         lbl.setText(tr("Motorcars"));
@@ -118,5 +120,5 @@
         
         cbBicyle = new JCheckBox();
-        cbBicyle.addItemListener(changeHandler);
+        cbBicyle.addItemListener(svtChangeListener);
         lbl = new JLabel();
         lbl.setText(tr("Bicycles"));
@@ -212,5 +214,5 @@
         bgStandardOrNonStandard.add(rbStandardException);
         
-        StandardNonStandardChangeHander changeHandler = new StandardNonStandardChangeHander();
+        StandardNonStandardChangeHandler changeHandler = new StandardNonStandardChangeHandler();
         rbNonStandardException.addItemListener(changeHandler);
         rbStandardException.addItemListener(changeHandler);
@@ -231,8 +233,15 @@
     
     protected void init() {
-        cbPsv.setSelected(exceptValue.isVehicleException("psv"));
-        cbBicyle.setSelected(exceptValue.isVehicleException("bicycle"));
-        cbMotorcar.setSelected(exceptValue.isVehicleException("motorcar"));
-        cbHgv.setSelected(exceptValue.isVehicleException("hgv"));
+    	try {
+    		// temporarily disable the checkbox listeners while initializing the
+    		// checkboxes with the input value
+    		this.svtChangeListener.setEnabled(false);
+	        cbPsv.setSelected(exceptValue.isVehicleException("psv"));
+	        cbBicyle.setSelected(exceptValue.isVehicleException("bicycle"));
+	        cbMotorcar.setSelected(exceptValue.isVehicleException("motorcar"));
+	        cbHgv.setSelected(exceptValue.isVehicleException("hgv"));
+    	} finally {
+    		this.svtChangeListener.setEnabled(true);
+    	}
         if (!exceptValue.isStandard()){
             rbNonStandardException.setSelected(true);
@@ -285,5 +294,5 @@
     /* inner classes                                                                        */
     /* ------------------------------------------------------------------------------------ */
-    class StandardNonStandardChangeHander implements ItemListener {
+    class StandardNonStandardChangeHandler implements ItemListener {
         public void itemStateChanged(ItemEvent e) {
             if (rbNonStandardException.isSelected()){
@@ -301,9 +310,16 @@
     
     class StandardVehicleTypeChangeListener implements ItemListener {
-        public void itemStateChanged(ItemEvent e) {
+    	private boolean enabled = true;
+    	
+    	public void setEnabled(boolean enabled){
+    		this.enabled = enabled;
+    	}
+    	
+        public void itemStateChanged(ItemEvent e) {        	
+        	if (!enabled) return;
             exceptValue.setVehicleException("bicycle", cbBicyle.isSelected());
             exceptValue.setVehicleException("hgv", cbHgv.isSelected());
             exceptValue.setVehicleException("psv", cbPsv.isSelected());
-            exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected());
+            exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected());            
             model.setExcept(exceptValue);
         }
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java	(revision 23571)
@@ -22,10 +22,10 @@
 
 /**
- * IssuesModel is a model for an observable list of {@code Issues}
- * related to turn restriction.
+ * <p>IssuesModel is a model for an observable list of {@code Issues}
+ * related to turn restriction.</p>
  * 
- * It is also an {@see Observer} to an {@see TurnRestrictionEditorModel}
+ * <p>It is also an {@link Observer} to an {@link TurnRestrictionEditorModel}
  * and populates itself with issues it derives from the current state
- * in the {@see TurnRestrictionEditorModel}.
+ * in the {@link TurnRestrictionEditorModel}.</p>
  *  
  */
@@ -36,8 +36,4 @@
     /**
      * Creates the model 
-     * 
-     * {@code controler} is used in resolution actions for issues in
-     * this model to direct the user to a specific input field in one
-     * of the editor tabs in order to fix an issue. 
      * 
      * @param editorModel the editor model. Must not be null.
@@ -224,14 +220,19 @@
                 issues.add(new IntersectionMissingAsViaError(this, from, to, intersect));
             }
-        }
-        
-        // 'from' intersects with 'to' - should be split  
-        if (intersect != null && from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){
-            issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect));
-        }
-        // 'to' intersects with 'from' - should be split
-        if (intersect != null && to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){
-            issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect));
-        }       
+            // 'from' intersects with 'to' - should be split  
+            if (from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){
+                issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect));
+            }
+            // 'to' intersects with 'from' - should be split
+            if (to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){
+                issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect));
+            }                  
+        } else {
+        	if (editorModel.getVias().isEmpty() && ! from.equals(to)){
+        		// the two turn restriction legs aren't connected and we don't have configured
+        		// via objects 
+        		issues.add(new MissingViaError(this));
+        	}        	
+        }               
     }
     
Index: applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingViaError.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingViaError.java	(revision 23571)
+++ applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingViaError.java	(revision 23571)
@@ -0,0 +1,39 @@
+package org.openstreetmap.josm.plugins.turnrestrictions.qa;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+
+/**
+ * Issue if the legs of a turn restriction aren't connected and if there 
+ * are no via objects configured. 
+ * 
+ */
+public class MissingViaError extends Issue {
+
+	public MissingViaError(IssuesModel parent) throws IllegalArgumentException {
+		super(parent, Severity.WARNING);
+		actions.add(new FixAction());
+	}
+
+	@Override
+	public String getText() {
+		 String msg = 
+			 tr("The two ways participating in the turn restriction <strong>aren''t connected.</strong>")
+			+ "<p>"
+			+ tr("Make sure you add one or more via objects (nodes or ways) to the turn restriction.");
+		 return msg;
+	}
+
+	class FixAction extends AbstractAction {
+        public FixAction() {
+            putValue(NAME, tr("Fix in editor"));
+            putValue(SHORT_DESCRIPTION, tr("Go to the Advanced Editor and add via objects"));
+        }
+        public void actionPerformed(ActionEvent e) {
+            getIssuesModel().getNavigationControler().gotoAdvancedEditor();
+        }       
+    }
+}
Index: applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/AllUnitTests.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/AllUnitTests.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/AllUnitTests.java	(revision 23571)
@@ -1,14 +1,12 @@
 package org.openstreetmap.josm.plugins.turnrestrictions;
 
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
 import org.openstreetmap.josm.plugins.turnrestrictions.editor.AllEditorTests;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllUnitTests {
-	public static Test suite() throws Exception {
-		TestSuite suite = new TestSuite(AllUnitTests.class.getName());
-		suite.addTest(AllEditorTests.suite());
-		return suite;
-	}
-}
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+	AllEditorTests.class,
+	TurnRestrictionBuilderTest.class
+})
+public class AllUnitTests {}
Index: applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilderTest.groovy
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilderTest.groovy	(revision 23571)
+++ applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilderTest.groovy	(revision 23571)
@@ -0,0 +1,350 @@
+package org.openstreetmap.josm.plugins.turnrestrictions;
+import groovy.util.GroovyTestCase;
+
+import static org.junit.Assert.*;
+import org.junit.*;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.plugins.turnrestrictions.fixtures.JOSMFixture;
+import org.openstreetmap.josm.data.coor.LatLon;
+
+class TurnRestrictionBuilderTest{
+	
+	def TurnRestrictionBuilder builder;
+
+	def boolean hasExactlyOneMemberWithRole(Relation r, String role ){
+		return r.getMembers().find {RelationMember rm -> rm.getRole() == role} != null
+	}
+	
+	def memberWithRole(Relation r, String role) {
+		def RelationMember rm = r.getMembers().find {RelationMember rm -> rm.getRole() == role}
+		return rm.getMember()
+	}
+	
+	def void assertEmptyTurnRestriction(Relation r){
+		assert r != null
+		assert r.get("type") == "restriction"
+		assert r.getMembersCount() == 0
+	}
+	
+	@Before
+	public void setUp() {
+		JOSMFixture.createUnitTestFixture().init()
+		builder = new TurnRestrictionBuilder() {
+			def double testPhi(Way w){
+				return super.phi(w)
+			}
+			
+			def double testPhi(Way w, boolean doRevert){
+				return super.phi(w,doRevert)
+			}
+		}
+	}
+
+	/**
+	 * Selection consist of one way and the start node of the way ->
+	 * propose a No-U-Turn restriction
+	 * 		
+	 */
+	@Test
+	public void noUTurn_1() {
+		Way w = new Way(1)
+		Node n1 = new Node(1)
+		Node n2 = new Node(2)
+		w.setNodes([n1,n2])
+		
+		def sel = [w,n1]
+		TurnRestrictionBuilder builder = new TurnRestrictionBuilder()
+		Relation r = builder.build(sel)  
+		
+		assert r != null
+		assert r.getMembersCount() == 3
+		assert hasExactlyOneMemberWithRole(r, "from")
+		assert hasExactlyOneMemberWithRole(r, "to")
+		assert hasExactlyOneMemberWithRole(r, "via")
+		assert memberWithRole(r, "from") == w
+		assert memberWithRole(r, "to") == w
+		assert memberWithRole(r, "via") == n1
+		assert r.get("restriction") == "no_u_turn"			
+	}
+	
+	
+	/**
+	* Selection consist of one way and the end node of the way ->
+	* propose a No-U-Turn restriction
+	*
+	*/
+   @Test
+   public void noUTurn_2() {
+	   Way w = new Way(1)
+	   Node n1 = new Node(1)
+	   Node n2 = new Node(2)
+	   w.setNodes([n1,n2])
+	   
+	   def sel = [w,n2]
+	   TurnRestrictionBuilder builder = new TurnRestrictionBuilder()
+	   Relation r = builder.build(sel)
+	   
+	   assert r != null
+	   assert r.getMembersCount() == 3
+	   assert hasExactlyOneMemberWithRole(r, "from")
+	   assert hasExactlyOneMemberWithRole(r, "to")
+	   assert hasExactlyOneMemberWithRole(r, "via")
+	   assert memberWithRole(r, "from") == w
+	   assert memberWithRole(r, "to") == w
+	   assert memberWithRole(r, "via") == n2
+	   assert r.get("restriction") == "no_u_turn"
+   }
+   
+   @Test
+   public void nullSelection() {
+	   def tr = builder.build(null)
+	   assertEmptyTurnRestriction(tr)
+   }
+   
+   @Test
+   public void emptySelection() {
+	   def tr = builder.build([])
+	   assertEmptyTurnRestriction(tr)
+   }
+   
+   /**
+    * One selected way -> build a turn restriction with a "from" leg
+    * only
+    */
+   @Test
+   public void oneSelectedWay() {
+	   Way w = new Way(1)
+	   Relation tr = builder.build([w])
+	   assert tr != null
+	   assert tr.get("type") == "restriction"
+	   assert tr.getMembersCount() == 1
+	   assert memberWithRole(tr, "from") == w
+   }   
+   
+   /**
+    * Two unconnected ways in the selection. The first one becomes the from leg,
+    * the second one the two leg.
+    */
+   @Test
+   public void twoUnconnectedWays() {
+	   Way w1 = new Way(1)
+	   w1.setNodes([new Node(11), new Node(12)])
+	   Way w2 = new Way(2)
+	   w2.setNodes([new Node(21), new Node(22)])
+	   
+	   Relation tr = builder.build([w1,w2])
+	   assert tr != null
+	   assert tr.get("type") == "restriction"
+	   assert ! tr.hasKey("restriction")
+	   assert tr.getMembersCount() == 2
+	   assert memberWithRole(tr, "from") == w1
+	   assert memberWithRole(tr, "to") == w2
+   }
+   
+   /**
+    * Two connected ways. end node of the first way connects to start node of 
+    * the second way. 
+    *       w2 
+    *    -------->
+    *    ^ 
+    *    | w1
+    *    |
+    */
+   @Test
+   public void twoConnectedWays_1() {
+	   Node n1 = new Node(1)
+	   n1.setCoor(new LatLon(1,1))
+	   Node n2 = new Node(2)
+	   n2.setCoor(new LatLon(2,1))
+	   Node n3 = new Node(3)
+	   n3.setCoor(new LatLon(2,2))
+	   
+	   Way w1 = new Way(1)
+	   w1.setNodes([n1,n2])
+	   Way w2 = new Way(2)
+	   w2.setNodes([n2,n3])
+
+	   assert builder.testPhi(w1) == Math.toRadians(90)	   
+	   assert builder.testPhi(w2) == Math.toRadians(0)
+	   	   
+	   Relation tr = builder.build([w1,w2,n2])
+	   
+	   assert tr != null
+	   assert tr.get("type") == "restriction"
+	   assert tr.getMembersCount() == 3
+	   assert memberWithRole(tr, "from") == w1
+	   assert memberWithRole(tr, "to") == w2
+	   assert memberWithRole(tr, "via") == n2
+	   
+	   assert tr.get("restriction") == "no_right_turn"
+	   	   
+	   /*
+	    * opposite order, from w2 to w1. In this case we have left turn.
+	    */
+	   
+	   tr = builder.build([w2,w1,n2])
+	   
+	   assert tr != null
+	   assert tr.get("type") == "restriction"
+	   assert tr.getMembersCount() == 3
+	   assert memberWithRole(tr, "from") == w2
+	   assert memberWithRole(tr, "to") == w1
+	   assert memberWithRole(tr, "via") == n2
+	   
+	   assert tr.get("restriction") == "no_left_turn"
+   }
+   
+   /**
+	* Two connected ways. end node of the first way connects to end node of
+	* the second way. left turn.
+	* 
+	*                   w2
+	*           (7,2) -------> (7,5)
+	*                            ^
+	*                            | w1
+	*                            |  
+	*                          (5,5)
+	*/
+   @Test
+   public void twoConnectedWays_2() {
+	   Node n1 = new Node(1)
+	   n1.setCoor(new LatLon(5,5))
+	   Node n2 = new Node(2)
+	   n2.setCoor(new LatLon(7,5))
+	   Node n3 = new Node(3)
+	   n3.setCoor(new LatLon(7,2))
+	   
+	   Way w1 = new Way(1)
+	   w1.setNodes([n1,n2])
+	   Way w2 = new Way(2)
+	   w2.setNodes([n3,n2])
+	   
+	   assert builder.testPhi(w1) == Math.toRadians(90)
+	   assert builder.testPhi(w2) == Math.toRadians(0)
+	   assert builder.testPhi(w2,true) == Math.toRadians(180)
+	   
+	   Relation tr = builder.build([w1,w2,n2])
+	   
+	   assert tr != null
+	   assert tr.get("type") == "restriction"
+	   assert tr.getMembersCount() == 3
+	   assert memberWithRole(tr, "from") == w1
+	   assert memberWithRole(tr, "to") == w2
+	   assert memberWithRole(tr, "via") == n2
+	   
+	   assert tr.get("restriction") == "no_left_turn"
+	   
+	   
+	   /*
+	    * opposite order, from w2 to w1. In this case we have right turn.
+	    */
+	   tr = builder.build([w2,w1,n2])
+	   
+	   assert tr != null
+	   assert tr.get("type") == "restriction"
+	   assert tr.getMembersCount() == 3
+	   assert memberWithRole(tr, "from") == w2
+	   assert memberWithRole(tr, "to") == w1
+	   assert memberWithRole(tr, "via") == n2	   
+	   assert tr.get("restriction") == "no_right_turn"
+   }
+   
+   /**
+   * Two connected ways. end node of the first way connects to end node of
+   * the second way. left turn.
+   *
+   *                 
+   *           (7,5) -
+   *             ^     -    w2
+   *             | w1     ------> (6,7)
+   *             |
+   *           (5,5)
+   */
+  @Test
+  public void twoConnectedWays_3() {
+	  Node n1 = new Node(1)
+	  n1.setCoor(new LatLon(5,5))
+	  Node n2 = new Node(2)
+	  n2.setCoor(new LatLon(7,5))
+	  Node n3 = new Node(3)
+	  n3.setCoor(new LatLon(6,7))
+	  
+	  Way w1 = new Way(1)
+	  w1.setNodes([n1,n2])
+	  Way w2 = new Way(2)
+	  w2.setNodes([n2,n3])
+	  	  	  
+	  Relation tr = builder.build([w1,w2,n2])
+	  
+	  assert tr != null
+	  assert tr.get("type") == "restriction"
+	  assert tr.getMembersCount() == 3
+	  assert memberWithRole(tr, "from") == w1
+	  assert memberWithRole(tr, "to") == w2
+	  assert memberWithRole(tr, "via") == n2
+	  
+	  assert tr.get("restriction") == "no_right_turn"	 
+  }
+  
+  
+  /**
+  * Two connected ways. end node of the first way connects to end node of
+  * the second way. left turn.
+  *
+  *           
+  *           (10,10)
+  *                 \                   
+  *                  \            
+  *                   \
+  *                    v           
+  *                     (8,15)
+  *                    /                     
+  *                   /
+  *                  /
+  *                 v
+  *            (5,11)
+  */
+ @Test
+ public void twoConnectedWays_4() {
+	 Node n1 = new Node(1)
+	 n1.setCoor(new LatLon(10,10))
+	 Node n2 = new Node(2)
+	 n2.setCoor(new LatLon(8,15))
+	 Node n3 = new Node(3)
+	 n3.setCoor(new LatLon(5,11))
+	 
+	 Way w1 = new Way(1)
+	 w1.setNodes([n1,n2])
+	 Way w2 = new Way(2)
+	 w2.setNodes([n2,n3])
+
+	 Relation tr = builder.build([w1,w2,n2])
+	 
+	 assert tr != null
+	 assert tr.get("type") == "restriction"
+	 assert tr.getMembersCount() == 3
+	 assert memberWithRole(tr, "from") == w1
+	 assert memberWithRole(tr, "to") == w2
+	 assert memberWithRole(tr, "via") == n2
+	 
+	 assert tr.get("restriction") == "no_right_turn"
+
+	 
+	 /*
+	  * opposite order, from w2 to w1. In  this case we have left turn.
+	  */
+	 tr = builder.build([w2,w1,n2])
+	 
+	 assert tr != null
+	 assert tr.get("type") == "restriction"
+	 assert tr.getMembersCount() == 3
+	 assert memberWithRole(tr, "from") == w2
+	 assert memberWithRole(tr, "to") == w1
+	 assert memberWithRole(tr, "via") == n2
+	 
+	 assert tr.get("restriction") == "no_left_turn"
+	}
+}
Index: applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AllEditorTests.java
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AllEditorTests.java	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AllEditorTests.java	(revision 23571)
@@ -1,26 +1,17 @@
 package org.openstreetmap.josm.plugins.turnrestrictions.editor;
 
-import groovy.util.GroovyTestSuite;
-import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestSuite;
 
-public class AllEditorTests extends TestCase{
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
 
-	private static final String TEST_ROOT = "test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/";
-	private static final GroovyTestSuite gsuite = new GroovyTestSuite();
-	
-	private static <T extends TestCase> Class<T> groovyts(String className) throws Exception {
-		return gsuite.compile(TEST_ROOT + className + ".groovy");
-	}
-	
-	public static Test suite() throws Exception {
-		TestSuite suite = new TestSuite(AllEditorTests.class.getName());
-		suite.addTestSuite(groovyts("JosmSelectionListModelTest"));
-		suite.addTestSuite(groovyts("TurnRestrictionEditorModelUnitTest"));
-		suite.addTestSuite(groovyts("TurnRestrictionLegEditorUnitTest"));
-		suite.addTestSuite(groovyts("TurnRestrictionTypeRendererTest"));
-		suite.addTestSuite(groovyts("TurnRestrictionTypeTest"));
-		return suite;
-	}
-}
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+	JosmSelectionListModelTest.class,
+	TurnRestrictionEditorModelUnitTest.class,
+	TurnRestrictionLegEditorUnitTest.class,
+	TurnRestrictionTypeRendererTest.class,
+	TurnRestrictionTypeTest.class,
+	ExceptValueModelTest.class
+})
+public class AllEditorTests extends TestCase{}
Index: applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ExceptValueModelTest.groovy
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ExceptValueModelTest.groovy	(revision 23571)
+++ applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ExceptValueModelTest.groovy	(revision 23571)
@@ -0,0 +1,70 @@
+package org.openstreetmap.josm.plugins.turnrestrictions.editor;
+
+import org.junit.*;
+import static org.junit.Assert.*;
+import org.openstreetmap.josm.plugins.turnrestrictions.editor.ExceptValueModel;
+
+class ExceptValueModelTest {
+
+	@Test
+	public void constructor() {
+		new ExceptValueModel()
+		
+		def evm = new ExceptValueModel(null)
+		evm = new ExceptValueModel("")	
+		evm = new ExceptValueModel("  ")
+		evm = new ExceptValueModel("hgv")
+		evm = new ExceptValueModel("hgv;psv")
+		evm = new ExceptValueModel("non_standard")
+	}
+	
+	@Test
+	public void setValue() {
+		def evm
+		
+		// null value allowed - means no vehicle exceptions 
+		evm = new ExceptValueModel()
+		evm.setValue(null)
+		assert evm.getValue() == ""
+		assert evm.isStandard()
+		
+		// empty string allowed - means no vehicle expections 
+		evm = new ExceptValueModel()
+		evm.setValue("")
+		assert evm.getValue() == ""
+		assert evm.isStandard()
+
+		// a single standard vehicle exeption 
+		evm = new ExceptValueModel()
+		evm.setValue("hgv")
+		assert evm.getValue() == "hgv"
+		assert evm.isVehicleException("hgv")
+		assert ! evm.isVehicleException("psv")
+		assert evm.isStandard()
+
+		// two standard vehicle exceptions 
+		evm = new ExceptValueModel()
+		evm.setValue("hgv;psv")
+		assert evm.getValue() == "hgv;psv"
+		assert evm.isVehicleException("hgv")
+		assert evm.isVehicleException("psv")
+		assert evm.isStandard()
+		
+		// white space and lowercase/uppercase mix allowed. Should be normalized
+		// by the except value model
+		evm = new ExceptValueModel()
+		evm.setValue(" hGv ; PsV  ")
+		assert evm.getValue() == "hgv;psv"
+		assert evm.isVehicleException("hgv")
+		assert evm.isVehicleException("psv")
+		assert evm.isStandard()
+		
+		// non standard value allowed 
+		evm = new ExceptValueModel()
+		evm.setValue("Non Standard")
+		assert evm.getValue() == "Non Standard"
+		assert !evm.isVehicleException("hgv")
+		assert !evm.isVehicleException("psv")
+		assert !evm.isStandard()
+	}	 
+}
Index: applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy
===================================================================
--- applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy	(revision 23568)
+++ applications/editors/josm/plugins/turnrestrictions/test/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy	(revision 23571)
@@ -33,12 +33,8 @@
 		DataSet ds = new DataSet()
 		OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
-		JosmSelectionListModel model = new JosmSelectionListModel(layer, new DefaultListSelectionModel());		
+		JosmSelectionListModel model = new JosmSelectionListModel(layer);		
 		
 		shouldFail(IllegalArgumentException){
-			model = new JosmSelectionListModel(layer, null)
-		}
-		
-		shouldFail(IllegalArgumentException){
-			model = new JosmSelectionListModel(null, new DefaultListSelectionModel())
+			model = new JosmSelectionListModel(null)
 		}
 	}
@@ -48,5 +44,5 @@
 		DataSet ds = new DataSet()
 		OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
-		JosmSelectionListModel model = new JosmSelectionListModel(layer, new DefaultListSelectionModel());
+		JosmSelectionListModel model = new JosmSelectionListModel(layer);
 		
 		// set a selection with three objects 
@@ -70,5 +66,5 @@
 		DataSet ds = new DataSet()
 		OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
-		JosmSelectionListModel model = new JosmSelectionListModel(layer, new DefaultListSelectionModel());
+		JosmSelectionListModel model = new JosmSelectionListModel(layer);
 		def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]	
 		model.setJOSMSelection(objects)
@@ -88,7 +84,8 @@
 		DataSet ds = new DataSet()
 		OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
-		DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
 		
-		JosmSelectionListModel model = new JosmSelectionListModel(layer, selectionModel);
+		JosmSelectionListModel model = new JosmSelectionListModel(layer);
+		DefaultListSelectionModel selectionModel = model.getListSelectionModel()
+		
 		assert model.getSelected() != null
 		assert model.getSelected().isEmpty()
@@ -109,8 +106,8 @@
 		DataSet ds = new DataSet()
 		OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
-		DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
 		
 		// set selected with null is OK - nothing selected thereafter
-		JosmSelectionListModel model = new JosmSelectionListModel(layer, selectionModel);
+		JosmSelectionListModel model = new JosmSelectionListModel(layer);
+		DefaultListSelectionModel selectionModel = model.getListSelectionModel()
 		model.setSelected(null)
 		assert model.getSelected().isEmpty()
@@ -135,5 +132,5 @@
 	public void test_editLayerChanged() {
 		DataSet ds = new DataSet()
-		DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();		
+			
 		def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]	
 		objects.each {ds.addPrimitive(it)}
@@ -142,6 +139,6 @@
 		OsmDataLayer layer2 = new OsmDataLayer(new DataSet(),"layer2", null)
 		
-		JosmSelectionListModel model = new JosmSelectionListModel(layer1, selectionModel);
-		
+		JosmSelectionListModel model = new JosmSelectionListModel(layer1);
+		DefaultListSelectionModel selectionModel = model.getListSelectionModel()
 		// switch from edit layer1 to edit layer2. content of the JOSM selection 
 		// should be empty thereafter 
