From 6639dd3d599535fa0e82591251171048ef21323b Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 12 May 2018 11:20:26 +0100
Subject: [PATCH v2 22/28] plugin preferences: small additions to ease testing

---
 .../josm/gui/preferences/PreferenceTabbedPane.java     |  8 +++++---
 .../josm/gui/preferences/plugin/PluginPreference.java  | 18 ++++++++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java b/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
index a1a340a89..2b9272610 100644
--- a/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
+++ b/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
@@ -25,7 +25,6 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
-import javax.swing.SwingUtilities;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
@@ -59,6 +58,7 @@ import org.openstreetmap.josm.gui.preferences.shortcut.ShortcutPreference;
 import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
 import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference;
 import org.openstreetmap.josm.gui.preferences.validator.ValidatorTestsPreference;
+import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.plugins.PluginDownloadTask;
 import org.openstreetmap.josm.plugins.PluginHandler;
 import org.openstreetmap.josm.plugins.PluginInformation;
@@ -174,7 +174,9 @@ public final class PreferenceTabbedPane extends JTabbedPane implements MouseWhee
                 }
             }
 
-            Main.parent.repaint();
+            if (Main.parent != null) {
+                Main.parent.repaint();
+            }
         }
     }
 
@@ -420,7 +422,7 @@ public final class PreferenceTabbedPane extends JTabbedPane implements MouseWhee
                 // if we have to launch a plugin download task we do it asynchronously, followed
                 // by the remaining "save preferences" activites run on the Swing EDT.
                 MainApplication.worker.submit(task);
-                MainApplication.worker.submit(() -> SwingUtilities.invokeLater(continuation));
+                MainApplication.worker.submit(() -> GuiHelper.runInEDT(continuation));
             } else {
                 // no need for asynchronous activities. Simply run the remaining "save preference"
                 // activities on this thread (we are already on the Swing EDT
diff --git a/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java b/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
index 9d4b3ed20..d884878a6 100644
--- a/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
+++ b/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
@@ -211,10 +211,20 @@ public final class PluginPreference extends DefaultTabPreferenceSetting {
     private JPanel buildActionPanel() {
         JPanel pnl = new JPanel(new GridLayout(1, 4));
 
-        pnl.add(new JButton(new DownloadAvailablePluginsAction()));
-        pnl.add(new JButton(new UpdateSelectedPluginsAction()));
-        ExpertToggleAction.addVisibilitySwitcher(pnl.add(new JButton(new SelectByListAction())));
-        ExpertToggleAction.addVisibilitySwitcher(pnl.add(new JButton(new ConfigureSitesAction())));
+        // assign some component names to these as we go to aid testing
+        final JButton downloadListButton = new JButton(new DownloadAvailablePluginsAction());
+        downloadListButton.setName("downloadListButton");
+        final JButton updatePluginsButton = new JButton(new UpdateSelectedPluginsAction());
+        updatePluginsButton.setName("updatePluginsButton");
+        final JButton loadFromListButton = new JButton(new SelectByListAction());
+        loadFromListButton.setName("loadFromListButton");
+        final JButton configureSitesButton = new JButton(new ConfigureSitesAction());
+        configureSitesButton.setName("configureSitesButton");
+
+        pnl.add(downloadListButton);
+        pnl.add(updatePluginsButton);
+        ExpertToggleAction.addVisibilitySwitcher(pnl.add(loadFromListButton));
+        ExpertToggleAction.addVisibilitySwitcher(pnl.add(configureSitesButton));
         return pnl;
     }
 
-- 
2.11.0

