1 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 45 public ColoredString getRichTextLabel(Object element) { 46 String 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 testKindDisplayName= fTestRunnerPart.getTestKindDisplayName(); 54 if (testKindDisplayName != null) { 55 String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object [] { label, testKindDisplayName }); 56 return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE); 57 } 58 } 59 } else { 60 if (element instanceof ITestCaseElement) { 61 String className= ((ITestCaseElement) element).getTestClassName(); 62 String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object [] { label, className }); 63 return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE); 64 } 65 } 66 return text; 67 } 68 69 private String getSimpleLabel(Object 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 getText(Object element) { 79 String 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 testKindDisplayName= fTestRunnerPart.getTestKindDisplayName(); 86 if (testKindDisplayName != null) { 87 return Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object [] { label, testKindDisplayName }); 88 } 89 } 90 } else { 91 if (element instanceof ITestCaseElement) { 92 String className= ((ITestCaseElement) element).getTestClassName(); 93 return Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object [] { label, className }); 94 } 95 } 96 return label; 97 } 98 99 public Image getImage(Object 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 (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 (element.toString()); 133 134 } else { 135 throw new IllegalArgumentException (String.valueOf(element)); 136 } 137 } 138 139 140 } 141 | Popular Tags |