Performing Undo and Redo Operations on a Query

The Query object provides the following mechanism for performing undo and redo operations:

Example: Performing an undo or redo for a Query object

This example assumes that the variables in the following table exist.

Variable

Description

m_query

Represents the Query object.

measureList

Represents a list of measure names.

dimensions

Represents an array of dimension layout arrays.

In preparation for performing an undo or a redo, the following code creates an UndoRedoListener that extends the standard QueryListener class.


private class UndoRedoListener extends QueryListener {  public UndoRedoListener(Query m_query) {    super(m_query);  //Called when a new undoable edit is available from the Query object.  public void undoAvailable(UndoAvailableEvent e) {    //Retrieve the undoable edit object.    m_edit = e.getEdit();  }  public void redo() {    if (m_edit != null){        m_edit.redo();      }  } public void undo(){    if (m_edit != null){      m_edit.undo();    }  }  QueryEdit m_edit = null; }

To demonstrate both an undo and a redo operation, the following code initializes a Query object m_query , swaps edges, and then performs an undo operation followed by a redo operation.


//Creates a listener for changes to the Query object m_ql = new UndoRedoListener(m_query); //Adds the listener to the Query object m_query.addQueryListener(m_ql); m_query.initCubeQuery(measureList, dimensions); m_query.swapEdges(DataDirector.PAGE_EDGE, DataDirector.COLUMN_EDGE); //Perform an undo operation (back to the state before //the initCubeQuery call). m_ql.undo(); //Perform a redo operation (to the state after the swapEdges call). m_ql.redo();