Search in sources :

Example 1 with EComponentType

use of org.talend.core.model.components.EComponentType 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 EComponentType

use of org.talend.core.model.components.EComponentType in project tdi-studio-se by Talend.

the class GEFPasteAction method run.

@Override
@SuppressWarnings("unchecked")
public void run() {
    Object clipBoardContent;
    try {
        clipBoardContent = Clipboard.getDefault().getContents();
    } catch (RuntimeException e) {
        return;
    }
    AbstractTalendEditor editor = (AbstractTalendEditor) this.getWorkbenchPart();
    org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
    Object systemObject = systemClipboard.getContents(TextTransfer.getInstance());
    if (clipBoardContent instanceof List) {
        List<EditPart> partsList = (List<EditPart>) clipBoardContent;
        if (partsList == null || partsList.isEmpty()) {
            return;
        }
        List<NodePart> nodeParts = new ArrayList<NodePart>();
        List<NoteEditPart> noteParts = new ArrayList<NoteEditPart>();
        List<SubjobContainerPart> subjobParts = new ArrayList<SubjobContainerPart>();
        for (Object o : partsList) {
            if (o instanceof NodePart) {
                if (!nodeParts.contains(o)) {
                    nodeParts.add((NodePart) o);
                }
            } else if (o instanceof NoteEditPart) {
                noteParts.add((NoteEditPart) o);
            } else if (o instanceof SubjobContainerPart) {
                SubjobContainerPart subjob = (SubjobContainerPart) o;
                for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
                    NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
                    // add for bug TDI-20206
                    if (nodeContainerPart instanceof JobletContainerPart) {
                        for (Object obj : nodeContainerPart.getChildren()) {
                            if (obj instanceof NodePart && !nodeParts.contains(obj)) {
                                nodeParts.add((NodePart) obj);
                            }
                        }
                    }
                    NodePart nodePart = nodeContainerPart.getNodePart();
                    if (nodePart != null) {
                        if (!nodeParts.contains(nodePart)) {
                            nodeParts.add(nodePart);
                        }
                        subjobParts.add(subjob);
                    }
                }
            }
        }
        Map<JobletContainerPart, List<NodePart>> jobletMap = new HashMap<JobletContainerPart, List<NodePart>>();
        for (NodePart nodePart : nodeParts) {
            boolean isCollapsedNode = false;
            if (editor.getProcess().getGraphicalNodes().contains(nodePart.getModel())) {
                isCollapsedNode = true;
            }
            if (!isCollapsedNode && nodePart.getParent() instanceof JobletContainerPart) {
                JobletContainerPart jobletContainer = (JobletContainerPart) nodePart.getParent();
                List<NodePart> jobletNodeParts = jobletMap.get(jobletContainer);
                if (jobletNodeParts == null) {
                    jobletNodeParts = new ArrayList<NodePart>();
                    jobletMap.put(jobletContainer, jobletNodeParts);
                }
                jobletNodeParts.add(nodePart);
            }
        }
        List<NodePart> expandedJobletNodes = new ArrayList<NodePart>();
        for (JobletContainerPart jobletContainer : jobletMap.keySet()) {
            boolean copyJobletNode = true;
            List<NodePart> list = jobletMap.get(jobletContainer);
            for (Object obj : jobletContainer.getChildren()) {
                if (obj instanceof NodePart) {
                    if (!list.contains(obj)) {
                        copyJobletNode = false;
                        break;
                    }
                }
            }
            if (copyJobletNode) {
                nodeParts.removeAll(list);
                PartFactory factory = new PartFactory();
                NodePart createEditPart = (NodePart) factory.createEditPart(jobletContainer, ((NodeContainer) jobletContainer.getModel()).getNode());
                createEditPart.setParent(jobletContainer);
                nodeParts.add(createEditPart);
                expandedJobletNodes.add(createEditPart);
            }
        }
        org.eclipse.draw2d.geometry.Point gefPoint = getCursorLocation();
        // qli comment
        // if the components instanceof JobletInputOutputComponent and current process instanceof not
        // JobletGEFProcess,just create a messageBox and return.
        AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
        if (findProcessProviderFromPID != null) {
            for (NodePart copiedNodePart : nodeParts) {
                Node copiedNode = (Node) copiedNodePart.getModel();
                // add for bug TDI-20207.if copy joblet/job to itself,then return.
                EComponentType componentType = null;
                String copideNodeId = null;
                String editorProcessId = null;
                if (copiedNode.getComponent() != null) {
                    componentType = copiedNode.getComponent().getComponentType();
                    if (copiedNode.getComponent().getProcess() != null) {
                        copideNodeId = copiedNode.getComponent().getProcess().getId();
                    }
                }
                if (editor.getProcess() != null) {
                    editorProcessId = editor.getProcess().getId();
                }
                for (IElementParameter element : copiedNode.getElementParametersFromField(EParameterFieldType.PROCESS_TYPE)) {
                    for (Map.Entry<String, IElementParameter> entry : element.getChildParameters().entrySet()) {
                        if (("PROCESS_TYPE_PROCESS").equals(entry.getKey())) {
                            if (editorProcessId != null && editorProcessId.equals(entry.getValue().getValue())) {
                                return;
                            }
                        }
                    }
                }
                if ((EComponentType.JOBLET).equals(componentType)) {
                    if (editorProcessId != null && editorProcessId.equals(copideNodeId)) {
                        return;
                    }
                }
                if (findProcessProviderFromPID.isJobletInputOrOutputComponent(copiedNode)) {
                    if (!findProcessProviderFromPID.isExtensionProcess(editor.getProcess())) {
                        MessageBox messagebox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.ICON_WARNING);
                        //$NON-NLS-1$
                        messagebox.setText(Messages.getString("GEFPasteAction.textWarning"));
                        //$NON-NLS-1$
                        messagebox.setMessage(Messages.getString("GEFPasteAction.warningMessages"));
                        messagebox.open();
                        return;
                    }
                }
                if (copiedNode.getJobletNode() != null) {
                    boolean canP = canPasteJobletNode(editor.getProcess(), copiedNode);
                    if (!canP) {
                        return;
                    }
                }
            }
        }
        if (nodeParts.size() != 0 && noteParts.size() != 0) {
            MultiplePasteCommand mpc = new MultiplePasteCommand(nodeParts, noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            mpc.setSelectedSubjobs(subjobParts);
            mpc.setSelectedExpandedJoblet(expandedJobletNodes);
            execute(mpc);
        } else if (nodeParts.size() != 0) {
            NodesPasteCommand cmd = new NodesPasteCommand(nodeParts, editor.getProcess(), gefPoint);
            cmd.setSelectedSubjobs(subjobParts);
            cmd.setSelectedExpandedJoblet(expandedJobletNodes);
            execute(cmd);
        } else if (noteParts.size() != 0) {
            NotesPasteCommand cmd = new NotesPasteCommand(noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint, false, null);
            execute(cmd);
        }
        setCursorLocation(null);
    } else if (clipBoardContent instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) clipBoardContent;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    } else if (systemObject != null && systemObject instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) systemObject;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) HashMap(java.util.HashMap) PartFactory(org.talend.designer.core.ui.editor.PartFactory) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) MultiplePasteCommand(org.talend.designer.core.ui.editor.cmd.MultiplePasteCommand) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) EComponentType(org.talend.core.model.components.EComponentType) NotesPasteCommand(org.talend.designer.core.ui.editor.cmd.NotesPasteCommand) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) NodesPasteCommand(org.talend.designer.core.ui.editor.cmd.NodesPasteCommand) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) JobletContainerPart(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) Clipboard(org.eclipse.gef.ui.actions.Clipboard) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) HashMap(java.util.HashMap) Map(java.util.Map) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 3 with EComponentType

use of org.talend.core.model.components.EComponentType in project tesb-studio-se by Talend.

the class RoutePasteAction method run.

@SuppressWarnings("unchecked")
@Override
public void run() {
    Object clipBoardContent;
    try {
        clipBoardContent = Clipboard.getDefault().getContents();
    } catch (RuntimeException e) {
        return;
    }
    org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
    Object systemObject = systemClipboard.getContents(TextTransfer.getInstance());
    if (clipBoardContent instanceof List) {
        List<EditPart> partsList = (List<EditPart>) clipBoardContent;
        if (partsList == null || partsList.isEmpty()) {
            return;
        }
        List<NodePart> nodeParts = new ArrayList<NodePart>();
        List<NoteEditPart> noteParts = new ArrayList<NoteEditPart>();
        for (Object o : partsList) {
            if (o instanceof NodePart) {
                if (!nodeParts.contains(o)) {
                    nodeParts.add((NodePart) o);
                }
            } else if (o instanceof NoteEditPart) {
                noteParts.add((NoteEditPart) o);
            }
        }
        CamelTalendEditor editor = (CamelTalendEditor) this.getWorkbenchPart();
        org.eclipse.draw2d.geometry.Point gefPoint = getCursorLocation();
        AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
        if (findProcessProviderFromPID != null) {
            boolean isDuplicateRoutelet = false;
            String duplicateRouteletName = "";
            for (NodePart copiedNodePart : nodeParts) {
                Node copiedNode = (Node) copiedNodePart.getModel();
                // add for bug TDI-20207.if copy joblet/job to itself,then return.
                EComponentType componentType = null;
                String copideNodeId = null;
                String editorProcessId = null;
                if (copiedNode.getComponent() != null) {
                    componentType = copiedNode.getComponent().getComponentType();
                    if (copiedNode.getComponent().getProcess() != null) {
                        copideNodeId = copiedNode.getComponent().getProcess().getId();
                    }
                }
                if (editor.getProcess() != null) {
                    editorProcessId = editor.getProcess().getId();
                }
                for (IElementParameter element : copiedNode.getElementParametersFromField(EParameterFieldType.PROCESS_TYPE)) {
                    for (Map.Entry<String, IElementParameter> entry : element.getChildParameters().entrySet()) {
                        if (("PROCESS_TYPE_PROCESS").equals(entry.getKey())) {
                            if (editorProcessId != null && editorProcessId.equals(entry.getValue().getValue())) {
                                return;
                            }
                        }
                    }
                }
                if ((EComponentType.JOBLET).equals(componentType)) {
                    // Check if is copying routelet in itself
                    if (editorProcessId != null && editorProcessId.equals(copideNodeId)) {
                        return;
                    }
                    // Check if is duplicate routelet
                    if (editor.getProcess().getNodesOfType(copiedNode.getComponent().getName()).size() > 0) {
                        isDuplicateRoutelet = true;
                        //$NON-NLS-1$
                        duplicateRouteletName += " ," + copiedNode.getComponent().getName();
                    }
                }
                // Check if it's Camel component
                if (!ComponentCategory.CATEGORY_4_CAMEL.getName().equals(copiedNode.getComponent().getType())) {
                    return;
                }
            }
            if (isDuplicateRoutelet) {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
                "Copying Routelet", //$NON-NLS-1$
                "Do not allow duplicate Routelets\nRoutelet \"" + duplicateRouteletName.substring(2) + "\" already exist.");
                return;
            }
        }
        if (nodeParts.size() != 0 && noteParts.size() != 0) {
            MultiplePasteCommand mpc = new MultiplePasteCommand(nodeParts, noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            mpc.setSelectedSubjobs(new ArrayList<SubjobContainerPart>());
            execute(mpc);
        } else if (nodeParts.size() != 0) {
            NodesPasteCommand cmd = new NodesPasteCommand(nodeParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
            cmd.setSelectedSubjobs(new ArrayList<SubjobContainerPart>());
            execute(cmd);
        } else if (noteParts.size() != 0) {
            NotesPasteCommand cmd = new NotesPasteCommand(noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint, false, null);
            execute(cmd);
        }
        setCursorLocation(null);
    } else if (clipBoardContent instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) clipBoardContent;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    } else if (systemObject != null && systemObject instanceof String) {
        List objects = getSelectedObjects();
        if (objects.size() == 1) {
            String content = (String) systemObject;
            if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
                if (text != null) {
                    text.insert(content);
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
                {
                    Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
                    if (text != null) {
                        text.insert(content);
                    }
                }
            }
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) MultiplePasteCommand(org.talend.designer.core.ui.editor.cmd.MultiplePasteCommand) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) EComponentType(org.talend.core.model.components.EComponentType) NotesPasteCommand(org.talend.designer.core.ui.editor.cmd.NotesPasteCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) NodesPasteCommand(org.talend.designer.core.ui.editor.cmd.NodesPasteCommand) CamelTalendEditor(org.talend.camel.designer.ui.editor.CamelTalendEditor) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) Text(org.eclipse.swt.widgets.Text) Clipboard(org.eclipse.gef.ui.actions.Clipboard) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) Map(java.util.Map) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 4 with EComponentType

use of org.talend.core.model.components.EComponentType 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

ArrayList (java.util.ArrayList)4 List (java.util.List)4 EComponentType (org.talend.core.model.components.EComponentType)4 EditPart (org.eclipse.gef.EditPart)3 Map (java.util.Map)2 CombinedTemplateCreationEntry (org.eclipse.gef.palette.CombinedTemplateCreationEntry)2 Clipboard (org.eclipse.gef.ui.actions.Clipboard)2 Text (org.eclipse.swt.widgets.Text)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 AbstractProcessProvider (org.talend.designer.core.model.process.AbstractProcessProvider)2 MultiplePasteCommand (org.talend.designer.core.ui.editor.cmd.MultiplePasteCommand)2 NodesPasteCommand (org.talend.designer.core.ui.editor.cmd.NodesPasteCommand)2 NotesPasteCommand (org.talend.designer.core.ui.editor.cmd.NotesPasteCommand)2 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)2 Node (org.talend.designer.core.ui.editor.nodes.Node)2 NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)2 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)2 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)2 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)2 Date (java.util.Date)1