/*
 * www.javagl.de - Flow
 *
 * Copyright (c) 2012-2017 Marco Hutter - http://www.javagl.de
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package de.javagl.flow.plugin;

import de.javagl.category.Categories;
import de.javagl.category.CategoriesBuilder;
import de.javagl.category.Category;
import de.javagl.flow.module.creation.ModuleCreator;

/**
 * Abstract base implementation of a simple {@link ModuleCreatorSource}. 
 * It offers a single abstract method {@link #addModuleCreators()}, which may 
 * be overridden to collect the {@link ModuleCreator} instances that should
 * be provided by this source.
 */
public abstract class AbstractModuleCreatorSource implements ModuleCreatorSource
{
    /**
     * The {@link CategoriesBuilder} that is used to build the 
     * {@link Category} of {@link ModuleCreator} instances
     */
    private final CategoriesBuilder<ModuleCreator> categoriesBuilder;
    
    /**
     * Creates a new source for {@link ModuleCreator} instances that belong 
     * to a {@link Category} hierarchy where the root {@link Category} 
     * has the given name
     * 
     * @param categoryName The name of the root {@link Category}
     */
    protected AbstractModuleCreatorSource(String categoryName)
    {
        categoriesBuilder = Categories.createBuilder(categoryName);
        addModuleCreators();
    }

    /**
     * Add all {@link ModuleCreator} instances that should be provided by
     * this source. An example implementation of this method might look
     * like this:
     * <pre><code>
     * protected void addModuleCreators()
     * {
     *   add(new ImageLoaderModuleCreator());
     *   add(new ImageViewerModuleCreator());
     *   
     *   get("Filter").add(new ImageEdgeDetectorModuleCreator()); 
     *   get("Filter").add(new ImageEmbossModuleCreator()); 
     * }
     * </code></pre>
     */
    protected abstract void addModuleCreators();

    /**
     * Add the given {@link ModuleCreator} to this source
     * 
     * @param moduleCreator The {@link ModuleCreator} to add
     */
    protected final void add(ModuleCreator moduleCreator)
    {
        categoriesBuilder.add(moduleCreator);
    }
    
    /**
     * Returns a {@link CategoriesBuilder} for a sub-{@link Category} with 
     * the given name
     * 
     * @param subCategoryName The name of the sub-{@link Category}
     * @return The {@link CategoriesBuilder} for the sub-{@link Category}
     */
    protected final CategoriesBuilder<ModuleCreator> get(String subCategoryName)
    {
        return categoriesBuilder.get(subCategoryName);
    }

    @Override
    public final Category<ModuleCreator> getCategory()
    {
        return categoriesBuilder.get();
    }
    
}

@@ -3712,24 +3712,354 @@
 me);%0D%0A    %7D%0D
+%0A    %0D%0A    /**%0D%0A     * Returns the %7B@link CategoriesBuilder%7D for the root category that %0D%0A     * is currently built. %0D%0A     * %0D%0A     * @return The %7B@link CategoriesBuilder%7D for the current %7B@link Category%7D%0D%0A     */%0D%0A    protected final CategoriesBuilder%3CModuleCreator%3E get()%0D%0A    %7B%0D%0A        return categoriesBuilder;%0D%0A    %7D%0D%0A    %0D
 %0A%0D%0A    @Over

Allow access to the root category