Search in sources :

Example 1 with ITag

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

the class UnmarshallerTest method tags.

@Test
public void tags() throws Exception {
    Object model = processResource("resources/node.xml");
    Marketplace marketplace = (Marketplace) model;
    INode node = marketplace.getNode().get(0);
    assertNotNull(node.getTags());
    assertEquals(5, node.getCategories().getCategory().size());
    ITag tag = node.getTags().getTags().get(3);
    assertEquals("mylyn", tag.getName());
    assertEquals("88", tag.getId());
    assertEquals("http://marketplace.eclipse.org/category/free-tagging/mylyn", tag.getUrl());
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) INode(org.eclipse.epp.mpc.core.model.INode) ITag(org.eclipse.epp.mpc.core.model.ITag) Test(org.junit.Test)

Example 2 with ITag

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

the class DiscoverFileSupportJob method orderNodesByTagSubExtensionCount.

/**
 * Sorts the given list of tags by number of sub extension dividers(.) and uses the sorted list to return an ordered
 * list of the nodes by first occurrence of highest sub extension tag in fileExtensionTags.
 *
 * @param nodes
 * @param fileExtensionTags
 * @return nodes ordered by first occurrence of highest sub extension count found in fileExtensionTags
 */
private static List<? extends INode> orderNodesByTagSubExtensionCount(List<? extends INode> nodes, List<String> fileExtensionTags) {
    Collections.sort(fileExtensionTags, new Comparator<String>() {

        public int compare(String s1, String s2) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return (s2.length() - s2.replace(".", "").length()) - (s1.length() - s1.replace(".", "").length());
        }
    });
    Map<String, List<INode>> nodesByTags = new HashMap<String, List<INode>>();
    for (INode iNode : nodes) {
        for (ITag nodeTag : iNode.getTags().getTags()) {
            boolean foundTag = false;
            for (String tag : fileExtensionTags) {
                if (nodeTag.getName().equals(tag)) {
                    if (nodesByTags.containsKey(tag)) {
                        nodesByTags.get(tag).add(iNode);
                    } else {
                        List<INode> newNodeList = new ArrayList<INode>();
                        newNodeList.add(iNode);
                        nodesByTags.put(tag, newNodeList);
                    }
                    foundTag = true;
                    break;
                }
            }
            if (foundTag) {
                break;
            }
        }
    }
    List<INode> ordered = new ArrayList<INode>();
    for (String tag : fileExtensionTags) {
        if (nodesByTags.containsKey(tag)) {
            ordered.addAll(nodesByTags.get(tag));
        }
    }
    return nodes;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ITag(org.eclipse.epp.mpc.core.model.ITag) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ITag

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

the class AbstractMarketplaceDiscoveryItem method createTagsTooltip.

private void createTagsTooltip(final StyledText tagsLink, final List<? extends ITag> tags) {
    final ToolTip tooltip = new ToolTip(tagsLink, ToolTip.NO_RECREATE, false) {

        @Override
        protected Composite createToolTipContentArea(Event event, Composite parent) {
            Composite result = new Composite(parent, SWT.NONE);
            result.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            result.setLayout(new GridLayout());
            StyledText fullTagLinks = StyledTextHelper.createStyledTextLabel(result);
            fullTagLinks.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            fullTagLinks.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
            for (int i = 0; i < MAX_TOTAL_TAGS && i < tags.size(); i++) {
                ITag tag = tags.get(i);
                String tagName = tag.getName();
                StyledTextHelper.appendLink(fullTagLinks, tagName, tagName, SWT.NORMAL);
                // $NON-NLS-1$
                fullTagLinks.append(" ");
            }
            if (tags.size() > MAX_TOTAL_TAGS) {
                // Limit shown tags to a hard maximum, because too many links
                // can crash the StyledText widget (at least on Windows...)
                fullTagLinks.append(ELLIPSIS);
            }
            new LinkListener() {

                @Override
                protected void selected(Object href, TypedEvent e) {
                    hide();
                    if (href != null) {
                        searchForTag(href.toString());
                    }
                }
            }.register(fullTagLinks);
            GridData gridData = new GridData();
            gridData.widthHint = tagsLink.getSize().x;
            fullTagLinks.setLayoutData(gridData);
            Dialog.applyDialogFont(result);
            return result;
        }

        @Override
        public Point getLocation(Point tipSize, Event event) {
            Point size = tagsLink.getSize();
            return tagsLink.toDisplay(0, size.y);
        }
    };
    tagsLink.setData(tooltip);
    tooltip.setHideOnMouseDown(false);
    tooltip.setPopupDelay(0);
    tooltip.activate();
}
Also used : ToolTip(org.eclipse.jface.window.ToolTip) TypedEvent(org.eclipse.swt.events.TypedEvent) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) ITag(org.eclipse.epp.mpc.core.model.ITag) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TypedEvent(org.eclipse.swt.events.TypedEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Event(org.eclipse.swt.widgets.Event) PropertyChangeEvent(java.beans.PropertyChangeEvent)

Example 4 with ITag

use of org.eclipse.epp.mpc.core.model.ITag 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)4 INode (org.eclipse.epp.mpc.core.model.INode)2 ToolTip (org.eclipse.jface.window.ToolTip)2 TypedEvent (org.eclipse.swt.events.TypedEvent)2 Point (org.eclipse.swt.graphics.Point)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)1 ITags (org.eclipse.epp.mpc.core.model.ITags)1 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)1 StyledText (org.eclipse.swt.custom.StyledText)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Event (org.eclipse.swt.widgets.Event)1 Test (org.junit.Test)1