package org.gcube.portlets.user.reportgenerator.client.dialog;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;


/**
 * 
 * @author massi
 *
 */
public class TSHeader extends HorizontalPanel {
	
	private CheckBox myCB;
	private HTML myHeader;	
	private int myColNo;
	private FlexTable myTable;
	TimeSeriesFilterDialog caller;
	TSHeader myinstance;

	/**
	 * @param tsf -
	 * @param myTable .
	 * @param cb .
	 * @param myColNo .
	 * @param myHeader .
	 */
	public TSHeader(TimeSeriesFilterDialog tsf, FlexTable myTable, CheckBox cb, int myColNo, HTML myHeader) {
		super();
		myinstance = this;
		caller = tsf;
		this.myTable = myTable;
		this.myCB = cb;
				
		this.myColNo = myColNo;
		this.myHeader = myHeader;
		setVerticalAlignment(ALIGN_MIDDLE);
		myHeader.setStyleName("timeSeries_header_font");
		add(myHeader);
		add(myCB);
		
		myCB.addClickListener(cbListener);
	}
	
	private void removeEmptyHeaders( FlexTable myTable) {
		
		for (int i = 0; i < myTable.getCellCount(0); i++) {
			if (myTable.getWidget(0, i) == null) {
				myTable.removeCell(0, i);
				myTable.removeCell(1, i);
			}
		}
			
	}
	
	ClickListener cbListener = new ClickListener() {
		public void onClick(Widget sender) {	
				caller.removeHeader(myinstance);
				myTable.remove(sender.getParent());		
				removeEmptyHeaders(myTable);
		}				
	};					
	/**
	 * 
	 * @return .
	 */
	public CheckBox getMyCB() {
		return myCB;
	}
	/**
	 * 
	 * @param myCB .
	 */
	public void setMyCB(CheckBox myCB) {
		this.myCB = myCB;
	}
	/**
	 * 
	 * @return . 
	 * 	 */
	public HTML getMyHeader() {
		return myHeader;
	}
	/**
	 * 
	 * @param myHeader .
	 */
	public void setMyHeader(HTML myHeader) {
		this.myHeader = myHeader;
	}
	/**
	 * 
	 * @return .
	 */
	public int getMyColNo() {
		return myColNo;
	}
	
	/**
	 * 
	 * @param myColNo .
	 */
	public void setMyColNo(int myColNo) {
		this.myColNo = myColNo;
	}
	
	
}
