Refactory: phphelp plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / TestPoolLabelProvider.java
1 /*************************************************************************
2  * @author Ali Echihabi (ali_echihabi@ieee.org, ali.echihabi@souss.ca)
3  *
4  * Plugin for PHP unit Testing.
5  * www.phpeclipse.de
6  * 
7  *************************************************************************/
8
9 package net.sourceforge.phpeclipse.phpunit;
10
11 import net.sourceforge.phpeclipse.phpunit.testpool.TestCase;
12 import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.viewers.LabelProvider;
16 import org.eclipse.swt.graphics.Image;
17
18 public class TestPoolLabelProvider extends LabelProvider {
19
20         public String getText(Object element) {
21
22                 String text = "";
23
24                 if (element instanceof TestSuite)
25                         return ((TestSuite) element).getName();
26                 else if (element instanceof TestCase) {
27
28                         text = ((TestCase) element).getTestName();
29
30                         // has the form: TESTSUITENAME_TESTNAME
31
32                 } else
33                         text = "UNKNOWN ELEMENT TYPE";
34
35                 return text;
36
37         }
38
39         public Image getImage(Object element) {
40
41                 Image image = null;
42                 ImageDescriptor descriptor = null;
43
44                 if (element instanceof TestSuite) {
45
46                         TestSuite suite = (TestSuite) element;
47                         descriptor = PHPUnitImages.DESC_TEST_SUITE_PASS;
48
49                         if (suite.hasError())
50                                 descriptor = PHPUnitImages.DESC_TEST_SUITE_ERROR;
51                         else if (suite.hasFailure())
52                                 descriptor = PHPUnitImages.DESC_TEST_SUITE_FAILURE;
53                         else if (suite.isAllPass())
54                                 descriptor = PHPUnitImages.DESC_TEST_SUITE_PASS;
55
56                 } else if (element instanceof TestCase) {
57
58                         TestCase test = (TestCase) element;
59
60                         descriptor = PHPUnitImages.DESC_TEST_PASS;
61
62                         if (test.isError())
63                                 descriptor = PHPUnitImages.DESC_TEST_ERROR;
64                         else if (test.isFailure())
65                                 descriptor = PHPUnitImages.DESC_TEST_FAILURE;
66                         else if (test.isPass())
67                                 descriptor = PHPUnitImages.DESC_TEST_PASS;
68
69                 }
70
71                 image = descriptor.createImage();
72
73                 return image;
74
75         }
76
77 }