1 11 package org.eclipse.jdt.internal.ui.viewsupport; 12 13 import org.eclipse.jface.preference.IPreferenceStore; 14 import org.eclipse.jface.util.IPropertyChangeListener; 15 import org.eclipse.jface.util.PropertyChangeEvent; 16 import org.eclipse.jface.viewers.LabelProviderChangedEvent; 17 18 import org.eclipse.ui.IEditorRegistry; 19 import org.eclipse.ui.IPropertyListener; 20 import org.eclipse.ui.PlatformUI; 21 22 import org.eclipse.jdt.ui.JavaElementLabels; 23 import org.eclipse.jdt.ui.PreferenceConstants; 24 25 29 public class AppearanceAwareLabelProvider extends JavaUILabelProvider implements IPropertyChangeListener, IPropertyListener { 30 31 public final static long DEFAULT_TEXTFLAGS= JavaElementLabels.ROOT_VARIABLE | JavaElementLabels.T_TYPE_PARAMETERS | JavaElementLabels.M_PARAMETER_TYPES | 32 JavaElementLabels.M_APP_TYPE_PARAMETERS | JavaElementLabels.M_APP_RETURNTYPE | JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED; 33 public final static int DEFAULT_IMAGEFLAGS= JavaElementImageProvider.OVERLAY_ICONS; 34 35 private long fTextFlagMask; 36 private int fImageFlagMask; 37 38 41 public AppearanceAwareLabelProvider(long textFlags, int imageFlags) { 42 super(textFlags, imageFlags); 43 initMasks(); 44 PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this); 45 PlatformUI.getWorkbench().getEditorRegistry().addPropertyListener(this); 46 } 47 48 51 public AppearanceAwareLabelProvider() { 52 this(DEFAULT_TEXTFLAGS, DEFAULT_IMAGEFLAGS); 53 } 54 55 private void initMasks() { 56 IPreferenceStore store= PreferenceConstants.getPreferenceStore(); 57 fTextFlagMask= -1; 58 if (!store.getBoolean(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE)) { 59 fTextFlagMask ^= JavaElementLabels.M_APP_RETURNTYPE; 60 } 61 if (!store.getBoolean(PreferenceConstants.APPEARANCE_METHOD_TYPEPARAMETERS)) { 62 fTextFlagMask ^= JavaElementLabels.M_APP_TYPE_PARAMETERS; 63 } 64 if (!store.getBoolean(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) { 65 fTextFlagMask ^= JavaElementLabels.P_COMPRESSED; 66 } 67 if (!store.getBoolean(PreferenceConstants.APPEARANCE_CATEGORY)) { 68 fTextFlagMask ^= JavaElementLabels.ALL_CATEGORY; 69 } 70 71 fImageFlagMask= -1; 72 } 73 74 77 public void propertyChange(PropertyChangeEvent event) { 78 String property= event.getProperty(); 79 if (property.equals(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE) 80 || property.equals(PreferenceConstants.APPEARANCE_METHOD_TYPEPARAMETERS) 81 || property.equals(PreferenceConstants.APPEARANCE_CATEGORY) 82 || property.equals(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW) 83 || property.equals(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) { 84 initMasks(); 85 LabelProviderChangedEvent lpEvent= new LabelProviderChangedEvent(this, null); fireLabelProviderChanged(lpEvent); 87 } 88 } 89 90 93 public void propertyChanged(Object source, int propId) { 94 if (propId == IEditorRegistry.PROP_CONTENTS) { 95 fireLabelProviderChanged(new LabelProviderChangedEvent(this, null)); } 97 } 98 99 102 public void dispose() { 103 PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this); 104 PlatformUI.getWorkbench().getEditorRegistry().removePropertyListener(this); 105 super.dispose(); 106 } 107 108 111 protected int evaluateImageFlags(Object element) { 112 return getImageFlags() & fImageFlagMask; 113 } 114 115 118 protected long evaluateTextFlags(Object element) { 119 return getTextFlags() & fTextFlagMask; 120 } 121 122 } 123 | Popular Tags |