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.ui.PHPUiImages;
18 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
19 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageImageDescriptor;
20 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.viewers.IDecoration;
24 import org.eclipse.jface.viewers.ILabelDecorator;
25 import org.eclipse.jface.viewers.ILabelProviderListener;
26 import org.eclipse.jface.viewers.ILightweightLabelDecorator;
27 import org.eclipse.swt.graphics.Image;
28 import org.eclipse.swt.graphics.Point;
29 import org.eclipse.swt.graphics.Rectangle;
32 * LabelDecorator that decorates an method's image with override or implements
33 * overlays. The viewer using this decorator is responsible for updating the
34 * images on element changes.
37 * This class may be instantiated; it is not intended to be subclassed.
42 public class OverrideIndicatorLabelDecorator implements ILabelDecorator,
43 ILightweightLabelDecorator {
45 private ImageDescriptorRegistry fRegistry;
47 private boolean fUseNewRegistry = false;
50 * Creates a decorator. The decorator creates an own image registry to cache
53 public OverrideIndicatorLabelDecorator() {
55 fUseNewRegistry = true;
59 * Creates decorator with a shared image registry.
61 * @param registry The registry to use or <code>null</code> to use the
62 * Java plugin's image registry.
65 * Note: This constructor is for internal use only. Clients should not call
68 public OverrideIndicatorLabelDecorator(ImageDescriptorRegistry registry) {
72 private ImageDescriptorRegistry getRegistry() {
73 if (fRegistry == null) {
74 fRegistry = fUseNewRegistry ? new ImageDescriptorRegistry()
75 : PHPeclipsePlugin.getImageDescriptorRegistry();
83 * @see ILabelDecorator#decorateText(String, Object)
85 public String decorateText(String text, Object element) {
92 * @see ILabelDecorator#decorateImage(Image, Object)
94 public Image decorateImage(Image image, Object element) {
95 int adornmentFlags = computeAdornmentFlags(element);
96 if (adornmentFlags != 0) {
97 ImageDescriptor baseImage = new ImageImageDescriptor(image);
98 Rectangle bounds = image.getBounds();
99 return getRegistry().get(
100 new JavaElementImageDescriptor(baseImage, adornmentFlags,
101 new Point(bounds.width, bounds.height)));
107 * Note: This method is for internal use only. Clients should not call this
110 public int computeAdornmentFlags(Object element) {
111 if (element instanceof IMethod) {
112 if (!PreferenceConstants.getPreferenceStore().getBoolean(
113 PreferenceConstants.APPEARANCE_OVERRIDE_INDICATOR)) {
118 IMethod method = (IMethod) element;
119 // if (!method.getJavaProject().isOnClasspath(method)) {
123 int flags = method.getFlags();
124 IType type = method.getDeclaringType();// jsurfer INSERT
125 if (type != null && type.isClass() && !method.isConstructor()
126 && !Flags.isPrivate(flags) && !Flags.isStatic(flags)) {
127 return getOverrideIndicators(method);
129 } catch (JavaModelException e) {
130 if (!e.isDoesNotExist()) {
131 PHPeclipsePlugin.log(e);
139 * Note: This method is for internal use only. Clients should not call this
142 protected int getOverrideIndicators(IMethod method)
143 throws JavaModelException {
144 IType type = method.getDeclaringType();
145 // ITypeHierarchy hierarchy=
146 // SuperTypeHierarchyCache.getTypeHierarchy(type);
147 // if (hierarchy != null) {
148 // return findInHierarchy(type, hierarchy, method.getElementName(),
149 // method.getParameterTypes());
155 * Note: This method is for internal use only. Clients should not call this
158 // protected int findInHierarchy(IType type, ITypeHierarchy hierarchy,
159 // String name, String[] paramTypes) throws JavaModelException {
160 // IMethod impl= JavaModelUtil.findMethodDeclarationInHierarchy(hierarchy,
161 // type, name, paramTypes, false);
162 // if (impl != null) {
163 // IMethod overridden=
164 // JavaModelUtil.findMethodImplementationInHierarchy(hierarchy, type, name,
165 // paramTypes, false);
166 // if (overridden != null) {
167 // return JavaElementImageDescriptor.OVERRIDES;
169 // return JavaElementImageDescriptor.IMPLEMENTS;
177 * @see IBaseLabelProvider#addListener(ILabelProviderListener)
179 public void addListener(ILabelProviderListener listener) {
185 * @see IBaseLabelProvider#dispose()
187 public void dispose() {
188 if (fRegistry != null && fUseNewRegistry) {
196 * @see IBaseLabelProvider#isLabelProperty(Object, String)
198 public boolean isLabelProperty(Object element, String property) {
205 * @see IBaseLabelProvider#removeListener(ILabelProviderListener)
207 public void removeListener(ILabelProviderListener listener) {
213 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
214 * org.eclipse.jface.viewers.IDecoration)
216 public void decorate(Object element, IDecoration decoration) {
217 int adornmentFlags = computeAdornmentFlags(element);
218 if (adornmentFlags != 0) {
219 decoration.addOverlay(PHPUiImages.DESC_OVR_OVERRIDES);