1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.core.resources.IResource; 16 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.widgets.Shell; 19 20 21 import org.eclipse.ui.IEditorInput; 22 23 import org.eclipse.jdt.core.ICompilationUnit; 24 import org.eclipse.jdt.core.IJavaElement; 25 26 import org.eclipse.jdt.ui.ProblemsLabelDecorator; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 import org.eclipse.jdt.internal.ui.viewsupport.IProblemChangedListener; 30 import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; 31 import org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider; 32 33 38 public class JavaEditorErrorTickUpdater implements IProblemChangedListener { 39 40 private JavaEditor fJavaEditor; 41 private JavaUILabelProvider fLabelProvider; 42 43 public JavaEditorErrorTickUpdater(JavaEditor editor) { 44 Assert.isNotNull(editor); 45 fJavaEditor= editor; 46 fLabelProvider= new JavaUILabelProvider(0, JavaElementImageProvider.SMALL_ICONS); 47 fLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null)); 48 JavaPlugin.getDefault().getProblemMarkerManager().addListener(this); 49 } 50 51 54 public void problemsChanged(IResource[] changedResources, boolean isMarkerChange) { 55 if (!isMarkerChange) 56 return; 57 58 IEditorInput input= fJavaEditor.getEditorInput(); 59 if (input != null) { IJavaElement jelement= (IJavaElement) input.getAdapter(IJavaElement.class); 61 if (jelement != null) { 62 IResource resource= jelement.getResource(); 63 for (int i = 0; i < changedResources.length; i++) { 64 if (changedResources[i].equals(resource)) { 65 updateEditorImage(jelement); 66 } 67 } 68 } 69 } 70 } 71 72 public void updateEditorImage(IJavaElement jelement) { 73 Image titleImage= fJavaEditor.getTitleImage(); 74 if (titleImage == null) { 75 return; 76 } 77 Image newImage; 78 if (jelement instanceof ICompilationUnit && !jelement.getJavaProject().isOnClasspath(jelement)) 79 newImage= fLabelProvider.getImage(jelement.getResource()); 80 else 81 newImage= fLabelProvider.getImage(jelement); 82 if (titleImage != newImage) { 83 postImageChange(newImage); 84 } 85 } 86 87 private void postImageChange(final Image newImage) { 88 Shell shell= fJavaEditor.getEditorSite().getShell(); 89 if (shell != null && !shell.isDisposed()) { 90 shell.getDisplay().syncExec(new Runnable () { 91 public void run() { 92 fJavaEditor.updatedTitleImage(newImage); 93 } 94 }); 95 } 96 } 97 98 public void dispose() { 99 fLabelProvider.dispose(); 100 JavaPlugin.getDefault().getProblemMarkerManager().removeListener(this); 101 } 102 103 104 } 105 106 107 | Popular Tags |