Search in sources :

Example 1 with IPaletteFilter

use of org.talend.designer.core.IPaletteFilter 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 2 with IPaletteFilter

use of org.talend.designer.core.IPaletteFilter 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 3 with IPaletteFilter

use of org.talend.designer.core.IPaletteFilter in project tdi-studio-se by Talend.

the class TalendPaletteDrawer method setFiltered.

/**
     * Sets the filtered.
     * 
     * @param filtered the filtered to set
     */
@Override
public void setFiltered(boolean filtered) {
    this.filtered = filtered;
    PaletteContainer parentContainer = getParent();
    if (parentContainer instanceof IPaletteFilter) {
        ((IPaletteFilter) parentContainer).setFiltered(filtered);
    }
}
Also used : IPaletteFilter(org.talend.designer.core.IPaletteFilter) PaletteContainer(org.eclipse.gef.palette.PaletteContainer)

Aggregations

IPaletteFilter (org.talend.designer.core.IPaletteFilter)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 CombinedTemplateCreationEntry (org.eclipse.gef.palette.CombinedTemplateCreationEntry)2 CreationToolEntry (org.eclipse.gef.palette.CreationToolEntry)2 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 IComponent (org.talend.core.model.components.IComponent)2 Node (org.talend.designer.core.ui.editor.nodes.Node)2 TalendCombinedTemplateCreationEntry (org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry)2 TalendPaletteDrawer (org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 PaletteContainer (org.eclipse.gef.palette.PaletteContainer)1