/*************************************************************************
 * @author Ali Echihabi (ali_echihabi@ieee.org, ali.echihabi@souss.ca)
 *
 * Plugin for PHP unit Testing.
 * www.phpeclipse.de
 * 
 *************************************************************************/


package net.sourceforge.phpeclipse.phpunit;

import net.sourceforge.phpeclipse.phpunit.testpool.TestCase;
import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
 
 
public class TestPoolLabelProvider extends LabelProvider {

	public String getText(Object element) {
		
		String text = "";
		
		if(element instanceof TestSuite) 
			return ((TestSuite)element).getName();
		else if(element instanceof TestCase) {
		
			text = ((TestCase)element).getTestName();
			
			//has the form: TESTSUITENAME_TESTNAME
			
		}
		else
			text = "UNKNOWN ELEMENT TYPE";
		
		return text;
		
	}

	public Image getImage(Object element) {
		
		Image image = null;
		ImageDescriptor descriptor = null;
			
		if(element instanceof TestSuite) {
			
			TestSuite suite = (TestSuite)element;
			descriptor = PHPUnitImages.DESC_TEST_SUITE_PASS;


			if(suite.hasError())
				descriptor = PHPUnitImages.DESC_TEST_SUITE_ERROR;
			else if(suite.hasFailure())
				descriptor = PHPUnitImages.DESC_TEST_SUITE_FAILURE;
			else if(suite.isAllPass())
				descriptor = PHPUnitImages.DESC_TEST_SUITE_PASS;
					
								
		} else if(element instanceof TestCase) {
			
			TestCase test = (TestCase)element;
			
			descriptor = PHPUnitImages.DESC_TEST_PASS;
			
			if(test.isError())
				descriptor = PHPUnitImages.DESC_TEST_ERROR;
			else if(test.isFailure())
				descriptor = PHPUnitImages.DESC_TEST_FAILURE;
			else if(test.isPass())
				descriptor = PHPUnitImages.DESC_TEST_PASS;
					
		}
		
		image = descriptor.createImage();
	
		
		return image;
		
	}

}