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.OverrideIndicatorLabelDecorator;
14 import net.sourceforge.phpdt.ui.ProblemsLabelDecorator;
15 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jface.viewers.DecoratingLabelProvider;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.ui.IDecoratorManager;
21 import org.eclipse.ui.PlatformUI;
25 * Decorator prepared for the switch to use lightweight label decorators:
26 * uncomment the lbale decorator entries in plugin.xml and change
27 * USE_LIGHTWEIGHT to true.
28 * Certain views don't want problems or override indicators, so they signal this
29 * in the constructor. So on each getImage the corrsponding decorators are
30 * turned off and on again.
32 public class DecoratingJavaLabelProvider extends DecoratingLabelProvider {
34 private static final boolean USE_LIGHTWEIGHT= false;
36 private static final String PROBLEM_DECORATOR_ID= "net.sourceforge.phpdt.ui.problem.decorator"; //$NON-NLS-1$
37 private static final String OVERRIDE_DECORATOR_ID= "net.sourceforge.phpdt.ui.override.decorator"; //$NON-NLS-1$
39 private boolean fUseErrorTick;
40 private boolean fUseOverride;
43 * Decorating label provider for Java. Combines a JavaUILabelProvider
44 * with problem and override indicuator with the workbench decorator (label
45 * decorator extension point).
47 public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider) {
48 this(labelProvider, true, true);
52 * Decorating label provider for Java. Combines a JavaUILabelProvider
53 * (if enabled with problem and override indicator) with the workbench
54 * decorator (label decorator extension point).
56 public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider, boolean errorTick, boolean override) {
57 super(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
58 fUseErrorTick= errorTick;
59 fUseOverride= override;
60 if (!USE_LIGHTWEIGHT) {
62 labelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
65 labelProvider.addLabelDecorator(new OverrideIndicatorLabelDecorator(null));
71 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
73 public Image getImage(Object element) {
74 if (USE_LIGHTWEIGHT) {
75 IDecoratorManager manager= PlatformUI.getWorkbench().getDecoratorManager();
77 boolean disableErrorTick= manager.getEnabled(PROBLEM_DECORATOR_ID) && !fUseErrorTick;
78 boolean disableOverride= manager.getEnabled(OVERRIDE_DECORATOR_ID) && !fUseOverride;
80 if (disableErrorTick) {
81 manager.setEnabled(PROBLEM_DECORATOR_ID, false);
83 if (disableOverride) {
84 manager.setEnabled(OVERRIDE_DECORATOR_ID, false);
86 Image image= super.getImage(element);
87 if (disableErrorTick) {
88 manager.setEnabled(PROBLEM_DECORATOR_ID, true);
90 if (disableOverride) {
91 manager.setEnabled(OVERRIDE_DECORATOR_ID, true);
94 } catch (CoreException e) {
95 PHPeclipsePlugin.log(e);
98 return super.getImage(element);
102 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
104 public String getText(Object element) {
105 if (USE_LIGHTWEIGHT) {
106 IDecoratorManager manager= PlatformUI.getWorkbench().getDecoratorManager();
108 boolean disableErrorTick= manager.getEnabled(PROBLEM_DECORATOR_ID) && !fUseErrorTick;
109 boolean disableOverride= manager.getEnabled(OVERRIDE_DECORATOR_ID) && !fUseOverride;
111 if (disableErrorTick) {
112 manager.setEnabled(PROBLEM_DECORATOR_ID, false);
114 if (disableOverride) {
115 manager.setEnabled(OVERRIDE_DECORATOR_ID, false);
117 String text= super.getText(element);
118 if (disableErrorTick) {
119 manager.setEnabled(PROBLEM_DECORATOR_ID, true);
121 if (disableOverride) {
122 manager.setEnabled(OVERRIDE_DECORATOR_ID, true);
125 } catch (CoreException e) {
126 PHPeclipsePlugin.log(e);
129 return super.getText(element);