package com.smartgwt.test.client;

import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.data.AdvancedCriteria;
import com.smartgwt.client.data.Criterion;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.types.OperatorId;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;

public class TreeGridExample {
    public static void example() {
        TreeGrid treeGrid = new TreeGrid();
        treeGrid.setWidth(870);
        treeGrid.setHeight(870);
        treeGrid.setDataSource(DataSource.get("wm_dim_field_bkp2"));
        treeGrid.setAutoFetchData(true);
        treeGrid.setLoadDataOnDemand(false);

        AdvancedCriteria crit = new AdvancedCriteria();
        crit.addCriteria(new Criterion("LOC_REGION", OperatorId.EQUALS, "Southern Asia"));
       /* crit.addCriteria(new Criterion("select_clause", OperatorId.EQUALS, "distinct("+stepName+"),"+ id+","+ parentId, group_level));*/
        /*
         * crit.addCriteria(new Criterion("FIELD_PARENT_ID", OperatorId.NOT_NULL));
         */// crit.addCriteria(new Criterion("dim_field_id", OperatorId.GREATER_THAN, "0"));
        crit.addCriteria(new Criterion(
                "group_by",
                OperatorId.EQUALS,
                "FIELD_PARENT_ID,field_name,dim_field_id,group_level , NET_WI_RES_COMM_REM_LIQ,NET_WI_RES_REM_GAS, NET_WI_RES_TECH_REM_GAS, OIL_RECOVERY_FACTOR"));
        treeGrid.setFetchOperation("Linear");
        TreeGridField stepName = new TreeGridField("field_name", "field_naameh");
        TreeGridField id = new TreeGridField("dim_field_id");
         TreeGridField NET_WI_RES_REM_GAS = new TreeGridField("NET_WI_RES_REM_GAS");
        TreeGridField NET_WI_RES_TECH_REM_GAS = new TreeGridField("NET_WI_RES_TECH_REM_GAS");
        TreeGridField OIL_RECOVERY_FACTOR = new TreeGridField("OIL_RECOVERY_FACTOR");
        TreeGridField parentId = new TreeGridField("FIELD_PARENT_ID");

        TreeGridField group_level = new TreeGridField("group_level");

        crit.addCriteria(new Criterion("select_clause", OperatorId.EQUALS, "distinct(field_name), dim_field_id, FIELD_PARENT_ID, group_level , NET_WI_RES_COMM_REM_LIQ,NET_WI_RES_REM_GAS, NET_WI_RES_TECH_REM_GAS, OIL_RECOVERY_FACTOR"));
        treeGrid.setFields(stepName, id, parentId, group_level, NET_WI_RES_REM_GAS, NET_WI_RES_TECH_REM_GAS, OIL_RECOVERY_FACTOR);
    SortSpecifier sample= new SortSpecifier("group_level", SortDirection.ASCENDING);
    SortSpecifier sample2= new SortSpecifier("field_name", SortDirection.ASCENDING);
        SortSpecifier[] arrey= new SortSpecifier[2];
        arrey[0]=sample;
        arrey[1]=sample2;
        treeGrid.setSort(arrey);
        treeGrid.setShowFilterEditor(true);
        treeGrid.setCriteria(crit);
        RootPanel.get().add(treeGrid);
    }

}
