Search in sources :

Example 1 with URLHyperlinkWithMacroDetector

use of org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector in project linuxtools by eclipse.

the class SpecfileConfiguration method getHyperlinkDetectors.

@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
    if (sourceViewer == null) {
        return null;
    }
    Map<String, IAdaptable> targets = getHyperlinkDetectorTargets(sourceViewer);
    HyperlinkDetectorRegistry hlDetectorRegistry = EditorsUI.getHyperlinkDetectorRegistry();
    HyperlinkDetectorDescriptor[] hlDetectorDescriptor = hlDetectorRegistry.getHyperlinkDetectorDescriptors();
    List<IHyperlinkDetector> tempHDList = new ArrayList<>();
    for (Map.Entry<String, IAdaptable> entry : targets.entrySet()) {
        for (HyperlinkDetectorDescriptor hdd : hlDetectorDescriptor) {
            try {
                AbstractHyperlinkDetector ahld = (AbstractHyperlinkDetector) hdd.createHyperlinkDetectorImplementation();
                // however, allow URLHyperlinkWithMacroDetector
                if (hdd.getTargetId().equals(entry.getKey()) && (!(ahld instanceof URLHyperlinkDetector) || ahld instanceof URLHyperlinkWithMacroDetector)) {
                    ahld.setContext(entry.getValue());
                    tempHDList.add(ahld);
                }
            } catch (CoreException e) {
                SpecfileLog.logError(e);
            }
        }
    }
    if (!tempHDList.isEmpty()) {
        return tempHDList.toArray(new IHyperlinkDetector[tempHDList.size()]);
    } else {
        return null;
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) ArrayList(java.util.ArrayList) URLHyperlinkWithMacroDetector(org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector) HyperlinkDetectorRegistry(org.eclipse.ui.texteditor.HyperlinkDetectorRegistry) URLHyperlinkDetector(org.eclipse.jface.text.hyperlink.URLHyperlinkDetector) HyperlinkDetectorDescriptor(org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor) AbstractHyperlinkDetector(org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector) CoreException(org.eclipse.core.runtime.CoreException) Map(java.util.Map)

Example 2 with URLHyperlinkWithMacroDetector

use of org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector in project linuxtools by eclipse.

the class URLHyperlinkWithMacroDetectorTest method testDetectHyperlinks.

@Test
public void testDetectHyperlinks() throws PartInitException {
    String testText = "Name: eclipse\nURL: http://www.%{name}.org/";
    newFile(testText);
    URLHyperlinkWithMacroDetector macroDetector = new URLHyperlinkWithMacroDetector();
    macroDetector.setSpecfile(specfile);
    IRegion region = new Region(20, 0);
    IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), testFile, "org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor");
    editor = (SpecfileEditor) openEditor;
    editor.doRevertToSaved();
    IHyperlink[] returned = macroDetector.detectHyperlinks(editor.getSpecfileSourceViewer(), region, false);
    URLHyperlink url = (URLHyperlink) returned[0];
    assertEquals("http://www.eclipse.org/", url.getURLString());
}
Also used : URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IEditorPart(org.eclipse.ui.IEditorPart) URLHyperlinkWithMacroDetector(org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector) IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Aggregations

URLHyperlinkWithMacroDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 AbstractHyperlinkDetector (org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)1 URLHyperlink (org.eclipse.jface.text.hyperlink.URLHyperlink)1 URLHyperlinkDetector (org.eclipse.jface.text.hyperlink.URLHyperlinkDetector)1 IEditorPart (org.eclipse.ui.IEditorPart)1 HyperlinkDetectorDescriptor (org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor)1 HyperlinkDetectorRegistry (org.eclipse.ui.texteditor.HyperlinkDetectorRegistry)1 Test (org.junit.Test)1