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:org.eclipse.linuxtools.systemtap.ui.systemtapgui.ApplicationWorkbenchWindowAdvisor.java

License:Open Source License

/**
* Used to whipe out all eclipses standard preferences.
*//* w  ww. j av  a  2  s  .  c om*/
public void removeExcessPreferences() {
    List l = PlatformUI.getWorkbench().getPreferenceManager().getElements(PreferenceManager.PRE_ORDER);
    String id;
    for (int i = 0; i < l.size(); i++) {
        id = ((PreferenceNode) l.get(i)).getId();
        if (id.startsWith("org.eclipse"))
            PlatformUI.getWorkbench().getPreferenceManager().remove(id);
    }
}

From source file:org.eclipse.objectteams.otdt.debug.ui.internal.preferences.OTDebugPreferencePage.java

License:Open Source License

private void updateStepFilteringPrefPage() {
    List prefs = PlatformUI.getWorkbench().getPreferenceManager().getElements(PreferenceManager.PRE_ORDER);
    for (Iterator iter = prefs.iterator(); iter.hasNext();) {
        PreferenceNode node = (PreferenceNode) iter.next();
        if (node.getId().indexOf(JAVA_STEP_FILTER_PREFERENCE_PAGE) != -1) {
            forcePreferencePageRecreation(node);
        }// w  w w.j a v a2s  .c o m
    }
}

From source file:org.eclipse.oomph.setup.ui.recorder.PreferenceInitializationDialog.java

License:Open Source License

@Override
protected void createUI(Composite parent) {
    final Object root = new Object();

    final Set<String> initializedPreferencePages = RecorderManager.INSTANCE.getInitializedPreferencePages();
    checkboxTreeViewer = new ContainerCheckedTreeViewer(parent, SWT.NONE);
    checkboxTreeViewer.setContentProvider(new ITreeContentProvider() {
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }/*  w w  w.  jav  a 2s.  c o  m*/

        public void dispose() {
        }

        public boolean hasChildren(Object element) {
            return true;
        }

        public Object getParent(Object element) {
            return null;
        }

        public Object[] getElements(Object inputElement) {
            return new Object[] { root };
        }

        public Object[] getChildren(Object parentElement) {
            List<IPreferenceNode> nodes = new ArrayList<IPreferenceNode>();
            if (parentElement == root) {
                nodes.addAll(Arrays.asList(preferenceManager.getRootSubNodes()));
            } else {
                IPreferenceNode preferenceNode = (IPreferenceNode) parentElement;
                nodes.addAll(Arrays.asList(preferenceNode.getSubNodes()));
            }

            return filter(nodes);
        }

        private Object[] filter(List<IPreferenceNode> nodes) {
            for (Iterator<IPreferenceNode> it = nodes.iterator(); it.hasNext();) {
                IPreferenceNode preferenceNode = it.next();
                if (initializedPreferencePages.contains(preferenceNode.getId())
                        && getChildren(preferenceNode).length == 0) {
                    it.remove();
                }
            }

            return nodes.toArray();
        }
    });

    checkboxTreeViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element == root) {
                return "All Pages";
            }

            IPreferenceNode preferenceNode = (IPreferenceNode) element;
            return preferenceNode.getLabelText();
        }
    });

    filteredTree = ReflectUtil.getValue("filteredTree", preferenceDialog);
    final TreeViewer viewer = filteredTree.getViewer();
    checkboxTreeViewer.setComparator(viewer.getComparator());

    checkboxTreeViewer.setInput(preferenceManager);

    checkboxTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

    checkboxTreeViewer.expandAll();

    checkboxTreeViewer.setSubtreeChecked(root, true);

    Set<String> ignoredPreferencePages = RecorderManager.INSTANCE.getIgnoredPreferencePages();
    for (IPreferenceNode preferenceNode : preferenceManager.getElements(PreferenceManager.PRE_ORDER)) {
        if (ignoredPreferencePages.contains(preferenceNode.getId())) {
            checkboxTreeViewer.setChecked(preferenceNode, false);
        }
    }

    showFirstTimeHelp(this);
}

From source file:org.eclipse.oomph.setup.ui.recorder.PreferenceInitializationDialog.java

License:Open Source License

@Override
protected void okPressed() {
    Set<String> initializedOrCheckedPreferencePages = RecorderManager.INSTANCE.getInitializedPreferencePages();
    final Set<String> checkedPreferencePages = new LinkedHashSet<String>();

    Object[] checkedElements = checkboxTreeViewer.getCheckedElements();
    for (Object object : checkedElements) {
        if (object instanceof IPreferenceNode) {
            IPreferenceNode preferenceNode = (IPreferenceNode) object;
            String id = preferenceNode.getId();
            initializedOrCheckedPreferencePages.add(id);
            checkedPreferencePages.add(id);
        }/*from   w  w  w.j a v  a  2s. c om*/
    }

    final Set<String> ignoredPreferencePages = new LinkedHashSet<String>();
    for (IPreferenceNode preferenceNode : preferenceManager.getElements(PreferenceManager.PRE_ORDER)) {
        String id = preferenceNode.getId();
        if (!initializedOrCheckedPreferencePages.contains(id)) {
            ignoredPreferencePages.add(id);
        }
    }

    RecorderManager.INSTANCE.setIgnoredPreferencePages(ignoredPreferencePages);

    super.okPressed();

    if (checkedElements.length == 0) {
        RecorderManager.INSTANCE.disposeInitializeItem();
    } else {
        new Initializer(preferenceDialog, checkedPreferencePages, ignoredPreferencePages).run();
    }
}

From source file:org.eclipse.oomph.setup.ui.recorder.RecorderManager.java

License:Open Source License

private boolean hasPreferencePagesToInitialize(PreferenceManager preferenceManager) {
    Set<String> preferencePages = getInitializedPreferencePages();
    preferencePages.addAll(getIgnoredPreferencePages());
    List<IPreferenceNode> preferenceNodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);
    for (IPreferenceNode element : preferenceNodes) {
        String id = element.getId();
        if (!preferencePages.contains(id)) {
            return true;
        }/* w  w w.j a  va 2s.c o m*/
    }

    return false;
}

From source file:org.eclipse.oomph.setup.ui.recorder.RecorderPreferencePage.java

License:Open Source License

@Override
protected void contributeButtons(Composite parent) {
    initializePreferencesButton = new Button(parent, SWT.PUSH);
    initializePreferencesButton.setText("Initialize...");

    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    Dialog.applyDialogFont(initializePreferencesButton);
    Point minButtonSize = initializePreferencesButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.widthHint = Math.max(widthHint, minButtonSize.x);
    initializePreferencesButton.setLayoutData(data);

    final PreferenceManager preferenceManager = PlatformUI.getWorkbench().getPreferenceManager();
    initializePreferencesButton.addSelectionListener(new SelectionAdapter() {
        @Override//from w  w  w .  j  av  a 2s .  c o m
        public void widgetSelected(SelectionEvent e) {
            new PreferenceInitializationDialog((PreferenceDialog) getContainer(), preferenceManager).open();
        }
    });

    Set<String> preferencePages = RecorderManager.INSTANCE.getInitializedPreferencePages();
    List<IPreferenceNode> preferenceNodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);
    for (IPreferenceNode element : preferenceNodes) {
        String id = element.getId();
        if (preferencePages.contains(id)) {
            initializePreferencesButton.setEnabled(false);
            break;
        }
    }
}

From source file:org.eclipse.php.internal.ui.actions.ConfigurePHPIncludePathAction.java

License:Open Source License

public void run() {
    if (fProject != null) {
        // TODO retrieve the page id via project nature
        PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(getShell(), fProject, null, null,
                null);// w w  w.j  a  v  a 2 s.  c om
        // search for the language specific page
        final List elements = dialog.getPreferenceManager().getElements(PreferenceManager.PRE_ORDER);
        for (Iterator i = elements.iterator(); i.hasNext();) {
            final IPreferenceNode node = (IPreferenceNode) i.next();
            final String nodeId = node.getId();
            if (nodeId.endsWith("IncludepathProperties")) { //$NON-NLS-1$
                // recreate dialog and select page found
                dialog.close();
                dialog = PreferencesUtil.createPropertyDialogOn(getShell(), fProject, nodeId, null, null);
                break;
            }
        }
        dialog.open();
    }
}

From source file:org.eclipse.team.internal.ui.SWTUtils.java

License:Open Source License

/**
 * Get the preference node with pageId.// w w  w . j a  v a2s .  c  o  m
 * 
 * @param pageId
 * @return IPreferenceNode
 */
private static 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;
        }
    }
    return null;
}

From source file:org.eclipse.ui.dialogs.PreferencesUtil.java

License:Open Source License

/**
 * Return all of the properties page contributors for an element.
 * @param element/*from   ww w .  ja v  a 2  s. co m*/
 * @return {@link IPreferenceNode}[]
 * @since 3.4
 */
public static IPreferenceNode[] propertiesContributorsFor(Object element) {
    PropertyPageManager pageManager = new PropertyPageManager();
    if (element == null) {
        return null;
    }
    // load pages for the selection
    // fill the manager with contributions from the matching contributors
    PropertyPageContributorManager.getManager().contribute(pageManager, element);
    // testing if there are pages in the manager
    List pages = pageManager.getElements(PreferenceManager.PRE_ORDER);
    IPreferenceNode[] nodes = new IPreferenceNode[pages.size()];
    pages.toArray(nodes);
    return nodes;
}

From source file:org.eclipse.ui.internal.dialogs.PropertyDialog.java

License:Open Source License

/**
 * Create a new property dialog./*  www . ja v a  2 s  .c om*/
 * 
 * @param shell
 *            the parent shell
 * @param propertyPageId
 *            the property page id
 * @param element
 *            the adaptable element
 * @return the property dialog
 */
public static PropertyDialog createDialogOn(Shell shell, final String propertyPageId, Object element) {

    PropertyPageManager pageManager = new PropertyPageManager();
    String title = "";//$NON-NLS-1$

    if (element == null) {
        return null;
    }
    // load pages for the selection
    // fill the manager with contributions from the matching contributors
    PropertyPageContributorManager.getManager().contribute(pageManager, element);
    // testing if there are pages in the manager
    Iterator pages = pageManager.getElements(PreferenceManager.PRE_ORDER).iterator();
    String name = getName(element);
    if (!pages.hasNext()) {
        MessageDialog.openInformation(shell, WorkbenchMessages.PropertyDialog_messageTitle,
                NLS.bind(WorkbenchMessages.PropertyDialog_noPropertyMessage, name));
        return null;
    }
    title = NLS.bind(WorkbenchMessages.PropertyDialog_propertyMessage, name);
    PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager, new StructuredSelection(element));

    if (propertyPageId != null) {
        propertyDialog.setSelectedNode(propertyPageId);
    }
    propertyDialog.create();

    propertyDialog.getShell().setText(title);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyDialog.getShell(),
            IWorkbenchHelpContextIds.PROPERTY_DIALOG);

    return propertyDialog;

}