~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - initial API and implementation
 
10
 *     QNX Software System
 
11
 *     Anton Leherbauer (Wind River Systems)
 
12
 *******************************************************************************/
 
13
package org.eclipse.cdt.ui;
 
14
 
 
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;
 
19
 
 
20
import org.eclipse.cdt.core.model.ICElement;
 
21
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
 
22
 
 
23
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
 
24
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
 
25
 
 
26
/**
 
27
 * The label provider for the c model elements.
 
28
 */
 
29
public class CElementLabelProvider extends LabelProvider {
 
30
 
 
31
        /**
 
32
         * Flag (bit mask) indicating that methods labels include the method return type. (appended)
 
33
         */
 
34
        public final static int SHOW_RETURN_TYPE = 0x001;
 
35
 
 
36
        /**
 
37
         * Flag (bit mask) indicating that method label include method parameter types.
 
38
         */
 
39
        public final static int SHOW_PARAMETERS = 0x002;
 
40
 
 
41
        /**
 
42
         * Flag (bit mask) indicating that method label include thrown exception.
 
43
         */
 
44
        public final static int SHOW_EXCEPTION = 0x004;
 
45
 
 
46
        /**
 
47
         * Flag (bit mask) indicating that the label should show the icons with no space
 
48
         * reserved for overlays.
 
49
         */
 
50
        public final static int SHOW_SMALL_ICONS = 0x100;
 
51
 
 
52
        /**
 
53
         * Flag (bit mask) indicating that the label should include overlay icons
 
54
         * for element type and modifiers.
 
55
         */
 
56
        public final static int SHOW_OVERLAY_ICONS = 0x010;
 
57
 
 
58
        /**
 
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()
 
62
         * 
 
63
         * @since 2.0
 
64
         */
 
65
        public final static int SHOW_QUALIFIED=                         0x400;
 
66
 
 
67
        /**
 
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
 
71
         * 
 
72
         * @since 2.0
 
73
         */
 
74
        public final static int SHOW_POST_QUALIFIED=    0x800;  
 
75
        
 
76
        
 
77
        /**
 
78
         * Constant (value <code>0</code>) indicating that the label should show 
 
79
         * the basic images only.
 
80
         */
 
81
        public final static int SHOW_BASICS= 0x000;
 
82
        
 
83
        
 
84
        public final static int SHOW_DEFAULT= new Integer(SHOW_PARAMETERS | SHOW_OVERLAY_ICONS).intValue();
 
85
        
 
86
        private volatile WorkbenchLabelProvider fWorkbenchLabelProvider;
 
87
        protected CElementImageProvider fImageLabelProvider;
 
88
        private CUILabelProvider fCElementLabelProvider;
 
89
 
 
90
        private int fFlags;
 
91
        private int fImageFlags;
 
92
        private int fTextFlags;
 
93
 
 
94
        public CElementLabelProvider() {
 
95
                this(SHOW_DEFAULT);
 
96
        }
 
97
 
 
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();
 
103
                } else {
 
104
                        // Delay initialization
 
105
                        CUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
 
106
                                public void run() {
 
107
                                        if (fCElementLabelProvider != null) {
 
108
                                                fWorkbenchLabelProvider= new WorkbenchLabelProvider();
 
109
                                        }
 
110
                                }});
 
111
                }
 
112
                fImageLabelProvider= new CElementImageProvider();
 
113
 
 
114
                fFlags = flags;
 
115
                fCElementLabelProvider= new CUILabelProvider(getTextFlags() | CElementLabels.TEMPLATE_PARAMETERS, getImageFlags());
 
116
        }
 
117
 
 
118
        @Override
 
119
        public String getText(Object element) {
 
120
                if (element instanceof ICElement) {
 
121
                        return fCElementLabelProvider.getText(element);
 
122
                }
 
123
                if (fWorkbenchLabelProvider != null) {
 
124
                        return fWorkbenchLabelProvider.getText(element);
 
125
                }
 
126
                return super.getText(element);
 
127
        }
 
128
 
 
129
        @Override
 
130
        public Image getImage(Object element) {
 
131
                return fImageLabelProvider.getImageLabel(element, getImageFlags());
 
132
        }
 
133
        
 
134
        @Override
 
135
        public void dispose() {
 
136
                if (fCElementLabelProvider != null) {
 
137
                        fCElementLabelProvider.dispose();
 
138
                        fCElementLabelProvider= null;
 
139
                }
 
140
                if (fWorkbenchLabelProvider != null) {
 
141
                        fWorkbenchLabelProvider.dispose();
 
142
                        fWorkbenchLabelProvider= null;
 
143
                }
 
144
                if(fImageLabelProvider != null) {
 
145
                        fImageLabelProvider.dispose();
 
146
                }
 
147
        }
 
148
 
 
149
        private boolean getFlag(int flag) {
 
150
                return (fFlags & flag) != 0;
 
151
        }
 
152
 
 
153
        /**
 
154
         * Gets the image flags.
 
155
         * Can be overwritten by super classes.
 
156
         * @return Returns a int
 
157
         */
 
158
        public int getImageFlags() {
 
159
                fImageFlags = 0;
 
160
                if (getFlag(SHOW_OVERLAY_ICONS)) {
 
161
                        fImageFlags |= CElementImageProvider.OVERLAY_ICONS;
 
162
                }
 
163
                if (getFlag(SHOW_SMALL_ICONS)) {
 
164
                        fImageFlags |= CElementImageProvider.SMALL_ICONS;
 
165
                }
 
166
                return fImageFlags;
 
167
        }
 
168
 
 
169
        /**
 
170
         * Gets the text flags. Can be overwritten by super classes.
 
171
         * @return Returns a int
 
172
         */
 
173
        public int getTextFlags() {
 
174
                fTextFlags = 0;
 
175
                if (getFlag(SHOW_RETURN_TYPE)) {
 
176
                        fTextFlags |= CElementLabels.M_APP_RETURNTYPE;
 
177
                }
 
178
                if (getFlag(SHOW_PARAMETERS)) {
 
179
                        fTextFlags |= CElementLabels.M_PARAMETER_TYPES;
 
180
                }
 
181
                if (getFlag(SHOW_EXCEPTION)) {
 
182
                        fTextFlags |= CElementLabels.M_EXCEPTIONS;
 
183
                }
 
184
                if (getFlag(SHOW_POST_QUALIFIED)) {
 
185
                        fTextFlags |= CElementLabels.M_POST_QUALIFIED;
 
186
                }
 
187
                return fTextFlags;
 
188
        }
 
189
}