Search in sources :

Example 1 with HyperlinkDetectorDescriptor

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

the class HyperlinkDetectorsConfigurationBlock method createListModel.

private ListItem[] createListModel() {
    ArrayList<ListItem> listModelItems = new ArrayList<>();
    for (int i = 0; i < fHyperlinkDetectorDescriptors.length; i++) {
        HyperlinkDetectorDescriptor desc = fHyperlinkDetectorDescriptors[i];
        HyperlinkDetectorTargetDescriptor target = desc.getTarget();
        int stateMask = fStore.getInt(desc.getId() + HyperlinkDetectorDescriptor.STATE_MASK_POSTFIX);
        String modifierKeys = getModifierString(stateMask);
        listModelItems.add(new ListItem(desc.getId(), desc.getName(), target.getName(), modifierKeys));
    }
    Comparator<ListItem> comparator = new Comparator<ListItem>() {

        @Override
        public int compare(ListItem o1, ListItem o2) {
            String label1 = o1.name;
            String label2 = o2.name;
            return Collator.getInstance().compare(label1, label2);
        }
    };
    Collections.sort(listModelItems, comparator);
    ListItem[] items = new ListItem[listModelItems.size()];
    listModelItems.toArray(items);
    return items;
}
Also used : HyperlinkDetectorTargetDescriptor(org.eclipse.ui.texteditor.HyperlinkDetectorTargetDescriptor) HyperlinkDetectorDescriptor(org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Comparator(java.util.Comparator)

Example 2 with HyperlinkDetectorDescriptor

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

Aggregations

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