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;
19 import net.sourceforge.phpeclipse.ui.WebUI;
21 import org.eclipse.core.resources.IResource;
23 //import org.eclipse.jface.text.Assert;
24 import org.eclipse.core.runtime.Assert;
25 import org.eclipse.swt.graphics.Image;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.ui.IEditorInput;
30 * The <code>JavaEditorErrorTickUpdater</code> will register as a
31 * IProblemChangedListener to listen on problem changes of the editor's input.
32 * It updates the title images when the annotation model changed.
34 public class JavaEditorErrorTickUpdater implements IProblemChangedListener {
36 private PHPEditor fJavaEditor;
38 private JavaUILabelProvider fLabelProvider;
40 public JavaEditorErrorTickUpdater(PHPEditor editor) {
41 Assert.isNotNull(editor);
43 fLabelProvider = new JavaUILabelProvider(0,
44 JavaElementImageProvider.SMALL_ICONS);
45 fLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
46 WebUI.getDefault().getProblemMarkerManager().addListener(
53 * @see IProblemChangedListener#problemsChanged(IResource[], boolean)
55 public void problemsChanged(IResource[] changedResources,
56 boolean isMarkerChange) {
60 IEditorInput input = fJavaEditor.getEditorInput();
61 if (input != null) { // might run async, tests needed
62 IJavaElement jelement = (IJavaElement) input
63 .getAdapter(IJavaElement.class);
64 if (jelement != null) {
65 IResource resource = jelement.getResource();
66 for (int i = 0; i < changedResources.length; i++) {
67 if (changedResources[i].equals(resource)) {
68 updateEditorImage(jelement);
75 public void updateEditorImage(IJavaElement jelement) {
76 Image titleImage = fJavaEditor.getTitleImage();
77 if (titleImage == null) {
80 Image newImage = fLabelProvider.getImage(jelement);
81 if (titleImage != newImage) {
82 postImageChange(newImage);
86 private void postImageChange(final Image newImage) {
87 Shell shell = fJavaEditor.getEditorSite().getShell();
88 if (shell != null && !shell.isDisposed()) {
89 shell.getDisplay().syncExec(new Runnable() {
91 fJavaEditor.updatedTitleImage(newImage);
97 public void dispose() {
98 fLabelProvider.dispose();
99 WebUI.getDefault().getProblemMarkerManager().removeListener(