package com.utilinc.planner.gwt.web.client;

import java.util.ArrayList;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

/*
 * CSS
 *    .borderedCell {
 *    border: 1px solid #ebebeb !important;
 *    }
 * 
 */
public class TestModule implements EntryPoint
{
    private static String[][] cellValues = new String[][] { { "BSOW9CCC-Grid Configurations", "7,545 " },
            { "BSOW9CCC-Projects Configuration", "67,655 " }, { "BSOW9CCC-Reporting", "9,545 " },
            { "BUD66CCC-BGRID - Budget Grid Configuration", }, { "BUD66CCC-DESGN - Design Docs", "646,555 " },
            { "BUD66CCC-DOCUM - Documentation (User Manual; Admin Manual)", "6,555 " },
            { "BUD66CCC-INFRA - Hardware Infrastructure (Servers; Database Setup)", "69,455 " },
            { "BUD66CCC-INTXX - Interfaces (General)", "45,555 " }, { "BUD66CCC-LABOR - Babor Screen/Calc", "4,655 " },
            { "BUD66CCC-LDGS - Live (Grid) Loadings", "46,555 " }, { "BUD66CCC-MERGE - Merge Actuals", "66,955 " },
            { "BUD66CCC-PMGMT - Project Management", "49,955 " },
            { "BUD66CCC-PSPPT - Product Support (Code/WAR Files; New Releases)", "64,555 " },
            { "BUD66CCC-RPRTS - Creation of B4ii Pivot Reports", "9,555 " },
            { "BUD66CCC-UTEST - Unit Testing", "65,555 " }, { "Design Documentation Support", "665,455 " },
            { "Integration/Interface Configuration", "65,545 " }, { "Labor Configuration", "7,545 " },
            { "BSOW9CCC-Grid Configurations", "7,545 " }, { "BSOW9CCC-Projects Configuration", "67,655 " },
            { "BSOW9CCC-Reporting", "9,545 " }, { "BUD66CCC-BGRID - Budget Grid Configuration", },
            { "BUD66CCC-DESGN - Design Docs", "646,555 " },
            { "BUD66CCC-DOCUM - Documentation (User Manual; Admin Manual)", "6,555 " },
            { "BUD66CCC-INFRA - Hardware Infrastructure (Servers; Database Setup)", "69,455 " },
            { "BUD66CCC-INTXX - Interfaces (General)", "45,555 " }, { "BUD66CCC-LABOR - Babor Screen/Calc", "4,655 " },
            { "BUD66CCC-LDGS - Live (Grid) Loadings", "46,555 " }, { "BUD66CCC-MERGE - Merge Actuals", "66,955 " },
            { "BUD66CCC-PMGMT - Project Management", "49,955 " },
            { "BUD66CCC-PSPPT - Product Support (Code/WAR Files; New Releases)", "64,555 " },
            { "BUD66CCC-RPRTS - Creation of B4ii Pivot Reports", "9,555 " },
            { "BUD66CCC-UTEST - Unit Testing", "65,555 " }, { "Design Documentation Support", "665,455 " },
            { "Integration/Interface Configuration", "65,545 " }, { "Labor Configuration", "7,545 " },
            { "BSOW9CCC-Grid Configurations", "7,545 " }, { "BSOW9CCC-Projects Configuration", "67,655 " },
            { "BSOW9CCC-Reporting", "9,545 " }, { "BUD66CCC-BGRID - Budget Grid Configuration", },
            { "BUD66CCC-DESGN - Design Docs", "646,555 " },
            { "BUD66CCC-DOCUM - Documentation (User Manual; Admin Manual)", "6,555 " },
            { "BUD66CCC-INFRA - Hardware Infrastructure (Servers; Database Setup)", "69,455 " },
            { "BUD66CCC-INTXX - Interfaces (General)", "45,555 " }, { "BUD66CCC-LABOR - Babor Screen/Calc", "4,655 " },
            { "BUD66CCC-LDGS - Live (Grid) Loadings", "46,555 " }, { "BUD66CCC-MERGE - Merge Actuals", "66,955 " },
            { "BUD66CCC-PMGMT - Project Management", "49,955 " },
            { "BUD66CCC-PSPPT - Product Support (Code/WAR Files; New Releases)", "64,555 " },
            { "BUD66CCC-RPRTS - Creation of B4ii Pivot Reports", "9,555 " },
            { "BUD66CCC-UTEST - Unit Testing", "65,555 " }, { "Design Documentation Support", "665,455 " },
            { "Integration/Interface Configuration", "65,545 " }, { "Labor Configuration", "7,545 " } };

    public void onModuleLoad()
    {
        RootPanel root = RootPanel.get("content");
        root.add(getMainPanel());
    }

    public Panel getMainPanel()
    {
        ListGrid grid = new ListGrid()
        {
            protected String getCellStyle(ListGridRecord record, int row, int column)
            {
                String sup = super.getCellStyle(record, row, column);
                return "borderedCell " + sup;
            }
        };
        ListGridField frozenField = new ListGridField("frozen");
        frozenField.setFrozen(true);
        frozenField.setMaxWidth(200);
        ListGridField unfrozenField = new ListGridField("unfrozen");
        unfrozenField.setMinWidth(80);

        grid.setWrapCells(true);
        grid.setFixedRecordHeights(false);
        grid.setFields(frozenField, unfrozenField);

        ArrayList<TestRecord> records = new ArrayList<TestRecord>();
        for (String[] row : cellValues)
        {
            TestRecord record = new TestRecord(row);
            records.add(record);
        }
        grid.setRecords(records.toArray(new ListGridRecord[0]));
        grid.setHeight("75%");
        grid.setWidth("98%");

        FlowPanel panel = new FlowPanel();
        panel.setHeight("100%");
        panel.setWidth("100%");
        panel.add(grid);
        return panel;
    }

    private class TestRecord extends ListGridRecord
    {
        public TestRecord(String[] values)
        {
            this.setAttribute("frozen", values[0]);
            this.setAttribute("unfrozen", values[1]);
        }
    }

}
