Index: trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java	(revision 16601)
@@ -13,4 +13,5 @@
 import java.beans.PropertyChangeListener;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.EnumMap;
 import java.util.HashSet;
@@ -40,4 +41,5 @@
 import org.openstreetmap.josm.gui.help.HelpUtil;
 import org.openstreetmap.josm.gui.util.ChangeNotifier;
+import org.openstreetmap.josm.gui.util.TableHelper;
 import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
@@ -522,10 +524,5 @@
         }
         fireModelDataChanged();
-        mergedEntriesSelectionModel.setValueIsAdjusting(true);
-        mergedEntriesSelectionModel.clearSelection();
-        for (int row: rows) {
-            mergedEntriesSelectionModel.addSelectionInterval(row-1, row-1);
-        }
-        mergedEntriesSelectionModel.setValueIsAdjusting(false);
+        TableHelper.setSelectedIndices(mergedEntriesSelectionModel, Arrays.stream(rows).map(row -> row - 1));
     }
 
@@ -550,10 +547,5 @@
         }
         fireModelDataChanged();
-        mergedEntriesSelectionModel.setValueIsAdjusting(true);
-        mergedEntriesSelectionModel.clearSelection();
-        for (int row: rows) {
-            mergedEntriesSelectionModel.addSelectionInterval(row+1, row+1);
-        }
-        mergedEntriesSelectionModel.setValueIsAdjusting(false);
+        TableHelper.setSelectedIndices(mergedEntriesSelectionModel, Arrays.stream(rows).map(row -> row + 1));
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java	(revision 16601)
@@ -69,4 +69,5 @@
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.gui.util.StayOpenPopupMenu;
+import org.openstreetmap.josm.gui.util.TableHelper;
 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
 import org.openstreetmap.josm.gui.widgets.FileChooserManager;
@@ -334,10 +335,5 @@
             int[] pos = tblStyles.getSelectedRows();
             MapPaintStyles.toggleStyleActive(pos);
-            selectionModel.setValueIsAdjusting(true);
-            selectionModel.clearSelection();
-            for (int p: pos) {
-                selectionModel.addSelectionInterval(p, p);
-            }
-            selectionModel.setValueIsAdjusting(false);
+            TableHelper.setSelectedIndices(selectionModel, Arrays.stream(pos));
         }
     }
@@ -371,11 +367,5 @@
             int[] sel = tblStyles.getSelectedRows();
             MapPaintStyles.moveStyles(sel, increment);
-
-            selectionModel.setValueIsAdjusting(true);
-            selectionModel.clearSelection();
-            for (int row: sel) {
-                selectionModel.addSelectionInterval(row + increment, row + increment);
-            }
-            selectionModel.setValueIsAdjusting(false);
+            TableHelper.setSelectedIndices(selectionModel, Arrays.stream(sel).map(row -> row + increment));
             model.ensureSelectedIsVisible();
         }
@@ -414,12 +404,6 @@
             final int[] rows = tblStyles.getSelectedRows();
             MapPaintStyleLoader.reloadStyles(rows);
-            MainApplication.worker.submit(() -> SwingUtilities.invokeLater(() -> {
-                selectionModel.setValueIsAdjusting(true);
-                selectionModel.clearSelection();
-                for (int r: rows) {
-                    selectionModel.addSelectionInterval(r, r);
-                }
-                selectionModel.setValueIsAdjusting(false);
-            }));
+            MainApplication.worker.submit(() -> SwingUtilities.invokeLater(() ->
+                    TableHelper.setSelectedIndices(selectionModel, Arrays.stream(rows))));
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 16601)
@@ -82,4 +82,5 @@
 import org.openstreetmap.josm.gui.util.AbstractTag2LinkPopupListener;
 import org.openstreetmap.josm.gui.util.HighlightHelper;
+import org.openstreetmap.josm.gui.util.TableHelper;
 import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
@@ -309,6 +310,6 @@
         } else {
             model.setSelectedRelations(relations);
-            Integer i = model.getVisibleRelationIndex(relations.iterator().next());
-            if (i != null) {
+            int i = model.getVisibleRelations().indexOf(relations.iterator().next());
+            if (i >= 0) {
                 // Not all relations have to be in the list
                 // (for example when the relation list is hidden, it's not updated with new relations)
@@ -584,25 +585,12 @@
          */
         public void setSelectedRelations(Collection<? extends IRelation<?>> sel) {
-            selectionModel.setValueIsAdjusting(true);
-            selectionModel.clearSelection();
             if (sel != null && !sel.isEmpty()) {
                 if (!getVisibleRelations().containsAll(sel)) {
                     resetFilter();
                 }
-                for (IRelation<?> r: sel) {
-                    Integer i = getVisibleRelationIndex(r);
-                    if (i != null) {
-                        selectionModel.addSelectionInterval(i, i);
-                    }
-                }
-            }
-            selectionModel.setValueIsAdjusting(false);
-        }
-
-        private Integer getVisibleRelationIndex(IRelation<?> rel) {
-            int i = getVisibleRelations().indexOf(rel);
-            if (i < 0)
-                return null;
-            return i;
+                TableHelper.setSelectedIndices(selectionModel, sel.stream().mapToInt(getVisibleRelations()::indexOf));
+            } else {
+                TableHelper.setSelectedIndices(selectionModel, IntStream.empty());
+            }
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java	(revision 16601)
@@ -79,4 +79,5 @@
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.gui.util.HighlightHelper;
+import org.openstreetmap.josm.gui.util.TableHelper;
 import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
@@ -578,15 +579,6 @@
          */
         public synchronized void setSelected(Collection<OsmPrimitive> sel) {
-            selectionModel.setValueIsAdjusting(true);
-            selectionModel.clearSelection();
-            if (sel != null) {
-                for (OsmPrimitive p: sel) {
-                    int i = selection.indexOf(p);
-                    if (i >= 0) {
-                        selectionModel.addSelectionInterval(i, i);
-                    }
-                }
-            }
-            selectionModel.setValueIsAdjusting(false);
+            TableHelper.setSelectedIndices(selectionModel,
+                    sel != null ? sel.stream().mapToInt(selection::indexOf) : IntStream.empty());
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java	(revision 16601)
@@ -10,4 +10,5 @@
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 import javax.swing.DefaultListSelectionModel;
@@ -19,4 +20,5 @@
 import org.openstreetmap.josm.data.osm.ChangesetCacheListener;
 import org.openstreetmap.josm.gui.util.GuiHelper;
+import org.openstreetmap.josm.gui.util.TableHelper;
 
 /**
@@ -111,15 +113,6 @@
      */
     public void setSelectedChangesets(Collection<Changeset> selected) {
-        selectionModel.setValueIsAdjusting(true);
-        selectionModel.clearSelection();
-        if (selected != null) {
-            for (Changeset cs: selected) {
-                final int idx = data.indexOf(cs);
-                if (idx >= 0) {
-                    selectionModel.addSelectionInterval(idx, idx);
-                }
-            }
-        }
-        GuiHelper.runInEDTAndWait(() -> selectionModel.setValueIsAdjusting(false));
+        GuiHelper.runInEDTAndWait(() -> TableHelper.setSelectedIndices(selectionModel,
+                selected != null ? selected.stream().mapToInt(data::indexOf) : IntStream.empty()));
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java	(revision 16601)
@@ -22,4 +22,5 @@
 import org.openstreetmap.josm.data.osm.Storage;
 import org.openstreetmap.josm.gui.util.GuiHelper;
+import org.openstreetmap.josm.gui.util.TableHelper;
 
 /**
@@ -62,15 +63,6 @@
      */
     public synchronized void setSelectedChangesets(Collection<Changeset> changesets) {
-        selectionModel.setValueIsAdjusting(true);
-        selectionModel.clearSelection();
-        if (changesets != null) {
-            for (Changeset cs: changesets) {
-                int idx = data.indexOf(cs);
-                if (idx >= 0) {
-                    selectionModel.addSelectionInterval(idx, idx);
-                }
-            }
-        }
-        selectionModel.setValueIsAdjusting(false);
+        TableHelper.setSelectedIndices(selectionModel,
+                changesets != null ? changesets.stream().mapToInt(data::indexOf) : IntStream.empty());
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java	(revision 16601)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.gui.history;
 
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -53,12 +54,10 @@
         preventRecursion = true;
         DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource();
+        int[] selectedIndices = TableHelper.getSelectedIndices(referenceModel);
         for (ListSelectionModel model : participants) {
             if (model == e.getSource()) {
                 continue;
             }
-            model.clearSelection();
-            for (int i : TableHelper.getSelectedIndices(referenceModel)) {
-                model.addSelectionInterval(i, i);
-            }
+            TableHelper.setSelectedIndices(model, Arrays.stream(selectedIndices));
         }
         preventRecursion = false;
Index: trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java	(revision 16601)
@@ -21,4 +21,5 @@
 import java.util.Optional;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 import javax.swing.AbstractAction;
@@ -46,4 +47,5 @@
 import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.preferences.display.GPXSettingsPanel;
+import org.openstreetmap.josm.gui.util.TableHelper;
 import org.openstreetmap.josm.gui.util.WindowGeometry;
 import org.openstreetmap.josm.tools.GBC;
@@ -219,12 +221,6 @@
         }
         ListSelectionModel s = table.getSelectionModel();
-        s.setValueIsAdjusting(true);
-        s.clearSelection();
-        for (int i = 0; i < layer.trackVisibility.length; i++) {
-            if (layer.trackVisibility[i]) {
-                s.addSelectionInterval(i, i);
-            }
-        }
-        s.setValueIsAdjusting(false);
+        TableHelper.setSelectedIndices(s,
+                IntStream.range(0, layer.trackVisibility.length).filter(i -> layer.trackVisibility[i]));
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java	(revision 16601)
@@ -745,13 +745,5 @@
             }
             fireTableDataChanged();
-            selectionModel.setValueIsAdjusting(true);
-            selectionModel.clearSelection();
-            for (ExtendedSourceEntry info: sources) {
-                int pos = data.indexOf(info);
-                if (pos >= 0) {
-                    selectionModel.addSelectionInterval(pos, pos);
-                }
-            }
-            selectionModel.setValueIsAdjusting(false);
+            TableHelper.setSelectedIndices(selectionModel, sources.stream().mapToInt(data::indexOf));
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/util/ReorderableTableModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/util/ReorderableTableModel.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/util/ReorderableTableModel.java	(revision 16601)
@@ -1,4 +1,6 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.gui.util;
+
+import java.util.Arrays;
 
 import javax.swing.JList;
@@ -135,10 +137,5 @@
             return false;
         final ListSelectionModel selectionModel = getSelectionModel();
-        selectionModel.setValueIsAdjusting(true);
-        selectionModel.clearSelection();
-        for (int row: selectedRows) {
-            selectionModel.addSelectionInterval(row + delta, row + delta);
-        }
-        selectionModel.setValueIsAdjusting(false);
+        TableHelper.setSelectedIndices(selectionModel, Arrays.stream(selectedRows).map(i -> i + delta));
         return true;
     }
Index: trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java	(revision 16600)
+++ trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java	(revision 16601)
@@ -3,4 +3,5 @@
 
 import java.awt.Component;
+import java.util.stream.IntStream;
 
 import javax.swing.JTable;
@@ -147,3 +148,17 @@
         return rv;
     }
+
+    /**
+     * Selects the given indices in the selection model
+     * @param selectionModel list selection model.
+     * @param indices the indices to select
+     * @see ListSelectionModel#addSelectionInterval(int, int)
+     * @since 16601
+     */
+    public static void setSelectedIndices(ListSelectionModel selectionModel, IntStream indices) {
+        selectionModel.setValueIsAdjusting(true);
+        selectionModel.clearSelection();
+        indices.filter(i -> i >= 0).forEach(i -> selectionModel.addSelectionInterval(i, i));
+        selectionModel.setValueIsAdjusting(false);
+    }
 }
