From e5b228bdbaf9b9ac267ca6ce710d20b739e8fc71 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Tue, 14 Feb 2023 08:27:57 -0700 Subject: [PATCH] Fix #22728: No URL for provider Signed-off-by: Taylor Smock --- .../data/mapwithai/MapWithAILayerInfo.java | 1 + .../mapwithai/MapWithAIProvidersPanel.java | 13 ++++ .../testutils/annotations/Projection.java | 73 ------------------- .../testutils/annotations/Territories.java | 1 + 4 files changed, 15 insertions(+), 73 deletions(-) delete mode 100644 src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Projection.java diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java index 5a4deb2..18858cd 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java @@ -625,6 +625,7 @@ public class MapWithAILayerInfo { return layers.stream() .filter(i -> i.getCategory() != MapWithAICategory.PREVIEW && !i.getAdditionalCategories().contains(MapWithAICategory.PREVIEW)) + .filter(info -> !Utils.isBlank(info.getUrlExpanded()) && !Utils.isBlank(info.getUrl())) .collect(Collectors.toList()); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java index b4fdcb8..44d34ab 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java @@ -187,6 +187,19 @@ public class MapWithAIProvidersPanel extends JPanel { @SuppressWarnings("unchecked") public final Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + // See #22740 + if (value == null) { + final StringBuilder message = new StringBuilder(); + for (int tableRow = 0; tableRow < table.getRowCount(); tableRow++) { + message.append('|'); + for (int tableCol = 0; tableCol < table.getColumnCount(); tableCol++) { + final Object tableVal = table.getValueAt(tableRow, tableCol); + message.append(tableVal).append('|'); + } + message.append(System.lineSeparator()); + } + throw new IllegalArgumentException("value was null:" + System.lineSeparator() + message); + } T obj = (T) value; JLabel label = (JLabel) super.getTableCellRendererComponent(table, mapper.apply(obj), isSelected, hasFocus, row, column); diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Projection.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Projection.java deleted file mode 100644 index c4b7077..0000000 --- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Projection.java +++ /dev/null @@ -1,73 +0,0 @@ -// License: GPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.mapwithai.testutils.annotations; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.Optional; - -import org.junit.jupiter.api.extension.AfterAllCallback; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.platform.commons.support.AnnotationSupport; -import org.openstreetmap.josm.data.projection.ProjectionRegistry; -import org.openstreetmap.josm.data.projection.Projections; -import org.openstreetmap.josm.testutils.JOSMTestRules; -import org.openstreetmap.josm.testutils.annotations.AnnotationUtils; - -/** - * Use projections in tests (Mercator). Prefer the JOSM implementation in the - * future. - * - * @author Taylor Smock - * @see JOSMTestRules#projection() - * - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.METHOD, ElementType.TYPE }) -@ExtendWith(Projection.ProjectionExtension.class) -public @interface Projection { - /** - * The value to use for the projection. Defaults to EPSG:3857 (Mercator). - * - * @return The value to use to get the projection from - * {@link Projections#getProjectionByCode}. - */ - String projectionCode() default "EPSG:3857"; - - /** - * Use projections in tests. Use {@link Projection} preferentially. - * - * @author Taylor Smock - * - */ - class ProjectionExtension implements BeforeEachCallback, BeforeAllCallback, AfterAllCallback { - @Override - public void afterAll(ExtensionContext context) throws Exception { - ProjectionRegistry.clearProjectionChangeListeners(); - AnnotationUtils.resetStaticClass(ProjectionRegistry.class); - } - - @Override - public void beforeAll(ExtensionContext context) throws Exception { - // Needed in order to run prior to Territories - beforeEach(context); - } - - @Override - public void beforeEach(ExtensionContext context) throws Exception { - Optional annotation = AnnotationSupport.findAnnotation(context.getElement(), Projection.class); - if (annotation.isPresent()) { - ProjectionRegistry.setProjection(Projections.getProjectionByCode(annotation.get().projectionCode())); - } else { - ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator - } - } - - } -} diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Territories.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Territories.java index 51a8295..2ea0b73 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Territories.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/annotations/Territories.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.platform.commons.support.AnnotationSupport; import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; +import org.openstreetmap.josm.testutils.annotations.Projection; /** * Use boundaries dataset in this test. FIXME: Use the JOSM version