Index: trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 5724)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 5725)
@@ -92,17 +92,19 @@
 public class RelationListDialog extends ToggleDialog implements DataSetListener {
     /** The display list. */
-    private JList displaylist;
+    private final JList displaylist;
     /** the list model used */
-    private RelationListModel model;
+    private final RelationListModel model;
 
     /** the edit action */
-    private EditAction editAction;
+    private final EditAction editAction;
     /** the delete action */
-    private DeleteAction deleteAction;
-    private NewAction newAction;
-    private AddToRelation addToRelation;
+    private final DeleteAction deleteAction;
+    private final NewAction newAction;
+    private final AddToRelation addToRelation;
     /** the popup menu */
-    private RelationDialogPopupMenu popupMenu;
-
+    private final RelationDialogPopupMenu popupMenu;
+
+    private final JTextField filter;
+    
     /**
      * constructor
@@ -155,5 +157,5 @@
         displaylist.addListSelectionListener(selectAction);
 
-        final JTextField filter = new DisableShortcutsOnFocusGainedTextField();
+        filter = new DisableShortcutsOnFocusGainedTextField();
         filter.setToolTipText(tr("Relation list filter"));
         filter.getDocument().addDocumentListener(new DocumentListener() {
@@ -228,4 +230,8 @@
         DataSet.removeSelectionListener(addToRelation);
     }
+    
+    private void resetFilter() {
+        filter.setText(null);
+    }
 
     /**
@@ -293,5 +299,5 @@
         } else {
             model.setSelectedRelations(relations);
-            Integer i = model.getRelationIndex(relations.iterator().next());
+            Integer i = model.getVisibleRelationIndex(relations.iterator().next());
             if (i != null) { // Not all relations have to be in the list (for example when the relation list is hidden, it's not updated with new relations)
                 displaylist.scrollRectToVisible(displaylist.getCellBounds(i, i));
@@ -907,6 +913,9 @@
             if (sel == null || sel.isEmpty())
                 return;
+            if (!getVisibleRelations().containsAll(sel)) {
+                resetFilter();
+            }
             for (Relation r: sel) {
-                int i = relations.indexOf(r);
+                int i = getVisibleRelationIndex(r);
                 if (i<0) {
                     continue;
@@ -928,4 +937,11 @@
             return i;
         }
+        
+        private Integer getVisibleRelationIndex(Relation rel) {
+            int i = getVisibleRelations().indexOf(rel);
+            if (i<0)
+                return null;
+            return i;
+        }
 
         public void updateTitle() {
