Mercurial > hg > de.codedo.java.editor
view src/de/codedo/java/editor/CodedoJavaEditor.java @ 6:6287f5e469f1
Reset the title image when an editor is closed.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Mon, 07 Sep 2015 14:42:44 +0200 |
parents | f7d908568cfc |
children | 778c251baa66 |
line wrap: on
line source
package de.codedo.java.editor; import java.lang.reflect.Field; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditorErrorTickUpdater; import org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorInput; public class CodedoJavaEditor extends CompilationUnitEditor { public CodedoJavaEditor() { super(); installJavaElementImageProvider(); } private void installJavaElementImageProvider() { try { JavaUILabelProvider labelProvider = getJavaUILabelProvider(); setupJavaElementImageProvider(labelProvider); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } private JavaUILabelProvider getJavaUILabelProvider() throws ReflectiveOperationException { JavaEditorErrorTickUpdater tickUpdater = getJavaEditorErrorTickUpdater(); Field field = tickUpdater.getClass().getDeclaredField("fLabelProvider"); field.setAccessible(true); return (JavaUILabelProvider)field.get(tickUpdater); } private JavaEditorErrorTickUpdater getJavaEditorErrorTickUpdater() throws ReflectiveOperationException { Field field = getClass().getSuperclass().getDeclaredField("fJavaEditorErrorTickUpdater"); field.setAccessible(true); return (JavaEditorErrorTickUpdater)field.get(this); } private void setupJavaElementImageProvider(JavaUILabelProvider labelProvider) throws ReflectiveOperationException { CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider(); Field field = labelProvider.getClass().getDeclaredField("fImageLabelProvider"); field.setAccessible(true); field.set(labelProvider, imageProvider); } public void toggleTitleImage() { IJavaElement javaElement = getJavaElement(); CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider(); Image newTitleImage = imageProvider.toggleTitleImage(javaElement); setTitleImage(newTitleImage); } @Override public void dispose() { CodedoJavaElementImageProvider imageProvider = Activator.getDefault().getJavaElementImageProvider(); IJavaElement javaElement = getJavaElement(); imageProvider.resetTitleImage(javaElement); super.dispose(); } private IJavaElement getJavaElement() { IEditorInput input = getEditorInput(); // this class is registered as Java editor so we should always have a java element here return (IJavaElement)input.getAdapter(IJavaElement.class); } }