Search in sources :

Example 6 with IContextParameter

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

the class ContextModifyCommand method undo.

@Override
public void undo() {
    tmpContext = currentContext.clone();
    currentContext.setName(oldContext.getName());
    currentContext.setConfirmationNeeded(oldContext.isConfirmationNeeded());
    List<IContextParameter> oldListContextParam = oldContext.getContextParameterList();
    List<IContextParameter> curListContextParam = currentContext.getContextParameterList();
    boolean found;
    IContextParameter oldParam = null;
    IContextParameter curParam;
    String name = null;
    for (int i = 0; i < oldListContextParam.size(); i++) {
        found = false;
        oldParam = oldListContextParam.get(i);
        for (int j = 0; j < curListContextParam.size() && !found; j++) {
            curParam = curListContextParam.get(j);
            name = oldParam.getName();
            if (curParam.getName().equals(name)) {
                found = true;
                curParam.setPromptNeeded(oldParam.isPromptNeeded());
                curParam.setComment(oldParam.getComment());
                curParam.setPrompt(oldParam.getPrompt());
                curParam.setType(oldParam.getType());
                curParam.setValue(oldParam.getValue());
            }
        }
    }
    oldContext = tmpContext;
    for (IContextParameter param : oldContext.getContextParameterList()) {
        String paramName = param.getName();
        IContextParameter newParam = currentContext.getContextParameter(paramName);
        if (!newParam.getType().equals(param.getType())) {
            propagateType(contextManager, newParam);
        }
    }
    contextManager.fireContextsChangedEvent();
    refreshContextView();
}
Also used : IContextParameter(org.talend.core.model.process.IContextParameter)

Example 7 with IContextParameter

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

the class ContextModifyCommand method execute.

@Override
public void execute() {
    // check modified type
    for (IContextParameter param : oldContext.getContextParameterList()) {
        String paramName = param.getName();
        IContextParameter newParam = currentContext.getContextParameter(paramName);
        if (!newParam.getType().equals(param.getType())) {
            propagateType(contextManager, newParam);
        }
    }
    contextManager.fireContextsChangedEvent();
    refreshContextView();
    // Removes the attached context files
    try {
        removeContextFiles(process, oldContext);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IContextParameter(org.talend.core.model.process.IContextParameter)

Example 8 with IContextParameter

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

the class ContextModifyCommand method redo.

@Override
public void redo() {
    tmpContext = currentContext.clone();
    currentContext.setName(oldContext.getName());
    currentContext.setConfirmationNeeded(oldContext.isConfirmationNeeded());
    List<IContextParameter> oldListContextParam = oldContext.getContextParameterList();
    List<IContextParameter> curListContextParam = currentContext.getContextParameterList();
    boolean found;
    IContextParameter oldParam = null;
    IContextParameter curParam;
    String name = null;
    for (int i = 0; i < oldListContextParam.size(); i++) {
        found = false;
        oldParam = oldListContextParam.get(i);
        for (int j = 0; j < curListContextParam.size() && !found; j++) {
            curParam = curListContextParam.get(j);
            name = oldParam.getName();
            if (curParam.getName().equals(name)) {
                found = true;
                curParam.setPromptNeeded(oldParam.isPromptNeeded());
                curParam.setComment(oldParam.getComment());
                curParam.setPrompt(oldParam.getPrompt());
                curParam.setType(oldParam.getType());
                curParam.setValue(oldParam.getValue());
            }
        }
    }
    oldContext = tmpContext;
    for (IContextParameter param : oldContext.getContextParameterList()) {
        String paramName = param.getName();
        IContextParameter newParam = currentContext.getContextParameter(paramName);
        if (!newParam.getType().equals(param.getType())) {
            propagateType(contextManager, newParam);
        }
    }
    contextManager.fireContextsChangedEvent();
    refreshContextView();
}
Also used : IContextParameter(org.talend.core.model.process.IContextParameter)

Example 9 with IContextParameter

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

the class MultiSchemasManager method getOriginalValue.

/**
     * 
     * cLi Comment method "getOriginalValue".
     * 
     * check the context or not.
     */
public String getOriginalValue(String value) {
    if (value != null) {
        IProcess process = this.getMultiSchemasComponent().getProcess();
        // TDI-21049:if not context mode,no need to deal with it use below code.
        if (process != null && ContextParameterUtils.containContextVariables(value)) {
            // add for bug9559
            String newValue = null;
            if (value.contains("+")) {
                //$NON-NLS-1$
                // not only use context variable .
                //$NON-NLS-1$ 
                String[] split = value.split("\\+");
                for (int i = 0; i < split.length; i++) {
                    split[i] = split[i].trim();
                    if (split[i].startsWith(TalendTextUtils.getQuoteChar()) && split[i].endsWith(TalendTextUtils.getQuoteChar()) && split[i].length() - 1 > 0) {
                        split[i] = split[i].substring(1, split[i].length() - 1);
                    }
                    String varName = ContextParameterUtils.getVariableFromCode(split[i]);
                    if (varName != null) {
                        IContextParameter contextParameter = process.getContextManager().getDefaultContext().getContextParameter(varName);
                        if (contextParameter != null) {
                            String value2 = contextParameter.getValue();
                            if (value2 != null) {
                                split[i] = value2;
                            }
                        }
                    }
                    if (newValue == null) {
                        newValue = split[i];
                    } else {
                        newValue = newValue + split[i];
                    }
                }
                if (newValue.startsWith(TalendTextUtils.getQuoteChar()) && newValue.endsWith(TalendTextUtils.getQuoteChar())) {
                    return newValue;
                } else {
                    return TalendTextUtils.addQuotes(newValue);
                }
            } else {
                // only use context variable.
                String varName = ContextParameterUtils.getVariableFromCode(value);
                if (varName != null) {
                    IContextParameter contextParameter = process.getContextManager().getDefaultContext().getContextParameter(varName);
                    if (contextParameter != null) {
                        String value2 = contextParameter.getValue();
                        if (value2 != null) {
                            if (value2.startsWith(TalendTextUtils.getQuoteChar()) && value2.endsWith(TalendTextUtils.getQuoteChar())) {
                                return value2;
                            } else {
                                // no quote
                                return TalendTextUtils.addQuotes(value2);
                            }
                        }
                    }
                }
            }
        }
    }
    return value;
}
Also used : IProcess(org.talend.core.model.process.IProcess) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 10 with IContextParameter

use of org.talend.core.model.process.IContextParameter 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)

Aggregations

IContextParameter (org.talend.core.model.process.IContextParameter)32 ArrayList (java.util.ArrayList)14 IContext (org.talend.core.model.process.IContext)14 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)4 Point (org.eclipse.swt.graphics.Point)3 JobContextParameter (org.talend.core.model.context.JobContextParameter)3 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)3 IProcess (org.talend.core.model.process.IProcess)3 ContextItem (org.talend.core.model.properties.ContextItem)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 File (java.io.File)2 Properties (java.util.Properties)2 EList (org.eclipse.emf.common.util.EList)2 CCombo (org.eclipse.swt.custom.CCombo)2 TableViewerCreatorColumnNotModifiable (org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)2 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)2