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;
 
  21 import net.sourceforge.phpeclipse.ui.WebUI;
 
  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;
 
  33  * LabelDecorator that decorates an method's image with override or implements
 
  34  * overlays. The viewer using this decorator is responsible for updating the
 
  35  * images on element changes.
 
  38  * This class may be instantiated; it is not intended to be subclassed.
 
  43 public class OverrideIndicatorLabelDecorator implements ILabelDecorator,
 
  44                 ILightweightLabelDecorator {
 
  46         private ImageDescriptorRegistry fRegistry;
 
  48         private boolean fUseNewRegistry = false;
 
  51          * Creates a decorator. The decorator creates an own image registry to cache
 
  54         public OverrideIndicatorLabelDecorator() {
 
  56                 fUseNewRegistry = true;
 
  60          * Creates decorator with a shared image registry.
 
  62          * @param registry The registry to use or <code>null</code> to use the
 
  63          * Java plugin's image registry.
 
  66          * Note: This constructor is for internal use only. Clients should not call
 
  69         public OverrideIndicatorLabelDecorator(ImageDescriptorRegistry registry) {
 
  73         private ImageDescriptorRegistry getRegistry() {
 
  74                 if (fRegistry == null) {
 
  75                         fRegistry = fUseNewRegistry ? new ImageDescriptorRegistry()
 
  76                                         : WebUI.getImageDescriptorRegistry();
 
  84          * @see ILabelDecorator#decorateText(String, Object)
 
  86         public String decorateText(String text, Object element) {
 
  93          * @see ILabelDecorator#decorateImage(Image, Object)
 
  95         public Image decorateImage(Image image, Object element) {
 
  96                 int adornmentFlags = computeAdornmentFlags(element);
 
  97                 if (adornmentFlags != 0) {
 
  98                         ImageDescriptor baseImage = new ImageImageDescriptor(image);
 
  99                         Rectangle bounds = image.getBounds();
 
 100                         return getRegistry().get(
 
 101                                         new JavaElementImageDescriptor(baseImage, adornmentFlags,
 
 102                                                         new Point(bounds.width, bounds.height)));
 
 108          * Note: This method is for internal use only. Clients should not call this
 
 111         public int computeAdornmentFlags(Object element) {
 
 112                 if (element instanceof IMethod) {
 
 113                         if (!PreferenceConstants.getPreferenceStore().getBoolean(
 
 114                                         PreferenceConstants.APPEARANCE_OVERRIDE_INDICATOR)) {
 
 119                                 IMethod method = (IMethod) element;
 
 120                                 // if (!method.getJavaProject().isOnClasspath(method)) {
 
 124                                 int flags = method.getFlags();
 
 125                                 IType type = method.getDeclaringType();// jsurfer INSERT
 
 126                                 if (type != null && type.isClass() && !method.isConstructor()
 
 127                                                 && !Flags.isPrivate(flags) && !Flags.isStatic(flags)) {
 
 128                                         return getOverrideIndicators(method);
 
 130                         } catch (JavaModelException e) {
 
 131                                 if (!e.isDoesNotExist()) {
 
 132                                         PHPeclipsePlugin.log(e);
 
 140          * Note: This method is for internal use only. Clients should not call this
 
 143         protected int getOverrideIndicators(IMethod method)
 
 144                         throws JavaModelException {
 
 145                 IType type = method.getDeclaringType();
 
 146                 // ITypeHierarchy hierarchy=
 
 147                 // SuperTypeHierarchyCache.getTypeHierarchy(type);
 
 148                 // if (hierarchy != null) {
 
 149                 // return findInHierarchy(type, hierarchy, method.getElementName(),
 
 150                 // method.getParameterTypes());
 
 156          * Note: This method is for internal use only. Clients should not call this
 
 159         // protected int findInHierarchy(IType type, ITypeHierarchy hierarchy,
 
 160         // String name, String[] paramTypes) throws JavaModelException {
 
 161         // IMethod impl= JavaModelUtil.findMethodDeclarationInHierarchy(hierarchy,
 
 162         // type, name, paramTypes, false);
 
 163         // if (impl != null) {
 
 164         // IMethod overridden=
 
 165         // JavaModelUtil.findMethodImplementationInHierarchy(hierarchy, type, name,
 
 166         // paramTypes, false);
 
 167         // if (overridden != null) {
 
 168         // return JavaElementImageDescriptor.OVERRIDES;
 
 170         // return JavaElementImageDescriptor.IMPLEMENTS;
 
 178          * @see IBaseLabelProvider#addListener(ILabelProviderListener)
 
 180         public void addListener(ILabelProviderListener listener) {
 
 186          * @see IBaseLabelProvider#dispose()
 
 188         public void dispose() {
 
 189                 if (fRegistry != null && fUseNewRegistry) {
 
 197          * @see IBaseLabelProvider#isLabelProperty(Object, String)
 
 199         public boolean isLabelProperty(Object element, String property) {
 
 206          * @see IBaseLabelProvider#removeListener(ILabelProviderListener)
 
 208         public void removeListener(ILabelProviderListener listener) {
 
 214          * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
 
 215          *      org.eclipse.jface.viewers.IDecoration)
 
 217         public void decorate(Object element, IDecoration decoration) {
 
 218                 int adornmentFlags = computeAdornmentFlags(element);
 
 219                 if (adornmentFlags != 0) {
 
 220                         decoration.addOverlay(PHPUiImages.DESC_OVR_OVERRIDES);