Search in sources :

Example 36 with MetadataTable

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

the class VirtualRowGeneratorNode method getArray.

/**
     * yzhang Comment method "initArray".
     */
private Object getArray() {
    List<Map<String, String>> map = new ArrayList<Map<String, String>>();
    MetadataTable table = (MetadataTable) this.getMetadataList().get(0);
    for (IMetadataColumn col : table.getListColumns()) {
        VirtualMetadataColumn ext = (VirtualMetadataColumn) col;
        Map<String, String> value = new HashMap<String, String>();
        value.put(RowGeneratorComponent.COLUMN_NAME, ext.getLabel());
        List<Variable> variables = ExpressionBuilderDialog.getTestComposite().getVariableList();
        String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
        // modify for bug 9471
        try {
            for (Variable varible : variables) {
                if (valueContains(expression, varible.getName())) {
                    Integer.parseInt(varible.getValue());
                }
            }
            for (Variable var : variables) {
                String talendType = var.getTalendType();
                JavaType javaTypeFromId = JavaTypesManager.getJavaTypeFromId(talendType);
                String label = null;
                String value2 = var.getValue();
                if (javaTypeFromId != null) {
                    label = javaTypeFromId.getLabel();
                    if ("BigDecimal".equals(label)) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$//$NON-NLS-1$
                        value2 = " new BigDecimal(" + value2 + ")";
                    }
                }
                expression = renameValues(expression, var.getName(), value2);
            }
        } catch (NumberFormatException e1) {
            for (Variable var : variables) {
                //$NON-NLS-1$ //$NON-NLS-2$
                expression = renameValues(expression, var.getName(), "\"" + var.getValue() + "\"");
            }
        }
        //$NON-NLS-1$//$NON-NLS-1$
        value.put(RowGeneratorComponent.ARRAY, "\"\"+(" + expression + ")+\"\"");
        map.add(value);
    }
    return map;
}
Also used : Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) JavaType(org.talend.core.model.metadata.types.JavaType) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with MetadataTable

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

the class RepositoryTypeProcessor method selectRepositoryNode.

@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    final String repositoryType = getRepositoryType();
    if (node == null) {
        return false;
    }
    if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    // for sub folders
    if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
        return false;
    }
    // for Db Connections
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    // }
    IRepositoryViewObject object = node.getObject();
    if (object == null || object.getProperty().getItem() == null) {
        return false;
    }
    if (object instanceof MetadataTable) {
        return false;
    }
    Item item = object.getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    if (item instanceof ConnectionItem) {
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection connection = connectionItem.getConnection();
        // tAdvancedFileOutputXML
        if (repositoryType != null && repositoryType.equals(ERepositoryCategoryType.XMLOUTPUT.getName())) {
            if (connection instanceof XmlFileConnection && ((XmlFileConnection) connection).isInputModel()) {
                return false;
            }
        }
        if (repositoryType.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
            //$NON-NLS-1$
            String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
            if (repositoryType.contains(":")) {
                // database //$NON-NLS-1$
                // is
                // specified
                // //$NON-NLS-1$
                //$NON-NLS-1$
                String neededDbType = repositoryType.substring(repositoryType.indexOf(":") + 1);
                if (hidenTypeSelection) {
                    return true;
                }
                if (!MetadataTalendType.sameDBProductType(neededDbType, currentDbType)) {
                    return false;
                }
            }
        }
    }
    if (repositoryType.startsWith(ERepositoryCategoryType.HEADERFOOTER.getName())) {
        if (item instanceof HeaderFooterConnectionItem) {
            HeaderFooterConnectionItem connectionItem = (HeaderFooterConnectionItem) item;
            HeaderFooterConnection connection = (HeaderFooterConnection) connectionItem.getConnection();
            boolean isHeader = connection.isIsHeader();
            if ((isHeader && isHeaderButton) || (!isHeader && !isHeaderButton)) {
                return true;
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.MetadataTable) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection)

Example 38 with MetadataTable

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

the class ValidationRuleTypeProcessor method selectRepositoryNode.

@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    ProjectManager pManager = ProjectManager.getInstance();
    if (!pManager.isInCurrentMainProject(node)) {
        if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
            return false;
        }
        if (node.getType() == ENodeType.SYSTEM_FOLDER) {
            return true;
        }
    }
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    if (node.getObject() == null || node.getObject().getProperty().getItem() == null) {
        return false;
    }
    if (node.getObject() instanceof MetadataTable) {
        return false;
    }
    Item item = node.getObject().getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    if (node.getObjectType() == getType()) {
        return true;
    }
    return false;
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) MetadataTable(org.talend.core.model.metadata.MetadataTable) ProjectManager(org.talend.repository.ProjectManager)

Example 39 with MetadataTable

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

the class MapperUI method prepareClosing.

public void prepareClosing(int response) {
    List<IMetadataTable> newMetadatas = new ArrayList<IMetadataTable>();
    EList<OutputXmlTree> outputTrees = null;
    if (response == SWT.OK || response == SWT.APPLICATION_MODAL) {
        // fix for bug TDI-18185
        mapperManager.fireCurrentDirectEditApply();
        // if press ok or apply , use copyOfMapData to check the metadata list
        outputTrees = copyOfMapData.getOutputTrees();
    } else {
        // if press cancel , use the original mapData
        outputTrees = ((XmlMapData) mapperComponent.getExternalEmfData()).getOutputTrees();
    }
    List<IMetadataTable> copyOfMetadata = new ArrayList<IMetadataTable>(mapperComponent.getMetadataList());
    for (OutputXmlTree outputTree : outputTrees) {
        IMetadataTable found = null;
        for (IMetadataTable table : mapperComponent.getMetadataList()) {
            if (outputTree.getName().equals(table.getTableName())) {
                found = table;
            }
        }
        if (found != null) {
            newMetadatas.add(found);
        } else {
            // create a new metadata if needed
            MetadataTable metadataTable = new MetadataTable();
            metadataTable.setTableName(outputTree.getName());
            mapperComponent.getProcess().addUniqueConnectionName(outputTree.getName());
            List<IMetadataColumn> listColumns = new ArrayList<IMetadataColumn>();
            for (OutputTreeNode treeNode : outputTree.getNodes()) {
                MetadataColumn column = new MetadataColumn();
                column.setLabel(treeNode.getName());
                column.setKey(treeNode.isKey());
                column.setTalendType(treeNode.getType());
                column.setNullable(treeNode.isNullable());
                column.setPattern(treeNode.getPattern());
                listColumns.add(column);
            }
            metadataTable.setListColumns(listColumns);
            newMetadatas.add(metadataTable);
        }
    }
    mapperComponent.setMetadataList(newMetadatas);
    copyOfMetadata.removeAll(newMetadatas);
    List<IODataComponent> outputs = mapperComponent.getIODataComponents().getOuputs();
    List<String> connectionNames = new ArrayList<String>();
    for (IODataComponent output : outputs) {
        connectionNames.add(output.getUniqueName());
    }
    for (IMetadataTable leftTree : copyOfMetadata) {
        if (!connectionNames.contains(leftTree.getTableName())) {
            mapperComponent.getProcess().removeUniqueConnectionName(leftTree.getTableName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IODataComponent(org.talend.core.model.components.IODataComponent)

Example 40 with MetadataTable

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

the class RepositoryXmlSelectionDialog method isSelectionValid.

@Override
protected boolean isSelectionValid(SelectionChangedEvent event) {
    boolean highlightOKButton = true;
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    if (selection == null || selection.size() != 1) {
        highlightOKButton = false;
    } else {
        RepositoryNode node = (RepositoryNode) selection.getFirstElement();
        if (node.getObject() == null || node.getObject().getProperty() == null) {
            return false;
        }
        if (node.getObject() instanceof Folder) {
            return false;
        }
        Item item = node.getObject().getProperty().getItem();
        if (item instanceof XmlFileConnectionItem) {
            ERepositoryObjectType t = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
            if (node.getType() != ENodeType.REPOSITORY_ELEMENT) {
                highlightOKButton = false;
            }
        } else if (item instanceof MDMConnectionItem) {
            if (node.getObject() instanceof MetadataTable) {
                highlightOKButton = true;
                updateErrorMessage(null);
            } else {
                highlightOKButton = false;
                updateErrorMessage(Messages.getString("RepositoryXmlSelectionDialog.UpdateErrorMessage"));
            }
        }
    }
    return highlightOKButton;
}
Also used : Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) MetadataTable(org.talend.core.model.metadata.MetadataTable) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) RepositoryNode(org.talend.repository.model.RepositoryNode) Folder(org.talend.core.model.repository.Folder) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Aggregations

MetadataTable (org.talend.core.model.metadata.MetadataTable)61 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)46 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)29 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)15 Map (java.util.Map)14 IElementParameter (org.talend.core.model.process.IElementParameter)14 Item (org.talend.core.model.properties.Item)14 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)13 IConnection (org.talend.core.model.process.IConnection)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 Node (org.talend.designer.core.ui.editor.nodes.Node)11 List (java.util.List)9 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)9 Command (org.eclipse.gef.commands.Command)8 Point (org.eclipse.swt.graphics.Point)8 INode (org.talend.core.model.process.INode)8 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)8 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)8 Connection (org.talend.designer.core.ui.editor.connections.Connection)8