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);
}
}
}
Aggregations