KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > browsing > ExcludingDecoratingLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.browsing;
12
13 import org.eclipse.core.runtime.CoreException;
14
15 import org.eclipse.swt.graphics.Image;
16
17 import org.eclipse.jface.viewers.DecoratingLabelProvider;
18 import org.eclipse.jface.viewers.ILabelDecorator;
19 import org.eclipse.jface.viewers.ILabelProvider;
20
21 import org.eclipse.ui.IDecoratorManager;
22 import org.eclipse.ui.PlatformUI;
23
24 /**
25  * Excludes a decorator from the decorator manager from being called.
26  *
27  * @since 2.1
28  */

29 class ExcludingDecoratingLabelProvider extends DecoratingLabelProvider {
30
31     private String JavaDoc fExcludedDecoratorId;
32
33     public ExcludingDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator, String JavaDoc excludedDecoratorId) {
34         super(provider, decorator);
35         fExcludedDecoratorId= excludedDecoratorId;
36     }
37
38
39     /*
40      * @see ILabelProvider#getImage
41      */

42     public Image getImage(Object JavaDoc element) {
43         IDecoratorManager decoratorMgr= PlatformUI.getWorkbench().getDecoratorManager();
44         boolean isDecoratorEnabled= decoratorMgr.getEnabled(fExcludedDecoratorId);
45
46         if (isDecoratorEnabled)
47             try {
48                 decoratorMgr.setEnabled(fExcludedDecoratorId, false);
49             } catch (CoreException e) {
50                 // continue
51
}
52
53         Image image= super.getImage(element);
54
55         if (isDecoratorEnabled)
56             try {
57                 decoratorMgr.setEnabled(fExcludedDecoratorId, true);
58             } catch (CoreException e) {
59                 // continue
60
}
61
62         return image;
63     }
64
65     /*
66      * @see ILabelProvider#getText
67      */

68     public String JavaDoc getText(Object JavaDoc element) {
69         IDecoratorManager decoratorMgr= PlatformUI.getWorkbench().getDecoratorManager();
70         boolean isDecoratorEnabled= decoratorMgr.getEnabled(fExcludedDecoratorId);
71
72         if (isDecoratorEnabled)
73             try {
74                 decoratorMgr.setEnabled(fExcludedDecoratorId, false);
75             } catch (CoreException e) {
76                 // continue
77
}
78
79         String JavaDoc text= super.getText(element);
80
81         if (isDecoratorEnabled)
82             try {
83                 decoratorMgr.setEnabled(fExcludedDecoratorId, true);
84             } catch (CoreException e) {
85                 // continue
86
}
87
88         return text;
89     }
90 }
91
Popular Tags