Search in sources :

Example 11 with CombinedTemplateCreationEntry

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

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

the class TalendPaletteViewer method addRecentlyUsedComponent.

public void addRecentlyUsedComponent(IComponent component) {
    EComponentType componentType = component.getComponentType();
    if (componentType == EComponentType.JOBLET_INPUT_OUTPUT || componentType == EComponentType.JOBLET_TRIGGER) {
        return;
    }
    if (recentlyUsedEditPart != null) {
        List children = recentlyUsedEditPart.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().compareTo(component.getName());
                if (0 == compareResult) {
                    alreadyExist = true;
                    break;
                }
            // if (0 < compareResult) {
            // break;
            // }
            }
        }
        // if already exist, remove first
        if (alreadyExist) {
            if (0 == insertIndex) {
                return;
            }
            TalendEntryEditPart entryEditPart = (TalendEntryEditPart) children.get(insertIndex);
            CombinedTemplateCreationEntry entryModule = (CombinedTemplateCreationEntry) entryEditPart.getModel();
            removeRecentlyUsedComponent(entryModule);
        }
        // if (!alreadyExist) {
        TalendCombinedTemplateCreationEntry newRecently = TalendEditorPaletteFactory.createEntryFrom(component);
        newRecently.setTimestemp(new Date());
        newRecently.setParent(recentlyUsedEditPart.getDrawer());
        EditPart child = recentlyUsedEditPart.createChild(newRecently);
        PaletteDrawer paletteDrawer = recentlyUsedEditPart.getDrawer();
        if (paletteDrawer != null) {
            // paletteDrawer.add(insertIndex, newRecently);
            paletteDrawer.add(0, newRecently);
        }
        // reobtain
        children = recentlyUsedEditPart.getChildren();
        if (children != null) {
            int size = children.size();
            final int recentlyUsedSize = PaletteSettingsPreferencePage.getPaletteRencentlyUsedListSize();
            if (recentlyUsedSize < size) {
                TalendEntryEditPart entryEditPart = (TalendEntryEditPart) children.get(recentlyUsedSize);
                CombinedTemplateCreationEntry entryModule = (CombinedTemplateCreationEntry) entryEditPart.getModel();
                removeRecentlyUsedComponent(entryModule);
            }
        }
        // needn't use this, or will cause problem
        // recentlyUsedEditPart.addChild(child, insertIndex);
        // }
        refreshRecentlyUsedComponentToReference();
    }
}
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) EComponentType(org.talend.core.model.components.EComponentType) Date(java.util.Date)

Aggregations

CombinedTemplateCreationEntry (org.eclipse.gef.palette.CombinedTemplateCreationEntry)12 ArrayList (java.util.ArrayList)11 List (java.util.List)8 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)8 ConnectionCreationToolEntry (org.eclipse.gef.palette.ConnectionCreationToolEntry)3 CreationToolEntry (org.eclipse.gef.palette.CreationToolEntry)3 PaletteEntry (org.eclipse.gef.palette.PaletteEntry)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 EditPart (org.eclipse.gef.EditPart)2 PaletteRoot (org.eclipse.gef.palette.PaletteRoot)2 SelectionToolEntry (org.eclipse.gef.palette.SelectionToolEntry)2 ToolEntry (org.eclipse.gef.palette.ToolEntry)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 EComponentType (org.talend.core.model.components.EComponentType)2 IPaletteFilter (org.talend.designer.core.IPaletteFilter)2