1 /*******************************************************************************
2  * Copyright (c) 2000, 2010 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.internal.ui.javaeditor;
15 
16 import org.eclipse.swt.graphics.Image;
17 
18 import org.eclipse.jface.resource.ImageDescriptor;
19 
20 import org.eclipse.jface.text.source.Annotation;
21 
22 import org.eclipse.ui.texteditor.IAnnotationImageProvider;
23 
24 import org.eclipse.jdt.internal.ui.JavaPluginImages;
25 
26 
27 /**
28  * Image provider for {@link org.eclipse.jdt.internal.ui.javaeditor.OverrideIndicatorManager.OverrideIndicator} annotations.
29  *
30  * @since 3.0
31  */
32 public class OverrideIndicatorImageProvider implements IAnnotationImageProvider {
33 
34 	/*
35 	 * @see org.eclipse.ui.texteditor.IAnnotationImageProvider#getManagedImage(org.eclipse.jface.text.source.Annotation)
36 	 */
37 	private static final String OVERRIDE_IMG_DESC_ID= "JavaPluginImages.DESC_OBJ_OVERRIDES"; //$NON-NLS-1$
38 	private static final String OVERWRITE_IMG_DESC_ID= "JavaPluginImages.DESC_OBJ_IMPLEMENTS"; //$NON-NLS-1$
39 	@Override
getManagedImage(Annotation annotation)40 	public Image getManagedImage(Annotation annotation) {
41 		return null;
42 	}
43 
44 	/*
45 	 * @see org.eclipse.ui.texteditor.IAnnotationImageProvider#getImageDescriptorId(org.eclipse.jface.text.source.Annotation)
46 	 */
47 	@Override
getImageDescriptorId(Annotation annotation)48 	public String getImageDescriptorId(Annotation annotation) {
49 		if (!isImageProviderFor(annotation))
50 			return null;
51 
52 		if (isOverwriting(annotation))
53 			return OVERWRITE_IMG_DESC_ID;
54 		else
55 			return OVERRIDE_IMG_DESC_ID;
56 	}
57 
58 	/*
59 	 * @see org.eclipse.ui.texteditor.IAnnotationImageProvider#getImageDescriptor(java.lang.String)
60 	 */
61 	@Override
getImageDescriptor(String imageDescritporId)62 	public ImageDescriptor getImageDescriptor(String imageDescritporId) {
63 		if (OVERWRITE_IMG_DESC_ID.equals(imageDescritporId))
64 			return JavaPluginImages.DESC_OBJ_IMPLEMENTS;
65 		else if (OVERRIDE_IMG_DESC_ID.equals(imageDescritporId))
66 			return JavaPluginImages.DESC_OBJ_OVERRIDES;
67 
68 		return null;
69 	}
70 
isImageProviderFor(Annotation annotation)71 	private boolean isImageProviderFor(Annotation annotation) {
72 		return annotation != null && OverrideIndicatorManager.ANNOTATION_TYPE.equals(annotation.getType());
73 	}
74 
isOverwriting(Annotation annotation)75 	private boolean isOverwriting(Annotation annotation) {
76 		return ((OverrideIndicatorManager.OverrideIndicator)annotation).isOverwriteIndicator();
77 	}
78 }
79