From a40c8e28d62920404d47f6e0d8f96ed874756a08 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:03:24 +0000 Subject: [PATCH] Force re-decoration on preferences change - Refactor UnitDecorator.refreshAll() to be static and thread-safe using asyncExec. - Fix TEST_CASE_DECORATOR constant to match the ID in plugin.xml. - Add IPropertyChangeListener in MoreUnitPlugin to trigger refresh on global preference changes. - Explicitly trigger refresh in MoreUnitPropertyPage when project-specific properties are saved. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../src/org/moreunit/MoreUnitPlugin.java | 11 +++++++++++ .../src/org/moreunit/decorator/UnitDecorator.java | 13 ++++++++----- .../moreunit/properties/MoreUnitPropertyPage.java | 3 +++ .../src/org/moreunit/util/MoreUnitContants.java | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/org.moreunit.plugin/src/org/moreunit/MoreUnitPlugin.java b/org.moreunit.plugin/src/org/moreunit/MoreUnitPlugin.java index 9d5aec8b..46ef73d7 100644 --- a/org.moreunit.plugin/src/org/moreunit/MoreUnitPlugin.java +++ b/org.moreunit.plugin/src/org/moreunit/MoreUnitPlugin.java @@ -6,12 +6,14 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.ui.IPartService; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.moreunit.annotation.AnnotationUpdateListener; import org.moreunit.annotation.MoreUnitAnnotationModel; +import org.moreunit.decorator.UnitDecorator; import org.moreunit.core.log.DefaultLogger; import org.moreunit.core.log.Logger; import org.moreunit.log.LogHandler; @@ -34,6 +36,7 @@ public class MoreUnitPlugin extends AbstractUIPlugin private Logger logger; private AnnotationUpdateListener annotationUpdateListener; + private IPropertyChangeListener propertyChangeListener; /** * The constructor. @@ -66,6 +69,9 @@ public void start(BundleContext context) throws Exception MoreUnitAnnotationModel.attachForAllOpenEditor(); removeMarkerFromOlderMoreUnitVersions(); + + propertyChangeListener = event -> UnitDecorator.refreshAll(); + getPreferenceStore().addPropertyChangeListener(propertyChangeListener); } protected IPartService getPartService() @@ -110,6 +116,11 @@ public void stop(BundleContext context) throws Exception if(partService != null) partService.removePartListener(annotationUpdateListener); + if(propertyChangeListener != null) + { + getPreferenceStore().removePropertyChangeListener(propertyChangeListener); + } + plugin = null; } diff --git a/org.moreunit.plugin/src/org/moreunit/decorator/UnitDecorator.java b/org.moreunit.plugin/src/org/moreunit/decorator/UnitDecorator.java index c3229507..a49c9e29 100644 --- a/org.moreunit.plugin/src/org/moreunit/decorator/UnitDecorator.java +++ b/org.moreunit.plugin/src/org/moreunit/decorator/UnitDecorator.java @@ -22,7 +22,6 @@ * Handles the decoration of java files. If the class has a testcase a overlay * icon is added. */ -// TODO force re-decoration on preferences change (use refreshAll) public class UnitDecorator extends LabelProvider implements ILightweightLabelDecorator { private final Logger logger; @@ -150,11 +149,15 @@ public static UnitDecorator getUnitDecorator() return null; } - public void refreshAll() + public static void refreshAll() { - UnitDecorator unitDecorator = getUnitDecorator(); + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + UnitDecorator unitDecorator = getUnitDecorator(); - if(unitDecorator != null) - unitDecorator.fireLabelProviderChanged(new LabelProviderChangedEvent(unitDecorator)); + if(unitDecorator != null) + { + unitDecorator.fireLabelProviderChanged(new LabelProviderChangedEvent(unitDecorator)); + } + }); } } diff --git a/org.moreunit.plugin/src/org/moreunit/properties/MoreUnitPropertyPage.java b/org.moreunit.plugin/src/org/moreunit/properties/MoreUnitPropertyPage.java index 0f44cf70..219868bd 100644 --- a/org.moreunit.plugin/src/org/moreunit/properties/MoreUnitPropertyPage.java +++ b/org.moreunit.plugin/src/org/moreunit/properties/MoreUnitPropertyPage.java @@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.ui.dialogs.PropertyPage; import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.moreunit.decorator.UnitDecorator; import org.moreunit.log.LogHandler; import org.moreunit.preferences.Preferences; @@ -189,6 +190,8 @@ private void saveProperties() IPreferenceStore store = Preferences.getInstance().getProjectStore(getJavaProject()); if(store instanceof ScopedPreferenceStore preferenceStore) preferenceStore.save(); + + UnitDecorator.refreshAll(); } catch (IOException e) { diff --git a/org.moreunit.plugin/src/org/moreunit/util/MoreUnitContants.java b/org.moreunit.plugin/src/org/moreunit/util/MoreUnitContants.java index 25da17a5..f466274a 100644 --- a/org.moreunit.plugin/src/org/moreunit/util/MoreUnitContants.java +++ b/org.moreunit.plugin/src/org/moreunit/util/MoreUnitContants.java @@ -10,7 +10,7 @@ public class MoreUnitContants { public static final String TEST_CASE_MARKER = "org.moreunit.testCase"; - public static final String TEST_CASE_DECORATOR = "moreunit.testdecorator"; + public static final String TEST_CASE_DECORATOR = "org.moreunit.testdecorator"; public static final String TEST_JUNIT3_METHOD_PRAEFIX = "test"; public static final String SUFFIX_NAME = "Suffix";