Search in sources :

Example 6 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class MultiSchemasManager method retrievePropertiesFromNode.

/**
     * 
     * cLi Comment method "retrievePropertiesFromNode".
     * 
     */
@SuppressWarnings("unchecked")
public SchemasKeyData retrievePropertiesFromNode() {
    //$NON-NLS-1$
    SchemasKeyData rootData = new SchemasKeyData("");
    IElementParameter elementParameter = getMultiSchemasComponent().getElementParameter(EParameterName.SCHEMAS.getName());
    final Object value = elementParameter.getValue();
    if (value == null) {
        return null;
    }
    List<Map<String, String>> schemasValues = (List<Map<String, String>>) value;
    createSimpleDatas(rootData, schemasValues);
    retrieveRelativeParent(rootData, schemasValues);
    return rootData;
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) Map(java.util.Map)

Example 7 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class ChangeMultiSchemasCommand method addSchemasMap.

private void addSchemasMap(List<Map<String, String>> newValueList, List<IMetadataTable> newTables, SchemasKeyData keyData) {
    if (keyData == null) {
        return;
    }
    if (keyData.getParent() != null) {
        // not root
        //
        Map<String, String> map = new HashMap<String, String>();
        final String uniqueRecord = keyData.getUniqueRecord();
        final String recordType = keyData.getRecordType();
        map.put(IMultiSchemaConstant.SCHEMA, uniqueRecord);
        map.put(IMultiSchemaConstant.RECORD, TalendTextUtils.addQuotes(recordType));
        map.put(IMultiSchemaConstant.PARENT_RECORD, TalendTextUtils.addQuotes(keyData.getParent().getRecordType()));
        map.put(IMultiSchemaConstant.CARDINALITY, keyData.getCard());
        map.put(IMultiSchemaConstant.FIELDDELIMITED, TalendTextUtils.addQuotes(keyData.getSeparator()));
        newValueList.add(map);
        //
        String connectionBaseName = MetadataToolHelper.validateColumnName(MultiSchemasUtil.getConnectionBaseName(uniqueRecord), 0);
        String uniqueConnName = node.getProcess().generateUniqueConnectionName(connectionBaseName);
        MetadataTable table = new MetadataTable();
        table.setLabel(uniqueRecord);
        table.setTableName(uniqueConnName);
        //$NON-NLS-1$
        String keyIndex = "";
        boolean first = true;
        List<MultiMetadataColumn> metadataColumnsInModel = keyData.getMetadataColumnsInModel();
        for (int i = 0; i < metadataColumnsInModel.size(); i++) {
            MultiMetadataColumn column = metadataColumnsInModel.get(i);
            table.getListColumns().add(column.clone(true));
            if (column.isKey()) {
                if (first) {
                    keyIndex += i;
                } else {
                    //$NON-NLS-1$
                    keyIndex += "," + i;
                }
                first = false;
            }
        }
        map.put(IMultiSchemaConstant.KEY_COLUMN_INDEX, TalendTextUtils.addQuotes(keyIndex));
        newTables.add(table);
    }
    for (SchemasKeyData child : keyData.getChildren()) {
        addSchemasMap(newValueList, newTables, child);
    }
}
Also used : HashMap(java.util.HashMap) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Example 8 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class MultiSchemasManager method findSchemasKeyData.

private SchemasKeyData findSchemasKeyData(SchemasKeyData schemaKeyData, String key) {
    key = key.trim();
    if (schemaKeyData != null || !"".equals(key)) {
        //$NON-NLS-1$
        if (schemaKeyData.getRecordType().equals(key)) {
            return schemaKeyData;
        }
        for (SchemasKeyData child : schemaKeyData.getChildren()) {
            String dataKey = child.getRecordType() + child.getSeparator();
            if (dataKey.equals(key)) {
                return child;
            }
            SchemasKeyData foundData = findSchemasKeyData(child, key);
            if (foundData != null) {
                return foundData;
            }
        }
    }
    return null;
}
Also used : SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 9 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class UIManager method moveRecord.

public void moveRecord(TreeViewer schemaTreeViewer, boolean left) {
    if (schemaTreeViewer == null) {
        return;
    }
    ISelection selection = schemaTreeViewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof SchemasKeyData) {
            SchemasKeyData data = (SchemasKeyData) element;
            SchemasKeyData parent = data.getParent();
            if (left) {
                SchemasKeyData grandfather = parent.getParent();
                if (grandfather != null) {
                    // not in root.
                    List<SchemasKeyData> children = grandfather.getChildren();
                    int index = -1;
                    for (int i = 0; i < children.size(); i++) {
                        if (children.get(i) == parent) {
                            index = i;
                            break;
                        }
                    }
                    if (index > -1) {
                        int index2 = index + 1;
                        if (index2 > children.size()) {
                            grandfather.addChild(data);
                        } else {
                            grandfather.addChild(index2, data);
                        }
                    }
                }
            } else {
                SchemasKeyData sibling = null;
                for (SchemasKeyData skd : parent.getChildren()) {
                    if (skd == data) {
                        break;
                    } else {
                        sibling = skd;
                    }
                }
                if (sibling != null) {
                    sibling.addChild(data);
                }
            }
            schemaTreeViewer.refresh();
        }
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 10 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class SchemaDetailsPropertiesCellModifier method canModify.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
     */
public boolean canModify(Object element, String property) {
    if (element instanceof MultiMetadataColumn) {
        MultiMetadataColumn column = (MultiMetadataColumn) element;
        SchemasKeyData container = column.getContainer();
        if (container == null) {
            return false;
        }
        List<MultiMetadataColumn> metadataColumnsInModel = container.getMetadataColumnsInModel();
        /*
             * ingore record type(first column);
             * 
             * if existed key column, should not edit other key.
             */
        if (EPropertyName.KEY.name().equals(property) && (metadataColumnsInModel.indexOf(column) == uiManager.getSelectedColumnIndex() || UIManager.existedKeyColumn(metadataColumnsInModel, column))) {
            return false;
        }
        if (!EPropertyName.TAGLEVEL.name().equals(property)) {
            return true;
        }
    }
    return false;
}
Also used : SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Aggregations

SchemasKeyData (org.talend.designer.filemultischemas.data.SchemasKeyData)21 MultiMetadataColumn (org.talend.designer.filemultischemas.data.MultiMetadataColumn)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 ArrayList (java.util.ArrayList)5 ISelection (org.eclipse.jface.viewers.ISelection)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Tree (org.eclipse.swt.widgets.Tree)2 TreeColumn (org.eclipse.swt.widgets.TreeColumn)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 CommandStackForComposite (org.talend.commons.ui.command.CommandStackForComposite)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1