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;
}
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);
}
}
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;
}
Aggregations