All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jface.wizard.WizardPage Maven / Gradle / Ivy

There is a newer version: 3.29.0
Show newest version
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.wizard;

import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;

/**
 * An abstract base implementation of a wizard page.
 * 

* Subclasses must implement the createControl method * to create the specific controls for the wizard page. *

*

* Subclasses may call the following methods to configure the wizard page: *

    *
  • setDescription
  • *
  • setErrorMessage
  • *
  • setImageDescriptor
  • *
  • setMessage
  • *
  • setPageComplete
  • *
  • setPreviousPage
  • *
  • setTitle
  • *
*

*

* Subclasses may override these methods if required: *

    *
  • performHelp - may be reimplemented to display help for the page
  • *
  • canFlipToNextPage - may be extended or reimplemented
  • *
  • isPageComplete - may be extended
  • *
  • setDescription - may be extended
  • *
  • setTitle - may be extended
  • *
  • dispose - may be extended to dispose additional allocated SWT resources
  • *
*

*

* Note that clients are free to implement IWizardPage from scratch * instead of subclassing WizardPage. Correct implementations of * IWizardPage will work with any correct implementation of * IWizard. *

*/ public abstract class WizardPage extends DialogPage implements IWizardPage { /** * This page's name. */ private String name; /** * The wizard to which this page belongs; null * if this page has yet to be added to a wizard. */ private IWizard wizard = null; /** * Indicates whether this page is complete. */ private boolean isPageComplete = true; /** * The page that was shown right before this page became visible; * null if none. */ private IWizardPage previousPage = null; /** * Creates a new wizard page with the given name, and * with no title or image. * * @param pageName the name of the page */ protected WizardPage(String pageName) { this(pageName, null, (ImageDescriptor) null); } /** * Creates a new wizard page with the given name, title, and image. * * @param pageName the name of the page * @param title the title for this wizard page, * or null if none * @param titleImage the image descriptor for the title of this wizard page, * or null if none */ protected WizardPage(String pageName, String title, ImageDescriptor titleImage) { super(title, titleImage); Assert.isNotNull(pageName); // page name must not be null name = pageName; } /** * The WizardPage implementation of this IWizardPage * method returns true if this page is complete (isPageComplete) * and there is a next page to flip to. Subclasses may override (extend or reimplement). * * @see #getNextPage * @see #isPageComplete() */ public boolean canFlipToNextPage() { return isPageComplete() && getNextPage() != null; } /** * Returns the wizard container for this wizard page. * * @return the wizard container, or null if this * wizard page has yet to be added to a wizard, or the * wizard has yet to be added to a container */ protected IWizardContainer getContainer() { if (wizard == null) { return null; } return wizard.getContainer(); } /** * Returns the dialog settings for this wizard page. * * @return the dialog settings, or null if none */ protected IDialogSettings getDialogSettings() { if (wizard == null) { return null; } return wizard.getDialogSettings(); } /* (non-Javadoc) * Method declared on IDialogPage. */ public Image getImage() { Image result = super.getImage(); if (result == null && wizard != null) { return wizard.getDefaultPageImage(); } return result; } /* (non-Javadoc) * Method declared on IWizardPage. */ public String getName() { return name; } /* (non-Javadoc) * Method declared on IWizardPage. * The default behavior is to ask the wizard for the next page. */ public IWizardPage getNextPage() { if (wizard == null) { return null; } return wizard.getNextPage(this); } /* (non-Javadoc) * Method declared on IWizardPage. * The default behavior is return the cached previous back or, * lacking that, to ask the wizard for the previous page. */ public IWizardPage getPreviousPage() { if (previousPage != null) { return previousPage; } if (wizard == null) { return null; } return wizard.getPreviousPage(this); } /** * The WizardPage implementation of this method declared on * DialogPage returns the shell of the container. * The advantage of this implementation is that the shell is accessable * once the container is created even though this page's control may not * yet be created. */ public Shell getShell() { IWizardContainer container = getContainer(); if (container == null) { return null; } // Ask the wizard since our contents may not have been created. return container.getShell(); } /* (non-Javadoc) * Method declared on IWizardPage. */ public IWizard getWizard() { return wizard; } /** * Returns whether this page is the current one in the wizard's container. * * @return true if the page is active, * and false otherwise */ protected boolean isCurrentPage() { return (getContainer() != null && this == getContainer() .getCurrentPage()); } /** * The WizardPage implementation of this IWizard method * returns the value of an internal state variable set by * setPageComplete. Subclasses may extend. */ public boolean isPageComplete() { return isPageComplete; } /** * The WizardPage implementation of this IDialogPage * method extends the DialogPage implementation to update * the wizard container title bar. Subclasses may extend. */ public void setDescription(String description) { super.setDescription(description); if (isCurrentPage()) { getContainer().updateTitleBar(); } } /** * The WizardPage implementation of this method * declared on DialogPage updates the container * if this is the current page. */ public void setErrorMessage(String newMessage) { super.setErrorMessage(newMessage); if (isCurrentPage()) { getContainer().updateMessage(); } } /** * The WizardPage implementation of this method * declared on DialogPage updates the container * if this page is the current page. */ public void setImageDescriptor(ImageDescriptor image) { super.setImageDescriptor(image); if (isCurrentPage()) { getContainer().updateTitleBar(); } } /** * The WizardPage implementation of this method * declared on DialogPage updates the container * if this is the current page. */ public void setMessage(String newMessage, int newType) { super.setMessage(newMessage, newType); if (isCurrentPage()) { getContainer().updateMessage(); } } /** * Sets whether this page is complete. *

* This information is typically used by the wizard to decide * when it is okay to move on to the next page or finish up. *

* * @param complete true if this page is complete, and * and false otherwise * @see #isPageComplete() */ public void setPageComplete(boolean complete) { isPageComplete = complete; if (isCurrentPage()) { getContainer().updateButtons(); } } /* (non-Javadoc) * Method declared on IWizardPage. */ public void setPreviousPage(IWizardPage page) { previousPage = page; } /** * The WizardPage implementation of this IDialogPage * method extends the DialogPage implementation to update * the wizard container title bar. Subclasses may extend. */ public void setTitle(String title) { super.setTitle(title); if (isCurrentPage()) { getContainer().updateTitleBar(); } } /* (non-Javadoc) * Method declared on IWizardPage. */ public void setWizard(IWizard newWizard) { wizard = newWizard; } /** * Returns a printable representation of this wizard page suitable * only for debug purposes. */ public String toString() { return name; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy