From c220b3749713665ba9513e7b51377fb69ebb6e95 Mon Sep 17 00:00:00 2001 From: Simeon Andreev Date: Tue, 31 Dec 2024 13:03:15 +0100 Subject: [PATCH] Dont depend on PreferenceConverter in ColorManager.initializeDefaults() This change adjusts ColorManager.initializeDefaults() to not depend on PreferenceConverter, to prevent the creation of an SWT Display object when in headless mode. With this change, start-up errors are avoided in headless mode. Fixes: #1486 Signed-off-by: Simeon Andreev --- .../internal/ui/editor/text/ColorManager.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java index 2e33ab5bc2..3f2036cc5e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java @@ -48,19 +48,19 @@ public static IColorManager getDefault() { } public static void initializeDefaults(IPreferenceStore store) { - PreferenceConverter.setDefault(store, P_DEFAULT, DEFAULT); - PreferenceConverter.setDefault(store, P_PROC_INSTR, PROC_INSTR); - PreferenceConverter.setDefault(store, P_STRING, STRING); - PreferenceConverter.setDefault(store, P_EXTERNALIZED_STRING, EXTERNALIZED_STRING); - PreferenceConverter.setDefault(store, P_TAG, TAG); - PreferenceConverter.setDefault(store, P_XML_COMMENT, XML_COMMENT); - PreferenceConverter.setDefault(store, P_HEADER_KEY, HEADER_KEY); - PreferenceConverter.setDefault(store, P_HEADER_OSGI, HEADER_OSGI); + setDefault(store, P_DEFAULT, DEFAULT); + setDefault(store, P_PROC_INSTR, PROC_INSTR); + setDefault(store, P_STRING, STRING); + setDefault(store, P_EXTERNALIZED_STRING, EXTERNALIZED_STRING); + setDefault(store, P_TAG, TAG); + setDefault(store, P_XML_COMMENT, XML_COMMENT); + setDefault(store, P_HEADER_KEY, HEADER_KEY); + setDefault(store, P_HEADER_OSGI, HEADER_OSGI); store.setDefault(P_HEADER_OSGI + IPDEColorConstants.P_BOLD_SUFFIX, true); - PreferenceConverter.setDefault(store, P_HEADER_VALUE, HEADER_VALUE); - PreferenceConverter.setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ATTRIBUTES); + setDefault(store, P_HEADER_VALUE, HEADER_VALUE); + setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ATTRIBUTES); store.setDefault(P_HEADER_ATTRIBUTES + IPDEColorConstants.P_ITALIC_SUFFIX, true); - PreferenceConverter.setDefault(store, P_HEADER_ASSIGNMENT, HEADER_ASSIGNMENT); + setDefault(store, P_HEADER_ASSIGNMENT, HEADER_ASSIGNMENT); if (!PlatformUI.isWorkbenchRunning()) { return; } @@ -68,9 +68,9 @@ public static void initializeDefaults(IPreferenceStore store) { Display display = PlatformUI.getWorkbench().getDisplay(); Runnable runnable = () -> { if (!display.isDisposed() && display.getHighContrast()) { - PreferenceConverter.setDefault(store, P_DEFAULT, DEFAULT_HIGH_CONTRAST); - PreferenceConverter.setDefault(store, P_HEADER_VALUE, HEADER_VALUE_HIGH_CONTRAST); - PreferenceConverter.setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ASSIGNMENT_HIGH_CONTRAST); + setDefault(store, P_DEFAULT, DEFAULT_HIGH_CONTRAST); + setDefault(store, P_HEADER_VALUE, HEADER_VALUE_HIGH_CONTRAST); + setDefault(store, P_HEADER_ATTRIBUTES, HEADER_ASSIGNMENT_HIGH_CONTRAST); } }; if (display == Display.getCurrent()) { @@ -142,4 +142,8 @@ public void handlePropertyChangeEvent(PropertyChangeEvent event) { putColor(event.getProperty(), StringConverter.asRGB(color.toString())); } } + + private static void setDefault(IPreferenceStore store, String name, RGB value) { + store.setDefault(name, StringConverter.asString(value)); + } }