Search in sources :

Example 1 with CreationToolEntry

use of org.eclipse.gef.palette.CreationToolEntry in project tdi-studio-se by Talend.

the class TalendPaletteContextMenuProvider method buildContextMenu.

@SuppressWarnings("rawtypes")
@Override
public void buildContextMenu(IMenuManager menu) {
    super.buildContextMenu(menu);
    boolean hasSearchComponentAction = true;
    List editParts = getPaletteViewer().getSelectedEditParts();
    if (!editParts.isEmpty()) {
        PaletteEntry element = (PaletteEntry) ((EditPart) editParts.get(0)).getModel();
        if (editParts.size() > 1) {
            // search component only process one .
            hasSearchComponentAction = false;
        } else {
            // check the entry is component or folder
            if (element instanceof CombinedTemplateCreationEntry) {
                Object template = ((CombinedTemplateCreationEntry) element).getTemplate();
                if (template == null || !Node.class.equals(template)) {
                    hasSearchComponentAction = false;
                }
            } else {
                // not component entry
                hasSearchComponentAction = false;
            }
        }
        // don't work for camel.
        if (hasSearchComponentAction && isComponentsTypePalette(ComponentCategory.CATEGORY_4_CAMEL)) {
            hasSearchComponentAction = false;
        }
        // note
        //$NON-NLS-1$
        boolean note = element.getLabel().equals(Messages.getString("TalendEditorPaletteFactory.Note"));
        if (!note) {
            if (hasSearchComponentAction) {
                menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new SearchComponentAction(getPaletteViewer()));
            }
            boolean showFavorAction = true;
            boolean showAddFavorAction = true;
            PaletteContainer pContainer = element.getParent();
            if (pContainer != null) {
                // Favorites Folder or components in Favorites Folder
                if ((pContainer instanceof PaletteRoot && TalendEditorPaletteFactory.FAVORITES.equals(element.getLabel())) || (pContainer.getParent() instanceof PaletteRoot && TalendEditorPaletteFactory.FAVORITES.equals(pContainer.getLabel()))) {
                    showAddFavorAction = false;
                }
            }
            // for INPUT/OUTPUT/TRIGGER, needn't to add to Favorites
            if (element instanceof CreationToolEntry) {
                Object obj = ((CreationToolEntry) element).getToolProperty(CreationTool.PROPERTY_CREATION_FACTORY);
                if (obj instanceof PaletteComponentFactory) {
                    IComponent component = ((PaletteComponentFactory) obj).getComponent();
                    EComponentType componentType = component.getComponentType();
                    if (componentType == EComponentType.JOBLET_INPUT_OUTPUT || componentType == EComponentType.JOBLET_TRIGGER) {
                        showFavorAction = false;
                    }
                }
            }
            if (showFavorAction) {
                // if (ShowFavoriteAction.state == true) {
                if (showAddFavorAction) {
                    menu.appendToGroup(GEFActionConstants.GROUP_COPY, new FavoriteComponentAction(getPaletteViewer()));
                } else {
                    menu.appendToGroup(GEFActionConstants.GROUP_COPY, new RemoveFavoriteComponentAction(getPaletteViewer()));
                }
            }
        }
    }
    menu.appendToGroup(GEFActionConstants.GROUP_COPY, new HiddenFloderAction(getPaletteViewer()));
    menu.appendToGroup(GEFActionConstants.GROUP_COPY, new DisplayFloderAction(getPaletteViewer()));
}
Also used : PaletteRoot(org.eclipse.gef.palette.PaletteRoot) PaletteComponentFactory(org.talend.designer.core.ui.editor.PaletteComponentFactory) IComponent(org.talend.core.model.components.IComponent) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) PaletteContainer(org.eclipse.gef.palette.PaletteContainer) EComponentType(org.talend.core.model.components.EComponentType) CreationToolEntry(org.eclipse.gef.palette.CreationToolEntry) ArrayList(java.util.ArrayList) List(java.util.List) CombinedTemplateCreationEntry(org.eclipse.gef.palette.CombinedTemplateCreationEntry)

Example 2 with CreationToolEntry

use of org.eclipse.gef.palette.CreationToolEntry 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 3 with CreationToolEntry

use of org.eclipse.gef.palette.CreationToolEntry 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)

Aggregations

ArrayList (java.util.ArrayList)3 CombinedTemplateCreationEntry (org.eclipse.gef.palette.CombinedTemplateCreationEntry)3 CreationToolEntry (org.eclipse.gef.palette.CreationToolEntry)3 IComponent (org.talend.core.model.components.IComponent)3 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 IPaletteFilter (org.talend.designer.core.IPaletteFilter)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 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 PaletteContainer (org.eclipse.gef.palette.PaletteContainer)1 PaletteEntry (org.eclipse.gef.palette.PaletteEntry)1