Search in sources :

Example 6 with HelperFunctionOrCategory

use of eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory in project hale by halestudio.

the class HelperFunctionsExtension method addToCategory.

/**
 * Add the given functions to the given category.
 *
 * @param category the category path
 * @param functions the functions to add to the category
 */
private void addToCategory(String category, Iterable<HelperFunctionWrapper> functions) {
    Iterable<String> path = Splitter.on('.').omitEmptyStrings().split(category);
    Category cat = new Category(path);
    Map<String, HelperFunctionOrCategory> catMap = children.get(cat);
    if (catMap == null) {
        catMap = new HashMap<>();
        children.put(cat, catMap);
    }
    for (HelperFunctionWrapper function : functions) {
        Object previous = catMap.put(function.getName(), function);
        if (previous != null) {
            log.error(MessageFormat.format("Duplicate helper function {0}.{1}", cat, function.getName()));
        }
    }
    // make sure category is listed
    while (cat != null) {
        Category parent = cat.getParent();
        Map<String, HelperFunctionOrCategory> parentMap = children.get(parent);
        if (parentMap == null) {
            parentMap = new HashMap<>();
            children.put(parent, parentMap);
        }
        parentMap.put(cat.getName(), cat);
        // check parent category
        cat = parent;
    }
}
Also used : HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory) Category(eu.esdihumboldt.cst.functions.groovy.helper.Category) HelperFunctionOrCategory(eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)

Aggregations

HelperFunctionOrCategory (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)6 Category (eu.esdihumboldt.cst.functions.groovy.helper.Category)4 HelperFunction (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunction)2 HelperFunctionsService (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService)2 HelperFunctionSpecification (eu.esdihumboldt.cst.functions.groovy.helper.spec.impl.HelperFunctionSpecification)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Splitter (com.google.common.base.Splitter)1 ExtensionUtil (de.fhg.igd.eclipse.util.extension.ExtensionUtil)1 ALogger (de.fhg.igd.slf4jplus.ALogger)1 ALoggerFactory (de.fhg.igd.slf4jplus.ALoggerFactory)1 ContextAwareHelperFunction (eu.esdihumboldt.cst.functions.groovy.helper.ContextAwareHelperFunction)1 HelperContext (eu.esdihumboldt.cst.functions.groovy.helper.HelperContext)1 Specification (eu.esdihumboldt.cst.functions.groovy.helper.spec.Specification)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ExecutionContext (eu.esdihumboldt.hale.common.align.transformation.function.ExecutionContext)1 ServiceProvider (eu.esdihumboldt.hale.common.core.service.ServiceProvider)1 TreePathFilteredTree (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)1 TreePathPatternFilter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter)1 TreePathProviderAdapter (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathProviderAdapter)1 Field (java.lang.reflect.Field)1