Fix 'Invalid Thread Access'

See: https://github.com/spring-projects/sts4/issues/128
This commit is contained in:
Kris De Volder
2018-10-31 15:32:42 -07:00
parent 74a85aca03
commit 8bfccb2df4
2 changed files with 25 additions and 10 deletions

View File

@@ -11,8 +11,10 @@
package org.springframework.tooling.ls.eclipse.commons;
import java.net.URL;
import java.time.Duration;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
@@ -27,6 +29,7 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.progress.UIJob;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl.UpdateHighlights;
@@ -90,18 +93,29 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
super.start(context);
getImageRegistry().put(BOOT_KEY, getImageDescriptor("icons/boot.png"));
colorRegistry = new ColorRegistry(PlatformUI.getWorkbench().getDisplay(), true);
RGB prefsColor = PreferenceConverter.getColor(EditorsPlugin.getDefault().getPreferenceStore(), PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
colorRegistry.put(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS, convertRGBtoNonTransparent(prefsColor));
getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
EditorsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
UIJob uiJob = new UIJob("Setup color registry") {
{
setSystem(true);
}
@Override
public IStatus runInUIThread(IProgressMonitor arg0) {
colorRegistry = new ColorRegistry(PlatformUI.getWorkbench().getDisplay(), true);
RGB prefsColor = PreferenceConverter.getColor(EditorsPlugin.getDefault().getPreferenceStore(), PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
colorRegistry.put(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS, convertRGBtoNonTransparent(prefsColor));
getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
EditorsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
return Status.OK_STATUS;
}
};
uiJob.schedule();
}
public Color getBootHighlightRangeColor() {
return colorRegistry.get(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
if (colorRegistry!=null) {
return colorRegistry.get(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
}
return null;
}
public final static ImageDescriptor getImageDescriptor(String path) {

View File

@@ -177,8 +177,9 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
f = AnnotationPainter.class.getDeclaredField("fAnnotationType2Color");
f.setAccessible(true);
if (((Map<Object, Color>)f.get(painter)).get(ALT_ANNOTATION_TYPE_ID) != LanguageServerCommonsActivator.getInstance().getBootHighlightRangeColor()) {
painter.setAnnotationTypeColor(ALT_ANNOTATION_TYPE_ID, LanguageServerCommonsActivator.getInstance().getBootHighlightRangeColor());
Color highlightColor = LanguageServerCommonsActivator.getInstance().getBootHighlightRangeColor();
if (highlightColor!=null && ((Map<Object, Color>)f.get(painter)).get(ALT_ANNOTATION_TYPE_ID) != highlightColor) {
painter.setAnnotationTypeColor(ALT_ANNOTATION_TYPE_ID, highlightColor);
painter.addDrawingStrategy(ALT_ANNOTATION_DRAWING_STRATEGY_ID, BOOT_RANGE_HIGHLIGHT_DRAWING_STRATEGY);
painter.addAnnotationType(ALT_ANNOTATION_TYPE_ID, ALT_ANNOTATION_DRAWING_STRATEGY_ID);
}