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

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

Introduction

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

Prototype

public List<IPreferenceNode> getElements(int order) 

Source Link

Document

Returns all preference nodes managed by this manager.

Usage

From source file:au.gov.ga.earthsci.application.preferences.PreferenceUtil.java

License:Apache License

private static IPreferenceNode findNode(PreferenceManager pm, String categoryId) {
    for (Object o : pm.getElements(PreferenceManager.POST_ORDER)) {
        if (o instanceof IPreferenceNode && ((IPreferenceNode) o).getId().equals(categoryId)) {
            return (IPreferenceNode) o;
        }/*  w  ww . ja  v a 2s.  c om*/
    }
    return null;
}

From source file:com.aptana.ui.preferences.GenericRootPreferencePage.java

License:Open Source License

/**
 * Creates the links.//ww  w  . ja va  2  s . c o m
 */
@SuppressWarnings({ "unchecked" })
protected Control createContents(Composite parent) {
    // pageNameToId = null
    if (pageNameToId == null) {
        pageNameToId = new HashMap<String, String>();
        String pageId = getPageId();
        // Locate all the pages that are defined as this page children
        PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
        List<IPreferenceNode> nodes = manager.getElements(PreferenceManager.POST_ORDER);
        for (Iterator<IPreferenceNode> i = nodes.iterator(); i.hasNext();) {
            IPreferenceNode node = i.next();
            if (node.getId().equals(pageId)) {
                // we found the node, so take its child nodes and add them to the cache
                IPreferenceNode[] subNodes = node.getSubNodes();
                for (IPreferenceNode child : subNodes) {
                    pageNameToId.put(child.getLabelText(), child.getId());
                }
                break;
            }
        }
    }
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    String contentsMessage = getContentsMessage();
    if (contentsMessage != null) {
        Label message = new Label(composite, SWT.WRAP);
        message.setText(contentsMessage);
    }
    Group group = new Group(composite, SWT.NONE);
    group.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    group.setLayoutData(gd);
    group.setText(EplMessages.GenericRootPage_preferences);
    List<String> pagesNames = new ArrayList<String>(pageNameToId.keySet());
    // In case there are no pages to link to, add a label that will indicate that there are no settings
    if (pagesNames.isEmpty()) {
        Label label = new Label(group, SWT.NONE);
        label.setText(EplMessages.GenericRootPage_noAvailablePages);
        label.setLayoutData(new GridData());
    } else {
        Collections.sort(pagesNames);
        for (String pageName : pagesNames) {
            String id = pageNameToId.get(pageName);
            final Link link = new Link(group, SWT.NONE);
            link.setText("<a>" + pageName + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$
            link.addSelectionListener(new LinkSelectionListener(id));
            gd = new GridData();
            gd.horizontalIndent = 30;
            link.setLayoutData(gd);
        }
    }

    Group dialogsResetGroup = new Group(composite, SWT.NONE);
    dialogsResetGroup.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
    dialogsResetGroup.setLayoutData(GridDataFactory.fillDefaults().create());
    dialogsResetGroup.setText(EplMessages.GenericRootPreferencePage_dialogsGroup);

    Label label = new Label(dialogsResetGroup, SWT.WRAP);
    label.setText(EplMessages.GenericRootPreferencePage_clearMessagesLabelText);
    label.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER)
            .hint(convertVerticalDLUsToPixels(50), SWT.DEFAULT).create());

    final Button clearBt = new Button(dialogsResetGroup, SWT.PUSH);
    clearBt.setText(EplMessages.GenericRootPreferencePage_clearMessagesButtonLabel);
    clearBt.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false));
    // enable the 'reset' button only if there are dialogs to reset.
    final IEclipsePreferences prefs = (EclipseUtil.instanceScope()).getNode(UIEplPlugin.PLUGIN_ID);
    String messages = prefs.get(IEplPreferenceConstants.HIDDEN_MESSAGES, null);
    clearBt.setEnabled(!StringUtil.isEmpty(messages));
    clearBt.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                prefs.remove(IEplPreferenceConstants.HIDDEN_MESSAGES);
                prefs.flush();
                clearBt.setEnabled(false);
            } catch (Exception ex) {
                IdeLog.logError(UIEplPlugin.getDefault(), ex);
            }
        }
    });

    Point point = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    gd = new GridData();
    composite.setLayoutData(gd);
    gd.heightHint = point.y;
    return composite;
}

From source file:com.google.dart.tools.deploy.ApplicationWorkbenchWindowAdvisor.java

License:Open Source License

private void filterUnwantedPreferenceNodes() {
    PreferenceManager preferenceManager = PlatformUI.getWorkbench().getPreferenceManager();
    for (Object elem : preferenceManager.getElements(PreferenceManager.POST_ORDER)) {
        if (elem instanceof IPreferenceNode) {
            IPreferenceNode node = (IPreferenceNode) elem;
            if (isBlacklisted(node)) {
                if (!preferenceManager.remove(node)) {
                    for (IPreferenceNode rootNode : preferenceManager.getRootSubNodes()) {
                        if (rootNode.findSubNode(node.getId()) != null) {
                            rootNode.remove(node);
                        }//ww  w.j  av  a  2 s  . c om
                    }
                }
            }
        }
    }
}

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   w w  w  . ja  va2  s  . 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 w w w.j  ava 2s  .  com*/
    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();
}

From source file:com.motorolamobility.preflighting.ui.utilities.EclipseUtils.java

License:Apache License

@SuppressWarnings("unchecked")
public static void openPreference(Shell shell, String nodeID) {
    // Makes the network preferences dialog manager
    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode networkNode = null;/*ww  w.ja va 2s .co  m*/
    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.nsn.squirrel.preferences.internal.E4PreferenceRegistry.java

License:Open Source License

private IPreferenceNode findNode(PreferenceManager pm, String categoryId) {

    for (Object o : pm.getElements(PreferenceManager.POST_ORDER)) {
        if (o instanceof IPreferenceNode && ((IPreferenceNode) o).getId().equals(categoryId)) {
            return (IPreferenceNode) o;
        }//from  w w w.  j a va  2 s.co m
    }
    return null;
}

From source file:com.opcoach.e4.preferences.internal.E4PreferenceRegistry.java

License:Open Source License

private IPreferenceNode findNode(PreferenceManager pm, String categoryId) {
    for (Object o : pm.getElements(PreferenceManager.POST_ORDER)) {
        if (o instanceof IPreferenceNode && ((IPreferenceNode) o).getId().equals(categoryId)) {
            return (IPreferenceNode) o;
        }// ww w .  j  a v  a2s.co  m
    }
    return null;
}

From source file:de.uni_jena.iaa.linktype.atomic.core.ApplicationWorkbenchAdvisor.java

License:Apache License

@Override
public void postStartup() {
    // Hide Eclipse preferences from preferences dialog (to not puzzle user)
    PreferenceManager preferenceManager = Activator.getDefault().getWorkbench().getPreferenceManager();

    List<?> preferenceNodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER);

    for (Iterator<?> it = preferenceNodes.iterator(); it.hasNext();) {
        IPreferenceNode preferenceNode = (IPreferenceNode) it.next();
        if (preferenceNode.getId().startsWith("org.eclipse")) {
            preferenceManager.remove(preferenceNode);
        }//w  w  w.  j ava2s  .co  m
    }
}

From source file:msi.gama.gui.views.GamaPreferencesView.java

License:Open Source License

private GamaPreferencesView(final Shell parent) {
    parentShell = parent;//  ww  w .j  a v  a 2  s .  c  o m
    shell = new Shell(parentShell, SWT.TITLE | SWT.RESIZE | SWT.APPLICATION_MODAL | SWT.SHEET);
    final GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 5;
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 5;
    shell.setLayout(gridLayout);
    PreferenceManager preferenceManager = PlatformUI.getWorkbench().getPreferenceManager();

    // We clean the default preference manager to remove useless preferences
    for (Object elem : preferenceManager.getElements(PreferenceManager.POST_ORDER)) {
        if (elem instanceof IPreferenceNode) {
            String id = ((IPreferenceNode) elem).getId();
            if (preferenceNames.containsKey(id)) {
                preferencePages.put(preferenceNames.get(id), (IPreferenceNode) elem);
            }
            if (id.contains("debug.ui") || id.contains("help.ui") || id.contains("search")
                    || id.contains("Spelling") || id.contains("Linked") || id.contains("Perspectives")
                    || id.contains("Content")) {
                preferenceManager.remove((IPreferenceNode) elem);
            }
            // GuiUtils.debug(((IPreferenceNode) elem).getId());
            // preferenceManager.remove((IPreferenceNode) elem);
        }
    }
    buildContents();
}