Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorDialog.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorDialog.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorDialog.java	(revision 16574)
@@ -43,5 +43,5 @@
 import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.ITagSelectorListener;
 import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.TabularTagSelector;
-
+import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
 /**
  * The dialog for editing name/value-pairs (aka <em>tags</em>) associated with {@link OsmPrimitive}s.
@@ -345,5 +345,5 @@
 			model.updateJOSMSelection();
 
-			Collection<OsmPrimitive> sel = Main.ds.getSelected();
+			Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
 			DataSet.fireSelectionChanged(sel);
 			Main.parent.repaint(); // repaint all - drawing could have been changed
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionCache.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionCache.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionCache.java	(revision 16574)
@@ -8,5 +8,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-
+import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
 /**
  * AutoCompletionCache temporarily holds a cache of keys with a list of
@@ -18,19 +18,19 @@
  *   <li>any value used in a tag for a specific key is part of the autocompletion list of
  *     this key</li>
- * </ol>  
+ * </ol>
  * 
  * Building up auto completion lists should not
  * slow down tabbing from input field to input field. Looping through the complete
  * data set in order to build up the auto completion list for a specific input
- * field is not efficient enough, hence this cache.   
+ * field is not efficient enough, hence this cache.
  *
  */
 public class AutoCompletionCache {
-	
+
 	/** the cache */
 	private HashMap<String, ArrayList<String>> cache;
-	
+
 	/**
-	 * constructor 
+	 * constructor
 	 */
 	public AutoCompletionCache() {
@@ -39,21 +39,21 @@
 
 	/**
-	 * make sure, <code>key</code> is in the cache 
+	 * make sure, <code>key</code> is in the cache
 	 * 
-	 * @param key  the key 
+	 * @param key  the key
 	 */
 	protected void cacheKey(String key) {
-		if (cache.containsKey(key)) {
+		if (cache.containsKey(key))
 			return;
-		} else {
+		else {
 			cache.put(key, new ArrayList<String>());
 		}
 	}
-	
+
 	/**
-	 * make sure, value is one of the auto completion values allowed for key 
+	 * make sure, value is one of the auto completion values allowed for key
 	 * 
-	 * @param key the key 
-	 * @param value the value 
+	 * @param key the key
+	 * @param value the value
 	 */
 	protected void cacheValue(String key, String value) {
@@ -64,10 +64,10 @@
 		}
 	}
-	
+
 	/**
 	 * make sure, the keys and values of all tags held by primitive are
-	 * in the auto completion cache 
-	 *  
-	 * @param primitive an OSM primitive 
+	 * in the auto completion cache
+	 * 
+	 * @param primitive an OSM primitive
 	 */
 	protected void cachePrimitive(OsmPrimitive primitive) {
@@ -77,5 +77,5 @@
 		}
 	}
-	
+
 	/**
 	 * initializes the cache from the current JOSM dataset {@link OsmPrimitive}s.
@@ -84,33 +84,32 @@
 	public void initFromJOSMDataset() {
 		cache = new HashMap<String, ArrayList<String>>();
-		Collection<OsmPrimitive> ds = Main.ds.allNonDeletedPrimitives();
+		Collection<OsmPrimitive> ds = getCurrentDataSet().allNonDeletedPrimitives();
 		for (OsmPrimitive primitive : ds) {
 			cachePrimitive(primitive);
 		}
 	}
-	
+
 	/**
 	 * replies the keys held by the cache
-	 *  
-	 * @return the list of keys held by the cache 
+	 * 
+	 * @return the list of keys held by the cache
 	 */
 	public List<String> getKeys() {
 		return new ArrayList<String>(cache.keySet());
 	}
-	
-	
+
+
 	/**
 	 * replies the auto completion values allowed for a specific key. Replies
 	 * an empty list if key is null or if key is not in {@link #getKeys()}.
 	 * 
-	 * @param key 
-	 * @return the list of auto completion values  
+	 * @param key
+	 * @return the list of auto completion values
 	 */
 	public List<String> getValues(String key) {
-		if (!cache.containsKey(key)) {
+		if (!cache.containsKey(key))
 			return new ArrayList<String>();
-		} else {
+		else
 			return cache.get(key);
-		}
 	}
 }
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionContext.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionContext.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionContext.java	(revision 16574)
@@ -2,23 +2,24 @@
 
 import org.openstreetmap.josm.Main;
+import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
 
 public class AutoCompletionContext {
-	
+
 	private boolean selectionIncludesNodes = false;
 	private boolean selectionIncludesWays = false;
 	private boolean selectionIncludesRelations = false;
-	private boolean selectionEmpty = false; 
-	
+	private boolean selectionEmpty = false;
+
 	public AutoCompletionContext(){
 	}
 
 	public void initFromJOSMSelection() {
-		selectionIncludesNodes = ! Main.ds.getSelectedNodes().isEmpty();
-		selectionIncludesWays = !Main.ds.getSelectedWays().isEmpty();
-		selectionIncludesRelations = !Main.ds.getSelectedRelations().isEmpty();
-		selectionEmpty = (Main.ds.getSelected().size() == 0);
+		selectionIncludesNodes = ! getCurrentDataSet().getSelectedNodes().isEmpty();
+		selectionIncludesWays = !getCurrentDataSet().getSelectedWays().isEmpty();
+		selectionIncludesRelations = !getCurrentDataSet().getSelectedRelations().isEmpty();
+		selectionEmpty = (getCurrentDataSet().getSelected().size() == 0);
 	}
-	
-	
+
+
 	public boolean isSelectionEmpty() {
 		return selectionEmpty;
@@ -48,7 +49,7 @@
 		this.selectionIncludesRelations = selectionIncludesRelations;
 	}
-	
-	
-	
+
+
+
 
 }
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java	(revision 16574)
@@ -23,5 +23,5 @@
 import org.openstreetmap.josm.plugins.tageditor.preset.Tag;
 import org.openstreetmap.josm.plugins.tageditor.tagspec.KeyValuePair;
-
+import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
 
 /**
@@ -273,5 +273,5 @@
 	 */
 	public void initFromJOSMSelection() {
-		Collection<OsmPrimitive> selection = Main.ds.getSelected();
+		Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
 		clear();
 		for (OsmPrimitive element : selection) {
@@ -354,5 +354,5 @@
 	public void updateJOSMSelection() {
 		ArrayList<Command> commands = new ArrayList<Command>();
-		Collection<OsmPrimitive> selection = Main.ds.getSelected();
+		Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
 		if (selection == null)
 			return;
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagFieldEditor.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagFieldEditor.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagFieldEditor.java	(revision 16574)
@@ -20,93 +20,105 @@
 /**
  * TagFieldEditor is an editor for tag names or tag values. It supports auto completion
- * from a list of auto completion items. 
+ * from a list of auto completion items.
  *
  */
 public class TagFieldEditor extends JTextField  {
-	
+
 	static private Logger logger = Logger.getLogger(TagFieldEditor.class.getName());
-	
- 	
+
+
 	/**
-	 * The document model for the editor 
+	 * The document model for the editor
 	 */
 	class AutoCompletionDocument extends PlainDocument {
-		
-		  /**
-		   * inserts a string at a specific position
-		   * 
-		   */
-		  public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
-			  if (autoCompletionList == null) {
-				  super.insertString(offs, str, a);
-				  return;
-			  }
-			  String currentText = getText(0, getLength());
-			  String prefix = currentText.substring(0, offs);
-			  autoCompletionList.applyFilter(prefix+str);
-			  if (autoCompletionList.getFilteredSize()>0) {
-				  // there are matches. Insert the new text and highlight the
-				  // auto completed suffix
-				  //
-				  String matchingString = autoCompletionList.getFilteredItem(0).getValue();
-				  remove(0,getLength());
-				  super.insertString(0,matchingString,a);
-				  
-				  // highlight from end to insert position 
-				  //
-				  setCaretPosition(getLength());
-			      moveCaretPosition(offs + str.length());  
-			  } else {
-				  // there are no matches. Insert the new text, do not highlight
-				  // 
-				  String newText = prefix + str; 
-				  remove(0,getLength());
-				  super.insertString(0,newText,a);
-				  setCaretPosition(getLength());
-			  }
-		  }
-		  
-		  
+
+		/**
+		 * inserts a string at a specific position
+		 * 
+		 */
+		@Override
+		public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+			if (autoCompletionList == null) {
+				super.insertString(offs, str, a);
+				return;
+			}
+			// if the current offset isn't at the end of the document we don't autocomplete.
+			// If a highlighted autocompleted suffix was present and we get here Swing has
+			// already removed it from the document. getLength() therefore doesn't include the
+			// autocompleted suffix.
+			//
+			if (offs < getLength()) {
+				super.insertString(offs, str, a);
+				return;
+			}
+
+			String currentText = getText(0, getLength());
+			String prefix = currentText.substring(0, offs);
+			autoCompletionList.applyFilter(prefix+str);
+			if (autoCompletionList.getFilteredSize()>0) {
+				// there are matches. Insert the new text and highlight the
+				// auto completed suffix
+				//
+				String matchingString = autoCompletionList.getFilteredItem(0).getValue();
+				remove(0,getLength());
+				super.insertString(0,matchingString,a);
+
+				// highlight from end to insert position
+				//
+				setCaretPosition(getLength());
+				moveCaretPosition(offs + str.length());
+			} else {
+				// there are no matches. Insert the new text, do not highlight
+				//
+				String newText = prefix + str;
+				remove(0,getLength());
+				super.insertString(0,newText,a);
+				setCaretPosition(getLength());
+			}
+		}
+
+
 	}
 
-	
+
 	/** the auto completion list user input is matched against */
 	protected AutoCompletionList autoCompletionList = null;
-		
+
 	/**
 	 * creates the default document model for this editor
 	 * 
 	 */
+	@Override
 	protected Document createDefaultModel() {
-	     return new AutoCompletionDocument();
+		return new AutoCompletionDocument();
 	}
- 
+
 	/**
-	 * constructor 
+	 * constructor
 	 */
 	public TagFieldEditor() {
-		
+
 		addFocusListener(
-		   new FocusAdapter() {
-				@Override public void focusGained(FocusEvent e) {
-					selectAll();
-					applyFilter(getText());
-	            }			   				
-		   }
-		);	
-		
+				new FocusAdapter() {
+					@Override public void focusGained(FocusEvent e) {
+						selectAll();
+						applyFilter(getText());
+					}
+				}
+		);
+
 		addKeyListener(
-			new KeyAdapter() {
+				new KeyAdapter() {
 
-				@Override
-				public void keyReleased(KeyEvent e) {
-					if (getText().equals("")) {
-						applyFilter("");
-					} 
-				}				
-			}
+					@Override
+					public void keyReleased(KeyEvent e) {
+						if (getText().equals("")) {
+							applyFilter("");
+						}
+					}
+				}
 		);
-	}	
-	
+	}
+
 	protected void applyFilter(String filter) {
 		if (autoCompletionList != null) {
@@ -114,17 +126,16 @@
 		}
 	}
-	
+
 	/**
 	 * 
-	 * @return the auto completion list; may be null, if no auto completion list is set 
+	 * @return the auto completion list; may be null, if no auto completion list is set
 	 */
 	public AutoCompletionList getAutoCompletionList() {
 		return autoCompletionList;
 	}
-	
-	
+
 	/**
-	 * sets the auto completion list 
-	 * @param autoCompletionList the auto completion list; if null, auto completion is 
+	 * sets the auto completion list
+	 * @param autoCompletionList the auto completion list; if null, auto completion is
 	 *   disabled
 	 */
@@ -133,7 +144,3 @@
 	}
 
-
-	
-	
-	
 }
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/josm/CompatibilityUtil.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/josm/CompatibilityUtil.java	(revision 16574)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/josm/CompatibilityUtil.java	(revision 16574)
@@ -0,0 +1,78 @@
+package org.openstreetmap.josm.plugins.tageditor.josm;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.DataSet;
+
+
+public class CompatibilityUtil {
+
+	private static boolean useMainDs = false;
+	private static boolean useGetCurrentDataSet = false;
+
+	private static boolean hasMainDs() {
+		try {
+			Field f = Main.class.getField("ds");
+		} catch(NoSuchFieldException e) {
+			return false;
+		}
+		return true;
+	}
+
+	private static boolean hasGetCurrentDataSet() {
+		try {
+			Method m = Main.class.getMethod("getCurrentDataSet");
+		} catch(NoSuchMethodException e) {
+			return false;
+		}
+		return true;
+	}
+
+	private static void analyse() {
+		if (useMainDs || useGetCurrentDataSet) return;
+		if (hasMainDs()) {
+			useMainDs = true;
+			System.out.println(tr("INFO: entering compatibilty mode for JOSM with Main.ds"));
+		} else if (hasGetCurrentDataSet()) {
+			useGetCurrentDataSet = true;
+			System.out.println(tr("INFO: entering compatibilty mode for JOSM with Main.getCurrentDataSet()"));
+		} else
+			throw new RuntimeException(tr("Unexpected version of JOSM. Neither Main.ds nor Main.getCurrentDataSet() found."));
+	}
+
+	private static DataSet getMainDs() throws RuntimeException{
+		DataSet ds = null;
+		try {
+			Field f = Main.class.getField("ds");
+			ds = (DataSet) f.get(null);
+		} catch(Exception e) {
+			throw new RuntimeException(e);
+		}
+		return ds;
+	}
+
+	private static DataSet getGetCurrentDataSet() throws RuntimeException{
+		DataSet ds = null;
+		try {
+			Method m = Main.class.getMethod("getCurrentDataSet");
+			ds = (DataSet) m.invoke(null);
+		} catch(Exception e) {
+			throw new RuntimeException(e);
+		}
+		return ds;
+	}
+
+	static public DataSet getCurrentDataSet() throws RuntimeException {
+		analyse();
+		if (useMainDs)
+			return getMainDs();
+		else if (useGetCurrentDataSet)
+			return getGetCurrentDataSet();
+
+		// should not happen
+		return null;
+	}
+}
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Item.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Item.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Item.java	(revision 16574)
@@ -20,5 +20,5 @@
 
 	private static Logger logger = Logger.getLogger(Item.class.getName());
-	
+
 	private String name;
 	private String iconName;
@@ -28,8 +28,8 @@
 	private Group parent;
 
-	public Item() {	
+	public Item() {
 		tags = new ArrayList<Tag>();
 	}
-	
+
 	public Group getParent() {
 		return parent;
@@ -40,5 +40,5 @@
 	}
 
-	
+
 	public String getLabel() {
 		return label;
@@ -49,5 +49,5 @@
 	}
 
-	
+
 	public Item(String name) {
 		setName(name);
@@ -69,9 +69,9 @@
 		this.iconName = iconName;
 	}
-	
+
 	public Icon getIcon() {
 		if (icon == null) {
 			// load the icon from the JOSM resources, use Main classloader
-			// for loading 
+			// for loading
 			URL url = Main.class.getResource("/images/" + getIconName());
 			if (url == null) {
@@ -83,17 +83,17 @@
 			Image i = icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT);
 			icon = new ImageIcon(i);
-			
+
 		}
-		return icon;	
+		return icon;
 	}
-	
+
 	public void addTag(Tag tag) {
 		tags.add(tag);
 	}
-	
+
 	public List<Tag> getTags() {
-		return tags; 
+		return tags;
 	}
-	
+
 	public void dump(IndentWriter writer) throws IOException {
 		writer.indent();
@@ -110,18 +110,17 @@
 		writer.decLevel();
 		writer.writeLine("</item>");
-	} 
-	
+	}
+
+	@Override
 	public String toString() {
 		StringBuilder builder  = new StringBuilder();
 		builder.append("[")
-			.append(getClass().getName())
-			.append(":")
-			.append("name=")
-			.append(name)
-			.append("]");
-		
+		.append(getClass().getName())
+		.append(":")
+		.append("name=")
+		.append(name)
+		.append("]");
+
 		return builder.toString();
 	}
-	
-	
 }
Index: applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/TagSpecification.java
===================================================================
--- applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/TagSpecification.java	(revision 16572)
+++ applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/TagSpecification.java	(revision 16574)
@@ -9,9 +9,9 @@
 /**
  * A TagSpecifications specifies a tag. The specifications consists of the following
- * elements: 
+ * elements:
  * <ul>
  * 	 <li>the <strong>key</strong> the of the tag</li>
  *   <li>the <strong>type</strong> of the tag</li>
- *   <li>whether the tag is applicable to a node, a way or a relation</li> 
+ *   <li>whether the tag is applicable to a node, a way or a relation</li>
  * </ul>
  * @author Gubaer
@@ -19,20 +19,20 @@
  */
 public class TagSpecification {
-	
+
 	/** the key of the tag */
 	private String key;
-	
+
 	/** the type of the tag */
 	private String type;
-	
+
 	/** the type of the tag */
-	
+
 	private boolean applicableToNode = true;
 	private boolean applicableToWay = true;
 	private boolean applicableToRelation = true;
-	
+
 	private ArrayList<LableSpecification> lables = null;
-	
-	
+
+
 	/**
 	 * constructor
@@ -41,6 +41,6 @@
 		lables = new ArrayList<LableSpecification>();
 	}
-		
-	
+
+	@Override
 	public String toString() {
 		StringBuilder builder = new StringBuilder();
@@ -54,24 +54,23 @@
 		return builder.toString();
 	}
-	
+
 	/**
-	 * @return the list of predefined labels for this tag; an empty list if no
-	 *   labels are defined 
+	 * @return th e list of predefined labels for this tag; an empty list if no
+	 *   labels are defined
 	 */
 	public List<LableSpecification> getLables() {
 		return lables;
 	}
-	
-	
+
+
 	/**
 	 * sets the list of lables for this tag specification
 	 * 
 	 * @param lables  the list of lables; must not be null
-	 * @exception IllegalArgumentException thrown, if lables is null 
+	 * @exception IllegalArgumentException thrown, if lables is null
 	 */
 	public void setLables(List<LableSpecification> lables) throws IllegalArgumentException {
-		if (lables == null) {
+		if (lables == null)
 			throw new IllegalArgumentException("argument 'lables' must not be null");
-		}
 		this.lables.clear();
 		for (LableSpecification l : lables) {
@@ -79,26 +78,25 @@
 		}
 	}
-	
-	
+
+
 	/**
 	 * adds a lable to the list of lables for this tag specification. The lable
 	 * is only added if i
-	 *  
+	 * 
 	 * @param lable the lable to add; must not be null
 	 * @exception IllegalArgumentException thrown, if lable is null
 	 */
 	public void addLable(LableSpecification lable) throws IllegalArgumentException  {
-		if (lable == null) {
+		if (lable == null)
 			throw new IllegalArgumentException("argument 'lable' must not be null");
-		}
 		if (!this.lables.contains(lable)) {
 			this.lables.add(lable);
 		}
 	}
-	
+
 	public boolean isApplicable(AutoCompletionContext context) {
 		boolean ret = false;
 		if (context.isSelectionEmpty()) {
-			ret = true; 
+			ret = true;
 		} else {
 			ret = ret || (applicableToNode && context.isSelectionIncludesNodes());
@@ -108,5 +106,5 @@
 		return ret;
 	}
-	
+
 	/* --------------------------------------------------------------------------- */
 	/* setters/getters                                                             */
@@ -141,8 +139,4 @@
 	public void setApplicableToRelation(boolean applicableToRelation) {
 		this.applicableToRelation = applicableToRelation;
-	} 
-
-	
-	
-	
+	}
 }
