Search in sources :

Example 46 with MetadataColumn

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

the class AbstractJSONFileStepForm method initMetadataTable.

protected void initMetadataTable(List<FOXTreeNode> list, EList columnList) {
    int maxColumnsNumber = CoreUIPlugin.getDefault().getPreferenceStore().getInt(ITalendCorePrefConstants.MAXIMUM_AMOUNT_OF_COLUMNS_FOR_XML);
    for (FOXTreeNode node : list) {
        if (columnList.size() > maxColumnsNumber) {
            return;
        }
        MetadataEmfTableEditor editor = new MetadataEmfTableEditor();
        if (node instanceof Element) {
            String label = node.getLabel();
            if (!node.hasChildren() && label != null && !label.equals("")) {
                String columnName = label;
                if (columnName.contains(":")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    columnName = columnName.split(":")[1];
                }
                columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
                String dataType = node.getDataType();
                MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
                metadataColumn.setOriginalField(label);
                metadataColumn.setTalendType(dataType);
                columnList.add(metadataColumn);
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
            }
        }
        if (node instanceof Attribute) {
            String label = node.getLabel();
            if (label != null && !label.equals("")) {
                String columnName = label;
                if (columnName.contains(":")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    columnName = columnName.split(":")[1];
                }
                columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
                String dataType = node.getDataType();
                MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
                metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
                metadataColumn.setOriginalField(label);
                metadataColumn.setTalendType(dataType);
                columnList.add(metadataColumn);
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
            }
        }
        if (node.hasChildren()) {
            List<FOXTreeNode> children = node.getChildren();
            initMetadataTable(children, columnList);
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 47 with MetadataColumn

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

the class JSONFileOutputStep2Form method updateJSONTreeViewer.

private void updateJSONTreeViewer() {
    LinksManager<Item, Object, Tree, Object> linkManager = linker.getLinkManager();
    List<LinkDescriptor<Item, Object, Tree, Object>> links = linkManager.getLinks();
    for (int i = 0; i < links.size(); i++) {
        LinkDescriptor<Item, Object, Tree, Object> linkDescriptor = links.get(i);
        IExtremityLink<Item, Object> ex1 = linkDescriptor.getExtremity1();
        IExtremityLink<Tree, Object> ex2 = linkDescriptor.getExtremity2();
        MetadataColumn metaColumn = (MetadataColumn) ex1.getDataItem();
        FOXTreeNode node = (FOXTreeNode) ex2.getDataItem();
        if (ex1.getGraphicalObject() != null) {
            Item item = ex1.getGraphicalObject();
            if (!item.isDisposed() && metaColumn.equals(item.getData())) {
                node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metaColumn));
            } else {
                node.setColumn(null);
            }
        }
        node.setDataType(metaColumn.getTalendType());
    }
    JSONViewer.refresh();
    updateConnection();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Item(org.eclipse.swt.widgets.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Tree(org.eclipse.swt.widgets.Tree) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Example 48 with MetadataColumn

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

the class GenerateSelectSQLAction method createTableSelect.

/**
     * @return query string for full table select
     */
protected String createTableSelect() {
    RepositoryNode node = (RepositoryNode) selectedNodes.get(0);
    String fix = getPrePostfix(node);
    String tablePrefix = getTablePrefix(node);
    //$NON-NLS-1$
    StringBuffer query = new StringBuffer("select ");
    //$NON-NLS-1$
    String sep = "";
    EList columns = ((MetadataTableRepositoryObject) node.getObject()).getTable().getColumns();
    Iterator it = columns.iterator();
    if (columns.isEmpty()) {
        //$NON-NLS-1$
        query.append("*");
    }
    while (it.hasNext()) {
        String column = ((MetadataColumn) it.next()).getOriginalField();
        if (column == null || column.trim().equals("")) {
            //$NON-NLS-1$
            continue;
        }
        query.append(sep);
        query.append(fix + column + fix);
        //$NON-NLS-1$
        sep = ", ";
    }
    //$NON-NLS-1$
    query.append(" from ");
    if (fix != null && !fix.trim().equals("")) {
        //$NON-NLS-1$
        if (tablePrefix == null || tablePrefix.equals("")) {
            //$NON-NLS-1$
            query.append(fix + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName() + fix);
        } else {
            query.append(//$NON-NLS-1$
            fix + tablePrefix + fix + "." + fix + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName() + fix);
        }
    } else {
        if (tablePrefix == null || tablePrefix.equals("")) {
            //$NON-NLS-1$
            query.append(((SqlBuilderRepositoryObject) node.getObject()).getSourceName());
        } else {
            //$NON-NLS-1$
            query.append(tablePrefix + "." + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName());
        }
    }
    return query.toString();
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject)

Example 49 with MetadataColumn

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

the class MetadataRefreshAction method init.

/**
     * DOC dev Comment method "init".
     */
public void init() {
    IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection();
    repositorynodes.clear();
    columnNodes.clear();
    boolean flag = true;
    for (Object object : selection.toList()) {
        if (!((RepositoryNode) object).getProperties(EProperties.CONTENT_TYPE).equals(RepositoryNodeType.COLUMN)) {
            this.setEnabled(false);
            return;
        }
        MetadataColumn col = ((DBTreeProvider.MetadataColumnRepositoryObject) ((RepositoryNode) object).getObject()).getColumn();
        if (col.getLabel().equals("")) {
            //$NON-NLS-1$
            this.setEnabled(false);
            return;
        }
        if (col.isSynchronised()) {
            if (!repositorynodes.isEmpty() && repositorynodes.get(0) != null && !SQLBuilderRepositoryNodeManager.getRoot(repositorynodes.get(0)).equals(SQLBuilderRepositoryNodeManager.getRoot(((RepositoryNode) object)))) {
                this.setEnabled(false);
                return;
            }
            repositorynodes.add((RepositoryNode) object);
            this.setEnabled(true);
            flag = false;
            columnNodes.add(col);
        }
    }
    if (flag) {
        this.setEnabled(false);
        return;
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 50 with MetadataColumn

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

the class MetadataUtils method createColumn.

/**
     * Create a column instance by <code>columnAttrMap</code>.
     * <p>
     * FIXME: will add more attributes support if needed.
     * 
     * @param columnAttrMap
     * @return
     */
private static MetadataColumn createColumn(Map<String, Object> columnAttrMap) {
    MetadataColumn column = ConnectionFactory.eINSTANCE.createMetadataColumn();
    Object columnNameObj = columnAttrMap.get(IMetadataTableConstants.COLUMN_NAME);
    if (columnNameObj == null) {
        // Column name must not be null.
        return null;
    }
    column.setName(String.valueOf(columnNameObj));
    column.setLabel(column.getName());
    //$NON-NLS-1$
    String columnType = "id_String";
    Object columnTypeObj = columnAttrMap.get(IMetadataTableConstants.COLUMN_TYPE);
    if (columnTypeObj != null) {
        columnType = String.valueOf(columnTypeObj);
    }
    column.setTalendType(columnType);
    return column;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)59 ArrayList (java.util.ArrayList)27 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)22 List (java.util.List)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)10 IModel (org.talend.designer.hl7.model.IModel)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Command (org.eclipse.gef.commands.Command)7 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 ExtendedTableResetDBTypesCommand (org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand)5 MetadataEmfExportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand)5 MetadataEmfImportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand)5 MetadataEmfPasteCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand)5 HL7MultiSchemaUI (org.talend.designer.hl7.ui.HL7MultiSchemaUI)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4