Search in sources :

Example 11 with Variable

use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.

the class ExpressionComposite method getReplaceExpression.

/**
     * yzhang Comment method "getExpression".
     * 
     * @return
     */
public String getReplaceExpression() {
    if (document != null) {
        IRegion region = viewer.getViewerRegion();
        try {
            String doc = document.get(region.getOffset(), region.getLength());
            List<Variable> variables = ExpressionBuilderDialog.getTestComposite().getVariableList();
            for (Variable variable : variables) {
                doc = doc.replaceAll(variable.getName(), variable.getValue());
            }
            return doc;
        // return document.get(region.getOffset(), region.getLength());
        } catch (BadLocationException e) {
            MessageBoxExceptionHandler.process(e);
        }
    }
    return null;
}
Also used : Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 12 with Variable

use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.

the class VirtualRowGeneratorNode method getArray.

/**
     * yzhang Comment method "initArray".
     */
private Object getArray() {
    List<Map<String, String>> map = new ArrayList<Map<String, String>>();
    MetadataTable table = (MetadataTable) this.getMetadataList().get(0);
    for (IMetadataColumn col : table.getListColumns()) {
        VirtualMetadataColumn ext = (VirtualMetadataColumn) col;
        Map<String, String> value = new HashMap<String, String>();
        value.put(RowGeneratorComponent.COLUMN_NAME, ext.getLabel());
        List<Variable> variables = ExpressionBuilderDialog.getTestComposite().getVariableList();
        String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
        // modify for bug 9471
        try {
            for (Variable varible : variables) {
                if (valueContains(expression, varible.getName())) {
                    Integer.parseInt(varible.getValue());
                }
            }
            for (Variable var : variables) {
                String talendType = var.getTalendType();
                JavaType javaTypeFromId = JavaTypesManager.getJavaTypeFromId(talendType);
                String label = null;
                String value2 = var.getValue();
                if (javaTypeFromId != null) {
                    label = javaTypeFromId.getLabel();
                    if ("BigDecimal".equals(label)) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$//$NON-NLS-1$
                        value2 = " new BigDecimal(" + value2 + ")";
                    }
                }
                expression = renameValues(expression, var.getName(), value2);
            }
        } catch (NumberFormatException e1) {
            for (Variable var : variables) {
                //$NON-NLS-1$ //$NON-NLS-2$
                expression = renameValues(expression, var.getName(), "\"" + var.getValue() + "\"");
            }
        }
        //$NON-NLS-1$//$NON-NLS-1$
        value.put(RowGeneratorComponent.ARRAY, "\"\"+(" + expression + ")+\"\"");
        map.add(value);
    }
    return map;
}
Also used : Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) JavaType(org.talend.core.model.metadata.types.JavaType) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with Variable

use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.

the class ExpressionBuilderDialog method openDialog.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.expressionbuilder.ui.IExpressionBuilderDialogController#openDialog()
     */
@Override
public void openDialog(Object obj) {
    if (obj instanceof IExpressionDataBean) {
        List<Variable> vars = new ArrayList<Variable>();
        IExpressionDataBean bean = (IExpressionDataBean) obj;
        setDefaultExpression(bean.getExpression());
        ExpressionPersistance persistance = ExpressionPersistance.getInstance();
        persistance.setOwnerId(bean.getOwnerId());
        persistance.setPath(getExpressionStorePath());
        List<Variable> varList = new ArrayList<Variable>(persistance.loadExpression().getVariables());
        vars.addAll(varList);
        if (bean.getVariables() != null) {
            for (Variable var1 : bean.getVariables()) {
                boolean needAdd = true;
                for (Variable var2 : varList) {
                    if (var1.getName() != null && var1.getName().equals(var2.getName())) {
                        needAdd = false;
                        break;
                    }
                }
                if (var1.getName() != null && needAdd) {
                    vars.add(var1);
                }
            }
        }
        addVariables(vars);
    }
    open();
    setBlockOnOpen(true);
}
Also used : IExpressionDataBean(org.talend.commons.ui.runtime.expressionbuilder.IExpressionDataBean) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) ExpressionPersistance(org.talend.expressionbuilder.ExpressionPersistance) ArrayList(java.util.ArrayList)

Aggregations

Variable (org.talend.commons.runtime.model.expressionbuilder.Variable)13 ArrayList (java.util.ArrayList)8 List (java.util.List)4 File (java.io.File)3 Path (org.eclipse.core.runtime.Path)3 IOException (java.io.IOException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Bundle (org.osgi.framework.Bundle)2 IExpressionDataBean (org.talend.commons.ui.runtime.expressionbuilder.IExpressionDataBean)2 Function (org.talend.designer.rowgenerator.data.Function)2 Document (org.w3c.dom.Document)2 SAXException (org.xml.sax.SAXException)2 OutputFormat (com.sun.org.apache.xml.internal.serialize.OutputFormat)1 XMLSerializer (com.sun.org.apache.xml.internal.serialize.XMLSerializer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1