Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java	(revision 2155)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java	(revision 2156)
@@ -70,7 +70,5 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField;
-import org.openstreetmap.josm.gui.tagging.TagCellEditor;
-import org.openstreetmap.josm.gui.tagging.TagEditorModel;
-import org.openstreetmap.josm.gui.tagging.TagTable;
+import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
@@ -92,8 +90,5 @@
 
     /** the tag table and its model */
-    private TagEditorModel tagEditorModel;
-    private TagTable tagTable;
-    private AutoCompletionCache acCache;
-    private AutoCompletionList acList;
+    private TagEditorPanel tagEditorPanel;
     private ReferringRelationsBrowser referrerBrowser;
     private ReferringRelationsBrowserModel referrerModel;
@@ -124,19 +119,18 @@
         // initialize the autocompletion infrastructure
         //
-        acCache = AutoCompletionCache.getCacheForLayer(getLayer());
-        acCache.initFromDataSet();
-        acList = new AutoCompletionList();
+        AutoCompletionCache.getCacheForLayer(getLayer()).initFromDataSet();
 
         // init the various models
         //
-        tagEditorModel = new TagEditorModel();
         memberTableModel = new MemberTableModel(getLayer());
         selectionTableModel = new SelectionTableModel(getLayer());
         referrerModel = new ReferringRelationsBrowserModel(relation);
 
+        tagEditorPanel = new TagEditorPanel();
         // populate the models
         //
         if (relation != null) {
-            this.tagEditorModel.initFromPrimitive(relation);
+            tagEditorPanel.getModel().initFromPrimitive(relation);
+            //this.tagEditorModel.initFromPrimitive(relation);
             this.memberTableModel.populate(relation);
             if (!getLayer().data.relations.contains(relation)) {
@@ -146,8 +140,8 @@
             }
         } else {
-            tagEditorModel.clear();
+            tagEditorPanel.getModel().clear();
             this.memberTableModel.populate(null);
         }
-        tagEditorModel.ensureOneTag();
+        tagEditorPanel.getModel().ensureOneTag();
 
         JSplitPane pane = buildSplitPane();
@@ -211,9 +205,9 @@
 
     /**
-     * build the panel with the buttons on the left
-     *
-     * @return
+     * builds the panel with the tag editor
+     *
+     * @return the panel with the tag editor
      */
-    protected JPanel buildTagEditorControlPanel() {
+    protected JPanel buildTagEditorPanel() {
         JPanel pnl = new JPanel();
         pnl.setLayout(new GridBagLayout());
@@ -224,55 +218,4 @@
         gc.gridheight = 1;
         gc.gridwidth = 1;
-        gc.insets = new Insets(0, 5, 0, 5);
-        gc.fill = GridBagConstraints.HORIZONTAL;
-        gc.anchor = GridBagConstraints.CENTER;
-        gc.weightx = 0.0;
-        gc.weighty = 0.0;
-
-        // -----
-        AddTagAction addTagAction = new AddTagAction();
-        pnl.add(new JButton(addTagAction), gc);
-
-        // -----
-        gc.gridy = 1;
-        DeleteTagAction deleteTagAction = new DeleteTagAction();
-        tagTable.getSelectionModel().addListSelectionListener(deleteTagAction);
-        pnl.add(new JButton(deleteTagAction), gc);
-
-        // ------
-        // just grab the remaining space
-        gc.gridy = 2;
-        gc.weighty = 1.0;
-        gc.fill = GridBagConstraints.BOTH;
-        pnl.add(new JPanel(), gc);
-        return pnl;
-    }
-
-    /**
-     * builds the panel with the tag editor
-     *
-     * @return the panel with the tag editor
-     */
-    protected JPanel buildTagEditorPanel() {
-        JPanel pnl = new JPanel();
-        pnl.setLayout(new GridBagLayout());
-
-        // setting up the tag table
-        //
-        tagTable = new TagTable(tagEditorModel);
-        TagCellEditor editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor());
-        editor.setAutoCompletionCache(acCache);
-        editor.setAutoCompletionList(acList);
-        editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());
-        editor.setAutoCompletionCache(acCache);
-        editor.setAutoCompletionList(acList);
-
-        final JScrollPane scrollPane = new JScrollPane(tagTable);
-
-        GridBagConstraints gc = new GridBagConstraints();
-        gc.gridx = 0;
-        gc.gridy = 0;
-        gc.gridheight = 1;
-        gc.gridwidth = 3;
         gc.fill = GridBagConstraints.HORIZONTAL;
         gc.anchor = GridBagConstraints.FIRST_LINE_START;
@@ -283,19 +226,9 @@
         gc.gridx = 0;
         gc.gridy = 1;
-        gc.gridheight = 1;
-        gc.gridwidth = 1;
-        gc.fill = GridBagConstraints.VERTICAL;
-        gc.anchor = GridBagConstraints.NORTHWEST;
-        gc.weightx = 0.0;
-        gc.weighty = 1.0;
-        pnl.add(buildTagEditorControlPanel(), gc);
-
-        gc.gridx = 1;
-        gc.gridy = 1;
         gc.fill = GridBagConstraints.BOTH;
         gc.anchor = GridBagConstraints.CENTER;
-        gc.weightx = 0.8;
+        gc.weightx = 1.0;
         gc.weighty = 1.0;
-        pnl.add(scrollPane, gc);
+        pnl.add(tagEditorPanel, gc);
         return pnl;
     }
@@ -311,8 +244,4 @@
         // setting up the member table
         memberTable = new MemberTable(getLayer(),memberTableModel);
-        MemberRoleCellEditor editor = ((MemberRoleCellEditor) memberTable.getColumnModel().getColumn(0).getCellEditor());
-        editor.setAutoCompletionCache(acCache);
-        editor.setAutoCompletionList(acList);
-
         memberTable.addMouseListener(new MemberTableDblClickAdapter());
         memberTableModel.addMemberModelListener(memberTable);
@@ -587,10 +516,11 @@
             }
         });
-        tfRole.setAutoCompletionList(acList);
+        tfRole.setAutoCompletionList(new AutoCompletionList());
         tfRole.addFocusListener(
                 new FocusAdapter() {
                     @Override
                     public void focusGained(FocusEvent e) {
-                        acCache.populateWithMemberRoles(acList);
+                        AutoCompletionList list = tfRole.getAutoCompletionList();
+                        AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(list);
                     }
                 }
@@ -629,7 +559,10 @@
 
     @Override
-    public void setVisible(boolean b) {
-        super.setVisible(b);
-        if (!b) {
+    public void setVisible(boolean visible) {
+        if (visible) {
+            tagEditorPanel.initAutoCompletion(Main.main.getEditLayer());
+        }
+        super.setVisible(visible);
+        if (!visible) {
             dispose();
         }
@@ -1063,8 +996,8 @@
             // If the user wanted to create a new relation, but hasn't added any members or
             // tags, don't add an empty relation
-            if (memberTableModel.getRowCount() == 0 && tagEditorModel.getKeys().isEmpty())
+            if (memberTableModel.getRowCount() == 0 && tagEditorPanel.getModel().getKeys().isEmpty())
                 return;
             Relation newRelation = new Relation();
-            tagEditorModel.applyToPrimitive(newRelation);
+            tagEditorPanel.getModel().applyToPrimitive(newRelation);
             memberTableModel.applyToRelation(newRelation);
             Main.main.undoRedo.add(new AddCommand(getLayer(),newRelation));
@@ -1089,5 +1022,5 @@
         protected void applyExistingConflictingRelation() {
             Relation editedRelation = new Relation(getRelation());
-            tagEditorModel.applyToPrimitive(editedRelation);
+            tagEditorPanel.getModel().applyToPrimitive(editedRelation);
             memberTableModel.applyToRelation(editedRelation);
             Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation);
@@ -1102,5 +1035,5 @@
         protected void applyExistingNonConflictingRelation() {
             Relation editedRelation = new Relation(getRelation());
-            tagEditorModel.applyToPrimitive(editedRelation);
+            tagEditorPanel.getModel().applyToPrimitive(editedRelation);
             memberTableModel.applyToRelation(editedRelation);
             Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation));
@@ -1165,5 +1098,5 @@
                 applyNewRelation();
             } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot())
-                    || tagEditorModel.isDirty()) {
+                    || tagEditorPanel.getModel().isDirty()) {
                 if (isDirtyRelation()) {
                     if (confirmClosingBecauseOfDirtyState()) {
@@ -1198,5 +1131,5 @@
                 applyNewRelation();
             } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot())
-                    || tagEditorModel.isDirty()) {
+                    || tagEditorPanel.getModel().isDirty()) {
                 if (isDirtyRelation()) {
                     if (confirmClosingBecauseOfDirtyState()) {
@@ -1246,70 +1179,5 @@
 
         public void actionPerformed(ActionEvent e) {
-            tagEditorModel.appendNewTag();
-        }
-    }
-
-    class DeleteTagAction extends AbstractAction implements ListSelectionListener {
-        public DeleteTagAction() {
-            putValue(SHORT_DESCRIPTION, tr("Delete the currently selected tags"));
-            putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
-            // putValue(NAME, tr("Cancel"));
-            refreshEnabled();
-        }
-
-        public void actionPerformed(ActionEvent e) {
-            run();
-        }
-
-        /**
-         * delete a selection of tag names
-         */
-        protected void deleteTagNames() {
-            int[] rows = tagTable.getSelectedRows();
-            tagEditorModel.deleteTagNames(rows);
-        }
-
-        /**
-         * delete a selection of tag values
-         */
-        protected void deleteTagValues() {
-            int[] rows = tagTable.getSelectedRows();
-            tagEditorModel.deleteTagValues(rows);
-        }
-
-        /**
-         * delete a selection of tags
-         */
-        protected void deleteTags() {
-            tagEditorModel.deleteTags(tagTable.getSelectedRows());
-        }
-
-        public void run() {
-            if (!isEnabled())
-                return;
-            if (tagTable.getSelectedColumnCount() == 1) {
-                if (tagTable.getSelectedColumn() == 0) {
-                    deleteTagNames();
-                } else if (tagTable.getSelectedColumn() == 1) {
-                    deleteTagValues();
-                } else
-                    // should not happen
-                    //
-                    throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is "
-                            + tagTable.getSelectedColumn());
-            } else if (tagTable.getSelectedColumnCount() == 2) {
-                deleteTags();
-            }
-            if (tagEditorModel.getRowCount() == 0) {
-                tagEditorModel.ensureOneTag();
-            }
-        }
-
-        protected void refreshEnabled() {
-            setEnabled(tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() > 0);
-        }
-
-        public void valueChanged(ListSelectionEvent e) {
-            refreshEnabled();
+            tagEditorPanel.getModel().appendNewTag();
         }
     }
@@ -1419,5 +1287,5 @@
         public void actionPerformed(ActionEvent e) {
             Relation copy = new Relation();
-            tagEditorModel.applyToPrimitive(copy);
+            tagEditorPanel.getModel().applyToPrimitive(copy);
             memberTableModel.applyToRelation(copy);
             RelationEditor editor = RelationEditor.getEditor(getLayer(), copy, memberTableModel.getSelectedMembers());
Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java	(revision 2155)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java	(revision 2156)
@@ -9,9 +9,8 @@
 import javax.swing.table.TableCellEditor;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache;
-import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
-import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
 
 public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
@@ -21,7 +20,4 @@
 
     private AutoCompletingTextField editor = null;
-
-    /** the cache of auto completion items derived from the current JOSM data set */
-    private AutoCompletionCache acCache = null;
 
     /** user input is matched against this list of auto completion items */
@@ -33,27 +29,6 @@
     public MemberRoleCellEditor() {
         editor = new AutoCompletingTextField();
-        acCache = new AutoCompletionCache();
-    }
-
-    /**
-     * initializes the autocompletion editor with the list of member roles in
-     * the current dataset
-     * 
-     */
-    protected void initAutoCompletionListRoles() {
-        if (autoCompletionList == null) {
-            logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into MemberRoleCellEditor.");
-            return;
-        }
-        autoCompletionList.clear();
-
-        // add the list of keys in the current data set
-        //
-        for (String key : acCache.getMemberRoles()) {
-            autoCompletionList.add(
-                    new AutoCompletionListItem(key, AutoCompletionItemPritority.IS_IN_DATASET)
-            );
-        }
-        autoCompletionList.fireTableDataChanged();
+        autoCompletionList = new AutoCompletionList();
+        editor.setAutoCompletionList(autoCompletionList);
     }
 
@@ -66,5 +41,7 @@
         String role = (String)value;
         editor.setText(role);
-        initAutoCompletionListRoles();
+        System.out.println(role + " - initializing autocompletion list ...");
+        AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(autoCompletionList);
+        autoCompletionList.dump();
         return editor;
     }
@@ -83,29 +60,3 @@
         return super.stopCellEditing();
     }
-
-    /**
-     * replies the {@link AutoCompletionList} this table cell editor synchronizes with
-     * 
-     * @return the auto completion list
-     */
-    public AutoCompletionList getAutoCompletionList() {
-        return autoCompletionList;
-    }
-
-    /**
-     * sets the {@link AutoCompletionList} this table cell editor synchronizes with
-     * @param autoCompletionList the auto completion list
-     */
-    public void setAutoCompletionList(AutoCompletionList autoCompletionList) {
-        this.autoCompletionList = autoCompletionList;
-        editor.setAutoCompletionList(autoCompletionList);
-    }
-
-    public void setAutoCompletionCache(AutoCompletionCache acCache) {
-        this.acCache = acCache;
-    }
-
-    public AutoCompletingTextField getEditor() {
-        return editor;
-    }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java	(revision 2155)
+++ /trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java	(revision 2156)
@@ -5,5 +5,4 @@
 
 import java.awt.BorderLayout;
-import java.awt.Component;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
Index: /trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java	(revision 2155)
+++ /trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java	(revision 2156)
@@ -272,4 +272,5 @@
      */
     public void clear() {
+        valutToItemMap.clear();
         list.clear();
         fireTableDataChanged();
@@ -290,3 +291,10 @@
     }
 
+    public void dump() {
+        System.out.println("---------------------------------");
+        for (AutoCompletionListItem item: list) {
+            System.out.println(item.getValue());
+        }
+        System.out.println("---------------------------------");
+    }
 }
