Search in sources :

Example 1 with ITags

use of org.eclipse.epp.mpc.core.model.ITags in project epp.mpc by eclipse.

the class AbstractMarketplaceDiscoveryItem method createTagsLabel.

protected void createTagsLabel(Composite parent) {
    tagsLink = StyledTextHelper.createStyledTextLabel(parent);
    setWidgetId(tagsLink, WIDGET_ID_TAGS);
    tagsLink.setEditable(false);
    GridDataFactory.fillDefaults().indent(DESCRIPTION_MARGIN_LEFT, TAGS_MARGIN_TOP).span(3, 1).align(SWT.BEGINNING, SWT.BEGINNING).grab(true, false).applyTo(tagsLink);
    ITags tagsObject = getCatalogItemNode().getTags();
    if (tagsObject == null) {
        return;
    }
    List<? extends ITag> tags = tagsObject.getTags();
    if (tags.isEmpty()) {
        return;
    }
    tags = new ArrayList<ITag>(tags);
    // sort list so that technical tags are at the end
    Collections.sort(tags, new Comparator<ITag>() {

        public int compare(ITag o1, ITag o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1.getName().startsWith(FILE_EXTENSION_TAG_PREFIX)) {
                if (o2.getName().startsWith(FILE_EXTENSION_TAG_PREFIX)) {
                    return 0;
                }
                return 1;
            }
            if (o2.getName().startsWith(FILE_EXTENSION_TAG_PREFIX)) {
                return -1;
            }
            return 0;
        }
    });
    boolean needsEllipsis = tags.size() > MAX_SHOWN_TAGS;
    for (int i = 0; i < MAX_SHOWN_TAGS && i < tags.size(); i++) {
        if (i > 0) {
            // $NON-NLS-1$
            tagsLink.append(" ");
        }
        ITag tag = tags.get(i);
        String tagName = tag.getName();
        StyledTextHelper.appendLink(tagsLink, tagName, tagName, SWT.NORMAL);
    }
    if (needsEllipsis) {
        // $NON-NLS-1$
        tagsLink.append(" ");
        StyledTextHelper.appendLink(tagsLink, ELLIPSIS, ELLIPSIS, SWT.NORMAL);
        createTagsTooltip(tagsLink, tags);
    }
    new LinkListener() {

        @Override
        protected void selected(Object href, TypedEvent e) {
            if (href == ELLIPSIS) {
                Object data = e.widget.getData();
                if (data instanceof ToolTip) {
                    ToolTip tooltip = (ToolTip) data;
                    tooltip.show(new Point(0, 0));
                }
            } else if (href != null) {
                searchForTag(href.toString());
            }
        }
    }.register(tagsLink);
}
Also used : ToolTip(org.eclipse.jface.window.ToolTip) TypedEvent(org.eclipse.swt.events.TypedEvent) Point(org.eclipse.swt.graphics.Point) ITags(org.eclipse.epp.mpc.core.model.ITags) Point(org.eclipse.swt.graphics.Point) ITag(org.eclipse.epp.mpc.core.model.ITag)

Aggregations

ITag (org.eclipse.epp.mpc.core.model.ITag)1 ITags (org.eclipse.epp.mpc.core.model.ITags)1 ToolTip (org.eclipse.jface.window.ToolTip)1 TypedEvent (org.eclipse.swt.events.TypedEvent)1 Point (org.eclipse.swt.graphics.Point)1