Search in sources :

Example 11 with IContextParameter

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

the class TalendJavaSourceViewer method createViewerWithVariables.

public static ReconcilerViewer createViewerWithVariables(Composite composite, int styles, IExpressionDataBean dataBean) {
    IDocument document = new Document();
    StringBuffer buff = new StringBuffer();
    //$NON-NLS-1$
    buff.append("\npackage internal;\n\n");
    buff.append(getImports());
    //$NON-NLS-1$ //$NON-NLS-2$
    buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
    IRunProcessService runProcessService = getRunProcessService();
    if (runProcessService != null && runProcessService.getSelectedContext() != null) {
        List<IContextParameter> params = runProcessService.getSelectedContext().getContextParameterList();
        buff.append(TEXT_1);
        for (IContextParameter ctxParam : params) {
            buff.append(TEXT_2);
            buff.append(ctxParam.getName());
            buff.append(TEXT_3);
            buff.append(ctxParam.getName());
            buff.append(TEXT_4);
        }
        buff.append(TEXT_5);
        for (IContextParameter ctxParam : params) {
            if (//$NON-NLS-1$ //$NON-NLS-2$
            ctxParam.getType().equals("id_List Of Value") || ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") || ctxParam.getType().equals("id_Character")) {
                //$NON-NLS-1$ //$NON-NLS-2$
                buff.append(TEXT_6);
                buff.append(ctxParam.getName());
                buff.append(TEXT_7);
            } else {
                buff.append(TEXT_8);
                buff.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
                buff.append(TEXT_9);
                buff.append(ctxParam.getName());
                buff.append(TEXT_10);
            }
        }
        buff.append(TEXT_11);
        //$NON-NLS-1$
        buff.append("\tprivate static ContextProperties context = new ContextProperties();\n");
        //$NON-NLS-1$
        buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
        if (dataBean != null) {
            buff.append(parseVariables(dataBean.getVariables()));
            //$NON-NLS-1$ //$NON-NLS-2$
            buff.append("\tpublic " + dataBean.getExpressionType() + " myFunction(){\n");
        }
        //$NON-NLS-1$
        buff.append("\t\treturn \n");
    }
    int length = buff.toString().length();
    //$NON-NLS-1$
    String defaultValue = "";
    //$NON-NLS-1$
    buff.append(defaultValue + "\n;\t\n}\n}");
    document.set(buff.toString());
    return initializeViewer(composite, styles, true, document, length);
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IContextParameter(org.talend.core.model.process.IContextParameter) IDocument(org.eclipse.jface.text.IDocument)

Example 12 with IContextParameter

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

the class ProcessContextComposite method checkIsSameContextParameter.

/*
     * check same ContextParameter or not.
     */
private boolean checkIsSameContextParameter() {
    List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
    for (IContext context : process.getContextManager().getListContext()) {
        for (IContextParameter param : context.getContextParameterList()) {
            if (allContextItem != null) {
                ContextItem contextItem = ContextUtils.getContextItemById(allContextItem, param.getSource());
                ContextType contextType = ContextUtils.getContextTypeByName(contextItem, context.getName(), true);
                ContextParameterType contextParameterType = ContextUtils.getContextParameterTypeByName(contextType, param.getName());
                if (!ContextUtils.samePropertiesForContextParameter(param, contextParameterType)) {
                    return false;
                }
                // if don't open the job to run it(not use the "Detect and update all jobs"), will show
                // UpdateDetectionDialog to update the context ,after updated the item, the contextComboViewer still
                // set the old one , so need refresh.
                IContext runJobViewContext = getSelectedContext();
                if (runJobViewContext != null) {
                    for (IContextParameter tempContext : runJobViewContext.getContextParameterList()) {
                        if (tempContext.getName().equals(contextParameterType.getName()) && !ContextUtils.samePropertiesForContextParameter(tempContext, contextParameterType)) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 13 with IContextParameter

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

the class ProcessContextComposite method promptConfirmLauch.

public static boolean promptConfirmLauch(Shell shell, IContext context, IProcess process) {
    boolean continueLaunch = true;
    int nbValues = 0;
    if (context == null) {
        //$NON-NLS-1$
        throw new IllegalArgumentException("Context is null");
    }
    // Prompt for context values ?
    for (IContextParameter parameter : context.getContextParameterList()) {
        if (parameter.isPromptNeeded()) {
            nbValues++;
        }
    }
    if (nbValues > 0) {
        IContext contextCopy = context.clone();
        PromptDialog promptDialog = new PromptDialog(shell, contextCopy);
        if (promptDialog.open() == PromptDialog.OK) {
            for (IContextParameter param : context.getContextParameterList()) {
                boolean found = false;
                IContextParameter paramCopy = null;
                for (int i = 0; i < contextCopy.getContextParameterList().size() & !found; i++) {
                    paramCopy = contextCopy.getContextParameterList().get(i);
                    if (param.getName().equals(paramCopy.getName())) {
                        // param.setValueList(paramCopy.getValueList());
                        param.setInternalValue(paramCopy.getValue());
                        found = true;
                    }
                }
            }
            contextComboViewer.refresh();
            contextTableViewer.refresh();
            processNeedGenCode(process);
        } else {
            continueLaunch = false;
        }
    } else {
        if (context.isConfirmationNeeded()) {
            continueLaunch = //$NON-NLS-1$
            MessageDialog.openQuestion(//$NON-NLS-1$
            shell, //$NON-NLS-1$
            Messages.getString("ProcessComposite.confirmTitle"), //$NON-NLS-1$ 
            Messages.getString("ProcessComposite.confirmText", context.getName()));
        }
        updateDefaultValueForListTypeParameter(context.getContextParameterList());
    }
    return continueLaunch;
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 14 with IContextParameter

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

the class ContextPartGenerator method tranformEncryptedParams.

private static List<IContextParameter> tranformEncryptedParams(List<IContextParameter> listParameters) {
    List<IContextParameter> listParametersCopy = new ArrayList<IContextParameter>(listParameters.size());
    // encrypt the password
    for (IContextParameter iContextParameter : listParameters) {
        if (PasswordEncryptUtil.isPasswordType(iContextParameter.getType())) {
            IContextParameter icp = iContextParameter.clone();
            String pwd = icp.getValue();
            if (pwd != null && !pwd.isEmpty()) {
                try {
                    icp.setValue(PasswordEncryptUtil.encryptPasswordHex(pwd));
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
            listParametersCopy.add(icp);
        } else {
            listParametersCopy.add(iContextParameter);
        }
    }
    return listParametersCopy;
}
Also used : ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException)

Example 15 with IContextParameter

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

the class TestComponentsAction method setDefaultProperties.

/**
     * DOC qwei Comment method "setDefaultProperties".
     * 
     * @param process
     */
private void setDefaultProperties(IProcess process, String componentPath) {
    // input_path / output_path
    IContext context = process.getContextManager().getDefaultContext();
    List<IContextParameter> tempContextParameter = context.getContextParameterList();
    for (IContextParameter parameter : tempContextParameter) {
        fillParameter(parameter, componentPath);
    }
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter)

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