Index: /applications/editors/josm/plugins/terracer/build.xml
===================================================================
--- /applications/editors/josm/plugins/terracer/build.xml	(revision 19677)
+++ /applications/editors/josm/plugins/terracer/build.xml	(revision 19678)
@@ -17,5 +17,5 @@
 **
 ** To build against the core in ../../core, create a correct manifest and deploy to
-** SVN, 
+** SVN,
 **    set the properties commit.message and plugin.main.version
 ** and run
@@ -30,10 +30,10 @@
     <property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
     <property name="ant.build.javac.target" value="1.5"/>
-	
 
-    <property name="commit.message" value="Changed the constructor signature of the plugin main class" />		
+
+    <property name="commit.message" value="josm terracer plugin: fixed reverse terrace, minor updates" />
     <property name="plugin.main.version" value="2830" />
-    	
-    	
+
+
     <target name="init">
         <mkdir dir="${plugin.build.dir}"/>
@@ -85,80 +85,80 @@
         <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
     </target>
-	
-	<!--
-		 ************************** Publishing the plugin *********************************** 
-		-->
-			<!--
-			  ** extracts the JOSM release for the JOSM version in ../core and saves it in the 
-			  ** property ${coreversion.info.entry.revision}
-			  **
-			-->
-			<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"/>
-				<echo>Building against core revision ${coreversion.info.entry.revision}.</echo>			
-				<echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
-				<delete file="core.info.xml" />
-			</target>
 
-			<!--
-			 ** commits the source tree for this plugin
-			-->
-			<target name="commit-current">
-				<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="."/>
-			    </exec>	    
-			</target>
+    <!--
+         ************************** Publishing the plugin ***********************************
+        -->
+            <!--
+              ** extracts the JOSM release for the JOSM version in ../core and saves it in the
+              ** property ${coreversion.info.entry.revision}
+              **
+            -->
+            <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"/>
+                <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
+                <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
+                <delete file="core.info.xml" />
+            </target>
 
-			<!--
-			** updates (svn up) the source tree for this plugin
-			-->
-			<target name="update-current">
-				<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="."/>
-			    </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}"/>
-			    </exec>	    
-			</target>
-			
-			<!--
-			 ** commits the plugin.jar 
-			 -->
-			<target name="commit-dist">
-					<echo>
-	***** Properties of published ${plugin.jar} *****
-	Commit message    : '${commit.message}'					
-	Plugin-Mainversion: ${plugin.main.version}
-	JOSM build version: ${coreversion.info.entry.revision}
-	Plugin-Version    : ${version.entry.commit.revision}
-	***** / Properties of published ${plugin.jar} *****					
-						
-	Now commiting ${plugin.jar} ...
-	</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}"/>
-				    </exec>	    
-		   	</target>
-					
-			<target name="publish" depends="core-info,commit-current,update-current,clean,dist,commit-dist">
-			</target>		
+            <!--
+             ** commits the source tree for this plugin
+            -->
+            <target name="commit-current">
+                <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="."/>
+                </exec>
+            </target>
+
+            <!--
+            ** updates (svn up) the source tree for this plugin
+            -->
+            <target name="update-current">
+                <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="."/>
+                </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}"/>
+                </exec>
+            </target>
+
+            <!--
+             ** commits the plugin.jar
+             -->
+            <target name="commit-dist">
+                    <echo>
+    ***** Properties of published ${plugin.jar} *****
+    Commit message    : '${commit.message}'
+    Plugin-Mainversion: ${plugin.main.version}
+    JOSM build version: ${coreversion.info.entry.revision}
+    Plugin-Version    : ${version.entry.commit.revision}
+    ***** / Properties of published ${plugin.jar} *****
+
+    Now commiting ${plugin.jar} ...
+    </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}"/>
+                    </exec>
+               </target>
+
+            <target name="publish" depends="core-info,commit-current,update-current,clean,dist,commit-dist">
+            </target>
 </project>
Index: /applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java
===================================================================
--- /applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java	(revision 19677)
+++ /applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java	(revision 19678)
@@ -6,6 +6,9 @@
 import java.awt.event.KeyEvent;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedList;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
@@ -49,28 +52,41 @@
      */
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
+        Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays();
 
-        // set to keep track of all the nodes that have been visited - that is: if
+        // Set to keep track of all the nodes that have been visited - that is: if
         // we encounter them again we will not follow onto the connected ways.
         HashSet<Node> visitedNodes = new HashSet<Node>();
 
-        // set to keep track of the ways the algorithm has seen, but not yet visited.
-        // since when a way is visited all of its nodes are marked as visited, there
+        // Set to keep track of the ways the algorithm has seen, but not yet visited.
+        // Since when a way is visited all of its nodes are marked as visited, there
         // is no need to keep a visitedWays set.
         HashSet<Way> front = new HashSet<Way>();
 
-        // initialise the set with all the buildings in the selection. this means
-        // there is undefined behaviour when there is a multiple selection, as the
-        // ordering will be based on the hash.
-        for (OsmPrimitive prim : sel) {
-            if (prim.keySet().contains("building") && prim instanceof Way) {
-                front.add((Way)prim);
+        // Find the first or last way from the teracced houses.
+        // It should be connected to exactly one other way.
+        for (Way w : selectedWays) {
+            int conn = 0;
+            for (Way v : selectedWays) {
+                if (w.equals(v)) continue;
+                if (!Collections.disjoint(w.getNodes(), v.getNodes())) {
+                    ++conn;
+                }
+            }
+            if (conn == 1) {
+                front.add(w);
+                break;
             }
         }
+        
+        if (front.isEmpty()) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("Cannot reverse!"));
+            return;
+        }                
 
-        // this is like a visitedWays set, but in a linear order.
+        // This is like a visitedWays set, but in a linear order.
         LinkedList<Way> orderedWays = new LinkedList<Way>();
 
-        // and the tags to reverse on the orderedWays.
+        // And the tags to reverse on the orderedWays.
         LinkedList<String> houseNumbers = new LinkedList<String>();
 
@@ -79,5 +95,5 @@
             Way w = front.iterator().next();
 
-            // visit all the nodes in the way, adding the building's they're members of
+            // Visit all the nodes in the way, adding the building's they're members of
             // to the front.
             for (Node n : w.getNodes()) {
@@ -92,5 +108,5 @@
             }
 
-            // we've finished visiting this way, so record the attributes we're interested
+            // We've finished visiting this way, so record the attributes we're interested
             // in for re-writing.
             front.remove(w);
@@ -100,5 +116,4 @@
 
         Collection<Command> commands = new LinkedList<Command>();
-        // what, no zipWith?
         for (int i = 0; i < orderedWays.size(); ++i) {
             commands.add(new ChangePropertyCommand(
@@ -112,3 +127,7 @@
     }
 
+    @Override
+    protected void updateEnabledState() {
+        setEnabled(getCurrentDataSet() != null);
+    }    
 }
Index: /applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
===================================================================
--- /applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 19677)
+++ /applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 19678)
@@ -34,4 +34,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.data.osm.TagCollection;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.tools.Pair;
@@ -209,4 +210,8 @@
             terr.addNode(new_nodes[1][i]);
             terr.addNode(new_nodes[0][i]);
+            
+            // add the tags of the outline to each building (e.g. source=*)
+            TagCollection.from(outline).applyTo(terr);
+            
             if (from != null) {
                 // only, if the user has specified house numbers
@@ -459,3 +464,8 @@
         return n;
     }
+
+    @Override
+    protected void updateEnabledState() {
+        setEnabled(getCurrentDataSet() != null);
+    }    
 }
