Example usage for org.eclipse.jface.preference IPreferenceNode getPage

List of usage examples for org.eclipse.jface.preference IPreferenceNode getPage

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceNode getPage.

Prototype

public IPreferencePage getPage();

Source Link

Document

Returns the preference page for this node.

Usage

From source file:au.gov.ga.earthsci.common.ui.preferences.LazyPreferenceDialog.java

License:Apache License

@Override
protected void okPressed() {
    SafeRunnable.run(new SafeRunnable() {
        private boolean errorOccurred;

        /*/*from ww w  . j  av a 2 s  .co  m*/
         * (non-Javadoc)
         * 
         * @see org.eclipse.core.runtime.ISafeRunnable#run()
         */
        @Override
        public void run() {
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            errorOccurred = false;
            boolean hasFailedOK = false;
            try {
                // Notify all the pages and give them a chance to abort
                Iterator<?> nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
                while (nodes.hasNext()) {
                    IPreferenceNode node = (IPreferenceNode) nodes.next();
                    IPreferencePage page = node.getPage();
                    if (page != null && pagesWithCreatedControls.contains(page)) {
                        if (!page.performOk()) {
                            hasFailedOK = true;
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(e);
            } finally {
                //Don't bother closing if the OK failed
                if (hasFailedOK) {
                    setReturnCode(FAILED);
                    getButton(IDialogConstants.OK_ID).setEnabled(true);
                    return;
                }

                if (!errorOccurred) {
                    //Give subclasses the choice to save the state of the
                    //preference pages.
                    handleSave();
                }
                setReturnCode(OK);
                close();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
         */
        @Override
        public void handleException(Throwable e) {
            errorOccurred = true;

            Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));

            setSelectedNodePreference(null);
            String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$

            Policy.getStatusHandler().show(new Status(IStatus.ERROR, Policy.JFACE, message, e),
                    JFaceResources.getString("Error")); //$NON-NLS-1$

        }
    });

    if (getReturnCode() == FAILED) {
        return;
    }

    if (workingCopyManager != null) {
        try {
            workingCopyManager.applyChanges();
        } catch (BackingStoreException e) {
            String msg = e.getMessage();
            if (msg == null) {
                msg = WorkbenchMessages.FilteredPreferenceDialog_PreferenceSaveFailed;
            }
            StatusUtil.handleStatus(WorkbenchMessages.PreferencesExportDialog_ErrorDialogTitle + ": " + msg, e, //$NON-NLS-1$
                    StatusManager.SHOW, getShell());
        }
    }

    // Run the update jobs
    Iterator<Job> updateIterator = updateJobs.iterator();
    while (updateIterator.hasNext()) {
        updateIterator.next().schedule();
    }
}

From source file:com.mindquarry.desktop.preferences.dialog.FilteredPreferenceDialog.java

License:Open Source License

/**
 * Save the values specified in the pages.
 * <p>//from w  w  w .  j  a  v a 2  s .c  o  m
 * The default implementation of this framework method saves all pages of
 * type <code>PreferencePage</code> (if their store needs saving and is a
 * <code>PreferenceStore</code>).
 * </p>
 * <p>
 * Subclasses may override.
 * </p>
 */
protected void handleSave() {
    Iterator nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator();
    while (nodes.hasNext()) {
        IPreferenceNode node = (IPreferenceNode) nodes.next();
        IPreferencePage page = node.getPage();
        if (page instanceof PreferencePage) {
            // Save now in case tbe workbench does not shutdown cleanly
            IPreferenceStore store = ((PreferencePage) page).getPreferenceStore();
            if (store != null && store.needsSaving() && store instanceof IPersistentPreferenceStore) {
                try {
                    ((IPersistentPreferenceStore) store).save();
                } catch (IOException e) {
                    MessageDialog.openError(getShell(),
                            JFaceResources.getString("PreferenceDialog.saveErrorTitle"), //$NON-NLS-1$
                            JFaceResources.format("PreferenceDialog.saveErrorMessage", //$NON-NLS-1$
                                    new Object[] { page.getTitle(), e.getMessage() }));
                }
            }
        }
    }
}

From source file:com.mindquarry.desktop.preferences.dialog.FilteredPreferenceDialog.java

License:Open Source License

/**
 * The preference dialog implementation of this <code>Dialog</code>
 * framework method sends <code>performOk</code> to all pages of the
 * preference dialog, then calls <code>handleSave</code> on this dialog to
 * save any state, and then calls <code>close</code> to close this dialog.
 *///  ww  w .j a va 2s.com
@Override
protected void okPressed() {
    SafeRunnable.run(new SafeRunnable() {
        private boolean errorOccurred;

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.core.runtime.ISafeRunnable#run()
         */
        public void run() {
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            errorOccurred = false;
            boolean hasFailedOK = false;
            try {
                // Notify all the pages and give them a chance to abort
                Iterator nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator();
                while (nodes.hasNext()) {
                    IPreferenceNode node = (IPreferenceNode) nodes.next();
                    IPreferencePage page = node.getPage();
                    if (page != null) {
                        if (!page.performOk()) {
                            hasFailedOK = true;
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(e);
            } finally {
                // Don't bother closing if the OK failed
                if (hasFailedOK) {
                    setReturnCode(FAILED);
                    getButton(IDialogConstants.OK_ID).setEnabled(true);
                    return;
                }

                if (!errorOccurred) {
                    // Give subclasses the choice to save the state of the
                    // preference pages.
                    handleSave();
                }
                setReturnCode(OK);
                close();
            }
        }

        /**
         * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
         */
        @Override
        public void handleException(Throwable e) {
            errorOccurred = true;

            log.error(e.toString(), e);
            //Policy.getLog().log(
            //        new Status(IStatus.ERROR, Policy.JFACE, 0,
            //                e.toString(), e));

            clearSelectedNode();
            String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
            MessageDialog.openError(getShell(), JFaceResources.getString("Error"), //$NON-NLS-1$
                    message + ": " + e.toString()); //$NON-NLS-1$

        }
    });
}

From source file:com.mindquarry.desktop.preferences.dialog.FilteredPreferenceDialog.java

License:Open Source License

/**
 * Shows the preference page corresponding to the given preference node.
 * Does nothing if that page is already current.
 * /*from ww  w.  j  a va  2  s. c o  m*/
 * @param node the preference node, or <code>null</code> if none
 * @return <code>true</code> if the page flip was successful, and
 *         <code>false</code> is unsuccessful
 */
protected boolean showPage(IPreferenceNode node) {
    if (node == null) {
        return false;
    }
    // Create the page if nessessary
    if (node.getPage() == null) {
        createPage(node);
    }
    if (node.getPage() == null) {
        return false;
    }
    IPreferencePage newPage = getPage(node);
    if (newPage == currentPage) {
        return true;
    }
    if (currentPage != null) {
        if (!currentPage.okToLeave()) {
            return false;
        }
    }
    IPreferencePage oldPage = currentPage;
    currentPage = newPage;
    // Set the new page's container
    currentPage.setContainer(this);
    // Ensure that the page control has been created
    // (this allows lazy page control creation)
    if (currentPage.getControl() == null) {
        final boolean[] failed = { false };
        SafeRunnable.run(new ISafeRunnable() {
            public void handleException(Throwable e) {
                failed[0] = true;
            }

            public void run() {
                createPageControl(currentPage, 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] = currentPage.computeSize();
        }
    });
    if (size[0].equals(failed)) {
        return false;
    }
    Point contentSize = size[0];
    // 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
    Shell shell = getShell();
    Point shellSize = shell.getSize();
    if (oldPage != null) {
        Rectangle rect = pageContainer.getClientArea();
        Point containerSize = new Point(rect.width, rect.height);
        int hdiff = contentSize.x - containerSize.x;
        int vdiff = contentSize.y - containerSize.y;
        if ((hdiff > 0 || vdiff > 0) && shellSize.equals(lastShellSize)) {
            hdiff = Math.max(0, hdiff);
            vdiff = Math.max(0, vdiff);
            setShellSize(shellSize.x + hdiff, shellSize.y + vdiff);
            lastShellSize = shell.getSize();
            if (currentPage.getControl().getSize().x == 0) {
                currentPage.getControl().setSize(containerSize);
            }

        } else {
            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
    update();
    return true;
}

From source file:com.mindquarry.desktop.preferences.dialog.FilteredPreferenceDialog.java

License:Open Source License

/**
 * Get the page for the node.//from   ww w  . j  ava 2  s  . co  m
 * 
 * @param node
 * @return IPreferencePage
 * 
 * @since 3.1
 */
protected IPreferencePage getPage(IPreferenceNode node) {
    return node.getPage();
}

From source file:net.sourceforge.eclipsetrader.trading.wizards.accounts.AccountSettingsDialog.java

License:Open Source License

protected void okPressed() {
    SafeRunnable.run(new SafeRunnable() {
        private boolean errorOccurred;

        /* (non-Javadoc)
         * @see org.eclipse.core.runtime.ISafeRunnable#run()
         *///from w  w  w.j a  v  a  2  s.co m
        public void run() {
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            errorOccurred = false;
            boolean hasFailedOK = false;
            try {
                // Notify all the pages and give them a chance to abort
                Iterator nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
                while (nodes.hasNext()) {
                    IPreferenceNode node = (IPreferenceNode) nodes.next();
                    IPreferencePage page = node.getPage();
                    if (page != null && page.getControl() != null) {
                        if (!page.performOk()) {
                            hasFailedOK = true;
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(e);
            } finally {
                //Don't bother closing if the OK failed
                if (hasFailedOK)
                    return;

                if (!errorOccurred)
                    //Give subclasses the choice to save the state of the
                    //preference pages.
                    handleSave();

                close();
            }
        }

        /* (non-Javadoc)
         * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
         */
        public void handleException(Throwable e) {
            errorOccurred = true;

            Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));

            setSelectedNodePreference(null);
            String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
            MessageDialog.openError(getShell(), JFaceResources.getString("Error"), message); //$NON-NLS-1$

        }
    });
}

From source file:org.bonitasoft.studio.preferences.dialog.BonitaPreferenceDialog.java

License:Open Source License

protected void openPreferencePage(String pageId) {

    IPreferenceNode node = PreferenceUtil.findNodeMatching(pageId);
    IPreferencePage p = node.getPage();
    if (p != null) {
        node.disposeResources();/*from   w ww  .  j a va2 s . com*/
    }
    node.createPage();

    for (Control c : preferencePageComposite.getChildren()) {
        c.dispose();
    }

    preferencePageComposite.pack(true);

    if (pageId.equals(JAVA_PAGE_ID)) {
        Composite parent = new Composite(preferencePageComposite, SWT.NONE);
        GridLayout gl = new GridLayout(1, false);
        gl.verticalSpacing = 0;
        gl.marginHeight = 0;
        gl.marginTop = 0;
        parent.setLayout(gl);
        createTitleBar(parent, Messages.BonitaPreferenceDialog_Java,
                Pics.getImage(PicsConstants.preferenceJava));
        node.getPage().createControl(parent);
        applyOnBack.add(node.getPage());
    } else if (pageId.equals(WEB_BROWSER_PAGE_ID)) {
        Composite parent = new Composite(preferencePageComposite, SWT.NONE);

        GridLayout gl = new GridLayout(1, false);
        gl.verticalSpacing = 0;
        gl.marginHeight = 0;
        gl.marginTop = 0;
        parent.setLayout(gl);

        createTitleBar(parent, Messages.BonitaPreferenceDialog_Browser,
                Pics.getImage(PicsConstants.preferenceWeb));
        Composite fillComposite = new Composite(parent, SWT.NONE);
        fillComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
        fillComposite.setLayout(new FillLayout());
        node.getPage().createControl(fillComposite);
    } else if (pageId.equals(PROXY_PAGE_ID)) {
        Composite parent = new Composite(preferencePageComposite, SWT.NONE);
        GridLayout gl = new GridLayout(1, false);
        gl.verticalSpacing = 0;
        gl.marginHeight = 0;
        gl.marginTop = 0;
        parent.setLayout(gl);

        createTitleBar(parent, Messages.BonitaPreferenceDialog_Proxy,
                Pics.getImage(PicsConstants.preferenceProxy));
        Composite fillComposite = new Composite(parent, SWT.NONE);
        fillComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
        fillComposite.setLayout(new FillLayout());
        node.getPage().createControl(fillComposite);
    } else {
        node.getPage().createControl(preferencePageComposite);
    }

    stack.topControl = preferencePageComposite;
    mainComposite.layout();
    btnDisplay.setEnabled(true);
    updateShellSize(false);
}

From source file:org.eclipse.birt.report.designer.ui.dialogs.StyleBuilder.java

License:Open Source License

private void saveAll(final boolean closeDialog) {
    SafeRunner.run(new SafeRunnable() {

        private boolean errorOccurred;

        private boolean invalid;

        public void run() {
            errorOccurred = false;//from  ww  w .java 2s .c  o  m
            invalid = false;
            try {
                // Notify all the pages and give them a chance to abort
                Iterator nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
                while (nodes.hasNext()) {
                    IPreferenceNode node = (IPreferenceNode) nodes.next();
                    IPreferencePage page = node.getPage();
                    if (page != null) {
                        if (!page.performOk()) {
                            invalid = true;
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(e);
            } finally {
                // Give subclasses the choice to save the state of the
                // preference pages.
                if (!errorOccurred) {
                    handleSave();
                }

                // Need to restore state
                if (!invalid && closeDialog) {
                    close();
                }

            }
        }

        public void handleException(Throwable e) {
            errorOccurred = true;
            if (Platform.isRunning()) {
                String bundle = Platform.PI_RUNTIME;
                Platform.getLog(Platform.getBundle(bundle))
                        .log(new Status(IStatus.ERROR, bundle, 0, e.toString(), e));
            } else {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }

            setSelectedNodePreference(null);
            String message = ""; //$NON-NLS-1$
            MessageDialog.openError(getShell(), "", message); //$NON-NLS-1$

        }
    });

}

From source file:org.eclipse.bpmn2.modeler.ui.preferences.Bpmn2HomePreferencePage.java

License:Open Source License

public static IPreferencePage getPage(IPreferencePageContainer container, String nodeId) {
    PreferenceDialog pd = (PreferenceDialog) container;
    PreferenceManager pm = pd.getPreferenceManager();

    List nodes = pm.getElements(PreferenceManager.POST_ORDER);
    for (Iterator i = nodes.iterator(); i.hasNext();) {
        IPreferenceNode node = (IPreferenceNode) i.next();
        if (node.getId().equals(nodeId)) {
            return node.getPage();
        }//from   w w w.j  a  v a2 s  .  com
    }
    return null;
}

From source file:org.eclipse.datatools.connectivity.internal.ui.ProfileUIManager.java

License:Open Source License

/**
 * Creates a new property page contribution of the specified connection profile.
 * @param profile   a connection profile
 * @return  the profile property page//from   w  w  w.j a  v  a 2 s  .  co  m
 */
public static ProfilePropertyPage createPropertyPage(IConnectionProfile profile) {
    IPreferenceNode[] nodes = PreferencesUtil.propertiesContributorsFor(profile);

    for (int i = 0; i < nodes.length; i++) {
        IPreferenceNode pageNode = nodes[i];
        IPreferencePage propPage = pageNode.getPage();
        if (propPage == null) // page is not created yet
        {
            pageNode.createPage();
            propPage = pageNode.getPage();
        }

        if (!(propPage instanceof ProfilePropertyPage)) {
            if (propPage != null)
                pageNode.disposeResources();
            continue; // try the next page contribution node
        }

        return (ProfilePropertyPage) propPage;
    }

    return null;
}