From 982ffe317d8fd74c8f3a1e8956758817bf9be511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 18 Dec 2024 14:35:39 +0100 Subject: [PATCH] Set the icons asynchronously to avoid a crash. --- .../provider/DataExplorerLabelProvider.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/provider/DataExplorerLabelProvider.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/provider/DataExplorerLabelProvider.java index 99ae52d7dd..170ff19362 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/provider/DataExplorerLabelProvider.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/provider/DataExplorerLabelProvider.java @@ -23,7 +23,6 @@ import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory; import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage; import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImageProvider; -import org.eclipse.chemclipse.support.settings.OperatingSystemUtils; import org.eclipse.chemclipse.ux.extension.ui.editors.EditorDescriptor; import org.eclipse.chemclipse.ux.extension.ui.swt.IdentifierCacheSupport; import org.eclipse.core.runtime.Adapters; @@ -31,16 +30,17 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.navigator.IDescriptionProvider; -public class DataExplorerLabelProvider extends LabelProvider implements ILabelProvider, IDescriptionProvider { +public class DataExplorerLabelProvider extends ColumnLabelProvider implements ILabelProvider, IDescriptionProvider { private final Function>> supplierFunction; private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); - private boolean isInitial = true; public DataExplorerLabelProvider(Collection supplierFileIdentifierList) { @@ -74,15 +74,22 @@ public String getDescription(Object element) { } @Override - public Image getImage(Object element) { - - /* - * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=573090 - */ - if(isInitial && OperatingSystemUtils.isLinux()) { - isInitial = false; - return null; - } + public void update(ViewerCell cell) { + + Object element = cell.getElement(); + cell.setText(getText(element)); + Image image = getIcon(element); + // https://github.com/eclipse-platform/eclipse.platform.swt/issues/678 + Display.getCurrent().asyncExec(() -> { + cell.setImage(image); + }); + cell.setBackground(getBackground(element)); + cell.setForeground(getForeground(element)); + cell.setFont(getFont(element)); + } + + public Image getIcon(Object element) { + if(element instanceof File file) { ImageDescriptor descriptor = null; //