package com.sncorp.gs2.ui.client.gsmc.component.mission.activityschedule.chart;

import com.smartgwt.client.types.TimeDisplayFormat;
import com.smartgwt.client.types.TimeUnit;
import com.smartgwt.client.util.DateUtil;
import com.smartgwt.client.util.LogicalDate;
import com.smartgwt.client.util.LogicalTime;
import com.smartgwt.client.widgets.calendar.HeaderLevel;
import com.smartgwt.client.widgets.calendar.Lane;
import com.smartgwt.client.widgets.calendar.Timeline;
import com.smartgwt.client.widgets.layout.VLayout;
import com.sncorp.gs2.ui.client.common.GSUI;

import java.util.Date;

/**
 * User: jp1263
 * Date: 4/16/13
 * Time: 10:19 AM
 */
public class Gantt2 extends VLayout {

    private final Timeline timeline;

    public Gantt2() {
        setWidth100();
        setHeight100();
        timeline = new Timeline();
        timeline.setWidth100();
        timeline.setHeight100();
        timeline.setDataSource(GSUI.getVideoStreamDS());
        timeline.setAutoFetchData(true);
        timeline.setAutoFetchData(true);
        timeline.setNameField("videoStreamName");
        timeline.setDescriptionField("description");
        timeline.setStartDateField("startTime");
        timeline.setEndDateField("stopTime");
        timeline.setLaneNameField("streamCategory");
        timeline.setLanes(new Lane("VIDEO_STREAM_LIVE", "Live Streams"), new Lane("CHIPOUT", "Chipout"));
        timeline.setShowControlsBar(true);
        timeline.setCanDragEvents(true);
        timeline.setCanResizeTimelineEvents(true);
        LogicalDate startLD = DateUtil.getLogicalDateOnly(new Date());
        LogicalTime startLT = DateUtil.createLogicalTime(startLD.getTimezoneOffset() / 60,0,0,0);
        Date start = DateUtil.combineLogicalDateAndTime(startLD, startLT);
        Date end = new Date(start.getTime() + 24 * 60 * 60 * 1000);
        timeline.setStartDate(start);
        timeline.setEndDate(end);
        HeaderLevel[] levels = new HeaderLevel[]{
                new HeaderLevel(TimeUnit.DAY),
                new HeaderLevel(TimeUnit.HOUR)
        };
        timeline.setHeaderLevels(levels);
        timeline.setCanDragEvents(true);
        timeline.setCanDragResize(true);
        timeline.setTimeFormatter(TimeDisplayFormat.TO24HOURTIME);
        addMember(timeline);
    }
}
