package com.tandbergtv.workflow.web.table;

import java.io.Serializable;
import java.util.HashMap;

/**
 * This class is an Object wrapper for an html table column
 * 
 * @author Rao
 */
public class Column implements Serializable {

	private static final long serialVersionUID = 1L;

	private HashMap<String, String> columnAttributesMap = new HashMap<String,String>();

	public String getColumnAttribute(String key) {
		return columnAttributesMap.get(key);
	}

	
	public void setColumnAttribute(String key, String value) {
		columnAttributesMap.put(key, value);
	}

	public HashMap<String,String> getColumnAttributesMap() {
		return columnAttributesMap;
	}

	public void setColumnAttributesMap(HashMap<String,String> columnAttributesMap) {
		this.columnAttributesMap = columnAttributesMap;
	}

	public String getMethodName() {
		return getColumnAttribute("MethodName");
	}
	
	public String getWidth() {
		return getColumnAttribute("Width");
	}
	
	public String getColumnName() {
		return getColumnAttribute("ColumnName");
	}
	
	public String getParameter() {
		return getColumnAttribute("ParmValue");
	}
	
	public String getSortingColumnName() {
		return getColumnAttribute("SortingColumnName");
	}
	
	public boolean getIsCheckBox() {
		return "check".equals(getColumnName());
	}
	
	public boolean getIsUrl() {
		return (getColumnAttribute("Url") != null);
	}
	
	public String getUrl() {
		return getColumnAttribute("Url");
	}
	
	public boolean getIsUrlProperty() {
		return (getColumnAttribute("UrlProperty") != null);
	}
	
	public String getUrlProperty() {
		return getColumnAttribute("UrlProperty");
	}
	
	public boolean getIsCollection() {
		return (getColumnAttribute("Collection") != null);
	}
	
	public String getCollection() {
		return getColumnAttribute("Collection");
	}
	
	public String getSortingProperty() {
		return getColumnAttribute("SortingProperty");
	}
	
	public String getTitleSection() {
		String sectionName = getColumnAttribute("TitleSection");
		return sectionName == null ? "" : sectionName;
	}

	/**
	 * Property indicating that the column name is a Resource to be read from a bundle
	 * 
	 * @return true if name must be read from a bundle, false otherwise
	 */
	public boolean getIsResource() {
		String value = getColumnAttribute("IsResource");
		boolean isResource = true;
		if (value != null && value.trim().length() > 0)
			isResource = Boolean.parseBoolean(value);
		return isResource; 
	}
	
	public String getPermission() {
		String permission = getColumnAttribute("Permission");
		return permission == null ? "" : permission;
	}
	
	public boolean isSelectedByDefault() {
		return Boolean.valueOf(getColumnAttribute("isSelectedByDefault"));
	}
	
	public boolean isMultiValued() {
		return Boolean.valueOf(getColumnAttribute("isMultiValued"));
	}
}
