package com.sample.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.HeaderSpan;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class NestedGrid implements EntryPoint {

    /**
     * This is the entry point method.
     */
    @Override
    public void onModuleLoad() {
        final ListGrid tileGrid = new ListGrid() {

            @Override
            protected Canvas getExpansionComponent(final ListGridRecord record) {

                final VLayout layout = new VLayout(5);
                layout.setPadding(5);

                final ListGrid countryGrid = new ListGrid();
                countryGrid.setHeight(224);
                countryGrid.setCellHeight(22);
                countryGrid.setDataSource(ProfileElevDS.getInstance());
                countryGrid.fetchRelatedData(record, ProfileElevDS.getInstance());
                final ListGridField profileId = new ListGridField("profileID", "profileId");
                final ListGridField profileType = new ListGridField("profileType", "profileType");
                final ListGridField side1 = new ListGridField("side1Type", "side1");
                final ListGridField side2 = new ListGridField("side2Type", "side2");
                final ListGridField side3 = new ListGridField("side3Type", "side3");
                countryGrid.setFields(profileId, profileType, side1, side2, side3);
                countryGrid.setHeaderSpans(new HeaderSpan("Sides", new String[] { "side1Type", "side2Type" }));

                layout.addMember(countryGrid);
                return layout;
            }
        };
        tileGrid.setWidth100();
        tileGrid.setHeight100();
        tileGrid.setSelectionType(SelectionStyle.SINGLE);
        tileGrid.setDataSource(ElevationLayoutDS.getInstance());
        final ListGridField elevationId = new ListGridField("elevationID", "elevationId");
        final ListGridField leftSidelite = new ListGridField("leftSidelite", "leftSidelite");
        final ListGridField leftHalfSidelite = new ListGridField("leftHalfSidelite", "leftHalfSidelite");
        final ListGridField leftRows = new ListGridField("leftRows", "leftRows");
        final ListGridField leftColumn = new ListGridField("leftColumns", "leftColumns");
        tileGrid.setFields(elevationId, leftSidelite, leftHalfSidelite, leftRows, leftColumn);
        tileGrid.setAutoFetchData(true);
        tileGrid.setCanFocus(false);
        tileGrid.setCanExpandRecords(true);
        tileGrid.setShowAllRecords(true);

    }
}
