Search in sources :

Example 1 with CtxHelpDocumentFactory

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

the class CheckContextsGenerator method updateContextsFile.

/**
 * Update contexts file.
 *
 * @param uri
 *          the uri to the current catalog
 * @param buildContext
 *          the context
 * @throws CoreException
 *           the core exception
 */
public void updateContextsFile(final URI uri, final IBuildContext buildContext) throws CoreException {
    IFile file = projectHelper.getHelpFile(uri, CheckContextsExtensionHelper.CONTEXTS_FILE_NAME);
    CtxHelpModel model = new CtxHelpModel(CoreUtility.getTextDocument(file.getContents()), false);
    model.setUnderlyingResource(file);
    model.load();
    CtxHelpRoot root = model.getCtxHelpRoot();
    CtxHelpDocumentFactory factory = model.getFactory();
    Iterable<CtxHelpContext> contexts = Iterables.filter(model.getCtxHelpRoot().getChildren(), CtxHelpContext.class);
    // all context ids belonging to the catalog
    Set<String> ids = Sets.newHashSet();
    String contextIdPrefix = projectHelper.getCatalog(buildContext, uri).getName().toLowerCase() + "_";
    for (CtxHelpContext context : contexts) {
        if (context.getId().startsWith(contextIdPrefix)) {
            ids.add(context.getId());
        }
    }
    Set<String> checkIds = Sets.newHashSet();
    // Add context for all checks which have been added
    for (Check check : projectHelper.getCatalog(buildContext, uri).getAllChecks()) {
        if (!ids.contains(generatorNaming.getContextId(check))) {
            root.addChild(createContextForCheck(factory, check));
        }
        // all contextIds constructed of the checks of the catalog
        checkIds.add(generatorNaming.getContextId(check));
    }
    // Remove context for checks which have been deleted.
    for (String id : ids) {
        if (!checkIds.contains(id)) {
            for (CtxHelpContext context : contexts) {
                if (context.getId().equals(id)) {
                    root.removeChild(context);
                }
            }
        }
    }
    sortAllContexts(model);
    model.save();
    model.dispose();
}
Also used : CtxHelpModel(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpModel) IFile(org.eclipse.core.resources.IFile) CtxHelpRoot(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpRoot) Check(com.avaloq.tools.ddk.check.check.Check) CtxHelpContext(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpContext) CtxHelpDocumentFactory(org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpDocumentFactory)

Aggregations

Check (com.avaloq.tools.ddk.check.check.Check)1 IFile (org.eclipse.core.resources.IFile)1 CtxHelpContext (org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpContext)1 CtxHelpDocumentFactory (org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpDocumentFactory)1 CtxHelpModel (org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpModel)1 CtxHelpRoot (org.eclipse.pde.internal.ua.core.ctxhelp.text.CtxHelpRoot)1