KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > ui > TestSessionLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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
12 package org.eclipse.jdt.internal.junit.ui;
13
14 import org.eclipse.swt.graphics.Image;
15
16 import org.eclipse.jface.viewers.LabelProvider;
17
18 import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
19 import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
20 import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider;
21
22 import org.eclipse.jdt.junit.model.ITestCaseElement;
23 import org.eclipse.jdt.junit.model.ITestElement;
24 import org.eclipse.jdt.junit.model.ITestRunSession;
25 import org.eclipse.jdt.junit.model.ITestSuiteElement;
26
27 import org.eclipse.jdt.internal.junit.Messages;
28 import org.eclipse.jdt.internal.junit.model.TestCaseElement;
29 import org.eclipse.jdt.internal.junit.model.TestSuiteElement;
30 import org.eclipse.jdt.internal.junit.model.TestElement.Status;
31
32 public class TestSessionLabelProvider extends LabelProvider implements IRichLabelProvider {
33     
34     private final TestRunnerViewPart fTestRunnerPart;
35     private final int fLayoutMode;
36     
37     public TestSessionLabelProvider(TestRunnerViewPart testRunnerPart, int layoutMode) {
38         fTestRunnerPart= testRunnerPart;
39         fLayoutMode= layoutMode;
40     }
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object)
44      */

45     public ColoredString getRichTextLabel(Object JavaDoc element) {
46         String JavaDoc label= getSimpleLabel(element);
47         if (label == null) {
48             return new ColoredString(element.toString());
49         }
50         ColoredString text= new ColoredString(label);
51         if (fLayoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
52             if (((ITestElement) element).getParentContainer() instanceof ITestRunSession) {
53                 String JavaDoc testKindDisplayName= fTestRunnerPart.getTestKindDisplayName();
54                 if (testKindDisplayName != null) {
55                     String JavaDoc decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object JavaDoc[] { label, testKindDisplayName });
56                     return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE);
57                 }
58             }
59         } else {
60             if (element instanceof ITestCaseElement) {
61                 String JavaDoc className= ((ITestCaseElement) element).getTestClassName();
62                 String JavaDoc decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object JavaDoc[] { label, className });
63                 return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE);
64             }
65         }
66         return text;
67     }
68     
69     private String JavaDoc getSimpleLabel(Object JavaDoc element) {
70         if (element instanceof ITestCaseElement) {
71             return ((ITestCaseElement) element).getTestMethodName();
72         } else if (element instanceof ITestSuiteElement) {
73             return ((ITestSuiteElement) element).getSuiteTypeName();
74         }
75         return null;
76     }
77
78     public String JavaDoc getText(Object JavaDoc element) {
79         String JavaDoc label= getSimpleLabel(element);
80         if (label == null) {
81             return element.toString();
82         }
83         if (fLayoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
84             if (((ITestElement) element).getParentContainer() instanceof ITestRunSession) {
85                 String JavaDoc testKindDisplayName= fTestRunnerPart.getTestKindDisplayName();
86                 if (testKindDisplayName != null) {
87                     return Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object JavaDoc[] { label, testKindDisplayName });
88                 }
89             }
90         } else {
91             if (element instanceof ITestCaseElement) {
92                 String JavaDoc className= ((ITestCaseElement) element).getTestClassName();
93                 return Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object JavaDoc[] { label, className });
94             }
95         }
96         return label;
97     }
98
99     public Image getImage(Object JavaDoc element) {
100         if (element instanceof TestCaseElement) {
101             TestCaseElement testCaseElement= ((TestCaseElement) element);
102             if (testCaseElement.isIgnored())
103                 return fTestRunnerPart.fTestIgnoredIcon;
104             
105             Status status=testCaseElement.getStatus();
106             if (status.isNotRun())
107                 return fTestRunnerPart.fTestIcon;
108             else if (status.isRunning())
109                 return fTestRunnerPart.fTestRunningIcon;
110             else if (status.isError())
111                 return fTestRunnerPart.fTestErrorIcon;
112             else if (status.isFailure())
113                 return fTestRunnerPart.fTestFailIcon;
114             else if (status.isOK())
115                 return fTestRunnerPart.fTestOkIcon;
116             else
117                 throw new IllegalStateException JavaDoc(element.toString());
118             
119         } else if (element instanceof TestSuiteElement) {
120             Status status= ((TestSuiteElement) element).getStatus();
121             if (status.isNotRun())
122                 return fTestRunnerPart.fSuiteIcon;
123             else if (status.isRunning())
124                 return fTestRunnerPart.fSuiteRunningIcon;
125             else if (status.isError())
126                 return fTestRunnerPart.fSuiteErrorIcon;
127             else if (status.isFailure())
128                 return fTestRunnerPart.fSuiteFailIcon;
129             else if (status.isOK())
130                 return fTestRunnerPart.fSuiteOkIcon;
131             else
132                 throw new IllegalStateException JavaDoc(element.toString());
133         
134         } else {
135             throw new IllegalArgumentException JavaDoc(String.valueOf(element));
136         }
137     }
138
139
140 }
141
Popular Tags