Changeset 16106 in josm


Ignore:
Timestamp:
2020-03-10T00:04:08+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #18901 - NPE when no WMTS layer is selected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r15586 r16106  
    4242
    4343import javax.imageio.ImageIO;
     44import javax.swing.ListSelectionModel;
    4445import javax.xml.namespace.QName;
    4546import javax.xml.stream.XMLStreamException;
     
    328329        }
    329330
     331        @Override
     332        public void setupDialog() {
     333            super.setupDialog();
     334            buttons.get(0).setEnabled(false);
     335            ListSelectionModel selectionModel = list.getTable().getSelectionModel();
     336            selectionModel.addListSelectionListener(e -> buttons.get(0).setEnabled(!selectionModel.isSelectionEmpty()));
     337        }
     338
    330339        public DefaultLayer getSelectedLayer() {
    331340            Layer selectedLayer = list.getSelectedLayer();
    332             return new DefaultLayer(ImageryType.WMTS, selectedLayer.identifier, selectedLayer.style, selectedLayer.tileMatrixSet.identifier);
    333         }
    334 
     341            return selectedLayer == null ? null :
     342                    new DefaultLayer(ImageryType.WMTS, selectedLayer.identifier, selectedLayer.style, selectedLayer.tileMatrixSet.identifier);
     343        }
    335344    }
    336345
Note: See TracChangeset for help on using the changeset viewer.