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.phpdt.ui;
13 import net.sourceforge.phpdt.core.Flags;
14 import net.sourceforge.phpdt.core.IMethod;
15 import net.sourceforge.phpdt.core.IType;
16 import net.sourceforge.phpdt.core.JavaModelException;
17 import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
18 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
19 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
20 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageImageDescriptor;
21 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.eclipse.jface.viewers.IDecoration;
25 import org.eclipse.jface.viewers.ILabelDecorator;
26 import org.eclipse.jface.viewers.ILabelProviderListener;
27 import org.eclipse.jface.viewers.ILightweightLabelDecorator;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.swt.graphics.Point;
30 import org.eclipse.swt.graphics.Rectangle;
34 * LabelDecorator that decorates an method's image with override or implements overlays.
35 * The viewer using this decorator is responsible for updating the images on element changes.
38 * This class may be instantiated; it is not intended to be subclassed.
43 public class OverrideIndicatorLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator {
45 private ImageDescriptorRegistry fRegistry;
46 private boolean fUseNewRegistry= false;
49 * Creates a decorator. The decorator creates an own image registry to cache
52 public OverrideIndicatorLabelDecorator() {
54 fUseNewRegistry= true;
58 * Creates decorator with a shared image registry.
60 * @param registry The registry to use or <code>null</code> to use the Java plugin's
64 * Note: This constructor is for internal use only. Clients should not call this constructor.
66 public OverrideIndicatorLabelDecorator(ImageDescriptorRegistry registry) {
70 private ImageDescriptorRegistry getRegistry() {
71 if (fRegistry == null) {
72 fRegistry= fUseNewRegistry ? new ImageDescriptorRegistry() : PHPeclipsePlugin.getImageDescriptorRegistry();
79 * @see ILabelDecorator#decorateText(String, Object)
81 public String decorateText(String text, Object element) {
86 * @see ILabelDecorator#decorateImage(Image, Object)
88 public Image decorateImage(Image image, Object element) {
89 int adornmentFlags= computeAdornmentFlags(element);
90 if (adornmentFlags != 0) {
91 ImageDescriptor baseImage= new ImageImageDescriptor(image);
92 Rectangle bounds= image.getBounds();
93 return getRegistry().get(new JavaElementImageDescriptor(baseImage, adornmentFlags, new Point(bounds.width, bounds.height)));
99 * Note: This method is for internal use only. Clients should not call this method.
101 public int computeAdornmentFlags(Object element) {
102 if (element instanceof IMethod) {
103 if (!PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.APPEARANCE_OVERRIDE_INDICATOR)) {
108 IMethod method= (IMethod) element;
109 // if (!method.getJavaProject().isOnClasspath(method)) {
113 int flags= method.getFlags();
114 IType type = method.getDeclaringType();//jsurfer INSERT
115 if (type!=null && type.isClass() && !method.isConstructor() && !Flags.isPrivate(flags) && !Flags.isStatic(flags)) {
116 return getOverrideIndicators(method);
118 } catch (JavaModelException e) {
119 if (!e.isDoesNotExist()) {
120 PHPeclipsePlugin.log(e);
128 * Note: This method is for internal use only. Clients should not call this method.
130 protected int getOverrideIndicators(IMethod method) throws JavaModelException {
131 IType type= method.getDeclaringType();
132 // ITypeHierarchy hierarchy= SuperTypeHierarchyCache.getTypeHierarchy(type);
133 // if (hierarchy != null) {
134 // return findInHierarchy(type, hierarchy, method.getElementName(), method.getParameterTypes());
140 * Note: This method is for internal use only. Clients should not call this method.
142 // protected int findInHierarchy(IType type, ITypeHierarchy hierarchy, String name, String[] paramTypes) throws JavaModelException {
143 // IMethod impl= JavaModelUtil.findMethodDeclarationInHierarchy(hierarchy, type, name, paramTypes, false);
144 // if (impl != null) {
145 // IMethod overridden= JavaModelUtil.findMethodImplementationInHierarchy(hierarchy, type, name, paramTypes, false);
146 // if (overridden != null) {
147 // return JavaElementImageDescriptor.OVERRIDES;
149 // return JavaElementImageDescriptor.IMPLEMENTS;
156 * @see IBaseLabelProvider#addListener(ILabelProviderListener)
158 public void addListener(ILabelProviderListener listener) {
162 * @see IBaseLabelProvider#dispose()
164 public void dispose() {
165 if (fRegistry != null && fUseNewRegistry) {
171 * @see IBaseLabelProvider#isLabelProperty(Object, String)
173 public boolean isLabelProperty(Object element, String property) {
178 * @see IBaseLabelProvider#removeListener(ILabelProviderListener)
180 public void removeListener(ILabelProviderListener listener) {
184 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
186 public void decorate(Object element, IDecoration decoration) {
187 int adornmentFlags= computeAdornmentFlags(element);
188 if (adornmentFlags != 0) {
189 decoration.addOverlay(PHPUiImages.DESC_OVR_OVERRIDES);