/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mars.helios.heliosweb.client.screen.debug;

import com.google.inject.Singleton;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.cube.CellRecord;
import com.smartgwt.client.widgets.cube.CubeGrid;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.events.ClickHandler;
import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;

/**
 *
 * @author Philippe SCHEFFER <philippe.scheffer@cgi.com>
 */
@Singleton
public class CubeGridDisplay {

    private CubeGrid cubeGrid;
    Menu menu = new Menu();

    public CubeGridDisplay() {

        cubeGrid = new CubeGrid();
        //in order to enable charting, the Drawing module must be present  
        if (SC.hasDrawing()) {
            cubeGrid.setEnableCharting(true);
        }
        cubeGrid.setData(ProductRevenueData.getData());

        cubeGrid.setWidth100();
        cubeGrid.setHeight100();
        cubeGrid.setHideEmptyFacetValues(true);
        cubeGrid.setShowCellContextMenus(true);

      //  cubeGrid.setCanEdit(Boolean.TRUE);

        cubeGrid.setColumnFacets("quarter", "month", "metric");
        cubeGrid.setRowFacets("region", "product");
        final MenuItem dataFill = new MenuItem("show months");
        dataFill.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(MenuItemClickEvent event) {
                CellRecord[] records = cubeGrid.getSelectedCells();
                String months = "";
                for (CellRecord cell : records) {
                    months += cell.getAttribute("month");
                }
                SC.say("selected months : " + months);
            }
        });
                menu.setItems(dataFill);
      //  cubeGrid.setContextMenu(menu);
    }

    public Canvas buildForm() {
        return cubeGrid;
    }
}
