Search in sources :

Example 1 with FunctionManager

use of org.talend.designer.rowgenerator.data.FunctionManager 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 FunctionManager

use of org.talend.designer.rowgenerator.data.FunctionManager in project tdi-studio-se by Talend.

the class CategoryManager method getInputCategory.

public java.util.List<Category> getInputCategory(String type) {
    FunctionManager functionManager = null;
    if (JavaUtils.JAVA_PIG_DIRECTORY.equals(type)) {
        functionManager = new FunctionManager(type);
    } else {
        functionManager = new FunctionManager();
    }
    java.util.List<TalendType> talendTypes = functionManager.getTalendTypes();
    List<Category> categories = convertTypesToCategories(talendTypes);
    Category allCategories = new Category();
    //$NON-NLS-1$
    allCategories.setName(Messages.getString("CategoryManager.all"));
    Category userDefined = new Category();
    //$NON-NLS-1$
    userDefined.setName(Messages.getString("CategoryManager.user.defined"));
    for (Category category : categories) {
        final List<Function> functions = category.getFunctions();
        allCategories.addFunctions(functions);
        for (Function function : functions) {
            if (function.isUserDefined()) {
                userDefined.addFunctions(function);
            }
        }
    }
    // remove the default category since it already added into user defined category.
    if (defaultCategory != null && categories.contains(defaultCategory)) {
        userDefined.addFunctions(defaultCategory.getFunctions());
        categories.remove(defaultCategory);
    }
    List<Category> input = new ArrayList<Category>();
    if (!JavaUtils.JAVA_PIG_DIRECTORY.equals(type)) {
        input.add(allCategories);
        input.add(userDefined);
    }
    input.addAll(categories);
    return input;
}
Also used : Function(org.talend.designer.rowgenerator.data.Function) ArrayList(java.util.ArrayList) FunctionManager(org.talend.designer.rowgenerator.data.FunctionManager) TalendType(org.talend.designer.rowgenerator.data.TalendType)

Aggregations

ArrayList (java.util.ArrayList)2 Function (org.talend.designer.rowgenerator.data.Function)2 FunctionManager (org.talend.designer.rowgenerator.data.FunctionManager)2 TalendType (org.talend.designer.rowgenerator.data.TalendType)2 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 INodeReturn (org.talend.core.model.process.INodeReturn)1 IProcess (org.talend.core.model.process.IProcess)1 IExternalProposals (org.talend.core.ui.proposal.IExternalProposals)1 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)1