activepivot

How can I determine a location corresponding to a PivotCell click ?


Lets say a user double click or right click on a pivot cell. How can I determine the location that has been selected ?

For instance, a user may want to select a location to reevaluate its position. Therefore, according to the location, I would need to send the corresponding book/region to the grid.


Solution

  • You can use com.quartetfs.pivot.live.client.drillthrough.impl.DrillthroughExecutor.execute(IPivotDataCell, IMdxSelect, Cube, IMemberHasChildren, IMdxVisitorContext) for this task. This is what Live uses internally for the Drillthrough. This can be done in your IPivotCellContextHandler like this:

    @Override
        public void onPivotCellContext(PivotCellContextEvent event) {
            final IPivotCell pivotCell = event.getPivotCell();
            if(null != pivotCell && pivotCell instanceof IPivotDataCell) {
                //Show the context menu only for pivot-table data
                IPivotDataCell pivotDataCell = (IPivotDataCell) pivotCell;
    
                IMdxSelect select = event.getMdxModelPresenter().getMdxModel().getMdxSelect();
                Cube cube = event.getMdxModelPresenter().getMdxModel().getCube(); 
                FilterDescription fd = locationExtractor.execute(
                        pivotDataCell, 
                        select, 
                        cube, 
                        new MdxModelMemberHasChildren(event.getMdxModelPresenter().getMdxModel()),
                        new DefaultMdxVisitorContext(select, cube)
                    );
    
    // If filter description is too complicated we do not display the menu
                if (fd == null) {
                    //TODO add entry in menu explaining that mdx is too complext to be converted to a location.
                }
                if (fd.getLocations().length != 1) {
                                //TODO handle, this should not happen but should be checked.
                }
    

    And then you can use fd.getLocations[0] for your purposes.