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());
}
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;
}
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();
}
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);
}
Aggregations