1 11 package org.eclipse.jdt.internal.ui.viewsupport; 12 13 import org.eclipse.jface.viewers.DecoratingLabelProvider; 14 import org.eclipse.jface.viewers.DecorationContext; 15 import org.eclipse.jface.viewers.ILabelDecorator; 16 import org.eclipse.jface.viewers.ILabelProvider; 17 import org.eclipse.jface.viewers.LabelDecorator; 18 19 import org.eclipse.ui.PlatformUI; 20 21 import org.eclipse.jdt.ui.ProblemsLabelDecorator; 22 23 import org.eclipse.jdt.internal.ui.packageview.HierarchicalDecorationContext; 24 25 public class DecoratingJavaLabelProvider extends DecoratingLabelProvider implements IRichLabelProvider { 26 27 33 public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider) { 34 this(labelProvider, true); 35 } 36 37 44 public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider, boolean errorTick) { 45 this(labelProvider, errorTick, true); 46 } 47 48 56 public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider, boolean errorTick, boolean flatPackageMode) { 57 super(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); 58 if (errorTick) { 59 labelProvider.addLabelDecorator(new ProblemsLabelDecorator(null)); 60 } 61 setFlatPackageMode(flatPackageMode); 62 } 63 64 68 public void setFlatPackageMode(boolean enable) { 69 if (enable) { 70 setDecorationContext(DecorationContext.DEFAULT_CONTEXT); 71 } else { 72 setDecorationContext(HierarchicalDecorationContext.CONTEXT); 73 } 74 } 75 76 79 public ColoredString getRichTextLabel(Object element) { 80 ILabelProvider labelProvider= getLabelProvider(); 81 if (labelProvider instanceof IRichLabelProvider) { 82 IRichLabelProvider richLabelProvider= (IRichLabelProvider) labelProvider; 84 ColoredString richLabel= richLabelProvider.getRichTextLabel(element); 85 if (richLabel != null) { 86 String decorated= null; 87 ILabelDecorator labelDecorator= getLabelDecorator(); 88 if (labelDecorator != null) { 89 if (labelDecorator instanceof LabelDecorator) { 90 decorated= ((LabelDecorator) labelDecorator).decorateText(richLabel.getString(), element, getDecorationContext()); 91 } else { 92 decorated= labelDecorator.decorateText(richLabel.getString(), element); 93 } 94 } 95 if (decorated != null) { 96 return ColoredJavaElementLabels.decorateColoredString(richLabel, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE); 97 } 98 return richLabel; 99 } 100 } 101 return null; 102 } 103 104 } 105 | Popular Tags |