public void visitPage(WizardPage page) {
      int idx = _path.indexOf(page);

      WizardPage lastPage = currentPage();
      if (null != lastPage) {
         // update the settings before leaving
         lastPage.updateSettings(getSettings());
      }

      // Buttons status of the new page.
      boolean cancelEnabled = true, previousEnabled = true, nextEnabled = true, finishEnabled = false;

      if (-1 == idx) {
         // new page
         if (null != lastPage) {
            // Save the current statuses
            _cancelStatuses.push(_cancelAction.isEnabled());
            _prevStatuses.push(_prevAction.isEnabled());
            _nextStatuses.push(_nextAction.isEnabled());
            _finishStatuses.push(_finishAction.isEnabled());
         }

         // add back all visited pages
         while (!_visitedPath.isEmpty()) {

            cancelEnabled = _visitedCancelStatuses.pop();
            previousEnabled = _visitedPrevStatuses.pop();
            nextEnabled = _visitedNextStatuses.pop();
            finishEnabled = _visitedFinishStatuses.pop();

            WizardPage visited = _visitedPath.pop();
            getPath().add(visited);

            if (visited == page) {

               // We have found it, use its statuses and exit from while.

               _cancelAction.setEnabled(cancelEnabled);
               setPrevEnabled(previousEnabled);
               setNextEnabled(nextEnabled);
               setFinishEnabled(finishEnabled);

               break;

            } else {

               _cancelStatuses.push(cancelEnabled);
               _prevStatuses.push(previousEnabled);
               _nextStatuses.push(nextEnabled);
               _finishStatuses.push(finishEnabled);

            }

         }

         // If we have never seen the page, we add it to the tail.
         if (currentPage() != page) {
            
            assert _visitedCancelStatuses.isEmpty();
            assert _visitedPrevStatuses.isEmpty();
            assert _visitedNextStatuses.isEmpty();
            assert _visitedFinishStatuses.isEmpty();
            
            getPath().add(page);
         }

         // And we prepare the page of settings for the new page.
         getSettings().newPage(page.getId());

      } else {
         // page is in the path at idx.

         // first, roll back the settings and trim the path:
         for (int i = _path.size() - 1; i > idx; i--) {
            getSettings().rollBack();
            // save visited pages
            _visitedPath.push(_path.remove(i));
            
            // Save current buttons statuses.
            _visitedCancelStatuses.push(_cancelStatuses.pop());
            _visitedPrevStatuses.push(_prevStatuses.pop());
            _visitedNextStatuses.push(_nextStatuses.pop());
            _visitedFinishStatuses.push(_finishStatuses.pop());
            
            // Restore the buttons status.
            cancelEnabled = _cancelStatuses.pop();
            previousEnabled = _prevStatuses.pop();
            nextEnabled = _nextStatuses.pop();
            finishEnabled = _finishStatuses.pop();
         }

         _cancelAction.setEnabled(cancelEnabled);
         setPrevEnabled(previousEnabled);
         setNextEnabled(nextEnabled);
         setFinishEnabled(finishEnabled);

      }

      page.rendering(_path, getSettings());
      _template.setPage(page);
      firePageChanged(page, _path);
   }