Search in sources :

Example 31 with MetadataColumn

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

the class HL7MetadataEmfToolbarEditor method createMoveDownPushButton.

@Override
protected MoveDownPushButton createMoveDownPushButton() {
    return new MoveDownPushButtonForExtendedTable(toolbar, extendedTableViewer) {

        @Override
        protected void afterCommandExecution(Command executedCommand) {
            MetadataEmfTableEditor tableEditorModel = (MetadataEmfTableEditor) getExtendedTableViewer().getExtendedControlModel();
            IStructuredSelection selection = (IStructuredSelection) ((HL7MultiSchemaUI) linker.getMainui()).getMetaTableViewer().getSelection();
            Object selectedObj = selection.getFirstElement();
            if (selectedObj != null) {
                String key = ((IModel) selectedObj).getDisplayName();
                List<MetadataColumn> metadataColumnList = tableEditorModel.getMetadataColumnList();
                Map<String, List<MetadataColumn>> schemaRelationMap = linker.getManager().getSchemaRelationMap();
                if (schemaRelationMap != null) {
                    List<MetadataColumn> schemas = new ArrayList<MetadataColumn>();
                    schemas.addAll(metadataColumnList);
                    schemaRelationMap.put(key, schemas);
                }
            }
            linker.getMainui().redrawLinkers();
            linker.getBackgroundRefresher().refreshBackground();
        }

        @Override
        public boolean getEnabledState() {
            // 13749
            return super.getEnabledState() && !isRepository;
        }
    };
}
Also used : IModel(org.talend.designer.hl7.model.IModel) MoveDownPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.MoveDownPushButtonForExtendedTable) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataEmfExportXmlCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand) MetadataEmfPasteCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand) ExtendedTableResetDBTypesCommand(org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand) MetadataEmfImportXmlCommand(org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand) Command(org.eclipse.gef.commands.Command) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) HL7MultiSchemaUI(org.talend.designer.hl7.ui.HL7MultiSchemaUI) ArrayList(java.util.ArrayList) List(java.util.List)

Example 32 with MetadataColumn

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

the class HL7UI method initLinkersByPrimitiveModels.

protected void initLinkersByPrimitiveModels(List<PrimitiveModel> pms) {
    TableItem[] tableItems = this.linker.getTarget().getItems();
    TreeItem[] treeItems = this.linker.getSource().getItems();
    TreeItem sourceItem = null;
    String sourceItemName = "";
    Object targetItemData = null;
    List<linkMapPropertis> allLinkProp = new ArrayList<linkMapPropertis>();
    for (PrimitiveModel pm : pms) {
        for (TableItem ti : tableItems) {
            Object data = ti.getData();
            MetadataColumn column = (MetadataColumn) data;
            if (column.getOriginalField().equals(pm.getDisplayName())) {
                sourceItemName = pm.getDisplayName();
                sourceItem = findSourceItem(sourceItemName, treeItems);
                targetItemData = ti.getData();
                linkMapPropertis linkProp = new linkMapPropertis(sourceItem, targetItemData);
                allLinkProp.add(linkProp);
            }
        }
    }
    for (linkMapPropertis linkProp : allLinkProp) {
        linker.addLinks(linkProp.getSource(), linkProp.getSource().getData(), this.linker.getTarget(), linkProp.getTargetData());
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) PrimitiveModel(org.talend.designer.hl7.model.PrimitiveModel)

Example 33 with MetadataColumn

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

the class DBTreeProvider method createColumns.

private void createColumns(RepositoryNode tableNode, IRepositoryViewObject repObj, Object currentTable, boolean isBuildIn) {
    for (Object currentColumn : ((MetadataTable) currentTable).getColumns()) {
        MetadataColumn metadataColumn = (MetadataColumn) currentColumn;
        RepositoryNode columnNode = createMetacolumn(tableNode, repObj, metadataColumn, isBuildIn);
        tableNode.getChildren().add(columnNode);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 34 with MetadataColumn

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

the class TableNode method isNodeSameToColumn.

/**
     * Check if ColumnNode and Column are the same.
     * 
     * @param node ColumnNode
     * @param column MetadataColumnImpl
     * @return isNodeSameToColumn
     * @exception
     */
private boolean isNodeSameToColumn(ColumnNode node, MetadataColumnImpl column) {
    SessionTreeNode sessionTreeNode = node.getSession();
    TableColumnInfo[] tableColumnInfo = null;
    try {
        tableColumnInfo = sessionTreeNode.getMetaData().getColumnInfo(ptableInfo);
    } catch (SQLException e) {
        SqlBuilderPlugin.log(e.getMessage(), e);
        return false;
    }
    // Retrive metadataColumns from Database
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
    List<TdColumn> metadataColumns = new ArrayList<TdColumn>();
    metadataColumns = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, getLabelText());
    Iterator iterate = metadataColumns.iterator();
    while (iterate.hasNext()) {
        MetadataColumn metadataColumn = (MetadataColumn) iterate.next();
        for (TableColumnInfo info : tableColumnInfo) {
            if (metadataColumn.getLabel().equals(node.getLabelText()) && info.getColumnName().equals(node.getLabelText())) {
                boolean divergency = isEquivalent(metadataColumn, column);
                metadataColumn.setDivergency(divergency);
                return divergency;
            }
        }
    }
    return true;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn) SQLException(java.sql.SQLException) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableColumnInfo(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection)

Example 35 with MetadataColumn

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

the class JSONFileStep3Form method refreshMetaDataTable.

/**
     * DOC ocarbone Comment method "refreshMetaData".
     * 
     * @param csvArray
     */
public void refreshMetaDataTable(final CsvArray csvArray, List<SchemaTarget> schemaTarget, Boolean flag) {
    informationLabel.setText("   " + "Guess successful");
    List mcolumns = new ArrayList();
    mcolumns.addAll(tableEditorView.getMetadataEditor().getMetadataColumnList());
    // clear all items
    tableEditorView.getMetadataEditor().removeAll();
    List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
    String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
    if (isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
        file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
    }
    if (csvArray == null || csvArray.getRows().isEmpty()) {
        return;
    } else {
        List<String[]> csvRows = csvArray.getRows();
        String[] fields = csvRows.get(0);
        int numberOfCol = fields.length;
        // define the label to the metadata width the content of the first row
        int firstRowToExtractMetadata = 0;
        // the first rows is used to define the label of any metadata
        String[] label = new String[numberOfCol];
        for (int i = 0; i < numberOfCol; i++) {
            label[i] = DEFAULT_LABEL + i;
            if (firstRowToExtractMetadata == 0) {
                if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
                    label[i] = MetadataToolHelper.validateColumnName(label[i], i);
                }
            }
        // if (firstRowToExtractMetadata == 1) {
        // String value = fields.get(i).getValue();
        // if (!value.equals("")) {
        // label[i] = value;
        // }
        // }
        }
        for (int i = 0; i < numberOfCol; i++) {
            // define the first currentType and assimile it to globalType
            String globalType = null;
            int lengthValue = 0;
            int precisionValue = 0;
            int current = firstRowToExtractMetadata;
            while (globalType == null) {
                if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "id_String";
                    } else {
                        globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    // if (current == csvRows.size()) {
                    // globalType = "id_String"; //$NON-NLS-1$
                    // }
                    }
                } else {
                    if (i >= csvRows.get(current).length) {
                        //$NON-NLS-1$
                        globalType = "String";
                    } else {
                        globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
                        current++;
                    // if (current == csvRows.size()) {
                    // globalType = "String"; //$NON-NLS-1$
                    // }
                    }
                }
            }
            // for another lines
            for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
                fields = csvRows.get(f);
                if (fields.length > i) {
                    String value = fields[i];
                    if (!value.equals("")) {
                        if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                            if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
                                globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
                            }
                        } else {
                            if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
                                globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
                            }
                        }
                        if (lengthValue < value.length()) {
                            lengthValue = value.length();
                        }
                        int positionDecimal = 0;
                        if (value.indexOf(',') > -1) {
                            positionDecimal = value.lastIndexOf(',');
                            precisionValue = lengthValue - positionDecimal;
                        } else if (value.indexOf('.') > -1) {
                            positionDecimal = value.lastIndexOf('.');
                            precisionValue = lengthValue - positionDecimal;
                        }
                    } else {
                        IPreferenceStore preferenceStore = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                            IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                            preferenceStore = designerCoreUiService.getPreferenceStore();
                        }
                        if (preferenceStore != null && preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
                            //$NON-NLS-1$
                            globalType = preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
                            if (preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
                                //$NON-NLS-1$
                                lengthValue = Integer.parseInt(preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
                            }
                        }
                    }
                }
            }
            // define the metadataColumn to field i
            MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
            // hshen bug7249
            //$NON-NLS-1$
            metadataColumn.setPattern("\"dd-MM-yyyy\"");
            // Convert javaType to TalendType
            String talendType = null;
            talendType = globalType;
            if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
                metadataColumn.setPrecision(precisionValue);
            } else {
                metadataColumn.setPrecision(0);
            }
            metadataColumn.setTalendType(talendType);
            metadataColumn.setLength(lengthValue);
            // Check the label and add it to the table
            metadataColumn.setLabel(tableEditorView.getMetadataEditor().getNextGeneratedColumnName(label[i]));
            columns.add(i, metadataColumn);
        }
    }
    if (!flag) {
        for (int i = 0; i < columns.size(); i++) {
            for (int j = 0; j < mcolumns.size(); j++) {
                if (columns.get(i).getLabel().equals(((MetadataColumn) mcolumns.get(j)).getLabel())) {
                    columns.remove(i);
                    columns.add(i, (MetadataColumn) mcolumns.get(j));
                }
            }
        }
    }
    tableEditorView.getMetadataEditor().addAll(columns);
    checkFieldsValue();
    tableEditorView.getTableViewerCreator().layout();
    tableEditorView.getTableViewerCreator().getTable().deselectAll();
    informationLabel.setText("Click to update schema preview");
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

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