Changeset 9422 in josm


Ignore:
Timestamp:
2016-01-12T20:12:47+01:00 (9 years ago)
Author:
simon04
Message:

see #12237 - Preset search: fix NPE when having selected a preset which is no longer shown after filtering

To reproduce: Select a primitive, open the preset search, select the first preset, type nonsense in the filter box

Location:
trunk/src/org/openstreetmap/josm/gui/tagging/presets
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java

    r9389 r9422  
    5757        super.buttonAction(buttonIndex, evt);
    5858        if (buttonIndex == 0) {
    59             TaggingPreset preset = selector.getSelectedPreset();
     59            TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
    6060            if (preset != null) {
    6161                preset.actionPerformed(null);
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java

    r9389 r9422  
    8686        super.buttonAction(buttonIndex, evt);
    8787        if (buttonIndex == 0) {
    88             TaggingPreset preset = selector.getSelectedPreset();
     88            TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
    8989            if (preset != null) {
    9090                final Set<OsmPrimitive> matching = new HashSet<>(Utils.filter(Main.main.getCurrentDataSet().allPrimitives(), preset));
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java

    r9347 r9422  
    222222            @Override
    223223            public void actionPerformed(ActionEvent ae) {
    224                 final TaggingPreset preset = lsResult.getSelectedValue();
     224                final TaggingPreset preset = getSelectedPreset();
    225225                if (preset != null) {
    226226                    Main.toolbar.addCustomButton(preset.getToolbarString(), -1, false);
     
    246246                text, onlyApplicable, inTags, getTypesInSelection(), selected);
    247247
    248         final TaggingPreset oldPreset = lsResult.getSelectedValue();
     248        final TaggingPreset oldPreset = getSelectedPreset();
    249249        lsResultModel.setItems(Utils.transform(result, new Utils.Function<PresetClassification, TaggingPreset>() {
    250250            @Override
     
    253253            }
    254254        }));
    255         final TaggingPreset newPreset = lsResult.getSelectedValue();
     255        final TaggingPreset newPreset = getSelectedPreset();
    256256        if (!Objects.equals(oldPreset, newPreset)) {
    257257            int[] indices = lsResult.getSelectedIndices();
     
    414414
    415415    /**
    416      * Determines, which preset is selected at the moment. Updates {@link PresetClassification#favoriteIndex}!
     416     * Determines, which preset is selected at the moment.
    417417     * @return selected preset (as action)
    418418     */
     
    423423            idx = 0;
    424424        }
    425         TaggingPreset preset = lsResultModel.getElementAt(idx);
     425        return lsResultModel.getElementAt(idx);
     426    }
     427
     428    /**
     429     * Determines, which preset is selected at the moment. Updates {@link PresetClassification#favoriteIndex}!
     430     * @return selected preset (as action)
     431     */
     432    public synchronized TaggingPreset getSelectedPresetAndUpdateClassification() {
     433        final TaggingPreset preset = getSelectedPreset();
    426434        for (PresetClassification pc: classifications) {
    427435            if (pc.preset == preset) {
Note: See TracChangeset for help on using the changeset viewer.