/*
 * ====================================================================
 * This software is subject to the terms of the Common Public License
 * Agreement, available at the following URL:
 *   http://www.opensource.org/licenses/cpl.html .
 * You must accept the terms of that agreement to use this software.
 * ====================================================================
 */
package org.pivot4j.ui.command;

import org.olap4j.CellSet;
import org.olap4j.CellSetAxis;
import org.olap4j.Position;
import org.pivot4j.PivotModel;
import org.pivot4j.sort.SortMode;
import org.pivot4j.ui.PivotRenderer;

public class ToggleSortCommand extends AbstractSortCommand {

	public static final String NAME = "sort";

	/**
	 * @param renderer
	 */
	public ToggleSortCommand(PivotRenderer<?> renderer) {
		super(renderer);
	}

	/**
	 * @see org.pivot4j.ui.command.UICommand#getName()
	 */
	@Override
	public String getName() {
		return NAME;
	}

	/**
	 * @see org.pivot4j.ui.command.UICommand#execute(org.pivot4j.PivotModel
	 *      , org.pivot4j.ui.command.UICommandParameters)
	 */
	@Override
	public Void execute(PivotModel model, UICommandParameters parameters) {
		CellSet cellSet = model.getCellSet();

		CellSetAxis axis = cellSet.getAxes().get(parameters.getAxisOrdinal());
		CellSetAxis otherAxis = cellSet.getAxes().get(
				Math.abs(parameters.getAxisOrdinal() - 1));

		Position position = axis.getPositions().get(
				parameters.getPositionOrdinal());

		SortMode mode = getRenderer().getSortMode();

		if (mode != null) {
			mode.toggleSort(model);
		}

		model.sort(otherAxis, position);

		return null;
	}
}

@@ -564,16 +564,55 @@
 rtMode;%0A
+import org.pivot4j.transform.SwapAxes;%0A
 import o
@@ -640,16 +640,16 @@
 nderer;%0A
-
 %0Apublic 
@@ -1051,16 +1051,18 @@
 votModel
+ ,
 %0A%09 *    
@@ -1062,18 +1062,16 @@
 %09 *     
- ,
  org.piv
@@ -1355,24 +1355,24 @@
 Axes().get(%0A
-
 %09%09%09%09Math.abs
@@ -1408,16 +1408,183 @@
 - 1));%0A%0A
+%09%09SwapAxes transform = model.getTransform(SwapAxes.class);%0A%0A%09%09if (transform.isSwapAxes()) %7B%0A%09%09%09CellSetAxis temp = axis;%0A%09%09%09axis = otherAxis;%0A%09%09%09otherAxis = temp;%0A%09%09%7D%0A%0A
 %09%09Positi

Fix #148: Sort + Swap Axes Combination