Search in sources :

Example 1 with INodeReturn

use of org.talend.core.model.process.INodeReturn in project tdi-studio-se by Talend.

the class TalendCompletionProposalComputer method computeCompletionProposals.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jdt.ui.text
     * .java.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
     */
public List computeCompletionProposals(ITextViewer textViewer, String prefix, int offset, IProgressMonitor monitor) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
    IProcess process = service.getCurrentProcess();
    if (process == null) {
        return Collections.EMPTY_LIST;
    }
    // Compute the length of replacement for proposal. See bug 0004266: Replace value with context value using
    // CTRL+Space.
    int replacementLength = textViewer.getSelectedRange().y;
    if (replacementLength == 0) {
        replacementLength = prefix.length();
    }
    // Proposals based on process context
    List<IContextParameter> ctxParams = process.getContextManager().getDefaultContext().getContextParameterList();
    for (IContextParameter ctxParam : ctxParams) {
        String display = CONTEXT_PREFIX + ctxParam.getName();
        String code = getContextContent(ctxParam);
        String description = getContextDescription(ctxParam, display);
        String ctxName = ctxParam.getName();
        if (prefix.equals("") || display.startsWith(prefix)) {
            //$NON-NLS-1$
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.CONTEXT);
            proposals.add(proposal);
        } else if (prefix.equals("") || ctxName.startsWith(prefix)) {
            //$NON-NLS-1$
            if (code.startsWith(CONTEXT_PREFIX)) {
                code = code.replaceFirst(CONTEXT_PREFIX, "");
            }
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.CONTEXT);
            proposals.add(proposal);
        }
    }
    // Proposals based on global variables
    List<? extends INode> nodes = process.getGraphicalNodes();
    for (INode node : nodes) {
        List<? extends INodeReturn> nodeReturns = node.getReturns();
        for (INodeReturn nodeReturn : nodeReturns) {
            //$NON-NLS-1$
            String display = node.getLabel() + "." + nodeReturn.getName();
            if (prefix.equals("") || display.startsWith(prefix)) {
                //$NON-NLS-1$
                String code = getNodeReturnContent(nodeReturn, node);
                String description = getNodeReturnDescription(nodeReturn, node, display);
                TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_16), display, null, description);
                proposal.setType(TalendCompletionProposal.NODE_RETURN);
                proposals.add(proposal);
            }
        }
    }
    // Proposals based on global variables(only perl ).
    // add proposals on global variables in java (bugtracker 2554)
    // add variables in java
    IContentProposal[] javavars = JavaGlobalUtils.getProposals();
    for (IContentProposal javavar : javavars) {
        String display = javavar.getLabel();
        if (prefix.equals("") || display.startsWith(prefix)) {
            //$NON-NLS-1$
            String code = javavar.getContent();
            String description = getGlobalVarDescription(javavar, display);
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.PROCESS_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.VARIABLE);
            proposals.add(proposal);
        }
    }
    FunctionManager functionManager = new FunctionManager();
    List<TalendType> talendTypes = functionManager.getTalendTypes();
    for (TalendType type : talendTypes) {
        for (Object objectFunction : type.getFunctions()) {
            Function function = (Function) objectFunction;
            //$NON-NLS-1$
            String display = function.getCategory() + "." + function.getName();
            if (prefix.equals("") || display.startsWith(prefix)) {
                //$NON-NLS-1$
                String code = FunctionManager.getFunctionMethod(function);
                String description = getFunctionDescription(function, display, code);
                TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.ROUTINE_ICON), display, null, description);
                proposal.setType(TalendCompletionProposal.ROUTINE);
                proposals.add(proposal);
            }
        }
    }
    for (IExternalProposals externalProposals : ProposalFactory.getInstances()) {
        proposals.addAll(externalProposals.getAdvancedProposals(offset, prefix));
    }
    return proposals;
}
Also used : IExternalProposals(org.talend.core.ui.proposal.IExternalProposals) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) TalendType(org.talend.designer.rowgenerator.data.TalendType) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) Function(org.talend.designer.rowgenerator.data.Function) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) INodeReturn(org.talend.core.model.process.INodeReturn) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) FunctionManager(org.talend.designer.rowgenerator.data.FunctionManager)

Example 2 with INodeReturn

use of org.talend.core.model.process.INodeReturn in project tdi-studio-se by Talend.

the class NodeReturnsTreeEditPart method refreshVisuals.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractTreeEditPart#refreshVisuals()
     */
@Override
protected void refreshVisuals() {
    INodeReturn nr = ((INodeReturn) getModel());
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setWidgetText(nr.getDisplayName() + " - " + nr.getName() + " (" + nr.getAvailability() + ")");
}
Also used : INodeReturn(org.talend.core.model.process.INodeReturn)

Aggregations

INodeReturn (org.talend.core.model.process.INodeReturn)2 ArrayList (java.util.ArrayList)1 IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IContextParameter (org.talend.core.model.process.IContextParameter)1 INode (org.talend.core.model.process.INode)1 IProcess (org.talend.core.model.process.IProcess)1 IExternalProposals (org.talend.core.ui.proposal.IExternalProposals)1 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)1 Function (org.talend.designer.rowgenerator.data.Function)1 FunctionManager (org.talend.designer.rowgenerator.data.FunctionManager)1 TalendType (org.talend.designer.rowgenerator.data.TalendType)1