1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.viewsupport;
13 import net.sourceforge.phpdt.ui.PreferenceConstants;
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18 import org.eclipse.jface.viewers.LabelProviderChangedEvent;
21 * JavaUILabelProvider that respects settings from the Appearance preference
22 * page. Triggers a viewer update when a preference changes.
24 public class AppearanceAwareLabelProvider extends JavaUILabelProvider implements
25 IPropertyChangeListener {
27 public final static int DEFAULT_TEXTFLAGS = JavaElementLabels.ROOT_VARIABLE
28 | JavaElementLabels.M_PARAMETER_TYPES
29 | JavaElementLabels.M_APP_RETURNTYPE
30 | JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED;
32 public final static int DEFAULT_IMAGEFLAGS = JavaElementImageProvider.OVERLAY_ICONS;
34 private int fTextFlagMask;
36 private int fImageFlagMask;
39 * Constructor for AppearanceAwareLabelProvider.
41 public AppearanceAwareLabelProvider(int textFlags, int imageFlags) {
42 super(textFlags, imageFlags);
44 PreferenceConstants.getPreferenceStore()
45 .addPropertyChangeListener(this);
49 * Creates a labelProvider with DEFAULT_TEXTFLAGS and DEFAULT_IMAGEFLAGS
51 public AppearanceAwareLabelProvider() {
52 this(DEFAULT_TEXTFLAGS, DEFAULT_IMAGEFLAGS);
55 private void initMasks() {
56 IPreferenceStore store = PreferenceConstants.getPreferenceStore();
58 if (!store.getBoolean(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE)) {
59 fTextFlagMask ^= JavaElementLabels.M_APP_RETURNTYPE;
62 .getBoolean(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) {
63 fTextFlagMask ^= JavaElementLabels.P_COMPRESSED;
70 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
72 public void propertyChange(PropertyChangeEvent event) {
73 String property = event.getProperty();
74 if (property.equals(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE)
76 .equals(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW)
78 .equals(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) {
80 LabelProviderChangedEvent lpEvent = new LabelProviderChangedEvent(
81 this, null); // refresh all
82 fireLabelProviderChanged(lpEvent);
87 * @see IBaseLabelProvider#dispose()
89 public void dispose() {
90 PreferenceConstants.getPreferenceStore().removePropertyChangeListener(
96 * @see JavaUILabelProvider#evaluateImageFlags()
98 protected int evaluateImageFlags(Object element) {
99 return getImageFlags() & fImageFlagMask;
103 * @see JavaUILabelProvider#evaluateTextFlags()
105 protected int evaluateTextFlags(Object element) {
106 return getTextFlags() & fTextFlagMask;