KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > decorator > ClassFileDecorator


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.decorator;
5
6 import org.eclipse.core.resources.IProject;
7 import org.eclipse.jdt.core.IClassFile;
8 import org.eclipse.jface.resource.ImageDescriptor;
9 import org.eclipse.jface.viewers.IDecoration;
10 import org.eclipse.jface.viewers.ILightweightLabelDecorator;
11 import org.eclipse.jface.viewers.LabelProvider;
12
13 import org.terracotta.dso.BootClassHelper;
14 import org.terracotta.dso.ConfigurationHelper;
15 import org.terracotta.dso.TcPlugin;
16
17 /**
18  * Adorns Java modules whose primary-type is instrumented.
19
20  * The adornment appears in the Package Explorer amd Outline view.
21  *
22  * @see org.eclipse.jface.viewers.LabelProvider
23  * @see org.terracotta.dso.ConfigurationHelper.isAdaptable
24  */

25
26 public class ClassFileDecorator extends LabelProvider
27   implements ILightweightLabelDecorator
28 {
29   private static final ImageDescriptor
30     m_imageDesc = ImageDescriptor.createFromURL(
31       AdaptedModuleDecorator.class.getResource(
32         "/com/tc/admin/icons/installed_ovr.gif"));
33
34   public static final String JavaDoc
35     DECORATOR_ID = "org.terracotta.dso.adaptedClassFileDecorator";
36
37   public void decorate(Object JavaDoc element, IDecoration decoration) {
38     TcPlugin plugin = TcPlugin.getDefault();
39     IClassFile classFile = (IClassFile)element;
40     IProject project = classFile.getJavaProject().getProject();
41
42     if(plugin.hasTerracottaNature(project)) {
43       ConfigurationHelper config = plugin.getConfigurationHelper(project);
44       BootClassHelper helper = BootClassHelper.getHelper();
45       
46       if(helper != null && config != null &&
47          (config.isAdaptable(classFile) || helper.isAdaptable(classFile)))
48       {
49         decoration.addOverlay(m_imageDesc);
50       }
51     }
52   }
53
54   public static void updateDecorators() {
55     TcPlugin.getDefault().updateDecorator(DECORATOR_ID);
56   }
57 }
58
Popular Tags