Skip to content

Commit

Permalink
Merge pull request #1624 from Mailaender/bug-573090
Browse files Browse the repository at this point in the history
Try to workaround a native crash in Data Explorer icon setting on Linux
  • Loading branch information
eselmeister authored Jan 31, 2024
2 parents 1adcbeb + 6ca45ef commit 6acdc13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2023 Lablicate GmbH.
* Copyright (c) 2016, 2024 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -122,7 +122,7 @@ public Image getImage(Object element) {
* Fallback
*/
if(descriptor != null) {
return (Image)resourceManager.get(descriptor);
return resourceManager.get(descriptor);
}
}
return null;
Expand Down Expand Up @@ -199,4 +199,4 @@ public String getText(Object element) {
}
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.eclipse.chemclipse.processing.converter.ISupplier;
import org.eclipse.chemclipse.processing.converter.ISupplierFileIdentifier;
import org.eclipse.chemclipse.support.ui.workbench.DisplayUtils;
import org.eclipse.chemclipse.ux.extension.ui.Activator;
import org.eclipse.chemclipse.ux.extension.ui.l10n.Messages;
import org.eclipse.chemclipse.ux.extension.ui.listener.DataExplorerDragListener;
Expand All @@ -39,6 +38,9 @@
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TreeItem;

public class DataExplorerTreeUI {

Expand All @@ -48,6 +50,7 @@ public class DataExplorerTreeUI {
private File directory = null;
private IPreferenceStore preferenceStore = null;
private String preferenceKey = null;
private DataExplorerLabelProvider labelProvider;

public DataExplorerTreeUI(Composite parent, DataExplorerTreeRoot dataExplorerTreeRoot, Collection<? extends ISupplierFileIdentifier> identifier) {

Expand Down Expand Up @@ -167,15 +170,35 @@ private void createTreeViewer(Composite parent, Function<File, Map<ISupplierFile
treeViewer.setUseHashlookup(true);
treeViewer.setExpandPreCheckFilters(true);
treeViewer.setContentProvider(new DataExplorerContentProvider(identifier));
DisplayUtils.getDisplay().asyncExec(() -> {
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=573090
treeViewer.setLabelProvider(new DataExplorerLabelProvider(identifier));
});
labelProvider = new DataExplorerLabelProvider(identifier);
treeViewer.getTree().addListener(SWT.SetData, createLabelListener());
treeViewer.getTree().addListener(SWT.Selection, createLabelListener());
setInput(treeViewer);
//
treeViewerControl.set(treeViewer);
}

private Listener createLabelListener() {

return new Listener() {

@Override
public void handleEvent(Event event) {

TreeItem item = (TreeItem)event.item;
item.setText(labelProvider.getText(item.getData()));
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=573090
Display.getDefault().asyncExec(new Runnable() {

@Override
public void run() {

item.setImage(labelProvider.getImage(item.getData()));
}
});
}
};
}

private void setInput(TreeViewer treeViewer) {

treeViewer.setInput(dataExplorerTreeRoot.getRootContent());
Expand Down

0 comments on commit 6acdc13

Please sign in to comment.