Example usage for org.eclipse.jface.preference IPreferencePage computeSize

List of usage examples for org.eclipse.jface.preference IPreferencePage computeSize

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferencePage computeSize.

Prototype

public Point computeSize();

Source Link

Document

Computes a size for this page's UI component.

Usage

From source file:org.mailster.gui.prefs.ConfigurationDialog.java

License:Open Source License

/**
 * Shows the preference page corresponding to the given preference node.
 * Does nothing if that page is already current. This implementation
 * prevents auto resizing./*from w ww  .  j  a  va2  s  .  c  om*/
 * 
 * @param node the preference node, or <code>null</code> if none
 * @return <code>true</code> if the page flip was successful;
 *         <code>false</code> if unsuccessful
 */
protected boolean showPage(IPreferenceNode node) {
    IPreferencePage currentPage = this.getCurrentPage();
    final Composite pageContainer = this.getPageContainer();

    if (node == null)
        return false;

    // Create the page if nessessary
    if (node.getPage() == null)
        this.createPage(node);

    if (node.getPage() == null)
        return false;

    IPreferencePage newPage = this.getPage(node);
    if (newPage == currentPage)
        return true;

    if (currentPage != null && !currentPage.okToLeave())
        return (false);

    IPreferencePage oldPage = currentPage;
    this.setCurrentPage(newPage);
    currentPage = this.getCurrentPage();
    // Set the new page's container
    currentPage.setContainer(this);

    // Ensure that the page control has been created
    // (this allows lazy page control creation)
    final IPreferencePage curPage = currentPage;
    if (currentPage.getControl() == null) {
        final boolean[] failed = { false };
        SafeRunnable.run(new ISafeRunnable() {
            public void handleException(Throwable e) {
                failed[0] = true;
            }

            public void run() {
                createPageControl(curPage, pageContainer);
            }
        });
        if (failed[0])
            return false;
        // the page is responsible for ensuring the created control is
        // accessable via getControl.
        Assert.isNotNull(currentPage.getControl());
    }

    // Force calculation of the page's description label because
    // label can be wrapped.
    final Point[] size = new Point[1];
    final Point failed = new Point(-1, -1);
    SafeRunnable.run(new ISafeRunnable() {
        public void handleException(Throwable e) {
            size[0] = failed;
        }

        public void run() {
            size[0] = curPage.computeSize();
        }
    });
    if (size[0].equals(failed))
        return false;

    // Do we need resizing. Computation not needed if the
    // first page is inserted since computing the dialog's
    // size is done by calling dialog.open().
    // Also prevent auto resize if the user has manually resized
    if (oldPage != null) {
        Rectangle rect = pageContainer.getClientArea();
        Point containerSize = new Point(rect.width, rect.height);
        // Set the size to be sure we use the result of computeSize
        currentPage.setSize(containerSize);
    }
    // Ensure that all other pages are invisible
    // (including ones that triggered an exception during
    // their creation).
    Control[] children = pageContainer.getChildren();
    Control currentControl = currentPage.getControl();
    for (int i = 0; i < children.length; i++) {
        if (children[i] != currentControl)
            children[i].setVisible(false);
    }
    // Make the new page visible
    currentPage.setVisible(true);
    if (oldPage != null)
        oldPage.setVisible(false);

    // update the dialog controls
    this.update();
    return true;
}