Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.hyperlinking;
  
 import java.util.List;
 
 import  org.eclipse.jface.text.Region;
 import  org.eclipse.jface.text.hyperlink.IHyperlink;
 import  org.eclipse.jface.viewers.ILabelProvider;
 

Author(s):
Sebastian Zarnekow - Initial contribution and API
 
 public class HyperlinkHelper implements IHyperlinkHelper {
 
 	protected static class HyperlinkAcceptor implements IHyperlinkAcceptor {
 
 		private final List<IHyperlink> links;
 
 		public HyperlinkAcceptor(List<IHyperlink> links) {
 			this. = links;
 		}
 		
 		public void accept(IHyperlink hyperlink) {
 			if (hyperlink != null)
 				.add(hyperlink);
 		}
 		
 	}
 	
 	private ILabelProvider labelProvider;
 
 	
 	
 	}
 	
 	protected ILabelProvider getLabelProvider() {
 		return ;
 	}

Since:
2.5
 
 	}
 	
 	public IHyperlink[] createHyperlinksByOffset(XtextResource resourceint offsetboolean createMultipleHyperlinks) {
 		List<IHyperlink> links = Lists.newArrayList();
 		IHyperlinkAcceptor acceptor = new HyperlinkAcceptor(links);
 		
 		createHyperlinksByOffset(resourceoffsetacceptor);
 		if (!links.isEmpty())
 			return Iterables.toArray(links, IHyperlink.class);
 		return null;
 	}
 
 	public void createHyperlinksByOffset(XtextResource resourceint offsetIHyperlinkAcceptor acceptor) {
 		INode crossRefNode = .getCrossReferenceNode(resourcenew TextRegion(offset, 0));
 		if (crossRefNode == null)
 			return;
 		EObject crossLinkedEObject = .getCrossReferencedElement(crossRefNode);
 		if (crossLinkedEObject != null && !crossLinkedEObject.eIsProxy()) {
 			createHyperlinksTo(resourcecrossRefNodecrossLinkedEObjectacceptor);
 		}
 	}

Produces hyperlinks for the given node which is associated with a cross reference that points to the referenced target.

Since:
2.4
See also:
createHyperlinksTo(XtextResource, Region, EObject, IHyperlinkAcceptor)
	protected void createHyperlinksTo(XtextResource resourceINode nodeEObject targetIHyperlinkAcceptor acceptor) {
		ITextRegion textRegion = node.getTextRegion();
		Region region = new Region(textRegion.getOffset(), textRegion.getLength());
		createHyperlinksTo(resourceregiontargetacceptor);
	}

Deprecated:
use EObjectAtOffsetHelper.getCrossReferenceNode(XtextResource, org.eclipse.xtext.util.ITextRegion)
	protected INode getParentNodeWithCrossReference(INode startNode) {
		if(startNode == null)
			return null;
		if(startNode.getGrammarElement() instanceof CrossReference)
			return startNode;
	}

Produces hyperlinks for the given region that point to the referenced target.
	public void createHyperlinksTo(XtextResource from, Region regionEObject targetIHyperlinkAcceptor acceptor) {
		final URIConverter uriConverter = from.getResourceSet().getURIConverter();
		final String hyperlinkText = .getText(target);
		final URI uri = EcoreUtil.getURI(target);
		final URI normalized = uri.isPlatformResource() ? uri : uriConverter.normalize(uri);
		result.setHyperlinkRegion(region);
		result.setURI(normalized);
		result.setHyperlinkText(hyperlinkText);
		acceptor.accept(result);
	}
New to GrepCode? Check out our FAQ X