Search in sources :

Example 1 with TocTopic

use of org.eclipse.pde.internal.ua.core.toc.text.TocTopic in project dsl-devkit by dsldevkit.

the class CheckTocGenerator method addTopicToToc.

/**
 * Adds the topic to toc model.
 *
 * @param model
 *          the model
 * @param label
 *          topic label
 * @param reference
 *          topic reference
 * @param uri
 *          the uri
 * @param buildContext
 *          the context
 * @throws CoreException
 *           CoreException
 */
private void addTopicToToc(final TocModel model, final String label, final String reference, final URI uri, final IBuildContext buildContext) throws CoreException {
    TocTopic topic = model.getFactory().createTocTopic();
    topic.setFieldLabel(label);
    topic.setFieldRef(reference);
    topic.setXMLAttribute(SORT_KEY, "false");
    // Add catalogs and checks as sub-topics
    TocTopic categoryTopic;
    TocTopic checkTopic;
    for (Category category : projectHelper.getCatalog(buildContext, uri).getCategories()) {
        categoryTopic = model.getFactory().createTocTopic();
        categoryTopic.setFieldLabel(category.getLabel());
        categoryTopic.setFieldRef(reference + '#' + generatorNaming.getContextId(category));
        for (Check check : category.getChecks()) {
            checkTopic = model.getFactory().createTocTopic();
            checkTopic.setFieldLabel(check.getLabel());
            checkTopic.setFieldRef(reference + '#' + generatorNaming.getContextId(check));
            categoryTopic.addChild(checkTopic);
        }
        topic.addChild(categoryTopic);
    }
    for (Check check : projectHelper.getCatalog(buildContext, uri).getChecks()) {
        checkTopic = model.getFactory().createTocTopic();
        checkTopic.setFieldLabel(check.getLabel());
        checkTopic.setFieldRef(reference + '#' + generatorNaming.getContextId(check));
        topic.addChild(checkTopic);
    }
    // Add TOC at the right position (to have them sorted alphabetically by label)
    IDocumentElementNode[] children = model.getToc().getChildNodes();
    String childLabel;
    boolean added = false;
    for (IDocumentElementNode child : children) {
        if (child instanceof TocTopic) {
            childLabel = ((TocTopic) child).getFieldLabel();
            if (childLabel.compareTo(label) > 0) {
                // childLabel is alphabetically after the label of the new toc
                model.getToc().addChild(topic, (TocTopic) child, true);
                added = true;
                break;
            }
        }
    }
    if (!added) {
        model.getToc().addChild(topic);
    }
}
Also used : Category(com.avaloq.tools.ddk.check.check.Category) IDocumentElementNode(org.eclipse.pde.internal.core.text.IDocumentElementNode) Check(com.avaloq.tools.ddk.check.check.Check) TocTopic(org.eclipse.pde.internal.ua.core.toc.text.TocTopic)

Aggregations

Category (com.avaloq.tools.ddk.check.check.Category)1 Check (com.avaloq.tools.ddk.check.check.Check)1 IDocumentElementNode (org.eclipse.pde.internal.core.text.IDocumentElementNode)1 TocTopic (org.eclipse.pde.internal.ua.core.toc.text.TocTopic)1