Search in sources :

Example 1 with ComponentHit

use of org.talend.designer.core.model.components.ComponentHit in project tdi-studio-se by Talend.

the class TalendEditorPaletteFactory method addComponentsByNameFilter.

protected static void addComponentsByNameFilter(final IComponentsFactory compFac, Set<IComponent> componentSet, String nameFilter) {
    if (compFac == null || componentSet == null) {
        return;
    }
    if (nameFilter != null && !nameFilter.trim().isEmpty()) {
        Set<IComponent> components = compFac.getComponents();
        Iterator<IComponent> iter = components.iterator();
        String regex = getFilterRegex(nameFilter);
        Pattern pattern = Pattern.compile(regex);
        Set<ComponentHit> resultByName = new LinkedHashSet<ComponentHit>();
        Set<ComponentHit> resultByLongName = new LinkedHashSet<ComponentHit>();
        while (iter.hasNext()) {
            IComponent xmlComponent = iter.next();
            Matcher matcher = pattern.matcher(xmlComponent.getName().toLowerCase());
            if (matcher.find()) {
                resultByName.add(new ComponentHit(xmlComponent, matcher.start()));
                continue;
            }
            matcher = pattern.matcher(xmlComponent.getLongName().toLowerCase());
            if (matcher.find()) {
                resultByLongName.add(new ComponentHit(xmlComponent, matcher.start()));
                continue;
            }
        }
        if (!resultByName.isEmpty()) {
            ComponentHit[] hitArray = resultByName.toArray(new ComponentHit[resultByName.size()]);
            Arrays.sort(hitArray);
            addComponents(componentSet, hitArray);
        }
        if (!resultByLongName.isEmpty()) {
            ComponentHit[] hitArray = resultByLongName.toArray(new ComponentHit[resultByLongName.size()]);
            Arrays.sort(hitArray);
            addComponents(componentSet, hitArray);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IComponent(org.talend.core.model.components.IComponent) ComponentHit(org.talend.designer.core.model.components.ComponentHit)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IComponent (org.talend.core.model.components.IComponent)1 ComponentHit (org.talend.designer.core.model.components.ComponentHit)1