/**
 * Licensed under the MICE s.r.l.
 * End User License Agreement
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.micegroup.it/voila/license.html
 */
package it.mice.voila.runtime.displaytag.basedec;

import java.math.BigDecimal;

/**
 * Display Column Decorator per la trasformazione dei campi valori con 2 cifre decimali. 
 */
public class ProgressBarDecorator extends Percentage2DecimalDecorator {
    private static final BigDecimal BIG_DECIMAL_100 = new BigDecimal(100);
    private static final BigDecimal BIG_DECIMAL_0 = new BigDecimal(0);

	public ProgressBarDecorator() {
        super();
    }

    public String decorate(Object value) {
    	if (value == null) {
    		return "";
    	}
    	String decoratedValue = super.decorate(value);
    	value = new BigDecimal(value.toString()).multiply(BIG_DECIMAL_100);

    	StringBuffer output = new StringBuffer();
    	output.append("<div class=\"progress\">");
    	output.append("<div class=\"progress-background\" style=\"width: " + value + "%" + "\"></div>");
    	output.append("<div class=\"progress-text\">" + decoratedValue + "</div>");
    	output.append("</div>");
   	
        return output.toString();
    }
}
