package com.oatsystems.raf.smartgwt.client;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceDateTimeField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;

public class TestTimestamp extends VLayout {

    public TestTimestamp() {

        setLayoutMargin(20);
        setHeight100();
        setWidth100();
        setBackgroundColor("#ABBCE1");

        addMember(createGrid());
    }

    private ListGrid createGrid() {
        ListGrid grid = new ListGrid();
        grid.setWidth100();
        grid.setHeight100();
        grid.setShowAllRecords(true);
        
        DataSource dataSource = new DataSource();  
        dataSource.setDataFormat(DSDataFormat.JSON);  
        
        String url = "data/TestTimestampData.js";
        
        dataSource.setDataURL(url);
  
        DataSourceTextField statusField = new DataSourceTextField("status", "Status");
        DataSourceDateTimeField dateTimefield = new DataSourceDateTimeField("dateTime", "Date/Time");
  
        dataSource.setFields(statusField, dateTimefield);  
        
        ListGridField statusLGF = new ListGridField("status", "Status");
        statusLGF.setAlign(Alignment.CENTER);
        ListGridField dateTimeLGF = new ListGridField("dateTime", "Date/Time");
        dateTimeLGF.setAlign(Alignment.CENTER);
        
        grid.setFields(statusLGF, dateTimeLGF);
        
        grid.setDataSource(dataSource);
        grid.setAutoFetchData(true);
        
        return grid;
    }

}
