Search in sources :

Example 26 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class InsertNewColumnCommand method creatMeatadataColumn.

private void creatMeatadataColumn(IMetadataColumn columnSource, String targetNodeName, AbstractNode sourceNode, IMetadataTable metadataTarget, int index) {
    IMetadataColumn createNewColumn = null;
    if (columnSource != null) {
        // dnd schema column
        createNewColumn = new MetadataColumn(columnSource);
        createNewColumn.setLabel(targetNodeName);
    } else {
        // dnd doc child
        createNewColumn = new MetadataColumn();
        createNewColumn.setLabel(targetNodeName);
        createNewColumn.setType(sourceNode.getType());
        createNewColumn.setTalendType(sourceNode.getType());
        if (sourceNode instanceof TreeNode) {
            createNewColumn.setKey(((TreeNode) sourceNode).isKey());
            createNewColumn.setNullable(((TreeNode) sourceNode).isNullable());
            createNewColumn.setPattern(((TreeNode) sourceNode).getPattern());
        }
    }
    if (index != -1) {
        metadataTarget.getListColumns().add(index, createNewColumn);
    } else {
        metadataTarget.getListColumns().add(createNewColumn);
    }
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 27 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class ProblemsAnalyserTest method createMetadataColumns.

private void createMetadataColumns(IMetadataTable table, int columns) {
    for (int i = 0; i < columns; i++) {
        MetadataColumn newColumn = new MetadataColumn();
        newColumn.setLabel("newColumn" + i);
        newColumn.setTalendType("id_String");
        table.getListColumns().add(newColumn);
    }
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn)

Example 28 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class FunctionManagerExtTest method testGetOneColData.

@Test
public void testGetOneColData() {
    FunctionManagerExt functionManagerExt = new FunctionManagerExt();
    MetadataColumn newColumn = new MetadataColumn();
    //$NON-NLS-1$
    newColumn.setLabel("newColumn");
    newColumn.setTalendType(JavaTypesManager.STRING.getId());
    MetadataColumnExt columnExt = new MetadataColumnExt(newColumn);
    Function function = new Function();
    //$NON-NLS-1$
    function.setName("UPCASE");
    function.setDescription(PURE_PERL_DESC);
    //$NON-NLS-1$
    function.setClassName("StringHandling");
    StringParameter param = new StringParameter();
    //$NON-NLS-1$
    param.setName("string");
    //$NON-NLS-1$
    param.setValue("\"Hello\"");
    param.setType(JavaTypesManager.STRING.getId());
    //$NON-NLS-1$
    param.setComment("String");
    List<Parameter> params = new ArrayList<Parameter>();
    params.add(param);
    function.setParameters(params);
    columnExt.setFunction(function);
    // replace as false
    String value = functionManagerExt.getOneColData(columnExt);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(\"Hello\")");
    value = functionManagerExt.getOneColData(columnExt, false);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(\"Hello\")");
    value = functionManagerExt.getOneColData(columnExt, false, false);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(\"Hello\")");
    // replace as true
    value = functionManagerExt.getOneColData(columnExt, true);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(${0})");
    value = functionManagerExt.getOneColData(columnExt, false, true);
    //$NON-NLS-1$
    assertEquals(value, "StringHandling.UPCASE(${0})");
}
Also used : MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ArrayList(java.util.ArrayList) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt) Test(org.junit.Test)

Example 29 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class FunctionManagerExtTest method testGetFuntionFromColumn.

@Test
public void testGetFuntionFromColumn() {
    FunctionManagerExt functionManagerExt = new FunctionManagerExt();
    MetadataColumn newColumn = new MetadataColumn();
    //$NON-NLS-1$
    newColumn.setLabel("newColumn");
    newColumn.setTalendType(JavaTypesManager.STRING.getId());
    MetadataColumnExt columnExt = new MetadataColumnExt(newColumn);
    List<Function> funcs = functionManagerExt.getFunctionsByType(newColumn.getTalendType());
    if (funcs.size() > 0) {
        Function func = funcs.get(0);
        columnExt.setFunction(func);
        Function function = functionManagerExt.getFunctionFromColumn(columnExt);
        assertEquals(func.getName(), function.getName());
        assertEquals(func.getParameters().size(), function.getParameters().size());
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.MetadataColumn) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt) Test(org.junit.Test)

Example 30 with MetadataColumn

use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.

the class ScdManager method createMetadataColumn.

/**
     * DOC chuang Comment method "createMetadataColumn".
     * 
     * @param outputColumns
     * 
     * @param schema
     * 
     * @param lang
     * @return
     */
private IMetadataColumn createMetadataColumn(Map<String, IMetadataColumn> outputColumns, IMetadataTable schema, String name, Class clazz, ECodeLanguage lang) {
    if (outputColumns.get(name) != null) {
        return null;
    }
    IMetadataColumn column = new MetadataColumn();
    column.setLabel(name);
    column.setOriginalDbColumnName(name);
    column.setTalendType(getType(clazz, lang));
    column.setComment(GENERATE_COLUMN);
    schema.getListColumns().add(column);
    outputColumns.put(column.getLabel(), column);
    return column;
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Aggregations

MetadataColumn (org.talend.core.model.metadata.MetadataColumn)44 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)35 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)20 ArrayList (java.util.ArrayList)14 MetadataTable (org.talend.core.model.metadata.MetadataTable)13 Test (org.junit.Test)6 MetadataColumnExt (org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)6 IElementParameter (org.talend.core.model.process.IElementParameter)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 IComponent (org.talend.core.model.components.IComponent)3 IConnection (org.talend.core.model.process.IConnection)3 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)3 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)3 List (java.util.List)2 Schema (org.apache.avro.Schema)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 Point (org.eclipse.swt.graphics.Point)2