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();
}
Aggregations