use of org.bndtools.templating.Template in project bndtools by bndtools.
the class BndRunFileWizard method getTemplateContents.
private InputStream getTemplateContents(String fileName) throws Exception {
// Load properties
Map<String, List<Object>> params = new HashMap<>();
params.put(PROP_FILE_NAME, Collections.<Object>singletonList(fileName));
params.put(PROP_FILE_BASE_NAME, Collections.<Object>singletonList(baseName(fileName)));
IPath containerPath = mainPage.getContainerFullPath();
if (containerPath != null) {
IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(containerPath);
if (container != null) {
String projectName = container.getProject().getName();
params.put(PROP_PROJECT_NAME, Collections.<Object>singletonList(projectName));
}
}
Map<String, String> editedParams = paramsPage.getValues();
for (Entry<String, String> editedParam : editedParams.entrySet()) {
params.put(editedParam.getKey(), Collections.<Object>singletonList(editedParam.getValue()));
}
// Run the template processor
Template template = templatePage.getTemplate();
ResourceMap outputs;
outputs = template.generateOutputs(params);
Resource output = outputs.get(fileName);
if (output == null) {
throw new IllegalArgumentException(String.format("Template error: file '%s' not found in outputs. Available names: %s", fileName, outputs.getPaths()));
}
// Pull the generated content
return output.getContent();
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class RepoTemplateContentProvider method getFirstTemplate.
public Template getFirstTemplate() {
Template result = null;
if (roots != null && roots.length > 0) {
if (roots[0] instanceof Category) {
Category cat = (Category) roots[0];
Iterator<Template> templateIter = cat.getTemplates().iterator();
if (templateIter.hasNext())
result = templateIter.next();
}
}
return result;
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class LatestTemplateFilter method filter.
@Override
public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
Object[] result;
if (parent instanceof Category) {
// Preserves the order of names, as they were
Map<String, Template> selected = new LinkedHashMap<>();
// already sorted by the content provider.
for (Object element : elements) {
Template template = (Template) element;
Template existing = selected.get(template.getName());
if (existing == null)
// no selected template for this name -> add
selected.put(template.getName(), template);
else if (template.getVersion().compareTo(existing.getVersion()) > 0)
// existing selected template for this name is lower -> replace
selected.put(template.getName(), template);
}
result = selected.values().toArray();
} else {
result = elements;
}
return result;
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class RepoTemplateLabelProvider method update.
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Category) {
Category cat = (Category) element;
cell.setText(cat.getName());
cell.setImage(IMG_FOLDER);
} else if (element instanceof Template) {
Template template = (Template) element;
// Name
StyledString label = new StyledString(template.getName(), BoldStyler.INSTANCE_DEFAULT);
// Version, with all segments except qualifier in bold
Version version = template.getVersion();
if (version != null) {
label.append(" ");
label.append(String.format("%d.%d.%d", version.getMajor(), version.getMinor(), version.getMicro()), BoldStyler.INSTANCE_COUNTER);
String q = version.getQualifier();
if (q != null && !q.isEmpty())
label.append("." + q, StyledString.COUNTER_STYLER);
}
String description = template.getShortDescription();
if (description != null) {
label.append(" \u2014 [", StyledString.QUALIFIER_STYLER).append(template.getShortDescription(), StyledString.QUALIFIER_STYLER).append("]", StyledString.QUALIFIER_STYLER);
}
cell.setText(label.toString());
cell.setStyleRanges(label.getStyleRanges());
Image image = loadedImages.get(template);
if (image == null)
cell.setImage(defaultIcon);
else
cell.setImage(image);
}
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class TemplateSelectionWizardPage method setTemplate.
public void setTemplate(final Template template) {
Template old = this.selected;
this.selected = template;
propSupport.firePropertyChange(PROP_TEMPLATE, old, template);
if (template != null) {
txtDescription.setText(String.format("<form>Loading help content for template '%s'...</form>", template.getName()));
Job updateDescJob = new UpdateDescriptionJob(template, txtDescription);
updateDescJob.setSystem(true);
updateDescJob.schedule();
} else {
txtDescription.setText(NO_HELP_CONTENT);
}
}
Aggregations