Search in sources :

Example 56 with MetadataColumn

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

the class HL7MultiSchemaUI method initMappingMap.

private void initMappingMap(List<SegmentModel> segments) {
    for (SegmentModel sm : segments) {
        List<MetadataColumn> list = new ArrayList<MetadataColumn>();
        hl7Manager.getSchemaRelationMap().put(sm.getDisplayName(), list);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ArrayList(java.util.ArrayList) SegmentModel(org.talend.designer.hl7.model.SegmentModel)

Example 57 with MetadataColumn

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

the class JSONFileOutputMetadataEmfTableEditorView method configureNameColumn.

protected void configureNameColumn(TableViewerCreator<MetadataColumn> tableViewerCreator) {
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setId(ID_COLUMN_NAME);
    //$NON-NLS-1$
    column.setTitle("Schema List");
    column.setWidth(100);
    column.setToolTipHeader("Column");
    column.setBeanPropertyAccessors(getLabelAccessor());
    final Image imageKey = ImageProvider.getImage(EImage.KEY_ICON);
    final Image imageEmpty = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.EMPTY);
    final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
    column.setCellEditor(cellEditor);
    cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            return validateColumnName(newValue, beanPosition);
        }
    });
    column.setImageProvider(new IColumnImageProvider() {

        public Image getImage(Object element) {
            if (getKeyAccesor().get((MetadataColumn) element)) {
                return imageKey;
            } else {
                return imageEmpty;
            }
        }
    });
    column.setWeight(25);
    column.setModifiable(!isReadOnly());
    column.setMinimumWidth(20);
// nameColumn = column;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IColumnImageProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnImageProvider) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) EImage(org.talend.commons.ui.runtime.image.EImage) Image(org.eclipse.swt.graphics.Image)

Example 58 with MetadataColumn

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

the class JSONFileSchemaDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new FillLayout());
    tableEditor = new MetadataEmfTableEditor("");
    MetadataTable metadataTable = form.getMetadataTable();
    tableEditor.setMetadataTable(metadataTable);
    // tableEditor.removeAll();
    List<MetadataColumn> list = (List<MetadataColumn>) form.getSchemaViewer().getInput();
    tableEditor.addAll(list);
    // if (list.size() > 0) {
    // for (MetadataColumn column : list) {
    // boolean toAdd = true;
    // for (int i = 0; i < currentColumnList.size(); i++) {
    // String label = column.getLabel();
    // String curLabel = currentColumnList.get(i).getLabel();
    // if (label.equals(curLabel)) {
    // toAdd = false;
    // break;
    // }
    // }
    // if (toAdd) {
    // tableEditor.add(column);
    // }
    // }
    // }
    tableEditorView = new MetadataEmfTableEditorView(composite, SWT.NONE);
    tableEditorView.setMetadataEditor(tableEditor);
    addListeners();
    return composite;
}
Also used : MetadataEmfTableEditorView(org.talend.core.ui.metadata.editor.MetadataEmfTableEditorView) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Composite(org.eclipse.swt.widgets.Composite) MetadataEmfTableEditor(org.talend.core.ui.metadata.editor.MetadataEmfTableEditor) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) List(java.util.List) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 59 with MetadataColumn

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

the class ColumnListController method updateColumnsOnElement.

private static void updateColumnsOnElement(IElement element, List<ColumnNameChanged> columnsChanged, boolean synWidthWithMetadataColumn, String[] prevColumnNameList, String[] curColumnNameList, String[] curColumnValueList, List<String> refColumnListNamesTmpWithSourceName, List<String> refColumnListValuesTmp, String[] refColumnListNames, String[] refColumnListValues, boolean isSCDComponent, boolean isEdifactComponent, Map<String, Boolean> customColMap) {
    List<String> columnList;
    String[] columnNameList;
    String edifactId = null;
    if (isEdifactComponent) {
        for (IElementParameter par : element.getElementParametersWithChildrens()) {
            if (par.getName().equals("REPOSITORY_PROPERTY_TYPE")) {
                edifactId = par.getValue().toString();
                break;
            }
        }
    }
    for (int i = 0; i < element.getElementParameters().size(); i++) {
        IElementParameter param = element.getElementParameters().get(i);
        columnList = getColumnList(element, param.getContext(), null);
        columnNameList = columnList.toArray(new String[0]);
        if (param.getFieldType() == EParameterFieldType.COLUMN_LIST && !isSCDComponent) {
            curColumnNameList = columnNameList;
            curColumnValueList = columnNameList;
        }
        if (param.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST) {
            curColumnNameList = prevColumnNameList;
            curColumnValueList = prevColumnNameList;
        }
        if (param.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
            curColumnNameList = refColumnListNames;
            curColumnValueList = refColumnListValues;
        }
        if ((param.getFieldType() == EParameterFieldType.COLUMN_LIST && !isSCDComponent) || param.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || param.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
            param.setListItemsDisplayName(curColumnNameList);
            param.setListItemsValue(curColumnValueList);
            // for bug 10945
            // 10155
            boolean currentColumnStillExist = ArrayUtils.contains(curColumnValueList, param.getValue());
            if (!currentColumnStillExist) {
                for (int j = 0; j < refColumnListNamesTmpWithSourceName.size(); j++) {
                    if (param.getValue().equals(refColumnListNamesTmpWithSourceName.get(j))) {
                        param.setValue(refColumnListValuesTmp.get(j));
                        break;
                    }
                }
                currentColumnStillExist = ArrayUtils.contains(curColumnValueList, param.getValue());
            }
            if (curColumnNameList.length > 0 && !currentColumnStillExist) {
                param.setValue(curColumnValueList[0]);
            } else if (!currentColumnStillExist) {
                //$NON-NLS-1$
                param.setValue("");
            }
            syncNodePropertiesColumns(param, columnsChanged, curColumnNameList);
        }
        if (param.getFieldType() == EParameterFieldType.TABLE) {
            Object[] itemsValue = param.getListItemsValue();
            for (Object element2 : itemsValue) {
                if (element2 instanceof IElementParameter) {
                    IElementParameter tmpParam = (IElementParameter) element2;
                    columnList = getColumnList(element, tmpParam.getContext(), customColMap);
                    String[] tableColumnNameList = columnList.toArray(new String[0]);
                    if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST) {
                        curColumnNameList = tableColumnNameList;
                        curColumnValueList = tableColumnNameList;
                    }
                    if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST && element instanceof INode) {
                        curColumnNameList = prevColumnNameList;
                        curColumnValueList = prevColumnNameList;
                    }
                    // needed for traces with breakpoint, feature:
                    if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST && element instanceof IConnection) {
                        curColumnNameList = tableColumnNameList;
                        curColumnValueList = tableColumnNameList;
                    }
                    if (tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                        curColumnNameList = refColumnListNames;
                        curColumnValueList = refColumnListValues;
                    }
                    if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                        List<String[]> filterColumns = filterColumns(tmpParam, curColumnNameList, curColumnValueList, customColMap);
                        curColumnNameList = filterColumns.get(0);
                        curColumnValueList = filterColumns.get(1);
                        tmpParam.setListItemsDisplayCodeName(curColumnNameList);
                        tmpParam.setListItemsDisplayName(curColumnNameList);
                        tmpParam.setListItemsValue(curColumnValueList);
                        if (curColumnValueList.length > 0) {
                            tmpParam.setDefaultClosedListValue(curColumnValueList[0]);
                        } else {
                            //$NON-NLS-1$
                            tmpParam.setDefaultClosedListValue("");
                        }
                        syncNodePropertiesTableColumns(param, columnsChanged, curColumnNameList, tmpParam);
                    }
                }
            }
        }
        if (param.isBasedOnSchema()) {
            List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
            List<Map<String, Object>> newParamValues = new ArrayList<Map<String, Object>>();
            for (int j = 0; j < columnNameList.length; j++) {
                String columnName = columnNameList[j];
                String[] codes = param.getListItemsDisplayCodeName();
                Map<String, Object> newLine = null;
                boolean found = false;
                ColumnNameChanged colChanged = null;
                if (columnsChanged != null) {
                    for (int k = 0; k < columnsChanged.size() && !found; k++) {
                        colChanged = columnsChanged.get(k);
                        if (colChanged.getNewName().equals(columnName)) {
                            found = true;
                        }
                    }
                }
                if (found) {
                    found = false;
                    for (int k = 0; k < paramValues.size() && !found; k++) {
                        Map<String, Object> currentLine = paramValues.get(k);
                        if (currentLine.get(codes[0]).equals(colChanged.getOldName())) {
                            currentLine.put(codes[0], colChanged.getNewName());
                            found = true;
                        }
                    }
                }
                found = false;
                for (int k = 0; k < paramValues.size() && !found; k++) {
                    Map<String, Object> currentLine = paramValues.get(k);
                    if (currentLine.get(codes[0]) == null) {
                        currentLine.put(codes[0], columnName);
                    }
                    if (currentLine.get(codes[0]).equals(columnName)) {
                        found = true;
                        newLine = currentLine;
                    }
                }
                if (!found) {
                    newLine = TableController.createNewLine(param);
                    newLine.put(codes[0], columnName);
                    reUsedColumnFunctionArrayCheck(newLine, element, codes);
                    if (!StringUtils.isEmpty(edifactId)) {
                        org.talend.core.model.metadata.builder.connection.Connection connection = MetadataToolHelper.getConnectionFromRepository(edifactId);
                        if (connection != null && connection instanceof EDIFACTConnection) {
                            List<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
                            for (MetadataColumn col : tables.get(0).getColumns()) {
                                if (col.getLabel().equals(columnName)) {
                                    if (col instanceof EDIFACTColumn) {
                                        EDIFACTColumn edicolumn = (EDIFACTColumn) col;
                                        String ediXpath = edicolumn.getEDIXpath();
                                        newLine.put(codes[0], columnName);
                                        newLine.put(codes[1], ediXpath);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (element instanceof Node) {
                        Node node = (Node) element;
                        String familyName = node.getComponent().getOriginalFamilyName();
                        /** need add second parameter for hbase input/output component **/
                        if (familyName != null && familyName.equals("Databases/HBase")) {
                            for (IElementParameter par : node.getElementParametersWithChildrens()) {
                                if (par.getName().equals("REPOSITORY_PROPERTY_TYPE")) {
                                    String hbaseConnectionId = par.getValue().toString();
                                    String columnFamily = null;
                                    org.talend.core.model.metadata.builder.connection.Connection connection = MetadataToolHelper.getConnectionFromRepository(hbaseConnectionId);
                                    if (connection != null && connection instanceof DatabaseConnection) {
                                        /* use imetadataconnection because maybe it's in context model */
                                        IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
                                        List<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
                                        boolean find = false;
                                        for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
                                            for (MetadataColumn column : table.getColumns()) {
                                                if (column.getLabel() != null && column.getLabel().equals(columnName)) {
                                                    for (TaggedValue tv : column.getTaggedValue()) {
                                                        String tag = tv.getTag();
                                                        if (tag != null && tag.equals("COLUMN FAMILY")) {
                                                            String value = tv.getValue();
                                                            if (value != null) {
                                                                columnFamily = value;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                if (find) {
                                                    break;
                                                }
                                            }
                                            if (find) {
                                                break;
                                            }
                                        }
                                    }
                                    if (columnFamily != null) {
                                        newLine.put(codes[1], TalendTextUtils.addQuotes(columnFamily));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                /* should put other attribute for edi mapping */
                }
                if (synWidthWithMetadataColumn) {
                    setColumnSize(newLine, element, codes, param);
                }
                newParamValues.add(j, newLine);
            }
            paramValues.clear();
            paramValues.addAll(newParamValues);
        } else if (param.isColumnsBasedOnSchema()) {
            List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
            List<Map<String, Object>> newParamValues = new ArrayList<Map<String, Object>>();
            String[] listRepositoryItem = new String[columnNameList.length];
            String[] listItemsDisplayValue = new String[columnNameList.length];
            String[] listItemsDisplayCodeValue = new String[columnNameList.length];
            Object[] listItemsValue = new Object[columnNameList.length];
            String[] listItemsShowIf = new String[columnNameList.length];
            String[] listItemsNotShowIf = new String[columnNameList.length];
            ElementParameter newParam;
            for (int j = 0; j < columnNameList.length; j++) {
                String columnName = columnNameList[j];
                listItemsDisplayCodeValue[j] = columnName;
                listItemsDisplayValue[j] = columnName;
                //$NON-NLS-1$
                listRepositoryItem[j] = "";
                listItemsShowIf[j] = null;
                listItemsNotShowIf[j] = null;
                newParam = new ElementParameter(element);
                newParam.setName(columnName);
                //$NON-NLS-1$
                newParam.setDisplayName("");
                newParam.setFieldType(EParameterFieldType.TEXT);
                //$NON-NLS-1$
                newParam.setValue("");
                listItemsValue[j] = newParam;
                boolean found = false;
                ColumnNameChanged colChanged = null;
                if (columnsChanged != null) {
                    for (int k = 0; k < columnsChanged.size() && !found; k++) {
                        colChanged = columnsChanged.get(k);
                        if (colChanged.getNewName().equals(columnName)) {
                            found = true;
                        }
                    }
                }
                for (int k = 0; k < paramValues.size(); k++) {
                    Map<String, Object> line = paramValues.get(k);
                    Map<String, Object> newline = new HashMap<String, Object>();
                    if (found) {
                        Object object = line.get(colChanged.getOldName());
                        if (object != null) {
                            newline.put(colChanged.getNewName(), object);
                            line.remove(colChanged.getOldName());
                            line.putAll(newline);
                        }
                    }
                }
            }
            param.setListItemsDisplayName(listItemsDisplayValue);
            param.setListItemsDisplayCodeName(listItemsDisplayCodeValue);
            param.setListItemsValue(listItemsValue);
            param.setListRepositoryItems(listRepositoryItem);
            param.setListItemsShowIf(listItemsShowIf);
            param.setListItemsNotShowIf(listItemsNotShowIf);
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) EDIFACTConnection(org.talend.core.model.metadata.builder.connection.EDIFACTConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) Connection(org.talend.core.model.metadata.builder.connection.Connection) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDIFACTColumn(org.talend.core.model.metadata.builder.connection.EDIFACTColumn) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Point(org.eclipse.swt.graphics.Point) JSONObject(org.talend.utils.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

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