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

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

Introduction

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

Prototype

public void removeAll() 

Source Link

Document

Removes all contribution nodes known to this manager.

Usage

From source file:at.nucle.e4.plugin.preferences.core.internal.registry.PreferenceRegistry.java

License:Open Source License

public PreferenceManager createPages(PreferenceManager preferenceManager) {
    preferenceManager.removeAll();
    elements.values().forEach(element -> {
        PreferencePage page = null;//from w w  w .  jav  a  2 s. c o m
        if (element.getAttribute(ATTRIBUTE_CLASS) != null) {
            try {
                Object obj = element.createExecutableExtension(ATTRIBUTE_CLASS);
                if (obj instanceof PreferencePage) {
                    page = (PreferencePage) obj;

                    ContextInjectionFactory.inject(page, context);
                    if ((page.getTitle() == null || page.getTitle().isEmpty())
                            && element.getAttribute(ATTRIBUTE_TITLE) != null) {
                        page.setTitle(element.getAttribute(ATTRIBUTE_TITLE));
                    }

                    setPreferenceStore(page, element.getNamespaceIdentifier());
                    String category = element.getAttribute(ATTRIBUTE_CATEGORY);
                    if (category != null) {
                        preferenceManager.addTo(category,
                                new PreferenceNode(element.getAttribute(ATTRIBUTE_ID), page));
                    } else {
                        preferenceManager
                                .addToRoot(new PreferenceNode(element.getAttribute(ATTRIBUTE_ID), page));
                    }
                } else {
                    System.out.println(TAG + " Object must extend FieldEditorPreferencePage or PreferencePage");
                }
            } catch (CoreException exception) {
                exception.printStackTrace();
            }
        } else {
            System.out.println(TAG + " Attribute class may not be null");
        }
    });
    return preferenceManager;
}

From source file:org.talend.repository.ui.dialog.ProjectSettingDialog.java

License:Open Source License

/**
 * get all projectsettingPage node dynamic. need get the different result each time. because the tester will calc
 * dymamic.//  www  . j ava 2  s  .co m
 * 
 * @return PreferenceManager
 */
private PreferenceManager getNodeManager() {
    // PreferenceManager manager = new PreferenceManager(WorkbenchPlugin.PREFERENCE_PAGE_CATEGORY_SEPARATOR);
    PreferenceManager manager = new PreferenceManager('/');
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] configurationElements = registry
            .getConfigurationElementsFor("org.talend.repository.projectsetting_page"); //$NON-NLS-1$

    Map<String, List<IPreferenceNode>> hasCategoriesNodes = new HashMap<String, List<IPreferenceNode>>();

    for (IConfigurationElement element : configurationElements) {
        ProjectSettingNode node = new ProjectSettingNode(element);
        try {
            IPreferencePage page = (IPreferencePage) element.createExecutableExtension("class"); //$NON-NLS-1$
            node.setPage(page);
            String id = element.getAttribute("id");//$NON-NLS-1$
            IConfigurationElement[] testers = element.getChildren("tester");
            if (testers != null && testers.length == 1) { // currently, only one tester is supported.
                try {
                    IProjectSettingPageTester pageTester = (IProjectSettingPageTester) testers[0]
                            .createExecutableExtension("class");
                    if (pageTester != null) {
                        if (!pageTester.valid(element, node)) {
                            continue; // don't add this page node.
                        }
                    }
                } catch (CoreException ex) {
                    // can't create the tester
                    log.log(Level.WARN, "can't create the project setting tester for " + id, ex);
                }
            }

            page.setDescription(element.getAttribute("description")); //$NON-NLS-1$
            page.setTitle(element.getAttribute("title")); //$NON-NLS-1$
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        // add all into root.
        manager.addToRoot(node);

        // has category
        String category = node.getCategory();
        if (category != null && category.length() > 0) {
            List<IPreferenceNode> list = hasCategoriesNodes.get(category);
            if (list == null) {
                list = new ArrayList<IPreferenceNode>();
                hasCategoriesNodes.put(category, list);
            }
            list.add(node);
        }
    }

    // add the speciall node for maven custom
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
        IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault()
                .getService(IMavenUIService.class);
        IPreferenceNode mavenCostomSetup = manager.find("projectsetting.MavenCustomSetup");
        mavenUIService.addCustomMavenSettingChildren(mavenCostomSetup);
    }

    // find parent nodes for category
    Map<String, IPreferenceNode> parentNodesMap = new HashMap<String, IPreferenceNode>();
    for (String category : hasCategoriesNodes.keySet()) {
        IPreferenceNode parent = manager.find(category);
        if (parent != null) {
            parentNodesMap.put(category, parent);
        }
    }
    // process children nodes
    for (String category : hasCategoriesNodes.keySet()) {
        List<IPreferenceNode> list = hasCategoriesNodes.get(category);
        if (list != null) {

            IPreferenceNode parent = parentNodesMap.get(category);
            Collections.sort(list, COMPARATOR);
            for (IPreferenceNode node : list) {
                // if the parent is not valid or not existed. the node won't show also.
                manager.remove(node); // remove from root node.
                if (parent != null) { // the parent existed.
                    parent.add(node);
                }
            }
        }
    }

    // sort the root nodes
    List<IPreferenceNode> rootSubNodesList = new ArrayList<IPreferenceNode>(
            Arrays.asList(manager.getRootSubNodes()));

    Collections.sort(rootSubNodesList, COMPARATOR);
    manager.removeAll(); // clean all to re-add for order

    // add the sorted list to manager
    for (IPreferenceNode rootSubNode : rootSubNodesList) {
        manager.addToRoot(rootSubNode);
    }
    return manager;
}