Search in sources :

Example 16 with MetadataColumn

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

the class InputTable method initFromExternalData.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.dbmap.model.table.AbstractInOutTable#initFromExternalData(org.talend.designer.dbmap.external
     * .data.ExternalMapperTable)
     */
@Override
public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
    boolean isAliasTable = externalMapperTable != null && externalMapperTable.getAlias() != null;
    if (isAliasTable) {
        // dbmap table is alias
        setMetadataTable(connection.getTable().clone());
    } else if (connection != null) {
        // dbmap table references a physical table
        setMetadataTable(connection.getTable());
    }
    super.initFromExternalData(externalMapperTable);
    List<IMetadataColumn> columns = getMetadataTable().getListColumns();
    Map<String, ExternalDbMapEntry> nameToPerTabEntry = new HashMap<String, ExternalDbMapEntry>();
    if (externalMapperTable != null && externalMapperTable.getMetadataTableEntries() != null) {
        for (ExternalDbMapEntry perTableEntry : externalMapperTable.getMetadataTableEntries()) {
            nameToPerTabEntry.put(perTableEntry.getName(), perTableEntry);
        }
    }
    ArrayList<IMetadataColumn> columnsToRemove = new ArrayList<IMetadataColumn>();
    for (IMetadataColumn column : columns) {
        InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
        ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
        // Entry match with current column
        if (externalMapperTableEntry != null) {
            fillInputEntry(inputEntry, externalMapperTableEntry);
            nameToPerTabEntry.remove(externalMapperTableEntry.getName());
        }
        if (externalMapperTableEntry != null || !isAliasTable) {
            dataMapTableEntries.add(inputEntry);
        } else {
            columnsToRemove.add(column);
        }
    }
    columns.removeAll(columnsToRemove);
    // create unmatching entries
    for (ExternalDbMapEntry perTableEntry : nameToPerTabEntry.values()) {
        MetadataColumn column = new MetadataColumn();
        column.setLabel(perTableEntry.getName());
        InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
        ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
        fillInputEntry(inputEntry, externalMapperTableEntry);
        dataMapTableEntries.add(inputEntry);
        columns.add(column);
    }
    if (externalMapperTable != null) {
        joinType = mapperManager.getCurrentLanguage().getJoin(externalMapperTable.getJoinType());
        if (joinType == null) {
            joinType = mapperManager.getCurrentLanguage().getAvailableJoins()[0];
        }
        alias = externalMapperTable.getAlias();
        tableName = externalMapperTable.getTableName() != null ? externalMapperTable.getTableName() : connection.getName();
    }
}
Also used : IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 17 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() {

        @Override
        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) {
            removeButton = (RemovePushButtonForExtendedTable) extendedPushButton;
        }
    }
    if (removeButton != null) {
        final TableViewerCreator tableViewerCreator = removeButton.getExtendedTableViewer().getTableViewerCreator();
        tableViewerCreator.getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {

            @Override
            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)
             */
        @Override
        public void widgetDisposed(DisposeEvent e) {
            for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
                extendedPushButton.removeListener(beforeCommandListenerForOutputButtons, true);
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) RemovePushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.RemovePushButton) TableItem(org.eclipse.swt.widgets.TableItem) 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) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) ExtendedPushButton(org.talend.commons.ui.swt.advanced.dataeditor.control.ExtendedPushButton) MetadataToolbarEditorView(org.talend.core.ui.metadata.editor.MetadataToolbarEditorView) ExtendedButtonEvent(org.talend.commons.ui.swt.extended.table.ExtendedButtonEvent)

Example 18 with MetadataColumn

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

the class MetadataEmfFactory method setMetadataTypeCommon.

@SuppressWarnings("unchecked")
private void setMetadataTypeCommon(final MetadataType metadataType) {
    this.metadataType = metadataType;
    IMetadataColumn metaCol;
    ColumnType colType;
    EList listColType;
    List<IMetadataColumn> listMetadataColumn;
    metadataTable.setComment(metadataType.getComment());
    metadataTable.setTableName(metadataType.getName());
    metadataTable.setLabel(metadataType.getLabel());
    metadataTable.setTableType(metadataType.getType());
    EMap<String, String> properties = metadataType.getAdditionalProperties();
    if (properties != null) {
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            metadataTable.getAdditionalProperties().put(entry.getKey(), entry.getValue());
        }
    }
    if (metadataType.getConnector() != null) {
        metadataTable.setAttachedConnector(metadataType.getConnector());
    } else {
        metadataTable.setAttachedConnector(EConnectionType.FLOW_MAIN.getName());
    }
    listColType = metadataType.getColumn();
    listMetadataColumn = new ArrayList<IMetadataColumn>();
    for (int i = 0; i < listColType.size(); i++) {
        colType = (ColumnType) listColType.get(i);
        metaCol = new MetadataColumn();
        metaCol.setComment(colType.getComment());
        metaCol.setKey(colType.isKey());
        metaCol.setNullable(colType.isNullable());
        if (colType.getLength() >= 0) {
            metaCol.setLength(new Integer(colType.getLength()));
        } else {
            metaCol.setLength(null);
        }
        if (colType.getOriginalLength() >= 0) {
            metaCol.setOriginalLength(new Integer(colType.getOriginalLength()));
        } else {
            metaCol.setOriginalLength(null);
        }
        if (colType.getAdditionalField().size() > 0) {
            Iterator it = colType.getAdditionalField().keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                metaCol.getAdditionalField().put(key, (String) colType.getAdditionalField().get(key));
            }
        }
        metaCol.setLabel(colType.getName());
        if (colType.getPrecision() >= 0) {
            metaCol.setPrecision(new Integer(colType.getPrecision()));
        } else {
            metaCol.setPrecision(null);
        }
        metaCol.setTalendType(colType.getType());
        metaCol.setType(colType.getSourceType());
        metaCol.setPattern(colType.getPattern());
        metaCol.setDefault(colType.getDefaultValue());
        metaCol.setRelatedEntity(colType.getRelatedEntity());
        metaCol.setRelationshipType(colType.getRelationshipType());
        if (colType.getOriginalDbColumnName() == null) {
            metaCol.setOriginalDbColumnName(colType.getName());
        } else {
            metaCol.setOriginalDbColumnName(colType.getOriginalDbColumnName());
        }
        metaCol.setUsefulColumn(colType.isUsefulColumn());
        listMetadataColumn.add(metaCol);
    }
    metadataTable.setListColumns(listMetadataColumn);
    List<String> columnNames = new ArrayList<String>();
    for (IMetadataColumn column : listMetadataColumn) {
        columnNames.add(column.getLabel());
    }
    metadataTable.setOriginalColumns(columnNames);
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) EMap(org.eclipse.emf.common.util.EMap) Map(java.util.Map)

Example 19 with MetadataColumn

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

the class MapperManager method addRejectOutput.

public void addRejectOutput() {
    String baseName = ERROR_REJECT;
    IProcess process = getAbstractMapComponent().getProcess();
    String tableName = baseName;
    if (!process.checkValidConnectionName(baseName) && process instanceof IProcess2) {
        final String uniqueName = ((IProcess2) process).generateUniqueConnectionName("row", baseName);
        tableName = uniqueName;
        ((IProcess2) process).addUniqueConnectionName(uniqueName);
    } else if (process instanceof IProcess2) {
        tableName = baseName;
        ((IProcess2) process).addUniqueConnectionName(baseName);
    }
    IMetadataTable metadataTable = getNewMetadataTable();
    metadataTable.setTableName(tableName);
    MetadataColumn errorMessageCol = new MetadataColumn();
    errorMessageCol.setLabel(ERROR_REJECT_MESSAGE);
    errorMessageCol.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
    errorMessageCol.setNullable(true);
    errorMessageCol.setOriginalDbColumnName(ERROR_REJECT_MESSAGE);
    errorMessageCol.setReadOnly(true);
    errorMessageCol.setCustom(true);
    errorMessageCol.setCustomId(0);
    metadataTable.getListColumns().add(errorMessageCol);
    MetadataColumn errorStackTrace = new MetadataColumn();
    errorStackTrace.setLabel(ERROR_REJECT_STACK_TRACE);
    errorStackTrace.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
    errorStackTrace.setNullable(true);
    errorStackTrace.setOriginalDbColumnName(ERROR_REJECT_STACK_TRACE);
    errorStackTrace.setReadOnly(true);
    errorStackTrace.setCustom(true);
    errorStackTrace.setCustomId(1);
    metadataTable.getListColumns().add(errorStackTrace);
    OutputTable abstractDataMapTable = new OutputTable(this, metadataTable, tableName);
    abstractDataMapTable.setErrorRejectTable(true);
    abstractDataMapTable.initFromExternalData(null);
    TablesZoneView tablesZoneViewOutputs = uiManager.getTablesZoneViewOutputs();
    DataMapTableView rejectDataMapTableView = uiManager.createNewOutputTableView(null, abstractDataMapTable, tablesZoneViewOutputs);
    tablesZoneViewOutputs.setSize(tablesZoneViewOutputs.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    List<DataMapTableView> outputsTablesView = uiManager.getOutputsTablesView();
    int sizeList = outputsTablesView.size();
    for (int i = 0; i < sizeList; i++) {
        if (i + 1 < sizeList) {
            FormData formData = (FormData) outputsTablesView.get(i + 1).getLayoutData();
            formData.top = new FormAttachment(outputsTablesView.get(i));
        }
    }
    CustomTableManager.addCustomManagementToTable(uiManager.getOutputMetaEditorView(), true);
    tablesZoneViewOutputs.setSize(tablesZoneViewOutputs.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    tablesZoneViewOutputs.layout();
    uiManager.moveOutputScrollBarZoneToMax();
    uiManager.refreshBackground(true, false);
    uiManager.selectDataMapTableView(rejectDataMapTableView, true, false);
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) FormData(org.eclipse.swt.layout.FormData) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IProcess2(org.talend.core.model.process.IProcess2) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) TablesZoneView(org.talend.designer.mapper.ui.visualmap.zone.scrollable.TablesZoneView) IProcess(org.talend.core.model.process.IProcess) FormAttachment(org.eclipse.swt.layout.FormAttachment) OutputTable(org.talend.designer.mapper.model.table.OutputTable)

Example 20 with MetadataColumn

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

the class MetadataExtPasteCommand method createPastableBeansList.

@Override
public List createPastableBeansList(ExtendedTableModel extendedTable, List copiedObjectsList) {
    ArrayList list = new ArrayList();
    ArrayList countList = new ArrayList();
    ArrayList<String> labelsExisted = getLabelsExisted(extendedTable);
    for (Object current : copiedObjectsList) {
        if (current instanceof IMetadataColumn) {
            IMetadataColumn copy = ((IMetadataColumn) current).clone();
            String nextGeneratedColumnName = ((MetadataTableEditor) extendedTable).getNextGeneratedColumnName(copy.getLabel());
            if (labelsExisted.contains(nextGeneratedColumnName)) {
                nextGeneratedColumnName = validateColumnName(nextGeneratedColumnName, labelsExisted);
            }
            labelsExisted.add(nextGeneratedColumnName);
            copy.setLabel(nextGeneratedColumnName);
            if (copy instanceof MetadataColumnExt) {
                list.add(copy);
            } else {
                MetadataColumnExt metadataColumnExt = new MetadataColumnExt((MetadataColumn) copy);
                metadataColumnExt.setFunction(functionManagerExt.getDefaultFunction(metadataColumnExt, metadataColumnExt.getTalendType()));
                list.add(metadataColumnExt);
            }
        } else if (current instanceof org.talend.core.model.metadata.builder.connection.MetadataColumn) {
            MetadataTableEditor tableEditor = (MetadataTableEditor) extendedTable;
            org.talend.core.model.metadata.builder.connection.MetadataColumn metadataColumn = (org.talend.core.model.metadata.builder.connection.MetadataColumn) current;
            String nextGeneratedColumnName = metadataColumn.getLabel();
            //$NON-NLS-1$
            String tempNewColumnName = "";
            boolean iMetaColumnUnique = false;
            boolean metaColumnUnique = false;
            while (iMetaColumnUnique == false || metaColumnUnique == false) {
                nextGeneratedColumnName = tableEditor.getNextGeneratedColumnName(nextGeneratedColumnName, null);
                iMetaColumnUnique = true;
                metaColumnUnique = false;
                if (list.size() == 0)
                    metaColumnUnique = true;
                else {
                    tempNewColumnName = this.getUniqueString(list, nextGeneratedColumnName);
                    if (tempNewColumnName.equals(nextGeneratedColumnName))
                        metaColumnUnique = true;
                    else {
                        metaColumnUnique = false;
                        nextGeneratedColumnName = tempNewColumnName;
                    }
                }
            }
            org.talend.core.model.metadata.builder.connection.MetadataColumn newColumnCopy = new ConnectionFactoryImpl().copy(metadataColumn, nextGeneratedColumnName);
            IMetadataColumn copy = (ConvertionHelper.convertToIMetaDataColumn(newColumnCopy)).clone();
            copy.setLabel(nextGeneratedColumnName);
            MetadataColumnExt metadataColumnExt = new MetadataColumnExt((MetadataColumn) copy);
            metadataColumnExt.setFunction(functionManagerExt.getDefaultFunction(metadataColumnExt, metadataColumnExt.getTalendType()));
            list.add(metadataColumnExt);
            countList.add(nextGeneratedColumnName);
        }
    }
    return list;
}
Also used : MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ConnectionFactoryImpl(org.talend.core.model.metadata.builder.connection.impl.ConnectionFactoryImpl)

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