Search in sources :

Example 1 with Component

use of org.talend.designer.core.generic.model.Component in project tdi-studio-se by Talend.

the class CodeGenerator method generateComponentsCode.

/**
     * Generate Code Parts for a Sub Process .
     * 
     * @param subProcess the suprocess
     * @param node the subprocess root
     * @param part the part of code to generate
     * @return the generated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
private StringBuffer generateComponentsCode(NodesSubTree subProcess, INode node, ECodePart part, String incomingName, ETypeGen typeGen) throws CodeGeneratorException {
    StringBuffer codeComponent = new StringBuffer();
    Boolean isMarked = subProcess.isMarkedNode(node, part);
    boolean isIterate = isSpecifyInputNode(node, incomingName, EConnectionType.ITERATE);
    boolean isOnRowsEnd = isSpecifyInputNode(node, incomingName, EConnectionType.ON_ROWS_END);
    if ((isMarked != null) && (!isMarked)) {
        switch(part) {
            case BEGIN:
                // if (isIterate) {
                // codeComponent.append(generateComponentCode(node,
                // ECodePart.BEGIN, incomingName));
                // }
                codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.BEGIN, typeGen));
                // if (!isIterate) {
                codeComponent.append(generateComponentCode(subProcess, node, ECodePart.BEGIN, incomingName, typeGen));
                // }
                break;
            case MAIN:
                if (isIterate) {
                    codeComponent.append(generateTypedComponentCode(EInternalTemplate.ITERATE_SUBPROCESS_HEADER, node, ECodePart.BEGIN, incomingName, subProcess));
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.BEGIN, typeGen));
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.BEGIN, incomingName, typeGen));
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.MAIN, incomingName, typeGen));
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.MAIN, typeGen));
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.END, incomingName, typeGen));
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.END, typeGen));
                    StringBuffer finallyPart = new StringBuffer();
                    // if iterate with parallel
                    finallyPart.append(generateComponentsCode(subProcess, node, ECodePart.FINALLY, incomingName, typeGen));
                    Vector iterate_Argument = new Vector(2);
                    iterate_Argument.add(node);
                    iterate_Argument.add(finallyPart.toString());
                    codeComponent.append(generateTypedComponentCode(EInternalTemplate.ITERATE_SUBPROCESS_FOOTER, iterate_Argument, ECodePart.END, incomingName, subProcess));
                } else {
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.MAIN, incomingName, typeGen));
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.MAIN, typeGen));
                }
                break;
            case END:
                if (isOnRowsEnd) {
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.BEGIN, typeGen));
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.BEGIN, incomingName, typeGen));
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.MAIN, incomingName, typeGen));
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.MAIN, typeGen));
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.END, incomingName, typeGen));
                    codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.END, typeGen));
                } else {
                    // if (!isIterate) {
                    codeComponent.append(generateComponentCode(subProcess, node, ECodePart.END, incomingName, typeGen));
                    // }
                    if (node.getComponent() instanceof Component) {
                        if (((Component) node.getComponent()).getComponentDefinition().isRejectAfterClose()) {
                            codeComponent.append(generateTypedComponentCode(EInternalTemplate.HANDLE_REJECTS_START, node, ECodePart.END, incomingName, subProcess));
                            codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.MAIN, typeGen));
                            codeComponent.append(generateTypedComponentCode(EInternalTemplate.HANDLE_REJECTS_END, node, ECodePart.END, incomingName, subProcess));
                        }
                    }
                    codeComponent.append(generatesTreeCode(subProcess, node, part, typeGen));
                // if (isIterate) {
                // codeComponent.append(generateComponentCode(node,
                // ECodePart.END, incomingName));
                // }
                }
                break;
            case FINALLY:
                codeComponent.append(generateComponentCode(subProcess, node, ECodePart.FINALLY, incomingName, typeGen));
                codeComponent.append(generatesTreeCode(subProcess, node, ECodePart.FINALLY, typeGen));
                break;
            default:
        }
        subProcess.markNode(node, part);
    }
    return codeComponent;
}
Also used : IComponent(org.talend.core.model.components.IComponent) Component(org.talend.designer.core.generic.model.Component) Vector(java.util.Vector)

Example 2 with Component

use of org.talend.designer.core.generic.model.Component in project tdi-studio-se by Talend.

the class ComponentsUtils method loadComponent.

private static void loadComponent(Set<IComponent> componentsList, ComponentDefinition componentDefinition, String paletteType) {
    try {
        Component currentComponent = new Component(componentDefinition, paletteType);
        Collection<IComponentFactoryFilter> filters = ComponentsFactoryProviderManager.getInstance().getProviders();
        boolean hiddenComponent = false;
        for (IComponentFactoryFilter filter : filters) {
            if (!filter.isAvailable(currentComponent.getName())) {
                hiddenComponent = true;
                break;
            }
        }
        // just don't load it
        if (hiddenComponent && !(currentComponent.getOriginalFamilyName().contains("Technical") || currentComponent.isTechnical())) {
            return;
        }
        // hide it
        if (hiddenComponent && (currentComponent.getOriginalFamilyName().contains("Technical") || currentComponent.isTechnical())) {
            currentComponent.setVisible(false);
            currentComponent.setTechnical(true);
        }
        componentsList.add(currentComponent);
    } catch (BusinessException e) {
        ExceptionHandler.process(e);
    }
}
Also used : BusinessException(org.talend.commons.exception.BusinessException) IComponentFactoryFilter(org.talend.core.model.components.filters.IComponentFactoryFilter) IComponent(org.talend.core.model.components.IComponent) Component(org.talend.designer.core.generic.model.Component)

Example 3 with Component

use of org.talend.designer.core.generic.model.Component in project tdi-studio-se by Talend.

the class GenericDragAndDropHandler method isValid.

private boolean isValid(RepositoryNode seletetedNode, IComponent component) {
    // TUP-4151
    IRepositoryViewObject object = seletetedNode.getObject();
    if (component == null || object == null) {
        return false;
    }
    ComponentProperties currentComponentProperties = null;
    if (object instanceof RepositoryViewObject) {
        RepositoryViewObject repositoryViewObj = (RepositoryViewObject) object;
        Connection connection = ((ConnectionItem) repositoryViewObj.getProperty().getItem()).getConnection();
        if (canHandle(connection)) {
            GenericConnection genericConnection = (GenericConnection) connection;
            currentComponentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(genericConnection.getCompProperties(), connection);
        }
    } else if (object instanceof MetadataTableRepositoryObject) {
        MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) object;
        currentComponentProperties = SchemaUtils.getCurrentComponentProperties(metaTableRepObj);
    } else if (object instanceof MetadataColumnRepositoryObject) {
        MetadataColumnRepositoryObject metaColumnRepObj = (MetadataColumnRepositoryObject) object;
        ModelElement element = metaColumnRepObj.getTdColumn();
        if (element != null && element.eContainer() instanceof MetadataTable) {
            MetadataTable metadataTable = (MetadataTable) element.eContainer();
            IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
            currentComponentProperties = SchemaUtils.getCurrentComponentProperties(newTable);
        }
    }
    if (currentComponentProperties != null) {
        try {
            List<ComponentDefinition> possibleComponents = ComponentsUtils.getComponentService().getPossibleComponents(currentComponentProperties);
            if (component instanceof Component) {
                ComponentDefinition componentDefinition = ((Component) component).getComponentDefinition();
                return possibleComponents.contains(componentDefinition);
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return false;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) IComponent(org.talend.core.model.components.IComponent) Component(org.talend.designer.core.generic.model.Component) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Aggregations

IComponent (org.talend.core.model.components.IComponent)3 Component (org.talend.designer.core.generic.model.Component)3 Vector (java.util.Vector)1 BusinessException (org.talend.commons.exception.BusinessException)1 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)1 ComponentProperties (org.talend.components.api.properties.ComponentProperties)1 IComponentFactoryFilter (org.talend.core.model.components.filters.IComponentFactoryFilter)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 RepositoryViewObject (org.talend.core.model.repository.RepositoryViewObject)1 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)1 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)1 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)1 GenericConnectionItem (org.talend.repository.generic.model.genericMetadata.GenericConnectionItem)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1