1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.internal.ui.viewsupport.IProblemChangedListener;
15 import net.sourceforge.phpdt.internal.ui.viewsupport.JavaElementImageProvider;
16 import net.sourceforge.phpdt.internal.ui.viewsupport.JavaUILabelProvider;
17 import net.sourceforge.phpdt.ui.ProblemsLabelDecorator;
18 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.jface.text.Assert;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.ui.IEditorInput;
27 * The <code>JavaEditorErrorTickUpdater</code> will register as a
28 * IProblemChangedListener to listen on problem changes of the editor's input.
29 * It updates the title images when the annotation model changed.
31 public class JavaEditorErrorTickUpdater implements IProblemChangedListener {
33 private PHPEditor fJavaEditor;
35 private JavaUILabelProvider fLabelProvider;
37 public JavaEditorErrorTickUpdater(PHPEditor editor) {
38 Assert.isNotNull(editor);
40 fLabelProvider = new JavaUILabelProvider(0,
41 JavaElementImageProvider.SMALL_ICONS);
42 fLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
43 PHPeclipsePlugin.getDefault().getProblemMarkerManager().addListener(
50 * @see IProblemChangedListener#problemsChanged(IResource[], boolean)
52 public void problemsChanged(IResource[] changedResources,
53 boolean isMarkerChange) {
57 IEditorInput input = fJavaEditor.getEditorInput();
58 if (input != null) { // might run async, tests needed
59 IJavaElement jelement = (IJavaElement) input
60 .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);
72 public void updateEditorImage(IJavaElement jelement) {
73 Image titleImage = fJavaEditor.getTitleImage();
74 if (titleImage == null) {
77 Image newImage = fLabelProvider.getImage(jelement);
78 if (titleImage != newImage) {
79 postImageChange(newImage);
83 private void postImageChange(final Image newImage) {
84 Shell shell = fJavaEditor.getEditorSite().getShell();
85 if (shell != null && !shell.isDisposed()) {
86 shell.getDisplay().syncExec(new Runnable() {
88 fJavaEditor.updatedTitleImage(newImage);
94 public void dispose() {
95 fLabelProvider.dispose();
96 PHPeclipsePlugin.getDefault().getProblemMarkerManager().removeListener(