KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > views > ConfigLabelProvider


1 package org.terracotta.dso.views;
2
3 import org.eclipse.jdt.core.IJavaElement;
4 import org.eclipse.jdt.ui.JavaElementLabelProvider;
5 import org.eclipse.jface.viewers.LabelProvider;
6 import org.eclipse.swt.graphics.Image;
7 import org.terracotta.dso.TcPlugin;
8
9 class ConfigLabelProvider extends LabelProvider {
10   private ConfigViewer fViewer;
11   private static Image m_rootsImage;
12   private static Image m_bootClassesImage;
13   private static Image m_distributedMethodsImage;
14   private static Image m_instrumentedClassesImage;
15   private static Image m_locksImage;
16   private static Image m_transientsImage;
17   private static Image m_missingElementImage;
18   
19   private static JavaElementLabelProvider m_javaLabelProvider;
20
21   static {
22     m_rootsImage = TcPlugin.createImage("/images/eclipse/roots.gif");
23     m_locksImage = TcPlugin.createImage("/images/eclipse/locks.gif");
24     m_transientsImage = TcPlugin.createImage("/images/eclipse/transients.gif");
25     m_bootClassesImage = TcPlugin.createImage("/images/eclipse/jar_obj.gif");
26     m_distributedMethodsImage = TcPlugin.createImage("/images/eclipse/jmeth_obj.gif");
27     m_instrumentedClassesImage = TcPlugin.createImage("/images/eclipse/class_obj.gif");
28     m_missingElementImage = TcPlugin.createImage("/images/eclipse/hprio_tsk.gif");
29   }
30     
31   ConfigLabelProvider(ConfigViewer viewer) {
32     super();
33     fViewer = viewer;
34     m_javaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_SMALL_ICONS);
35   }
36   
37   public String JavaDoc getText(Object JavaDoc element) {
38     if(element instanceof RootsWrapper) {
39       return "Roots";
40     } else if(element instanceof InstrumentedClassesWrapper) {
41       return "Instrumented classes";
42     } else if(element instanceof LocksWrapper) {
43       return "Locks";
44     } else if(element instanceof DistributedMethodsWrapper) {
45       return "Distributed methods";
46     } else if(element instanceof AdditionalBootJarClassesWrapper) {
47       return "Additional boot classes";
48     } else if(element instanceof TransientFieldsWrapper) {
49       return "Transient fields";
50     }
51     return super.getText(element);
52   }
53
54   public Image getImage(Object JavaDoc element) {
55     if(element instanceof RootWrapper) {
56       RootWrapper wrapper = (RootWrapper)element;
57       return getJavaElementImage(fViewer.getPart().getField(wrapper.getFieldName()));
58     } else if(element instanceof RootsWrapper) {
59       return m_rootsImage;
60     } else if(element instanceof LocksWrapper) {
61       return m_locksImage;
62     } else if(element instanceof DistributedMethodsWrapper) {
63       return m_distributedMethodsImage;
64     } else if(element instanceof AdditionalBootJarClassesWrapper) {
65       return m_bootClassesImage;
66     } else if(element instanceof TransientFieldsWrapper) {
67       return m_transientsImage;
68     } else if(element instanceof InstrumentedClassesWrapper) {
69       return m_instrumentedClassesImage;
70     } else if(element instanceof BootClassWrapper) {
71       String JavaDoc className = ((BootClassWrapper)element).getClassName();
72       return getJavaElementImage(fViewer.getPart().getType(className));
73     } else if(element instanceof TransientFieldWrapper) {
74       String JavaDoc fieldName = ((TransientFieldWrapper)element).getFieldName();
75       return getJavaElementImage(fViewer.getPart().getField(fieldName));
76     }
77     
78     return null;
79   }
80   
81   private Image getJavaElementImage(IJavaElement element) {
82     if(element != null) {
83       return m_javaLabelProvider.getImage(element);
84     }
85     return m_missingElementImage;
86   }
87 }
88
Popular Tags