Search in sources :

Example 1 with HyperlinkDetectorRegistry

use of org.eclipse.ui.texteditor.HyperlinkDetectorRegistry 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 HyperlinkDetectorRegistry

use of org.eclipse.ui.texteditor.HyperlinkDetectorRegistry in project eclipse.platform.text by eclipse.

the class TextSourceViewerConfiguration method getRegisteredHyperlinkDetectors.

/**
 * Returns the registered hyperlink detectors which are used to detect
 * hyperlinks in the given source viewer.
 *
 * @param sourceViewer the source viewer to be configured by this configuration
 * @return an array with hyperlink detectors or <code>null</code> if no hyperlink detectors are registered
 * @since 3.3
 */
protected final IHyperlinkDetector[] getRegisteredHyperlinkDetectors(ISourceViewer sourceViewer) {
    HyperlinkDetectorRegistry registry = EditorsUI.getHyperlinkDetectorRegistry();
    Map<String, IAdaptable> targets = getHyperlinkDetectorTargets(sourceViewer);
    Assert.isNotNull(targets);
    IHyperlinkDetector[] result = null;
    Iterator<Entry<String, IAdaptable>> iter = targets.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, IAdaptable> target = iter.next();
        String targetId = target.getKey();
        IAdaptable context = target.getValue();
        result = merge(result, registry.createHyperlinkDetectors(targetId, context));
    }
    return result;
}
Also used : HyperlinkDetectorRegistry(org.eclipse.ui.texteditor.HyperlinkDetectorRegistry) IAdaptable(org.eclipse.core.runtime.IAdaptable) Entry(java.util.Map.Entry) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector)

Aggregations

IAdaptable (org.eclipse.core.runtime.IAdaptable)2 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)2 HyperlinkDetectorRegistry (org.eclipse.ui.texteditor.HyperlinkDetectorRegistry)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 CoreException (org.eclipse.core.runtime.CoreException)1 AbstractHyperlinkDetector (org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector)1 URLHyperlinkDetector (org.eclipse.jface.text.hyperlink.URLHyperlinkDetector)1 URLHyperlinkWithMacroDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector)1 HyperlinkDetectorDescriptor (org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor)1