alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation 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
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.pde.internal.ui.editor;

import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.pde.internal.core.text.*;
import org.eclipse.pde.internal.ui.editor.text.XMLUtil;

/**
 * PDEHyperlinkDetector
 *
 */
public abstract class PDEHyperlinkDetector implements IHyperlinkDetector {

	private PDESourcePage fSourcePage;

	/**
	 * @param page
	 */
	public PDEHyperlinkDetector(PDESourcePage page) {
		fSourcePage = page;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
	 */
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {

		if (region == null)
			return null;

		IDocumentRange element = fSourcePage.getRangeElement(region.getOffset(), true);
		if (!XMLUtil.withinRange(element, region.getOffset()))
			return null;

		if (element instanceof IDocumentAttributeNode)
			return detectAttributeHyperlink((IDocumentAttributeNode) element);
		if (element instanceof IDocumentElementNode)
			return detectNodeHyperlink((IDocumentElementNode) element);
		if (element instanceof IDocumentTextNode)
			return detectTextNodeHyperlink((IDocumentTextNode) element);
		return null;
	}

	/**
	 * @param attr
	 * @return
	 */
	protected IHyperlink[] detectAttributeHyperlink(IDocumentAttributeNode attr) {
		return null;
	}

	/**
	 * @param node
	 * @return
	 */
	protected IHyperlink[] detectNodeHyperlink(IDocumentElementNode node) {
		return null;
	}

	/**
	 * @param node
	 * @return
	 */
	protected IHyperlink[] detectTextNodeHyperlink(IDocumentTextNode node) {
		return null;
	}

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.