Changeset 9877 in josm


Ignore:
Timestamp:
2016-02-24T22:48:05+01:00 (9 years ago)
Author:
simon04
Message:

fix #12488 - Fix ArrayIndexOutOfBoundsException when using tag filter in properties dialog

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r9833 r9877  
    4545import javax.swing.event.ListSelectionEvent;
    4646import javax.swing.event.ListSelectionListener;
     47import javax.swing.event.RowSorterEvent;
     48import javax.swing.event.RowSorterListener;
    4749import javax.swing.table.DefaultTableCellRenderer;
    4850import javax.swing.table.DefaultTableModel;
     
    309311        tagTable.setRowSorter(tagRowSorter);
    310312
     313        final RemoveHiddenSelection removeHiddenSelection = new RemoveHiddenSelection();
     314        tagTable.getSelectionModel().addListSelectionListener(removeHiddenSelection);
     315        tagTable.getRowSorter().addRowSorterListener(removeHiddenSelection);
     316
    311317        tagRowSorter.setComparator(0, AlphanumComparator.getInstance());
    312318        tagRowSorter.setComparator(1, new Comparator<Object>() {
     
    14171423        }
    14181424    }
     1425
     1426    /**
     1427     * Clears the row selection when it is filtered away by the row sorter.
     1428     */
     1429    private class RemoveHiddenSelection implements ListSelectionListener, RowSorterListener {
     1430
     1431        void removeHiddenSelection() {
     1432            try {
     1433                tagTable.getRowSorter().convertRowIndexToModel(tagTable.getSelectedRow());
     1434            } catch (IndexOutOfBoundsException ignore) {
     1435                Main.debug("Clearing tagTable selection, {0}", ignore.toString());
     1436                tagTable.clearSelection();
     1437            }
     1438        }
     1439
     1440        @Override
     1441        public void valueChanged(ListSelectionEvent event) {
     1442            removeHiddenSelection();
     1443        }
     1444
     1445        @Override
     1446        public void sorterChanged(RowSorterEvent e) {
     1447            removeHiddenSelection();
     1448        }
     1449    }
    14191450}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r9795 r9877  
    668668                }
    669669                for (int i = 0; i < tagData.getRowCount(); ++i) {
    670                     if (item.getValue().equals(getDataKey(i))) {
     670                    if (item.getValue().equals(tagData.getValueAt(i, 0) /* sic! do not use getDataKey*/)) {
    671671                        if (itemToSelect == item) {
    672672                            itemToSelect = null;
Note: See TracChangeset for help on using the changeset viewer.