1 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 35 public final class JavaModelLabelProvider extends AppearanceAwareLabelProvider { 36 37 38 private static final String NAME_SETTINGS_FOLDER= ".settings"; 40 41 private final RefactoringHistoryLabelProvider fHistoryLabelProvider= new RefactoringHistoryLabelProvider(new RefactoringHistoryControlConfiguration(null, false, false)); 42 43 44 private final String fPreferencesLabel; 45 46 47 private final String fRefactoringsLabel; 48 49 50 private Image fSettingsImage= null; 51 52 55 public JavaModelLabelProvider() { 56 this(ModelMessages.JavaModelLabelProvider_project_preferences_label, ModelMessages.JavaModelLabelProvider_refactorings_label); 57 } 58 59 67 public JavaModelLabelProvider(final String preferences, final String 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 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 90 public Image getImage(final Object 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 113 public String getText(final Object 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 text= super.getText(element); 120 if (text == null || "".equals(text)) { 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 |