/**
 * 
 */
package org.richfaces.demo.progressBar;

import java.util.Date;

/**
 * @author Ilya Shaikovsky
 *
 */
public class ProgressBarBean {
	
	private boolean enabled=false;
	private Long startTime;
	
	public ProgressBarBean() {
	}
	
	public String startProcess() {
		setEnabled(true);
		setStartTime(new Date().getTime());
		return null;
	}

	public Long getCurrentValue(){
		if (isEnabled()){
			Long current = (new Date().getTime() - startTime)/1000;
			if (current>100){
				setEnabled(false);
			}else if (current.equals(0)){
				System.out.println("called");
				return new Long(1);
			}
			return (new Date().getTime() - startTime)/1000;
		}else
			return Long.valueOf(-1);
	}
	
	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Long getStartTime() {
		return startTime;
	}

	public void setStartTime(Long startTime) {
		this.startTime = startTime;
	}
}
