package com.psydex.servicemanager.client.panels;



import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.DataArrivedEvent;
import com.smartgwt.client.widgets.grid.events.DataArrivedHandler;

public class ServicesPanel extends ListGrid {

	public ServicesPanel(DataSource servicesDS) {
		
		setDataSource(servicesDS);
		setUseAllDataSourceFields(true);
		setAutoFetchData(true);
		
		ListGridField source = new ListGridField("sourceidentifier","Source");
		ListGridField status = new ListGridField("status","Status");
		ListGridField statusmessage = new ListGridField("statusmessage","Status Message");
		statusmessage.setShowHover(true);
	
		setHoverWidth(300);  
		setHoverHeight(40);  
		setUseCellRollOvers(true);
		setWidth100();
		setHeight100();
		
		
		draw();
	}
	
	
	@Override  
	protected String getBaseStyle(ListGridRecord record, int rowNum, int colNum) {
		String fieldname = getFieldName(colNum);
		 
		 if (getFieldName(colNum).equalsIgnoreCase("status")) {

			 String att = record.getAttribute("status");
			 
			if (record.getAttribute("status").equalsIgnoreCase("online")) {
				 SC.logWarn("SET background  CSS to GREEN");
				return "background-color:green";
			} else {
				 SC.logWarn("SET background CSS to RED");
				return "background-color:red";
			}
		} else {
			 SC.logWarn("SET default base CSS");
			return super.getBaseStyle(record, rowNum, colNum);
		}
		
		
	}
	
	
}
