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.internal.ui.viewsupport.JavaElementImageProvider;
14 import net.sourceforge.phpdt.internal.ui.viewsupport.JavaElementLabels;
15 import net.sourceforge.phpdt.internal.ui.viewsupport.StorageLabelProvider;
17 import org.eclipse.core.resources.IStorage;
18 import org.eclipse.jface.viewers.LabelProvider;
19 import org.eclipse.swt.graphics.Image;
24 * Standard label provider for Java elements.
25 * Use this class when you want to present the Java elements in a viewer.
27 * The implementation also handles non-Java elements by forwarding the requests to the
28 * <code>IWorkbenchAdapter</code> of the element.
31 * This class may be instantiated; it is not intended to be subclassed.
34 public class JavaElementLabelProvider extends LabelProvider {
37 * Flag (bit mask) indicating that methods labels include the method return type. (appended)
39 public final static int SHOW_RETURN_TYPE= 0x001;
42 * Flag (bit mask) indicating that method label include method parameter types.
44 public final static int SHOW_PARAMETERS= 0x002;
47 * Flag (bit mask) indicating that the label of a member should include the container.
48 * For example, include the name of the type enclosing a field.
49 * @deprecated Use SHOW_QUALIFIED or SHOW_ROOT instead
51 public final static int SHOW_CONTAINER= 0x004;
54 * Flag (bit mask) indicating that the label of a type should be fully qualified.
55 * For example, include the fully qualified name of the type enclosing a type.
56 * @deprecated Use SHOW_QUALIFIED instead
58 public final static int SHOW_CONTAINER_QUALIFICATION= 0x008;
61 * Flag (bit mask) indicating that the label should include overlay icons
62 * for element type and modifiers.
64 public final static int SHOW_OVERLAY_ICONS= 0x010;
67 * Flag (bit mask) indicating thata field label should include the declared type.
69 public final static int SHOW_TYPE= 0x020;
72 * Flag (bit mask) indicating that the label should include the name of the
73 * package fragment root (appended).
75 public final static int SHOW_ROOT= 0x040;
78 * Flag (bit mask) indicating that the label qualification of a type should
79 * be shown after the name.
80 * @deprecated SHOW_POST_QUALIFIED instead
82 public final static int SHOW_POSTIFIX_QUALIFICATION= 0x080;
85 * Flag (bit mask) indicating that the label should show the icons with no space
86 * reserved for overlays.
88 public final static int SHOW_SMALL_ICONS= 0x100;
91 * Flag (bit mask) indicating that the packagefragment roots from variables should
92 * be rendered with the variable in the name
94 public final static int SHOW_VARIABLE= 0x200;
97 * Flag (bit mask) indicating that Complation Units, Class Files, Types, Declarations and Members
98 * should be rendered qualified.
99 * Examples: java.lang.String, java.util.Vector.size()
103 public final static int SHOW_QUALIFIED= 0x400;
106 * Flag (bit mask) indicating that Complation Units, Class Files, Types, Declarations and Members
107 * should be rendered qualified. The qualifcation is appended
108 * Examples: String - java.lang, size() - java.util.Vector
112 public final static int SHOW_POST_QUALIFIED= 0x800;
116 * Constant (value <code>0</code>) indicating that the label should show
117 * the basic images only.
119 public final static int SHOW_BASICS= 0x000;
123 * Constant indicating the default label rendering.
124 * Currently the default is equivalent to
125 * <code>SHOW_PARAMETERS | SHOW_OVERLAY_ICONS</code>.
127 public final static int SHOW_DEFAULT= new Integer(SHOW_PARAMETERS | SHOW_OVERLAY_ICONS).intValue();
129 private JavaElementImageProvider fImageLabelProvider;
131 private StorageLabelProvider fStorageLabelProvider;
133 private int fImageFlags;
134 private int fTextFlags;
137 * Creates a new label provider with <code>SHOW_DEFAULT</code> flag.
142 public JavaElementLabelProvider() {
147 * Creates a new label provider.
149 * @param flags the initial options; a bitwise OR of <code>SHOW_* </code> constants
151 public JavaElementLabelProvider(int flags) {
152 fImageLabelProvider= new JavaElementImageProvider();
153 fStorageLabelProvider= new StorageLabelProvider();
155 updateImageProviderFlags();
156 updateTextProviderFlags();
159 private boolean getFlag( int flag) {
160 return (fFlags & flag) != 0;
164 * Turns on the rendering options specified in the given flags.
166 * @param flags the options; a bitwise OR of <code>SHOW_* </code> constants
168 public void turnOn(int flags) {
170 updateImageProviderFlags();
171 updateTextProviderFlags();
175 * Turns off the rendering options specified in the given flags.
177 * @param flags the initial options; a bitwise OR of <code>SHOW_* </code> constants
179 public void turnOff(int flags) {
181 updateImageProviderFlags();
182 updateTextProviderFlags();
185 private void updateImageProviderFlags() {
187 if (getFlag(SHOW_OVERLAY_ICONS)) {
188 fImageFlags |= JavaElementImageProvider.OVERLAY_ICONS;
190 if (getFlag(SHOW_SMALL_ICONS)) {
191 fImageFlags |= JavaElementImageProvider.SMALL_ICONS;
195 private void updateTextProviderFlags() {
197 if (getFlag(SHOW_RETURN_TYPE)) {
198 fTextFlags |= JavaElementLabels.M_APP_RETURNTYPE;
200 if (getFlag(SHOW_PARAMETERS)) {
201 fTextFlags |= JavaElementLabels.M_PARAMETER_TYPES;
203 if (getFlag(SHOW_CONTAINER)) {
204 fTextFlags |= JavaElementLabels.P_POST_QUALIFIED | JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.F_POST_QUALIFIED;
206 if (getFlag(SHOW_POSTIFIX_QUALIFICATION)) {
207 fTextFlags |= (JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED);
208 } else if (getFlag(SHOW_CONTAINER_QUALIFICATION)) {
209 fTextFlags |=(JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED);
211 if (getFlag(SHOW_TYPE)) {
212 fTextFlags |= JavaElementLabels.F_APP_TYPE_SIGNATURE;
214 if (getFlag(SHOW_ROOT)) {
215 fTextFlags |= JavaElementLabels.APPEND_ROOT_PATH;
217 if (getFlag(SHOW_VARIABLE)) {
218 fTextFlags |= JavaElementLabels.ROOT_VARIABLE;
220 if (getFlag(SHOW_QUALIFIED)) {
221 fTextFlags |= (JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.I_FULLY_QUALIFIED
222 | JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.D_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED);
224 if (getFlag(SHOW_POST_QUALIFIED)) {
225 fTextFlags |= (JavaElementLabels.F_POST_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.I_POST_QUALIFIED
226 | JavaElementLabels.T_POST_QUALIFIED | JavaElementLabels.D_POST_QUALIFIED | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED);
231 * @see ILabelProvider#getImage
233 public Image getImage(Object element) {
234 Image result= fImageLabelProvider.getImageLabel(element, fImageFlags);
235 if (result != null) {
239 if (element instanceof IStorage)
240 return fStorageLabelProvider.getImage(element);
246 * @see ILabelProvider#getText
248 public String getText(Object element) {
249 String text= JavaElementLabels.getTextLabel(element, fTextFlags);
250 if (text.length() > 0) {
254 if (element instanceof IStorage)
255 return fStorageLabelProvider.getText(element);
262 * @see IBaseLabelProvider#dispose
264 public void dispose() {
265 fStorageLabelProvider.dispose();
266 fImageLabelProvider.dispose();