Example usage for org.eclipse.jface.preference PreferenceManager PRE_ORDER

List of usage examples for org.eclipse.jface.preference PreferenceManager PRE_ORDER

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceManager PRE_ORDER.

Prototype

int PRE_ORDER

To view the source code for org.eclipse.jface.preference PreferenceManager PRE_ORDER.

Click Source Link

Document

Pre-order traversal means visit the root first, then the children.

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;

        /*/*  w  w  w. jav  a2 s.com*/
         * (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:au.gov.ga.earthsci.common.ui.preferences.LazyPreferenceDialog.java

License:Apache License

@Override
protected void cancelPressed() {
    // Inform all pages that we are cancelling
    Iterator<?> nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
    final boolean[] cancelOK = new boolean[] { true };
    while (nodes.hasNext()) {
        final IPreferenceNode node = (IPreferenceNode) nodes.next();
        final IPreferencePage page = getPage(node);
        if (page != null && pagesWithCreatedControls.contains(page)) {
            SafeRunnable.run(new SafeRunnable() {
                @Override/*from w  w  w  .  j a va  2s.  c  o m*/
                public void run() {
                    if (!page.performCancel()) {
                        cancelOK[0] = false;
                    }
                }
            });
            if (!cancelOK[0]) {
                return;
            }
        }
    }

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

    setReturnCode(CANCEL);
    close();
}

From source file:com.aptana.formatter.ui.dialogs.PropertyLinkArea.java

License:Open Source License

@SuppressWarnings("rawtypes")
private IPreferenceNode getPreferenceNode(String pageId) {
    /*//from   ww w.j  av  a  2s.  com
     * code pulled from org.eclipse.ui.internal.dialogs.PropertyDialog - i'm not sure why this type of class doesn't
     * already exist for property pages like it does for preference pages since it seems it would be very useful -
     * guess we're breaking new ground :)
     */
    PropertyPageManager pageManager = new PropertyPageManager();
    PropertyPageContributorManager.getManager().contribute(pageManager, element);

    Iterator pages = pageManager.getElements(PreferenceManager.PRE_ORDER).iterator();

    while (pages.hasNext()) {
        IPreferenceNode node = (IPreferenceNode) pages.next();
        if (node.getId().equals(pageId)) {
            return node;
        }
    }

    return null;
}

From source file:com.aptana.formatter.ui.dialogs.PropToPrefLinkArea.java

License:Open Source License

@SuppressWarnings("rawtypes")
private IPreferenceNode getPreferenceNode(String pageId) {
    Iterator iterator = PlatformUI.getWorkbench().getPreferenceManager()
            .getElements(PreferenceManager.PRE_ORDER).iterator();
    while (iterator.hasNext()) {
        IPreferenceNode next = (IPreferenceNode) iterator.next();
        if (next.getId().equals(pageId)) {
            return next;
        }/*  w  ww . j a  v  a 2 s .c om*/
    }
    return null;
}

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

License:Open Source License

@Override
protected void cancelPressed() {
    // Inform all pages that we are cancelling
    Iterator nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator();
    while (nodes.hasNext()) {
        final IPreferenceNode node = (IPreferenceNode) nodes.next();
        if (getPage(node) != null) {
            SafeRunnable.run(new SafeRunnable() {
                public void run() {
                    if (!getPage(node).performCancel()) {
                        return;
                    }//from  w ww.jav a  2s  .c o m
                }
            });
        }
    }
    setReturnCode(CANCEL);
    close();
}

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

License:Open Source License

@Override
public boolean close() {
    List nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);
    for (int i = 0; i < nodes.size(); i++) {
        IPreferenceNode node = (IPreferenceNode) nodes.get(i);
        node.disposeResources();/*from  w ww  .j  av a  2  s  .  com*/
    }
    return super.close();
}

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

License:Open Source License

/**
 * Save the values specified in the pages.
 * <p>/* ww w .j av a 2  s .co 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.
 *///from  ww  w  .j a  v a  2 s.co  m
@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.motorola.studio.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Open the preference page with the specified ID
 * @param nodeID the id of preference page to show
 *///from  ww  w .j  av  a 2s  . c  o  m
@SuppressWarnings("unchecked")
public static void openPreference(Shell shell, String nodeID) {
    // Makes the network preferences dialog manager
    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode networkNode = null;
    for (IPreferenceNode node : (List<IPreferenceNode>) manager.getElements(PreferenceManager.PRE_ORDER)) {
        if (node.getId().equals(nodeID)) {
            networkNode = node;
            break;
        }
    }
    PreferenceManager prefMan = new PreferenceManager();
    if (networkNode != null) {
        prefMan.addToRoot(networkNode);
    }
    PreferenceDialog preferencesDialog = new WorkbenchPreferenceDialog(shell, prefMan);
    preferencesDialog.create();
    preferencesDialog.open();
}

From source file:com.motorola.studio.android.emulator.device.ui.PropertiesMainComposite.java

License:Apache License

@SuppressWarnings("unchecked")
protected void openNetworkPreferences() {
    // Makes the network preferences dialog manager
    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode networkNode = null;//from   www. j av  a2 s. c  o m
    for (IPreferenceNode node : (List<IPreferenceNode>) manager.getElements(PreferenceManager.PRE_ORDER)) {
        if (node.getId().equals(ORG_ECLIPSE_UI_NET_NET_PREFERENCES)) {
            networkNode = node;
            break;
        }
    }
    PreferenceManager prefMan = new PreferenceManager();
    if (networkNode != null) {
        prefMan.addToRoot(networkNode);
    }
    PreferenceDialog networkPreferencesDialog = new WorkbenchPreferenceDialog(getShell(), prefMan);
    networkPreferencesDialog.create();
    networkPreferencesDialog.open();
}