Search in sources :

Example 16 with PaletteDrawer

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

the class TalendPaletteEditPartFactory method createDrawerEditPart.

@Override
protected EditPart createDrawerEditPart(EditPart parentEditPart, Object model) {
    PaletteDrawer paletteDrawer = (PaletteDrawer) model;
    TalendDrawerEditPart drawerEditPart = new TalendDrawerEditPart(paletteDrawer, cssStyleSetting);
    if (parentEditPart instanceof TalendSliderPaletteEditPart) {
        String label = paletteDrawer.getLabel();
        if (TalendEditorPaletteFactory.FAVORITES.equals(label)) {
            ((TalendPaletteViewer) parentEditPart.getViewer()).setFavoritesEditPart(drawerEditPart);
        } else if (TalendEditorPaletteFactory.RECENTLY_USED.equals(label)) {
            ((TalendPaletteViewer) parentEditPart.getViewer()).setRecentlyUsedEditPart(drawerEditPart);
        }
    }
    return drawerEditPart;
}
Also used : PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer)

Example 17 with PaletteDrawer

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

the class TalendPaletteViewer method addFavoritesComponent.

public void addFavoritesComponent(CombinedTemplateCreationEntry component) {
    if (favoritesEditPart != null) {
        List children = favoritesEditPart.getChildren();
        int insertIndex = 0;
        boolean alreadyExist = false;
        if (children != null) {
            for (; insertIndex < children.size(); insertIndex++) {
                TalendEntryEditPart entryEditPart = (TalendEntryEditPart) children.get(insertIndex);
                CombinedTemplateCreationEntry entryModule = (CombinedTemplateCreationEntry) entryEditPart.getModel();
                int compareResult = entryModule.getLabel().toLowerCase().compareTo(component.getLabel().toLowerCase());
                if (0 == compareResult) {
                    alreadyExist = true;
                    break;
                }
                if (0 < compareResult) {
                    break;
                }
            }
        }
        if (!alreadyExist) {
            TalendEditorPaletteFactory.addNewFavoriteIntoPreference(component.getLabel());
            CombinedTemplateCreationEntry newFavorite = TalendEditorPaletteFactory.createEntryFrom(component);
            newFavorite.setParent(favoritesEditPart.getDrawer());
            EditPart child = favoritesEditPart.createChild(newFavorite);
            PaletteDrawer paletteDrawer = favoritesEditPart.getDrawer();
            if (paletteDrawer != null) {
                paletteDrawer.add(insertIndex, newFavorite);
            }
        // needn't use this, or will cause problem
        // favoritesEditPart.addChild(child, insertIndex);
        }
    }
}
Also used : EditPart(org.eclipse.gef.EditPart) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) List(java.util.List) ArrayList(java.util.ArrayList) CombinedTemplateCreationEntry(org.eclipse.gef.palette.CombinedTemplateCreationEntry)

Example 18 with PaletteDrawer

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

the class TalendEditorPaletteFactory method createComponentDrawer.

private static PaletteDrawer createComponentDrawer(Hashtable<String, PaletteDrawer> ht, String familyToCreate) {
    int index = familyToCreate.lastIndexOf(FAMILY_HIER_SEPARATOR);
    String family;
    PaletteDrawer parentPaletteDrawer = null;
    if (index > -1) {
        family = familyToCreate.substring(index + 1);
        String parentFamily = familyToCreate.substring(0, index);
        parentPaletteDrawer = ht.get(parentFamily);
        if (parentPaletteDrawer == null) {
            parentPaletteDrawer = createComponentDrawer(ht, parentFamily);
        }
    } else {
        family = familyToCreate;
    }
    final PaletteDrawer paletteDrawer = new TalendPaletteDrawer(family);
    paletteDrawer.setInitialState(loadFamilyState(familyToCreate));
    if (parentPaletteDrawer == null) {
        palette.add(paletteDrawer);
    } else {
        parentPaletteDrawer.add(paletteDrawer);
    }
    ht.put(familyToCreate, paletteDrawer);
    return paletteDrawer;
}
Also used : TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer)

Example 19 with PaletteDrawer

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

the class TalendEditorPaletteFactory method saveFamilyState.

public static void saveFamilyState(PaletteViewer viewer) {
    IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
    for (Object o : palette.getChildren()) {
        if (o instanceof PaletteDrawer) {
            PaletteDrawer paletteItem = (PaletteDrawer) o;
            saveFamilyState(viewer, preferenceStore, paletteItem);
        }
    }
}
Also used : TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 20 with PaletteDrawer

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

Aggregations

PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)28 CombinedTemplateCreationEntry (org.eclipse.gef.palette.CombinedTemplateCreationEntry)10 ArrayList (java.util.ArrayList)9 List (java.util.List)6 PaletteRoot (org.eclipse.gef.palette.PaletteRoot)6 TalendPaletteDrawer (org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer)6 SelectionToolEntry (org.eclipse.gef.palette.SelectionToolEntry)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)4 Iterator (java.util.Iterator)3 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)3 IComponent (org.talend.core.model.components.IComponent)3 Node (org.talend.designer.core.ui.editor.nodes.Node)3 TalendCombinedTemplateCreationEntry (org.talend.designer.core.ui.editor.palette.TalendCombinedTemplateCreationEntry)3 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 LinkedList (java.util.LinkedList)2 TreeMap (java.util.TreeMap)2 EditPart (org.eclipse.gef.EditPart)2 ConnectionCreationToolEntry (org.eclipse.gef.palette.ConnectionCreationToolEntry)2