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;
24 * Decorator prepared for the switch to use lightweight label decorators:
25 * uncomment the lbale decorator entries in plugin.xml and change
26 * USE_LIGHTWEIGHT to true. Certain views don't want problems or override
27 * indicators, so they signal this in the constructor. So on each getImage the
28 * corrsponding decorators are turned off and on again.
30 public class DecoratingJavaLabelProvider extends DecoratingLabelProvider {
32 private static final boolean USE_LIGHTWEIGHT = false;
34 private static final String PROBLEM_DECORATOR_ID = "net.sourceforge.phpdt.ui.problem.decorator"; //$NON-NLS-1$
36 private static final String OVERRIDE_DECORATOR_ID = "net.sourceforge.phpdt.ui.override.decorator"; //$NON-NLS-1$
38 private boolean fUseErrorTick;
40 private boolean fUseOverride;
43 * Decorating label provider for Java. Combines a JavaUILabelProvider with
44 * 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 (if
53 * enabled with problem and override indicator) with the workbench decorator
54 * (label decorator extension point).
56 public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider,
57 boolean errorTick, boolean override) {
58 super(labelProvider, PlatformUI.getWorkbench().getDecoratorManager()
59 .getLabelDecorator());
60 fUseErrorTick = errorTick;
61 fUseOverride = override;
62 if (!USE_LIGHTWEIGHT) {
65 .addLabelDecorator(new ProblemsLabelDecorator(null));
69 .addLabelDecorator(new OverrideIndicatorLabelDecorator(
78 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
80 public Image getImage(Object element) {
81 if (USE_LIGHTWEIGHT) {
82 IDecoratorManager manager = PlatformUI.getWorkbench()
83 .getDecoratorManager();
85 boolean disableErrorTick = manager.getEnabled(PROBLEM_DECORATOR_ID)
87 boolean disableOverride = manager.getEnabled(OVERRIDE_DECORATOR_ID)
90 if (disableErrorTick) {
91 manager.setEnabled(PROBLEM_DECORATOR_ID, false);
93 if (disableOverride) {
94 manager.setEnabled(OVERRIDE_DECORATOR_ID, false);
96 Image image = super.getImage(element);
97 if (disableErrorTick) {
98 manager.setEnabled(PROBLEM_DECORATOR_ID, true);
100 if (disableOverride) {
101 manager.setEnabled(OVERRIDE_DECORATOR_ID, true);
104 } catch (CoreException e) {
105 PHPeclipsePlugin.log(e);
108 return super.getImage(element);
114 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
116 public String getText(Object element) {
117 if (USE_LIGHTWEIGHT) {
118 IDecoratorManager manager = PlatformUI.getWorkbench()
119 .getDecoratorManager();
121 boolean disableErrorTick = manager.getEnabled(PROBLEM_DECORATOR_ID)
123 boolean disableOverride = manager.getEnabled(OVERRIDE_DECORATOR_ID)
126 if (disableErrorTick) {
127 manager.setEnabled(PROBLEM_DECORATOR_ID, false);
129 if (disableOverride) {
130 manager.setEnabled(OVERRIDE_DECORATOR_ID, false);
132 String text = super.getText(element);
133 if (disableErrorTick) {
134 manager.setEnabled(PROBLEM_DECORATOR_ID, true);
136 if (disableOverride) {
137 manager.setEnabled(OVERRIDE_DECORATOR_ID, true);
140 } catch (CoreException e) {
141 PHPeclipsePlugin.log(e);
144 return super.getText(element);