Ticket #17740: 17740.patch

File 17740.patch, 1.8 KB (added by taylor.smock, 7 years ago)

Modify the sel list such that there are no null objects, no deleted objects (duplicates some functionality), and no objects without a dataset.

  • src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

     
    9696import org.openstreetmap.josm.tools.Logging;
    9797import org.openstreetmap.josm.tools.PlatformManager;
    9898import org.openstreetmap.josm.tools.Shortcut;
     99import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    99100import org.openstreetmap.josm.tools.Utils;
    100101
    101102/**
     
    264265    */
    265266    public void editTag(final int row, boolean focusOnKey) {
    266267        changedKey = null;
    267         sel = OsmDataManager.getInstance().getInProgressSelection();
     268        sel = checkForBadPrimitives(OsmDataManager.getInstance().getInProgressSelection());
    268269        if (sel == null || sel.isEmpty())
    269270            return;
    270271
     
    279280    }
    280281
    281282    /**
     283     * Ensure that all OsmPrimitives in sel can be used elsewhere
     284     * @param <T> Some class T that extends {@link OsmPrimitive}
     285     * @param sel The collection of objects that may have bad primitives
     286     * @return A collection of objects without null objects, deleted objects, and objects without DataSets.
     287     */
     288    private static <T extends OsmPrimitive> Collection<T> checkForBadPrimitives(Collection<T> sel) {
     289        // !p.isDeleted duplicates what OsmDataManager.getInstance().getInProgressSelection() does
     290        if (sel != null) {
     291            return new SubclassFilteredCollection<>(sel, p -> p != null && !p.isDeleted() && p.getDataSet() != null);
     292        } else {
     293            return Collections.emptyList();
     294        }
     295    }
     296
     297    /**
    282298     * Extracted interface of {@link EditTagDialog}.
    283299     */
    284300    protected interface IEditTagDialog extends IExtendedDialog {