Search in sources :

Example 1 with MetadataColumn

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

the class RowGeneratorComponent method convert.

/**
     * Coverts <code>MetadataColumn</code> to <code>MetadataColumnExt</code>
     * 
     * @param metadataTable
     * @return
     */
private void convert(IMetadataTable metadataTable) {
    List<IMetadataColumn> exts = new ArrayList<IMetadataColumn>();
    for (int j = 0; j < metadataTable.getListColumns().size(); j++) {
        IMetadataColumn column = metadataTable.getListColumns().get(j);
        if (column instanceof MetadataColumn) {
            MetadataColumnExt ext = new MetadataColumnExt((MetadataColumn) column);
            String columnValue = this.getColumnValue(ext, j);
            if (columnValue != null && columnValue.length() > 0) {
                //$NON-NLS-1$ //$NON-NLS-2$
                columnValue = columnValue.replaceAll("\"", "");
                //$NON-NLS-1$
                columnValue = columnValue.substring(columnValue.lastIndexOf(".") + 1);
                Function function = new Function();
                function.setName(columnValue);
                ext.setFunction(function);
            }
            exts.add(ext);
        }
    }
    metadataTable.setListColumns(exts);
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) Function(org.talend.designer.rowgenerator.data.Function) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumnExt(org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt)

Example 2 with MetadataColumn

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

the class TabFolderEditors method addListenersToOutputButtons.

/**
     * DOC amaumont Comment method "addListenersToInputButtons".
     */
private void addListenersToOutputButtons() {
    MetadataToolbarEditorView toolBar = outputMetaEditor.getToolBar();
    outputToolBarButtons = toolBar.getButtons();
    beforeCommandListenerForOutputButtons = new IExtendedButtonListener() {

        public void handleEvent(ExtendedButtonEvent event) {
            TableViewerCreator tableViewerCreator = mapperManager.getUiManager().getCurrentSelectedOutputTableView().getTableViewerCreatorForColumns();
            if (tableViewerCreator != null) {
                tableViewerCreator.applyActivatedCellEditor();
            }
        }
    };
    for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
        extendedPushButton.addListener(beforeCommandListenerForOutputButtons, true);
        if (extendedPushButton instanceof RemovePushButton && !mapperManager.componentIsReadOnly()) {
            removeButton = (RemovePushButtonForExtendedTable) extendedPushButton;
        }
    }
    if (removeButton != null) {
        final TableViewerCreator tableViewerCreator = removeButton.getExtendedTableViewer().getTableViewerCreator();
        tableViewerCreator.getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {

            public void handle(LineSelectionEvent e) {
                for (TableItem item : tableViewerCreator.getTable().getSelection()) {
                    if (item.getData() instanceof MetadataColumn) {
                        MetadataColumn column = (MetadataColumn) item.getData();
                        removeButton.getButton().setEnabled(!column.isCustom());
                        break;
                    }
                }
            }
        });
    }
    this.addDisposeListener(new DisposeListener() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
             */
        public void widgetDisposed(DisposeEvent e) {
            for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
                extendedPushButton.removeListener(beforeCommandListenerForOutputButtons, true);
            }
        }
    });
}
Also used : MetadataColumn(org.talend.core.model.metadata.MetadataColumn) DisposeListener(org.eclipse.swt.events.DisposeListener) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) RemovePushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.RemovePushButton) ExtendedPushButton(org.talend.commons.ui.swt.advanced.dataeditor.control.ExtendedPushButton) TableItem(org.eclipse.swt.widgets.TableItem) MetadataToolbarEditorView(org.talend.core.ui.metadata.editor.MetadataToolbarEditorView) IExtendedButtonListener(org.talend.commons.ui.swt.extended.table.IExtendedButtonListener) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ExtendedButtonEvent(org.talend.commons.ui.swt.extended.table.ExtendedButtonEvent)

Example 3 with MetadataColumn

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

the class ChangeValuesFromRepositoryTest method createSimpleMetadata.

private IMetadataTable createSimpleMetadata() {
    IMetadataTable table = new org.talend.core.model.metadata.MetadataTable();
    IMetadataColumn column1 = new MetadataColumn();
    //$NON-NLS-1$
    column1.setLabel("C1");
    //$NON-NLS-1$
    column1.setTalendType("id_String");
    table.getListColumns().add(column1);
    IMetadataColumn column2 = new MetadataColumn();
    //$NON-NLS-1$
    column2.setLabel("C2");
    //$NON-NLS-1$
    column2.setTalendType("id_String");
    table.getListColumns().add(column2);
    IMetadataColumn column3 = new MetadataColumn();
    //$NON-NLS-1$
    column3.setLabel("C3");
    //$NON-NLS-1$
    column3.setTalendType("id_Integer");
    table.getListColumns().add(column3);
    return table;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 4 with MetadataColumn

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

the class RepositoryChangeMetadataCommandTest method testComponentSchemaUpdated.

@Test
public void testComponentSchemaUpdated() {
    IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
    Node node = new Node(component, new Process(new FakePropertyImpl()));
    IMetadataTable table = node.getMetadataList().get(0);
    IMetadataColumn column = new MetadataColumn();
    column.setLabel("C1");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C2");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C3");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    IMetadataTable newTable = table.clone(true);
    newTable.getListColumns().remove(0);
    IElementParameter schemaParam = null;
    for (IElementParameter param : node.getElementParameters()) {
        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
            schemaParam = param;
            break;
        }
    }
    assertNotNull(schemaParam);
    //$NON-NLS-1$
    String fullParamName = SCHEMA_PARAM_NAME + ":REPOSITORY_SCHEMA_TYPE";
    //$NON-NLS-1$ //$NON-NLS-2$
    String propValue = "testconnid" + " - " + newTable.getTableName();
    RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand(node, fullParamName, propValue, newTable, null, null);
    changeMetadataCommand.execute();
    newTable = node.getMetadataList().get(0);
    String avroSchemaStr = ((SchemaProperties) node.getComponentProperties().getProperties("module.main")).schema.getStringValue();
    assertNotNull(avroSchemaStr);
    Schema avroSchema = new Schema.Parser().parse(avroSchemaStr);
    assertEquals(2, avroSchema.getFields().size());
    //$NON-NLS-1$
    assertNull(avroSchema.getField("C1"));
    assertEquals(avroSchemaStr, schemaParam.getValue().toString());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) Schema(org.apache.avro.Schema) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Test(org.junit.Test)

Example 5 with MetadataColumn

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

the class ChangeMetadataCommandTest method testComponentSchemaUpdated.

@Test
public void testComponentSchemaUpdated() {
    IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
    Node node = new Node(component, new Process(new FakePropertyImpl()));
    IMetadataTable table = node.getMetadataList().get(0);
    IMetadataColumn column = new MetadataColumn();
    column.setLabel("C1");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C2");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C3");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    IMetadataTable newTable = table.clone(true);
    newTable.getListColumns().remove(0);
    IElementParameter schemaParam = null;
    for (IElementParameter param : node.getElementParameters()) {
        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
            schemaParam = param;
            break;
        }
    }
    assertNotNull(schemaParam);
    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, schemaParam, null, null, null, table, newTable);
    changeMetadataCommand.execute();
    String avroSchemaStr = ((SchemaProperties) node.getComponentProperties().getProperties("module.main")).schema.getStringValue();
    assertNotNull(avroSchemaStr);
    Schema avroSchema = new Schema.Parser().parse(avroSchemaStr);
    assertEquals(2, avroSchema.getFields().size());
    //$NON-NLS-1$
    assertNull(avroSchema.getField("C1"));
    assertEquals(avroSchemaStr, schemaParam.getValue().toString());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) Schema(org.apache.avro.Schema) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Test(org.junit.Test)

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