You can download this version of the sample, and an improved version of the component library from here.

This version includes the capability to expand/collapse a hierarchy in the cellset table. An expanded hierarchy initially shows all of its members, and the user can drill-up to hide details. A collapsed hierarchy initially shows only its root members, and the user can drill-down to show further detail.

Expanded Hierarchy: Store Type hierarchy expanded with some undrilled members

I've modified the queryCellSet composite component (and QueryCellSetBean, its associated managed bean) to include a hierarchy expansion button in the header of both cellset axes, allowing the user toggling the expand state for a hierarchy.

This functionality is supported by three methods in the QueryAxis class:

void expandHierarchy(QueryHierarchy h)Expands the hierarchy, invalidating any previous drill/undrill operation on every appearance of h in this axis

void collapseHierarchy(QueryHierarchy h)
Collapses the hierarchy, invalidating any previous drill/undrill operation on every appearance of h in this axis

boolean isExpanded(QueryHierarchy h)
Tests if the provided hierarchy is expanded in this axis.

QueryHierarchy Expression Generation

The strategy to MDX generation for an expanded hierarchy is as follows:

// Processes current member, including or excluding it from the
// expression as necessary.Member currentMember = current.getMember();if (isMemberIncluded) {expression.include(currentMember);if (expander.isDrilled(currentMember, drillList)) {// Current member is included in the hierarchy but collapsed.
// Ends this visit as we should not include any descendant.return;}
}

I'm using an inputHidden control to keep the selected hierarchy name: its value is changed by the inner queryAxisEditorBase controls, responsible for displaying the contents of a single axis. Those controls receive the query bean, the current selected hierarchy name, the client id of the hidden input field and the name of the axis they are displaying. Each axis is displayed using a table:

The axis name and the non-empty toggle button are displayed within the table's header.

Each hierarchy within the axis is displayed in a row with three columns:

A column for the remove button.

A column for the hierarchy's caption. The caption includes javascript to change the selected hierarchy on clicking.

A column for the other action buttons: rows, columns, filter, push up and push down.

Both composite components (queryAxisEditor and queryAxisEditorBase) relay on the QueryAxisEditorBean managed bean to execute actions and simplify facelets.

Required Query Package Improvements

The improvements implemented in the query package have been straightforward and all of them consisted in implementing methods already defined by the org.olap4j.query package:

Query.swapAxes to allow axes swapping

QueryHierarchy.isNonEmpty(), QueryHierarchy.setNonEmpty() to check/set the flag controlling the generation of NON EMPTY axis.

QueryHierarchy.pushUp(), QueryHierarchy.pushDown()to allow moving a hierarchy within an axis.