Ignore:
Timestamp:
2013-02-17T20:09:56+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #8433 - NPEs when opening relation editor or selecting in list from selection toggle dialog's context menu with active filter of relation list

File:
1 edited

Legend:

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

    r5720 r5725  
    9292public class RelationListDialog extends ToggleDialog implements DataSetListener {
    9393    /** The display list. */
    94     private JList displaylist;
     94    private final JList displaylist;
    9595    /** the list model used */
    96     private RelationListModel model;
     96    private final RelationListModel model;
    9797
    9898    /** the edit action */
    99     private EditAction editAction;
     99    private final EditAction editAction;
    100100    /** the delete action */
    101     private DeleteAction deleteAction;
    102     private NewAction newAction;
    103     private AddToRelation addToRelation;
     101    private final DeleteAction deleteAction;
     102    private final NewAction newAction;
     103    private final AddToRelation addToRelation;
    104104    /** the popup menu */
    105     private RelationDialogPopupMenu popupMenu;
    106 
     105    private final RelationDialogPopupMenu popupMenu;
     106
     107    private final JTextField filter;
     108   
    107109    /**
    108110     * constructor
     
    155157        displaylist.addListSelectionListener(selectAction);
    156158
    157         final JTextField filter = new DisableShortcutsOnFocusGainedTextField();
     159        filter = new DisableShortcutsOnFocusGainedTextField();
    158160        filter.setToolTipText(tr("Relation list filter"));
    159161        filter.getDocument().addDocumentListener(new DocumentListener() {
     
    228230        DataSet.removeSelectionListener(addToRelation);
    229231    }
     232   
     233    private void resetFilter() {
     234        filter.setText(null);
     235    }
    230236
    231237    /**
     
    293299        } else {
    294300            model.setSelectedRelations(relations);
    295             Integer i = model.getRelationIndex(relations.iterator().next());
     301            Integer i = model.getVisibleRelationIndex(relations.iterator().next());
    296302            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)
    297303                displaylist.scrollRectToVisible(displaylist.getCellBounds(i, i));
     
    907913            if (sel == null || sel.isEmpty())
    908914                return;
     915            if (!getVisibleRelations().containsAll(sel)) {
     916                resetFilter();
     917            }
    909918            for (Relation r: sel) {
    910                 int i = relations.indexOf(r);
     919                int i = getVisibleRelationIndex(r);
    911920                if (i<0) {
    912921                    continue;
     
    928937            return i;
    929938        }
     939       
     940        private Integer getVisibleRelationIndex(Relation rel) {
     941            int i = getVisibleRelations().indexOf(rel);
     942            if (i<0)
     943                return null;
     944            return i;
     945        }
    930946
    931947        public void updateTitle() {
Note: See TracChangeset for help on using the changeset viewer.