Search in sources :

Example 21 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(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 22 with PaletteDrawer

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

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

the class TalendEditorPaletteFactory method saveFamilyState.

private static void saveFamilyState(PaletteViewer viewer, IPreferenceStore preferenceStore, PaletteDrawer paletteItem) {
    String family = paletteItem.getLabel();
    int value;
    if (viewer.isExpanded(paletteItem)) {
        value = PaletteDrawer.INITIAL_STATE_OPEN;
    } else {
        value = PaletteDrawer.INITIAL_STATE_CLOSED;
    }
    preferenceStore.setValue(PALETTE_STATE + family, value);
    for (Iterator iter = paletteItem.getChildren().iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        if (object instanceof PaletteDrawer) {
            PaletteDrawer paletteDrawer = (PaletteDrawer) object;
            saveFamilyState(viewer, preferenceStore, paletteDrawer);
        }
    }
}
Also used : Iterator(java.util.Iterator) TalendPaletteDrawer(org.talend.designer.core.ui.editor.palette.TalendPaletteDrawer) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer)

Example 24 with PaletteDrawer

use of org.eclipse.gef.palette.PaletteDrawer in project dbeaver by dbeaver.

the class ERDGraphicalViewer method setContents.

@Override
public void setContents(EditPart editpart) {
    loadContents = true;
    try {
        super.setContents(editpart);
        // Reset palette contents
        if (editpart instanceof DiagramPart) {
            List<DBSEntity> tables = new ArrayList<>();
            for (Object child : editpart.getChildren()) {
                if (child instanceof EntityPart) {
                    tables.add(((EntityPart) child).getTable().getObject());
                }
            }
            Collections.sort(tables, DBUtils.<DBSEntity>nameComparator());
            Map<PaletteDrawer, List<ToolEntryTable>> toolMap = new LinkedHashMap<>();
            for (DBSEntity table : tables) {
                DBPDataSourceContainer container = table.getDataSource().getContainer();
                PaletteDrawer drawer = getContainerPaletteDrawer(container);
                if (drawer != null) {
                    List<ToolEntryTable> tools = toolMap.get(drawer);
                    if (tools == null) {
                        tools = new ArrayList<>(tables.size());
                        toolMap.put(drawer, tools);
                    }
                    tools.add(new ToolEntryTable(table));
                }
            }
            for (Map.Entry<PaletteDrawer, List<ToolEntryTable>> entry : toolMap.entrySet()) {
                entry.getKey().setChildren(entry.getValue());
            }
        // editor.getPaletteContents().setChildren(tools);
        }
    } finally {
        loadContents = false;
    }
}
Also used : PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart)

Example 25 with PaletteDrawer

use of org.eclipse.gef.palette.PaletteDrawer in project dbeaver by dbeaver.

the class ERDGraphicalViewer method acquireContainer.

private void acquireContainer(DBPDataSourceContainer container) {
    container.acquire(editor);
    container.getRegistry().addDataSourceListener(this);
    PaletteRoot paletteRoot = editor.getPaletteRoot();
    PaletteDrawer dsDrawer = new PaletteDrawer(container.getName(), DBeaverIcons.getImageDescriptor(container.getDriver().getIcon()));
    dsDrawer.setDescription(container.getDescription());
    dsDrawer.setId(container.getId());
    paletteRoot.add(dsDrawer);
}
Also used : PaletteRoot(org.eclipse.gef.palette.PaletteRoot) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer)

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