Search in sources :

Example 1 with Category

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;
}
Also used : Category(org.bndtools.templating.Category) Template(org.bndtools.templating.Template)

Example 2 with Category

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);
    }
}
Also used : Category(org.bndtools.templating.Category) Version(org.osgi.framework.Version) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) Template(org.bndtools.templating.Template)

Example 3 with Category

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;
}
Also used : Category(org.bndtools.templating.Category) Template(org.bndtools.templating.Template) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Category

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));
}
Also used : Category(org.bndtools.templating.Category) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Template(org.bndtools.templating.Template)

Aggregations

Category (org.bndtools.templating.Category)4 Template (org.bndtools.templating.Template)4 LinkedHashMap (java.util.LinkedHashMap)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 StyledString (org.eclipse.jface.viewers.StyledString)1 Image (org.eclipse.swt.graphics.Image)1 Version (org.osgi.framework.Version)1