Changeset 18338 in josm


Ignore:
Timestamp:
2021-12-20T16:50:08+01:00 (3 years ago)
Author:
Don-vip
Message:

fix #21655 - fix selection of changesets after sorting the table

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r17371 r18338  
    110110
    111111    private ChangesetCacheManagerModel model;
     112    private ChangesetCacheTableRowSorter sorter;
    112113    private JSplitPane spContent;
    113114    private boolean needsSplitPaneAdjustment;
     
    272273                model.getSelectionModel()
    273274        );
    274         tblChangesets.setRowSorter(new ChangesetCacheTableRowSorter(model));
     275        tblChangesets.setRowSorter(sorter);
    275276        tblChangesets.addMouseListener(new MouseEventHandler());
    276277        InputMapUtils.addEnterAction(tblChangesets, new ShowDetailAction(model));
     
    304305
    305306        model = buildModel();
     307        sorter = new ChangesetCacheTableRowSorter(model);
     308        model.setChangesetCacheTableRowSorter(sorter);
    306309        actRemoveFromCacheAction = new RemoveFromCacheAction(model);
    307310        actCloseSelectedChangesetsAction = new CloseSelectedChangesetsAction(model);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java

    r17093 r18338  
    55import java.beans.PropertyChangeSupport;
    66import java.util.ArrayList;
     7import java.util.Arrays;
    78import java.util.Collection;
    89import java.util.Comparator;
     
    3233    private final transient List<Changeset> data = new ArrayList<>();
    3334    private final DefaultListSelectionModel selectionModel;
     35    private transient ChangesetCacheTableRowSorter sorter;
    3436    private transient Changeset changesetInDetailView;
    3537    private final PropertyChangeSupport support = new PropertyChangeSupport(this);
     
    8890     */
    8991    public List<Changeset> getSelectedChangesets() {
    90         List<Changeset> ret = new ArrayList<>();
    91         for (int i = 0; i < data.size(); i++) {
    92             Changeset cs = data.get(i);
    93             if (selectionModel.isSelectedIndex(i)) {
    94                 ret.add(cs);
    95             }
    96         }
    97         return ret;
     92        return Arrays.stream(TableHelper.getSelectedIndices(selectionModel))
     93                .map(sorter::convertRowIndexToModel).mapToObj(data::get).collect(Collectors.toList());
    9894    }
    9995
     
    166162    }
    167163
     164    void setChangesetCacheTableRowSorter(ChangesetCacheTableRowSorter sorter) {
     165        this.sorter = sorter;
     166    }
     167
    168168    /* ------------------------------------------------------------------------------ */
    169169    /* interface ChangesetCacheListener                                               */
Note: See TracChangeset for help on using the changeset viewer.