protected void assertCanRemoveDynamicWizardPage(IWizardPage page) {
    if (dynamicWizardDialog == null) return;

    IWizardPage currentPage = dynamicWizardDialog.getCurrentPage();
    if (currentPage == null) return;

    if (getPageCount() == 0 && getDynamicWizardPageCount() == 0) {
      throw new IllegalStateException(
          "Cannot remove wizard page! Nothing to remove!"); //$NON-NLS-1$
    }

    IWizardPage pageToCheck = getFirstPage();
    while (pageToCheck != null && pageToCheck != currentPage) {
      if (pageToCheck == page)
        throw new IllegalStateException(
            "Cannot remove page \""
                + page.getName()
                + "\", because it is part of the path BEFORE the current page! Can only remove pages that are following the current page!"); //$NON-NLS-1$ //$NON-NLS-2$
      pageToCheck = pageToCheck.getNextPage();
    }

    if (!dynamicWizardPages.contains(page))
      throw new IllegalStateException(
          "Cannot remove page \""
              + page.getName()
              + "\", because it is not registered as dynamic page! If it is static, you cannot remove it and if it is part of a WizardHop, you must remove it there!"); //$NON-NLS-1$ //$NON-NLS-2$
  }
  @Override
  public boolean canFinish() {
    IWizardPage page = getFirstPage();
    IWizardPage lastPage = null;
    while (page != null) {
      if (!page.isPageComplete()) return false;
      lastPage = page;
      page = page.getNextPage();
      if (lastPage == page)
        throw new IllegalStateException(
            "Page \""
                + page.getName()
                + "\" returned itself as next page!"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    if (!(lastPage instanceof IDynamicPathWizardPage)) return true;
    if (lastPage == null
        || (lastPage instanceof IDynamicPathWizardPage
            && ((IDynamicPathWizardPage) lastPage).canBeLastPage())) return true;
    else return false;

    //		if (!getWizardEntryPage().isPageComplete())
    //		return false;

    //		if (dynamicWizardPages.size() > 0) {
    //		for (int i = 0; i < dynamicWizardPages.size(); i++) {
    //		if (!((IWizardPage) dynamicWizardPages.get(i)).isPageComplete())
    //		return false;
    //		}
    //		return true; // no page is incomplete
    //		}
    //		else {
    //		return true; // only wizardEntryPage matters
    //		}
  }
  /**
   * Test whether a page can be added at the given index.
   *
   * @param index The index to test
   * @throws IllegalStateException if the value of index is illegal
   */
  protected void assertCanInsertDynamicWizardPage(int index) {
    int lastReadOnlyIndex = -1;
    IWizardPage currentPage = dynamicWizardDialog.getCurrentPage();
    if (currentPage == null) return;

    if (getPageCount() == 0 && getDynamicWizardPageCount() == 0) {
      if (index == 0) return;
      else
        throw new IllegalStateException(
            "Cannot add a wizard page at index "
                + index
                + ", it is the first page for this wizard!"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    IWizardPage page = getFirstPage();
    while (page != null && page != currentPage) {
      if (page instanceof IDynamicPathWizardPage) {
        int i = getDynamicWizardPageIndex(page);
        if (i > lastReadOnlyIndex) lastReadOnlyIndex = i;
      }
      page = page.getNextPage();
    }

    if (index <= lastReadOnlyIndex)
      throw new IllegalStateException(
          "Cannot add a wizard page at index "
              + index
              + ", because the current page forces all indices <="
              + lastReadOnlyIndex
              + " to be unchangeable!"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  // CODINGSPECTATOR: Added button as a parameter to the method so that it can tell which one was
  // pressed "next" or "preview".
  private void nextOrPreviewPressed(Button button) {
    // CODINGSPECTATOR: Record the event of pressing the button on the current page.
    fWizard.addNavigationHistoryItem(
        new NavigationHistoryItem(fCurrentPage.getName(), button.getText()));

    IWizardPage current = fCurrentPage;
    saveInitialSize();

    fCurrentPage = fCurrentPage.getNextPage();
    if (current == fCurrentPage) return;
    if (!fHasAdditionalPages && IErrorWizardPage.PAGE_NAME.equals(fCurrentPage.getName())) {
      if (showErrorDialog((ErrorWizardPage) fCurrentPage)) {
        fCurrentPage = fCurrentPage.getNextPage();
      } else {
        return;
      }
    }
    fCurrentPage.setPreviousPage(current);

    showCurrentPage();
  }