/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

package demo.editing;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.faces.context.FacesContext;

import ilog.views.gantt.IlvGanttChart;
import ilog.views.gantt.faces.dhtml.component.IlvFacesGanttPropertyAccessor;
import ilog.views.gantt.graphic.IlvTimeIndicator;
import ilog.views.gantt.graphic.timeindicator.IlvFixedTimeIndicator;
import ilog.views.util.styling.IlvStylingException;

/**
 * The bean that contains the logic of the JSF Gantt Chart Editing sample.
 */
public class EditingBean {

  /**
   * The property accessor used to get and set properties of Gantt model
   * elements.
   */
  private IlvFacesGanttPropertyAccessor propertyAccessor = new PropertyAccessor();

  private Date startDate;

  private IlvGanttChart ganttChart;

  /**
   * Creates a <code>EditingBean</code>.
   */
  public EditingBean() {
  }

  // Getters and Setters.

  /**
   * Returns the property accessor used to get and set properties of Gantt model
   * elements.
   * 
   * @return The property accessor.
   */
  public IlvFacesGanttPropertyAccessor getPropertyAccessor() {
    return propertyAccessor;
  }

  public IlvGanttChart getGantt() {
    if (ganttChart == null) {
      ganttChart = new IlvGanttChart();
      FacesContext context = FacesContext.getCurrentInstance();
      URL projectURL;
      try {
        projectURL = context.getExternalContext().getResource("/data/gantt.igpr");
        ganttChart.setProject(projectURL);
        Calendar instance = new GregorianCalendar();
        instance.set(2007, 0, 21);
        IlvTimeIndicator timeIndicator = new IlvFixedTimeIndicator(instance.getTime(), "2007,Jan");
        ganttChart.getGanttSheet().addTimeIndicator(timeIndicator);
      } catch (MalformedURLException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } catch (IlvStylingException e) {
        e.printStackTrace();
      }
    }
    return ganttChart;
  }

  public void setGantt(IlvGanttChart gantt) {
    this.ganttChart = gantt;
  }

  public Date getStartDate() {
    Calendar calendar = new GregorianCalendar();
    calendar.set(2009, 9 - 1, 27);
    this.startDate = calendar.getTime();
    return this.startDate;
  }

  public void setStartDate(Date date) {

  }
}