Search in sources :

Example 1 with IProjectSettingPageTester

use of org.talend.core.runtime.preference.IProjectSettingPageTester in project tdi-studio-se by Talend.

the class ProjectSettingDialog method getNodeManager.

/**
     * get all projectsettingPage node dynamic. need get the different result each time. because the tester will calc
     * dymamic.
     * 
     * @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(//$NON-NLS-1$
    "org.talend.repository.projectsetting_page");
    Map<String, List<IPreferenceNode>> hasCategoriesNodes = new HashMap<String, List<IPreferenceNode>>();
    for (IConfigurationElement element : configurationElements) {
        ProjectSettingNode node = new ProjectSettingNode(element);
        try {
            //$NON-NLS-1$
            IPreferencePage page = (IPreferencePage) element.createExecutableExtension("class");
            node.setPage(page);
            //$NON-NLS-1$
            String id = element.getAttribute("id");
            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)) {
                            // don't add this page node.
                            continue;
                        }
                    }
                } catch (CoreException ex) {
                    // can't create the tester
                    log.log(Level.WARN, "can't create the project setting tester for " + id, ex);
                }
            }
            //$NON-NLS-1$
            page.setDescription(element.getAttribute("description"));
            //$NON-NLS-1$
            page.setTitle(element.getAttribute("title"));
        } 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.
                // remove from root node.
                manager.remove(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);
    // clean all to re-add for order
    manager.removeAll();
    // add the sorted list to manager
    for (IPreferenceNode rootSubNode : rootSubNodesList) {
        manager.addToRoot(rootSubNode);
    }
    return manager;
}
Also used : ProjectSettingNode(org.talend.repository.model.ProjectSettingNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) IPreferencePage(org.eclipse.jface.preference.IPreferencePage) ArrayList(java.util.ArrayList) List(java.util.List) IMavenUIService(org.talend.core.runtime.services.IMavenUIService) IProjectSettingPageTester(org.talend.core.runtime.preference.IProjectSettingPageTester) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 IPreferenceNode (org.eclipse.jface.preference.IPreferenceNode)1 IPreferencePage (org.eclipse.jface.preference.IPreferencePage)1 PreferenceManager (org.eclipse.jface.preference.PreferenceManager)1 IProjectSettingPageTester (org.talend.core.runtime.preference.IProjectSettingPageTester)1 IMavenUIService (org.talend.core.runtime.services.IMavenUIService)1 ProjectSettingNode (org.talend.repository.model.ProjectSettingNode)1