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;
22 * Standard label provider for Java elements. Use this class when you want to
23 * present the Java elements in a viewer.
25 * The implementation also handles non-Java elements by forwarding the requests
26 * to the <code>IWorkbenchAdapter</code> of the element.
29 * This class may be instantiated; it is not intended to be subclassed.
32 public class JavaElementLabelProvider extends LabelProvider {
35 * Flag (bit mask) indicating that methods labels include the method return
38 public final static int SHOW_RETURN_TYPE = 0x001;
41 * Flag (bit mask) indicating that method label include method parameter
44 public final static int SHOW_PARAMETERS = 0x002;
47 * Flag (bit mask) indicating that the label of a member should include the
48 * container. For example, include the name of the type enclosing a field.
50 * @deprecated Use SHOW_QUALIFIED or SHOW_ROOT instead
52 public final static int SHOW_CONTAINER = 0x004;
55 * Flag (bit mask) indicating that the label of a type should be fully
56 * qualified. For example, include the fully qualified name of the type
59 * @deprecated Use SHOW_QUALIFIED instead
61 public final static int SHOW_CONTAINER_QUALIFICATION = 0x008;
64 * Flag (bit mask) indicating that the label should include overlay icons
65 * for element type and modifiers.
67 public final static int SHOW_OVERLAY_ICONS = 0x010;
70 * Flag (bit mask) indicating thata field label should include the declared
73 public final static int SHOW_TYPE = 0x020;
76 * Flag (bit mask) indicating that the label should include the name of the
77 * package fragment root (appended).
79 public final static int SHOW_ROOT = 0x040;
82 * Flag (bit mask) indicating that the label qualification of a type should
83 * be shown after the name.
85 * @deprecated SHOW_POST_QUALIFIED instead
87 public final static int SHOW_POSTIFIX_QUALIFICATION = 0x080;
90 * Flag (bit mask) indicating that the label should show the icons with no
91 * space reserved for overlays.
93 public final static int SHOW_SMALL_ICONS = 0x100;
96 * Flag (bit mask) indicating that the packagefragment roots from variables
97 * should be rendered with the variable in the name
99 public final static int SHOW_VARIABLE = 0x200;
102 * Flag (bit mask) indicating that Complation Units, Class Files, Types,
103 * Declarations and Members should be rendered qualified. Examples:
104 * java.lang.String, java.util.Vector.size()
108 public final static int SHOW_QUALIFIED = 0x400;
111 * Flag (bit mask) indicating that Complation Units, Class Files, Types,
112 * Declarations and Members should be rendered qualified. The qualifcation
113 * is appended Examples: String - java.lang, size() - java.util.Vector
117 public final static int SHOW_POST_QUALIFIED = 0x800;
120 * Constant (value <code>0</code>) indicating that the label should show
121 * the basic images only.
123 public final static int SHOW_BASICS = 0x000;
126 * Constant indicating the default label rendering. Currently the default is
127 * equivalent to <code>SHOW_PARAMETERS | SHOW_OVERLAY_ICONS</code>.
129 public final static int SHOW_DEFAULT = new Integer(SHOW_PARAMETERS
130 | SHOW_OVERLAY_ICONS).intValue();
132 private JavaElementImageProvider fImageLabelProvider;
134 private StorageLabelProvider fStorageLabelProvider;
138 private int fImageFlags;
140 private int fTextFlags;
143 * Creates a new label provider with <code>SHOW_DEFAULT</code> flag.
148 // public JavaElementLabelProvider() {
149 // this(SHOW_DEFAULT);
153 * Creates a new label provider.
156 * the initial options; a bitwise OR of <code>SHOW_* </code>
159 public JavaElementLabelProvider(int flags) {
160 fImageLabelProvider = new JavaElementImageProvider();
161 fStorageLabelProvider = new StorageLabelProvider();
163 updateImageProviderFlags();
164 updateTextProviderFlags();
167 private boolean getFlag(int flag) {
168 return (fFlags & flag) != 0;
172 * Turns on the rendering options specified in the given flags.
175 * the options; a bitwise OR of <code>SHOW_* </code> constants
177 // public void turnOn(int flags) {
179 // updateImageProviderFlags();
180 // updateTextProviderFlags();
184 * Turns off the rendering options specified in the given flags.
187 * the initial options; a bitwise OR of <code>SHOW_* </code>
190 // public void turnOff(int flags) {
191 // fFlags &= (~flags);
192 // updateImageProviderFlags();
193 // updateTextProviderFlags();
196 private void updateImageProviderFlags() {
198 if (getFlag(SHOW_OVERLAY_ICONS)) {
199 fImageFlags |= JavaElementImageProvider.OVERLAY_ICONS;
201 if (getFlag(SHOW_SMALL_ICONS)) {
202 fImageFlags |= JavaElementImageProvider.SMALL_ICONS;
206 private void updateTextProviderFlags() {
208 if (getFlag(SHOW_RETURN_TYPE)) {
209 fTextFlags |= JavaElementLabels.M_APP_RETURNTYPE;
211 if (getFlag(SHOW_PARAMETERS)) {
212 fTextFlags |= JavaElementLabels.M_PARAMETER_TYPES;
214 if (getFlag(SHOW_CONTAINER)) {
215 fTextFlags |= JavaElementLabels.P_POST_QUALIFIED
216 | JavaElementLabels.T_POST_QUALIFIED
217 | JavaElementLabels.CF_POST_QUALIFIED
218 | JavaElementLabels.CU_POST_QUALIFIED
219 | JavaElementLabels.M_POST_QUALIFIED
220 | JavaElementLabels.F_POST_QUALIFIED;
222 if (getFlag(SHOW_POSTIFIX_QUALIFICATION)) {
223 fTextFlags |= (JavaElementLabels.T_POST_QUALIFIED
224 | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED);
225 } else if (getFlag(SHOW_CONTAINER_QUALIFICATION)) {
226 fTextFlags |= (JavaElementLabels.T_FULLY_QUALIFIED
227 | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED);
229 if (getFlag(SHOW_TYPE)) {
230 fTextFlags |= JavaElementLabels.F_APP_TYPE_SIGNATURE;
232 if (getFlag(SHOW_ROOT)) {
233 fTextFlags |= JavaElementLabels.APPEND_ROOT_PATH;
235 if (getFlag(SHOW_VARIABLE)) {
236 fTextFlags |= JavaElementLabels.ROOT_VARIABLE;
238 if (getFlag(SHOW_QUALIFIED)) {
239 fTextFlags |= (JavaElementLabels.F_FULLY_QUALIFIED
240 | JavaElementLabels.M_FULLY_QUALIFIED
241 | JavaElementLabels.I_FULLY_QUALIFIED
242 | JavaElementLabels.T_FULLY_QUALIFIED
243 | JavaElementLabels.D_QUALIFIED
244 | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED);
246 if (getFlag(SHOW_POST_QUALIFIED)) {
247 fTextFlags |= (JavaElementLabels.F_POST_QUALIFIED
248 | JavaElementLabels.M_POST_QUALIFIED
249 | JavaElementLabels.I_POST_QUALIFIED
250 | JavaElementLabels.T_POST_QUALIFIED
251 | JavaElementLabels.D_POST_QUALIFIED
252 | JavaElementLabels.CF_POST_QUALIFIED | JavaElementLabels.CU_POST_QUALIFIED);
259 * @see ILabelProvider#getImage
261 public Image getImage(Object element) {
262 Image result = fImageLabelProvider.getImageLabel(element, fImageFlags);
263 if (result != null) {
267 if (element instanceof IStorage)
268 return fStorageLabelProvider.getImage(element);
276 * @see ILabelProvider#getText
278 public String getText(Object element) {
279 String text = JavaElementLabels.getTextLabel(element, fTextFlags);
280 if (text.length() > 0) {
284 if (element instanceof IStorage)
285 return fStorageLabelProvider.getText(element);
293 * @see IBaseLabelProvider#dispose
295 public void dispose() {
296 fStorageLabelProvider.dispose();
297 fImageLabelProvider.dispose();