Search in sources :

Example 81 with IComponent

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

the class TalendEditorPaletteFactory method createComponentsDrawer.

/** Create the "Shapes" drawer. */
private static void createComponentsDrawer(final List<IComponent> componentList, final boolean needHiddenComponent, final int a, final String paletteType) {
    // clearGroup();
    PaletteDrawer componentsDrawer;
    String name, longName;
    String family;
    String oraFamily;
    List<CreationToolEntry> nodeList = new LinkedList<CreationToolEntry>();
    List<String> families = new ArrayList<String>();
    HashMap<String, String> familyMap = new HashMap<String, String>();
    CombinedTemplateCreationEntry component;
    Hashtable<String, PaletteDrawer> ht = new Hashtable<String, PaletteDrawer>();
    List<String> favoriteComponentNames = null;
    if (a == 0) {
        //$NON-NLS-1$
        componentsDrawer = new PaletteDrawer(Messages.getString("TalendEditorPaletteFactory.Default"));
        favoriteComponentNames = getFavoritesList();
    }
    Set<String> displayedFamilies = ComponentsSettingsHelper.getDisplayedFamilies(paletteType);
    Iterator<IComponent> componentIter = componentList.iterator();
    while (componentIter.hasNext()) {
        IComponent xmlComponent = componentIter.next();
        if (xmlComponent.isTechnical()) {
            continue;
        }
        // if (xmlComponent.isTechnical() || !xmlComponent.isVisible()) {
        // continue;
        // }
        oraFamily = xmlComponent.getOriginalFamilyName();
        family = xmlComponent.getTranslatedFamilyName();
        if (xmlComponent.isLoaded()) {
            String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            for (int j = 0; j < strings.length; j++) {
                if (displayedFamilies.contains(oraStrings[j])) {
                    families.add(strings[j]);
                    familyMap.put(strings[j], oraStrings[j]);
                }
            }
        }
    }
    Collections.sort(families);
    List<String> recentlyUsedComponentNames = null;
    List<RecentlyUsedComponent> recentlyUsedComponents = null;
    if (a == 0) {
        // if a==1, then means hide folder mode
        recentlyUsedComponents = new LinkedList<TalendEditorPaletteFactory.RecentlyUsedComponent>();
        recentlyUsedComponentNames = getRecentlyUsedList(recentlyUsedComponents);
        recentlyUsedComponents = sortRecentlyUsed(recentlyUsedComponents);
        families.add(0, FAVORITES);
        familyMap.put(FAVORITES, FAVORITES);
        families.add(1, RECENTLY_USED);
        familyMap.put(RECENTLY_USED, RECENTLY_USED);
        for (Object element : families) {
            family = (String) element;
            String oraFam = familyMap.get(family);
            componentsDrawer = ht.get(family);
            if (componentsDrawer == null) {
                componentsDrawer = createComponentDrawer(ht, family);
                // }
                if (componentsDrawer instanceof IPaletteFilter) {
                    ((IPaletteFilter) componentsDrawer).setOriginalName(oraFam);
                }
            }
        }
    }
    boolean noteAeeded = false;
    boolean needAddNote = true;
    boolean needToAdd = false;
    Map<String, IComponent> recentlyUsedMap = new HashMap<String, IComponent>();
    IPreferenceStore store = DesignerPlugin.getDefault().getPreferenceStore();
    String largeIconsSize = store.getString(TalendDesignerPrefConstants.LARGE_ICONS_SIZE);
    componentIter = componentList.iterator();
    while (componentIter.hasNext()) {
        IComponent xmlComponent = componentIter.next();
        if (xmlComponent.isTechnical()) {
            continue;
        }
        family = xmlComponent.getTranslatedFamilyName();
        oraFamily = xmlComponent.getOriginalFamilyName();
        if (filter != null) {
            String regex = getFilterRegex(filter);
            //$NON-NLS-1$
            needAddNote = "Note".toLowerCase().matches(regex);
        }
        if ((oraFamily.equals("Misc") || oraFamily.equals("Miscellaneous")) && !noteAeeded && needAddNote) {
            //$NON-NLS-1$
            CreationToolEntry noteCreationToolEntry = createNoteEntry(largeIconsSize);
            if (a == 0) {
                PaletteDrawer drawer = ht.get(family);
                if (drawer != null) {
                    noteCreationToolEntry.setParent(drawer);
                    drawer.add(noteCreationToolEntry);
                }
            } else if (a == 1) {
                for (String s : families) {
                    if (s.equals(family)) {
                        needToAdd = true;
                    }
                }
                if (needToAdd == true) {
                    nodeList.add(0, noteCreationToolEntry);
                // noteCreationToolEntry.setParent(paGroup);
                // paGroup.add(noteCreationToolEntry);
                }
            }
            noteAeeded = true;
        }
        if (xmlComponent.isLoaded()) {
            name = xmlComponent.getName();
            longName = xmlComponent.getLongName();
            ImageDescriptor imageSmall = xmlComponent.getIcon16();
            ImageDescriptor imageLarge;
            if (largeIconsSize.equals("24")) {
                //$NON-NLS-1$
                imageLarge = xmlComponent.getIcon24();
            } else {
                imageLarge = xmlComponent.getIcon32();
            }
            if (favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName())) {
                componentsDrawer = ht.get(FAVORITES);
                if (componentsDrawer != null) {
                    component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
                    component.setDescription(longName);
                    component.setParent(componentsDrawer);
                    componentsDrawer.add(component);
                }
            }
            if (recentlyUsedComponentNames != null && recentlyUsedComponentNames.contains(name)) {
                recentlyUsedMap.put(name, xmlComponent);
            }
            String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            for (int j = 0; j < strings.length; j++) {
                if (!needHiddenComponent && !xmlComponent.isVisible(oraStrings[j])) {
                    continue;
                }
                component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
                component.setDescription(longName);
                if (a == 0) {
                    componentsDrawer = ht.get(strings[j]);
                    if (componentsDrawer == null) {
                        continue;
                    }
                    component.setParent(componentsDrawer);
                    componentsDrawer.add(component);
                } else if (a == 1) {
                    boolean canAdd = true;
                    // listName = paGroup.getChildren();
                    // for (int z = 0; z < listName.size(); z++) {
                    // if ((((PaletteEntry) listName.get(z)).getLabel()).equals(component.getLabel())) {
                    // canAdd = false;
                    // }
                    // }
                    Iterator<CreationToolEntry> iter = nodeList.iterator();
                    while (iter.hasNext()) {
                        if ((iter.next().getLabel()).equals(component.getLabel())) {
                            canAdd = false;
                        }
                    }
                    if (canAdd == true) {
                        nodeList.add(component);
                    // component.setParent(paGroup);
                    // paGroup.add(component);
                    }
                }
            }
        }
    }
    if (a == 0) {
        createRecentlyUsedEntryList(ht, recentlyUsedComponents, recentlyUsedMap);
    }
    if (a == 1) {
        Iterator<CreationToolEntry> iter = nodeList.iterator();
        while (iter.hasNext()) {
            CreationToolEntry entryCom = iter.next();
            entryCom.setParent(paGroup);
            paGroup.add(entryCom);
        }
        palette.add(paGroup);
    }
}
Also used : HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IPaletteFilter(org.talend.designer.core.IPaletteFilter) TalendCombinedTemplateCreationEntry(org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry) CreationToolEntry(org.eclipse.gef.palette.CreationToolEntry) Iterator(java.util.Iterator) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Hashtable(java.util.Hashtable) LinkedList(java.util.LinkedList) TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CombinedTemplateCreationEntry(org.eclipse.gef.palette.CombinedTemplateCreationEntry) TalendCombinedTemplateCreationEntry(org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry)

Example 82 with IComponent

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

the class TalendEditorPaletteFactory method getRelatedComponents.

protected static List<IComponent> getRelatedComponents(final IComponentsFactory compFac, String keyword, boolean needCheckVisible) {
    Set<IComponent> componentSet = null;
    IComponentsHandler componentsHandler = compFac.getComponentsHandler();
    String lowerCasedKeyword = null;
    if (keyword != null) {
        lowerCasedKeyword = keyword.toLowerCase().trim();
    }
    /**
         * No need to sort result from help, since it may confuse user
         */
    boolean needSort = true;
    if (compFac != null && lowerCasedKeyword != null && 0 < lowerCasedKeyword.length()) {
        componentSet = new LinkedHashSet<IComponent>();
        // 1. match the full name component
        Map<String, Map<String, Set<IComponent>>> componentNameMap = compFac.getComponentNameMap();
        if (componentNameMap != null) {
            Map<String, Set<IComponent>> map = componentNameMap.get(lowerCasedKeyword);
            if (map != null) {
                Collection<Set<IComponent>> componentSets = map.values();
                Iterator<Set<IComponent>> componentSetIter = componentSets.iterator();
                List<IComponent> filteredComponent = new ArrayList<IComponent>();
                while (componentSetIter.hasNext()) {
                    filteredComponent.addAll(componentSetIter.next());
                }
                if (componentsHandler != null) {
                    filteredComponent = componentsHandler.filterComponents(filteredComponent);
                }
                Iterator<IComponent> componentIter = filteredComponent.iterator();
                while (componentIter.hasNext()) {
                    IComponent iComponent = componentIter.next();
                    if (iComponent == null || !ComponentUtilities.isComponentVisible(iComponent) || iComponent.isTechnical()) {
                        componentIter.remove();
                    }
                }
                if (!filteredComponent.isEmpty()) {
                    componentSet.addAll(filteredComponent);
                }
            }
        }
        // 2. do usual search
        if (componentNameMap != null) {
            // 2.1 search from local palette
            addComponentsByNameFilter(compFac, componentSet, lowerCasedKeyword);
            if (!componentSet.isEmpty()) {
                componentSet = new LinkedHashSet<IComponent>(sortResultsBasedOnRecentlyUsed(new ArrayList<IComponent>(componentSet)));
                needSort = false;
            }
            // 2.2 search from help document
            boolean shouldSearchFromHelpAPI = PaletteSettingsPreferencePage.isPaletteSearchFromHelp();
            if (shouldSearchFromHelpAPI) {
                String helpKeyword = keyword;
                if (helpKeyword != null) {
                    helpKeyword = helpKeyword.trim();
                }
                Set<String> componentNames = getRelatedComponentNamesFromHelp(helpKeyword);
                if (componentNames != null && 0 < componentNames.size()) {
                    int limit = PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
                    int i = 0;
                    Iterator<String> nameIter = componentNames.iterator();
                    while (nameIter.hasNext()) {
                        if (limit <= i) {
                            break;
                        }
                        String componentName = nameIter.next();
                        Map<String, Set<IComponent>> map = componentNameMap.get(componentName.toLowerCase());
                        if (map == null) {
                            continue;
                        }
                        Set<IComponent> findedComponents = map.get(componentName);
                        if (findedComponents != null && !findedComponents.isEmpty()) {
                            for (IComponent iComponent : findedComponents) {
                                if (limit <= i) {
                                    break;
                                }
                                if (ComponentUtilities.isComponentVisible(iComponent) && !iComponent.isTechnical() && filterComponent(iComponent, componentsHandler)) {
                                    componentSet.add(iComponent);
                                    i++;
                                }
                            }
                        // componentSet.addAll(findedComponents);
                        }
                    }
                    if (0 < i) {
                        needSort = false;
                    }
                }
            }
        }
    } else if (compFac != null) {
        componentSet = compFac.getComponents();
    }
    List<IComponent> relatedComponents = null;
    if (componentSet == null || componentSet.isEmpty()) {
        relatedComponents = new LinkedList<IComponent>();
    } else {
        relatedComponents = new LinkedList<IComponent>(componentSet);
    }
    if (compFac != null && componentsHandler != null && !relatedComponents.isEmpty()) {
        relatedComponents = componentsHandler.filterComponents(relatedComponents);
    }
    if (needCheckVisible && relatedComponents != null && !relatedComponents.isEmpty()) {
        Iterator<IComponent> iter = relatedComponents.iterator();
        while (iter.hasNext()) {
            IComponent component = iter.next();
            if (component == null || !ComponentUtilities.isComponentVisible(component) || component.isTechnical()) {
                iter.remove();
            }
        }
    }
    if (needSort) {
        relatedComponents = sortResultsBasedOnRecentlyUsed(relatedComponents);
    }
    return relatedComponents;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IComponentsHandler(org.talend.core.model.components.IComponentsHandler) Map(java.util.Map) HashMap(java.util.HashMap)

Example 83 with IComponent

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

the class TalendEditorPaletteFactory method createComponentsDrawer.

/** Create the "Shapes" drawer. */
private static void createComponentsDrawer(List<IComponent> componentList, boolean needHiddenComponent, boolean isFavorite, int a) {
    clearGroup();
    List<CreationToolEntry> nodeList = new LinkedList<CreationToolEntry>();
    // } else if (a == 0) {
    PaletteDrawer componentsDrawer;
    String name, longName;
    String family;
    String oraFamily;
    List<String> families = new ArrayList<String>();
    HashMap<String, String> familyMap = new HashMap<String, String>();
    // boolean favoriteFlag;
    // List listName = new ArrayList();
    CombinedTemplateCreationEntry component;
    Hashtable<String, PaletteDrawer> ht = new Hashtable<String, PaletteDrawer>();
    paletteState = isFavorite;
    List<String> favoriteComponentNames = null;
    if (a == 0) {
        //            componentsDrawer = new PaletteDrawer(Messages.getString("TalendEditorPaletteFactory.Default")); //$NON-NLS-1$
        favoriteComponentNames = getFavoritesList();
    }
    Iterator<IComponent> componentIter = componentList.iterator();
    while (componentIter.hasNext()) {
        IComponent xmlComponent = componentIter.next();
        if (xmlComponent.isTechnical()) {
            continue;
        }
        oraFamily = xmlComponent.getOriginalFamilyName();
        family = xmlComponent.getTranslatedFamilyName();
        if (xmlComponent.isLoaded()) {
            String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            for (int j = 0; j < strings.length; j++) {
                if (!needHiddenComponent && !xmlComponent.isVisible(oraStrings[j])) {
                    continue;
                }
                if (a == 0) {
                    if (!oraStrings[j].equals("Misc")) {
                        //$NON-NLS-1$
                        if (isFavorite && !(favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName()))) {
                            continue;
                        }
                    }
                }
                families.add(strings[j]);
                familyMap.put(strings[j], oraStrings[j]);
            }
        }
    }
    Collections.sort(families);
    List<String> recentlyUsedComponentNames = null;
    List<RecentlyUsedComponent> recentlyUsedComponents = null;
    if (a == 0) {
        // if a==1, then means hide folder mode
        recentlyUsedComponents = new LinkedList<TalendEditorPaletteFactory.RecentlyUsedComponent>();
        recentlyUsedComponentNames = getRecentlyUsedList(recentlyUsedComponents);
        Collections.sort(recentlyUsedComponents, new Comparator<TalendEditorPaletteFactory.RecentlyUsedComponent>() {

            @Override
            public int compare(RecentlyUsedComponent arg0, RecentlyUsedComponent arg1) {
                return -1 * arg0.getTimestamp().compareTo(arg1.getTimestamp());
            }
        });
        families.add(0, FAVORITES);
        familyMap.put(FAVORITES, FAVORITES);
        families.add(1, RECENTLY_USED);
        familyMap.put(RECENTLY_USED, RECENTLY_USED);
        for (Object element : families) {
            family = (String) element;
            String oraFam = familyMap.get(family);
            componentsDrawer = ht.get(family);
            if (componentsDrawer == null) {
                componentsDrawer = createComponentDrawer(ht, family);
                if (componentsDrawer instanceof IPaletteFilter) {
                    ((IPaletteFilter) componentsDrawer).setOriginalName(oraFam);
                }
            }
        }
    }
    boolean noteAeeded = false;
    boolean needAddNote = true;
    boolean needToAdd = false;
    Map<String, IComponent> recentlyUsedMap = new HashMap<String, IComponent>();
    // For bug TDI-25745, to add "note" entry to Misc drawer for m/r job and common job editor. It should create
    // Misc drawer first if there is not the drawer in palette.
    //$NON-NLS-1$
    PaletteDrawer drawer = ht.get("Miscellaneous");
    if (drawer == null) {
        //$NON-NLS-1$
        drawer = ht.get("Misc");
        if (drawer == null) {
            //$NON-NLS-1$
            drawer = createComponentDrawer(ht, "Misc");
            if (drawer instanceof IPaletteFilter) {
                //$NON-NLS-1$
                ((IPaletteFilter) drawer).setOriginalName("Misc");
            }
        }
    }
    IPreferenceStore store = DesignerPlugin.getDefault().getPreferenceStore();
    String largeIconsSize = store.getString(TalendDesignerPrefConstants.LARGE_ICONS_SIZE);
    CreationToolEntry noteCreationToolEntry = createNoteEntry(largeIconsSize);
    noteCreationToolEntry.setParent(drawer);
    drawer.add(noteCreationToolEntry);
    componentIter = componentList.iterator();
    while (componentIter.hasNext()) {
        IComponent xmlComponent = componentIter.next();
        if (xmlComponent.isTechnical()) {
            continue;
        }
        family = xmlComponent.getTranslatedFamilyName();
        oraFamily = xmlComponent.getOriginalFamilyName();
        if (filter != null) {
            //$NON-NLS-1$
            Pattern pattern = Pattern.compile("^[A-Za-z0-9]+$");
            Matcher matcher = pattern.matcher(filter);
            if (!matcher.matches() && filter.length() != 0) {
                filter = "None";
            }
            String regex = getFilterRegex(filter);
            //$NON-NLS-1$
            needAddNote = "Note".toLowerCase().matches(regex);
        }
        family = xmlComponent.getTranslatedFamilyName();
        oraFamily = xmlComponent.getOriginalFamilyName();
        //                key = xmlComponent.getName() + "#" + oraKeys[j];//$NON-NLS-1$
        if (isFavorite && !(favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName()))) {
            continue;
        }
        if (xmlComponent.isLoaded()) {
            name = xmlComponent.getName();
            longName = xmlComponent.getLongName();
            ImageDescriptor imageSmall = xmlComponent.getIcon16();
            ImageDescriptor imageLarge;
            if (largeIconsSize.equals("24")) {
                //$NON-NLS-1$
                imageLarge = xmlComponent.getIcon24();
            } else {
                imageLarge = xmlComponent.getIcon32();
            }
            if (favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName())) {
                componentsDrawer = ht.get(FAVORITES);
                if (componentsDrawer != null) {
                    component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
                    component.setDescription(longName);
                    component.setParent(componentsDrawer);
                    componentsDrawer.add(component);
                }
            }
            if (recentlyUsedComponentNames != null && recentlyUsedComponentNames.contains(name)) {
                recentlyUsedMap.put(name, xmlComponent);
            }
            if (isFavorite && !(favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName()))) {
                continue;
            }
            String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
            for (int j = 0; j < strings.length; j++) {
                if (!needHiddenComponent && !xmlComponent.isVisible(oraStrings[j])) {
                    continue;
                }
                // String key = null;
                // key = xmlComponent.getName() + "#" + oraStrings[j];//$NON-NLS-1$
                component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
                component.setDescription(longName);
                if (a == 0) {
                    componentsDrawer = ht.get(strings[j]);
                    component.setParent(componentsDrawer);
                    componentsDrawer.add(component);
                } else if (a == 1) {
                    boolean canAdd = true;
                    // listName = paGroup.getChildren();
                    // for (int z = 0; z < listName.size(); z++) {
                    // if ((((PaletteEntry) listName.get(z)).getLabel()).equals(component.getLabel())) {
                    // canAdd = false;
                    // }
                    // }
                    Iterator<CreationToolEntry> iter = nodeList.iterator();
                    while (iter.hasNext()) {
                        if ((iter.next().getLabel()).equals(component.getLabel())) {
                            canAdd = false;
                        }
                    }
                    if (canAdd == true) {
                        nodeList.add(component);
                    // component.setParent(paGroup);
                    // paGroup.add(component);
                    }
                }
            }
        }
    }
    if (a == 0) {
        createRecentlyUsedEntryList(ht, recentlyUsedComponents, recentlyUsedMap);
    }
    if (a == 1) {
        Iterator<CreationToolEntry> iter = nodeList.iterator();
        while (iter.hasNext()) {
            CreationToolEntry entryComponent = iter.next();
            entryComponent.setParent(paGroup);
            paGroup.add(entryComponent);
        }
        palette.add(paGroup);
    }
    //$NON-NLS-1$
    setFilter("");
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IPaletteFilter(org.talend.designer.core.IPaletteFilter) TalendCombinedTemplateCreationEntry(org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry) CreationToolEntry(org.eclipse.gef.palette.CreationToolEntry) Iterator(java.util.Iterator) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Pattern(java.util.regex.Pattern) Hashtable(java.util.Hashtable) LinkedList(java.util.LinkedList) TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CombinedTemplateCreationEntry(org.eclipse.gef.palette.CombinedTemplateCreationEntry) TalendCombinedTemplateCreationEntry(org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry)

Example 84 with IComponent

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

the class TalendEditorPaletteFactory method createRecentlyUsedEntryList.

/**
     * DOC cmeng Comment method "createRecentlyUsedEntry".
     * 
     * @param componentsDrawer
     * @param ht
     * @param recentlyUsedList
     * @param recentlyUsedMap
     * @return
     */
protected static void createRecentlyUsedEntryList(Hashtable<String, PaletteDrawer> ht, List<RecentlyUsedComponent> recentlyUsedList, Map<String, IComponent> recentlyUsedMap) {
    String name;
    String longName;
    TalendCombinedTemplateCreationEntry component;
    final int recentlyUsedSize = PaletteSettingsPreferencePage.getPaletteRencentlyUsedListSize();
    int i = 1;
    for (RecentlyUsedComponent recentlyUsed : recentlyUsedList) {
        if (recentlyUsedSize < i) {
            break;
        }
        IComponent recentlyUsedComponent = recentlyUsedMap.get(recentlyUsed.getName());
        if (recentlyUsedComponent == null) {
            continue;
        }
        if (!ComponentUtilities.isComponentVisible(recentlyUsedComponent)) {
            continue;
        }
        ++i;
        PaletteDrawer componentsDrawer = ht.get(RECENTLY_USED);
        if (componentsDrawer != null) {
            name = recentlyUsedComponent.getName();
            longName = recentlyUsedComponent.getLongName();
            ImageDescriptor imageSmall = recentlyUsedComponent.getIcon16();
            IPreferenceStore store = DesignerPlugin.getDefault().getPreferenceStore();
            ImageDescriptor imageLarge;
            final String string = store.getString(TalendDesignerPrefConstants.LARGE_ICONS_SIZE);
            if (string.equals("24")) {
                //$NON-NLS-1$
                imageLarge = recentlyUsedComponent.getIcon24();
            } else {
                imageLarge = recentlyUsedComponent.getIcon32();
            }
            component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, recentlyUsedComponent, imageSmall, imageLarge);
            component.setDescription(longName);
            component.setParent(componentsDrawer);
            component.setTimestemp(recentlyUsed.getTimestamp());
            componentsDrawer.add(component);
        }
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendCombinedTemplateCreationEntry(org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry)

Example 85 with IComponent

use of org.talend.core.model.components.IComponent 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

IComponent (org.talend.core.model.components.IComponent)146 Node (org.talend.designer.core.ui.editor.nodes.Node)54 ArrayList (java.util.ArrayList)47 IElementParameter (org.talend.core.model.process.IElementParameter)36 Process (org.talend.designer.core.ui.editor.process.Process)36 Test (org.junit.Test)35 INode (org.talend.core.model.process.INode)33 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)22 List (java.util.List)15 Property (org.talend.core.model.properties.Property)15 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)15 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)13 IComponentsFactory (org.talend.core.model.components.IComponentsFactory)12 Connection (org.talend.designer.core.ui.editor.connections.Connection)12 HashMap (java.util.HashMap)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 DataNode (org.talend.designer.core.model.process.DataNode)10 HashSet (java.util.HashSet)9 IConnection (org.talend.core.model.process.IConnection)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8