KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > model > JavaModelLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.model;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.core.resources.IFolder;
16
17 import org.eclipse.swt.graphics.Image;
18
19 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
20 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
21 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration;
22 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryLabelProvider;
23
24 import org.eclipse.jdt.ui.JavaElementLabels;
25
26 import org.eclipse.jdt.internal.ui.JavaPluginImages;
27 import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
28 import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
29
30 /**
31  * Label provider for Java models.
32  *
33  * @since 3.2
34  */

35 public final class JavaModelLabelProvider extends AppearanceAwareLabelProvider {
36
37     /** The name of the settings folder */
38     private static final String JavaDoc NAME_SETTINGS_FOLDER= ".settings"; //$NON-NLS-1$
39

40     /** The refactoring history label provider */
41     private final RefactoringHistoryLabelProvider fHistoryLabelProvider= new RefactoringHistoryLabelProvider(new RefactoringHistoryControlConfiguration(null, false, false));
42
43     /** The project preferences label */
44     private final String JavaDoc fPreferencesLabel;
45
46     /** The pending refactorings label */
47     private final String JavaDoc fRefactoringsLabel;
48
49     /** The project settings image, or <code>null</code> */
50     private Image fSettingsImage= null;
51
52     /**
53      * Creates a new java model label provider.
54      */

55     public JavaModelLabelProvider() {
56         this(ModelMessages.JavaModelLabelProvider_project_preferences_label, ModelMessages.JavaModelLabelProvider_refactorings_label);
57     }
58
59     /**
60      * Creates a new java model label provider.
61      *
62      * @param preferences
63      * the preferences label
64      * @param refactorings
65      * the refactorings label
66      */

67     public JavaModelLabelProvider(final String JavaDoc preferences, final String JavaDoc refactorings) {
68         super(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.P_COMPRESSED, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS);
69         Assert.isNotNull(preferences);
70         Assert.isNotNull(refactorings);
71         fPreferencesLabel= preferences;
72         fRefactoringsLabel= refactorings;
73     }
74
75     /**
76      * {@inheritDoc}
77      */

78     public void dispose() {
79         super.dispose();
80         fHistoryLabelProvider.dispose();
81         if (fSettingsImage != null && !fSettingsImage.isDisposed()) {
82             fSettingsImage.dispose();
83             fSettingsImage= null;
84         }
85     }
86
87     /**
88      * {@inheritDoc}
89      */

90     public Image getImage(final Object JavaDoc element) {
91         if (element instanceof IFolder) {
92             final IFolder folder= (IFolder) element;
93             if (folder.getName().equals(NAME_SETTINGS_FOLDER)) {
94                 if (fSettingsImage == null || fSettingsImage.isDisposed())
95                     fSettingsImage= JavaPluginImages.DESC_OBJS_PROJECT_SETTINGS.createImage();
96                 return decorateImage(fSettingsImage, element);
97             }
98         }
99         Image image= super.getImage(element);
100         if (image == null) {
101             if (element instanceof RefactoringHistory)
102                 image= fHistoryLabelProvider.getImage(element);
103             else if (element instanceof RefactoringDescriptorProxy)
104                 image= fHistoryLabelProvider.getImage(element);
105             return decorateImage(image, element);
106         }
107         return image;
108     }
109
110     /**
111      * {@inheritDoc}
112      */

113     public String JavaDoc getText(final Object JavaDoc element) {
114         if (element instanceof IFolder) {
115             final IFolder folder= (IFolder) element;
116             if (folder.getName().equals(NAME_SETTINGS_FOLDER))
117                 return decorateText(fPreferencesLabel, element);
118         }
119         String JavaDoc text= super.getText(element);
120         if (text == null || "".equals(text)) { //$NON-NLS-1$
121
if (element instanceof RefactoringHistory)
122                 text= fRefactoringsLabel;
123             else if (element instanceof RefactoringDescriptorProxy)
124                 text= fHistoryLabelProvider.getText(element);
125             return decorateText(text, element);
126         }
127         return text;
128     }
129 }
130
Popular Tags