1
/*******************************************************************************
2
* Copyright (c) 2000, 2010 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
11
* Anton Leherbauer (Wind River Systems)
12
*******************************************************************************/
13
package org.eclipse.cdt.ui;
15
import org.eclipse.jface.viewers.LabelProvider;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.ui.model.WorkbenchLabelProvider;
20
import org.eclipse.cdt.core.model.ICElement;
21
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
23
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
24
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
27
* The label provider for the c model elements.
29
public class CElementLabelProvider extends LabelProvider {
32
* Flag (bit mask) indicating that methods labels include the method return type. (appended)
34
public final static int SHOW_RETURN_TYPE = 0x001;
37
* Flag (bit mask) indicating that method label include method parameter types.
39
public final static int SHOW_PARAMETERS = 0x002;
42
* Flag (bit mask) indicating that method label include thrown exception.
44
public final static int SHOW_EXCEPTION = 0x004;
47
* Flag (bit mask) indicating that the label should show the icons with no space
48
* reserved for overlays.
50
public final static int SHOW_SMALL_ICONS = 0x100;
53
* Flag (bit mask) indicating that the label should include overlay icons
54
* for element type and modifiers.
56
public final static int SHOW_OVERLAY_ICONS = 0x010;
59
* Flag (bit mask) indicating that Complation Units, Class Files, Types, Declarations and Members
60
* should be rendered qualified.
61
* Examples: java.lang.String, java.util.Vector.size()
65
public final static int SHOW_QUALIFIED= 0x400;
68
* Flag (bit mask) indicating that Compilation Units, Class Files, Types, Declarations and Members
69
* should be rendered qualified. The qualification is appended
70
* Examples: String - java.lang, size() - java.util.Vector
74
public final static int SHOW_POST_QUALIFIED= 0x800;
78
* Constant (value <code>0</code>) indicating that the label should show
79
* the basic images only.
81
public final static int SHOW_BASICS= 0x000;
84
public final static int SHOW_DEFAULT= new Integer(SHOW_PARAMETERS | SHOW_OVERLAY_ICONS).intValue();
86
private volatile WorkbenchLabelProvider fWorkbenchLabelProvider;
87
protected CElementImageProvider fImageLabelProvider;
88
private CUILabelProvider fCElementLabelProvider;
91
private int fImageFlags;
92
private int fTextFlags;
94
public CElementLabelProvider() {
98
public CElementLabelProvider(int flags) {
99
// WorkbenchLabelProvider may only be initialized on the UI thread
100
// http://bugs.eclipse.org/247274
101
if (Display.getCurrent() != null) {
102
fWorkbenchLabelProvider= new WorkbenchLabelProvider();
104
// Delay initialization
105
CUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
107
if (fCElementLabelProvider != null) {
108
fWorkbenchLabelProvider= new WorkbenchLabelProvider();
112
fImageLabelProvider= new CElementImageProvider();
115
fCElementLabelProvider= new CUILabelProvider(getTextFlags() | CElementLabels.TEMPLATE_PARAMETERS, getImageFlags());
119
public String getText(Object element) {
120
if (element instanceof ICElement) {
121
return fCElementLabelProvider.getText(element);
123
if (fWorkbenchLabelProvider != null) {
124
return fWorkbenchLabelProvider.getText(element);
126
return super.getText(element);
130
public Image getImage(Object element) {
131
return fImageLabelProvider.getImageLabel(element, getImageFlags());
135
public void dispose() {
136
if (fCElementLabelProvider != null) {
137
fCElementLabelProvider.dispose();
138
fCElementLabelProvider= null;
140
if (fWorkbenchLabelProvider != null) {
141
fWorkbenchLabelProvider.dispose();
142
fWorkbenchLabelProvider= null;
144
if(fImageLabelProvider != null) {
145
fImageLabelProvider.dispose();
149
private boolean getFlag(int flag) {
150
return (fFlags & flag) != 0;
154
* Gets the image flags.
155
* Can be overwritten by super classes.
156
* @return Returns a int
158
public int getImageFlags() {
160
if (getFlag(SHOW_OVERLAY_ICONS)) {
161
fImageFlags |= CElementImageProvider.OVERLAY_ICONS;
163
if (getFlag(SHOW_SMALL_ICONS)) {
164
fImageFlags |= CElementImageProvider.SMALL_ICONS;
170
* Gets the text flags. Can be overwritten by super classes.
171
* @return Returns a int
173
public int getTextFlags() {
175
if (getFlag(SHOW_RETURN_TYPE)) {
176
fTextFlags |= CElementLabels.M_APP_RETURNTYPE;
178
if (getFlag(SHOW_PARAMETERS)) {
179
fTextFlags |= CElementLabels.M_PARAMETER_TYPES;
181
if (getFlag(SHOW_EXCEPTION)) {
182
fTextFlags |= CElementLabels.M_EXCEPTIONS;
184
if (getFlag(SHOW_POST_QUALIFIED)) {
185
fTextFlags |= CElementLabels.M_POST_QUALIFIED;