use of org.bndtools.templating.Category 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.Category 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.Category 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.Category in project bndtools by bndtools.
the class TemplateSelectionWizardPage method setTemplates.
private void setTemplates(final Collection<Template> templates) {
viewer.setInput(templates);
viewer.expandAll();
Template templateToSelect = null;
if (viewer.getFilters().length == 0) {
templateToSelect = contentProvider.getFirstTemplate();
} else {
for (Object element : contentProvider.getElements(null)) {
if (element instanceof Category) {
Object[] filteredTemplates = latestFilter.filter(viewer, element, contentProvider.getChildren(element));
if (filteredTemplates.length > 0) {
templateToSelect = (Template) filteredTemplates[0];
break;
}
} else {
templateToSelect = (Template) element;
break;
}
}
}
if (templateToSelect == null) {
return;
}
viewer.setSelection(new StructuredSelection(templateToSelect));
}
Aggregations