use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.
the class JobletConnectionReconnectCommand method undo.
@Override
public void undo() {
if (newSource != null) {
INodeConnector connector = oldSource.getConnectorFromName(connectorName);
connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
connector = newSource.getConnectorFromName(connectorName);
connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() - 1);
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
boolean builtInNewSource = newSource.getConnectorFromName(connectorName).isMultiSchema();
boolean builtInOldSource = oldSource.getConnectorFromName(connectorName).isMultiSchema();
if ((!builtInNewSource) && (!builtInOldSource)) {
setSchemaToNotBuiltInNode(newSource, oldSource, oldMetadataTable);
if (oldSource.getJobletNode() != null) {
connection.setMetaName(oldSource.getJobletNode().getUniqueName());
} else
connection.setMetaName(oldSource.getUniqueName());
} else {
if (!builtInNewSource) {
oldSource.getMetadataList().add(oldMetadataTable);
connection.setMetaName(oldMetadataTable.getTableName());
}
if (!builtInOldSource) {
int num = 0;
for (int i = 0; i < newSource.getMetadataList().size(); i++) {
IMetadataTable meta = newSource.getMetadataList().get(i);
if (meta.getTableName().equals(connection.getUniqueName())) {
num = i;
}
}
newSource.getMetadataList().remove(num);
setSchemaToNotBuiltInNode(newSource, oldSource, oldMetadataTable);
if (oldSource.getJobletNode() != null) {
connection.setMetaName(oldSource.getJobletNode().getUniqueName());
} else
connection.setMetaName(oldSource.getUniqueName());
}
if ((builtInOldSource) && (builtInNewSource)) {
int num = 0;
for (int i = 0; i < newSource.getMetadataList().size(); i++) {
IMetadataTable meta = newSource.getMetadataList().get(i);
if (meta.getTableName().equals(oldMetadataTable.getTableName())) {
num = i;
}
}
newSource.getMetadataList().remove(num);
oldSource.getMetadataList().add(oldMetadataTable);
}
}
if (newSourceSchemaType != null) {
for (ChangeMetadataCommand cmd : metadataChanges) {
cmd.undo();
}
newSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newSourceSchemaType);
}
if (oldSourceSchemaType != null) {
oldSource.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), oldSourceSchemaType);
}
} else {
if (oldSource.getJobletNode() != null) {
connection.setMetaName(oldSource.getJobletNode().getUniqueName());
} else
connection.setMetaName(oldSource.getUniqueName());
}
} else if (newTarget != null) {
INodeConnector connector = oldTarget.getConnectorFromType(oldLineStyle);
connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
connector = newTarget.getConnectorFromType(newLineStyle);
connector.setCurLinkNbInput(connector.getCurLinkNbInput() - 1);
if (newTargetSchemaType != null) {
for (ChangeMetadataCommand cmd : metadataChanges) {
cmd.undo();
}
newTarget.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), newTargetSchemaType);
}
}
connection.reconnect(oldSource, oldTarget, oldLineStyle);
connection.updateName();
((Process) oldSource.getProcess()).checkStartNodes();
((Process) oldSource.getProcess()).checkProcess();
}
use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.
the class JobletConnectionReconnectCommand method setSchemaToNotBuiltInNode.
private void setSchemaToNotBuiltInNode(INode oldNode, INode newNode, IMetadataTable newSchema) {
if ((newNode.getMetadataList() != null) && newNode.getMetadataList().get(0).getListColumns().size() == 0) {
// only override if there is no schema defined in the component
if (oldMetadataTable == null) {
return;
}
String sourceConnector = oldMetadataTable.getAttachedConnector();
String baseConnector = oldNode.getConnectorFromName(sourceConnector).getBaseSchema();
for (INodeConnector connector : newNode.getListConnector()) {
if (connector.getBaseSchema().equals(baseConnector)) {
IMetadataTable meta = newNode.getMetadataFromConnector(connector.getName());
if (meta == null) {
continue;
}
if (newSchema != null) {
meta.setComment(newSchema.getComment());
MetadataToolHelper.copyTable(newSchema, meta);
}
}
}
}
}
use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.
the class Component method createConnectors.
@Override
public List<INodeConnector> createConnectors(INode parentNode) {
List<INodeConnector> listConnector = new ArrayList<>();
ComponentProperties componentProperties = ComponentsUtils.getComponentProperties(getName());
Set<? extends Connector> inputConnectors = componentProperties.getPossibleConnectors(false);
if (inputConnectors.isEmpty()) {
INodeConnector connector = null;
connector = addStandardType(listConnector, EConnectionType.FLOW_MAIN, parentNode);
connector.setMaxLinkInput(0);
connector.setMaxLinkOutput(0);
} else {
for (Connector connector : inputConnectors) {
addGenericType(listConnector, EConnectionType.FLOW_MAIN, connector.getName(), parentNode, componentProperties, false);
}
}
Set<? extends Connector> outputConnectors = componentProperties.getPossibleConnectors(true);
List<? extends Connector> sortedOutputConnectors = new ArrayList<>(outputConnectors);
sortedOutputConnectors.sort(new Comparator<Connector>() {
@Override
public int compare(Connector o1, Connector o2) {
if (Connector.MAIN_NAME.equals(o1.getName())) {
return -1;
}
if (Connector.MAIN_NAME.equals(o2.getName())) {
return 1;
}
return 0;
}
});
for (Connector connector : sortedOutputConnectors) {
EConnectionType type = EConnectionType.FLOW_MAIN;
if (Connector.REJECT_NAME.equals(connector.getName())) {
type = EConnectionType.REJECT;
}
addGenericType(listConnector, type, connector.getName(), parentNode, componentProperties, true);
}
addStandardType(listConnector, EConnectionType.RUN_IF, parentNode);
addStandardType(listConnector, EConnectionType.ON_COMPONENT_OK, parentNode);
addStandardType(listConnector, EConnectionType.ON_COMPONENT_ERROR, parentNode);
addStandardType(listConnector, EConnectionType.ON_SUBJOB_OK, parentNode);
addStandardType(listConnector, EConnectionType.ON_SUBJOB_ERROR, parentNode);
Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
createIterateConnectors(topologies, listConnector, parentNode);
for (int i = 0; i < EConnectionType.values().length; i++) {
EConnectionType currentType = EConnectionType.values()[i];
if ((currentType == EConnectionType.FLOW_REF) || (currentType == EConnectionType.FLOW_MERGE)) {
continue;
}
boolean exists = false;
for (INodeConnector curNodeConn : listConnector) {
if (curNodeConn.getDefaultConnectionType().equals(currentType)) {
exists = true;
if (currentType == EConnectionType.FLOW_MAIN) {
curNodeConn.addConnectionProperty(EConnectionType.FLOW_REF, EConnectionType.FLOW_REF.getRGB(), EConnectionType.FLOW_REF.getDefaultLineStyle());
curNodeConn.addConnectionProperty(EConnectionType.FLOW_MERGE, EConnectionType.FLOW_MERGE.getRGB(), EConnectionType.FLOW_MERGE.getDefaultLineStyle());
}
}
}
if (!exists) {
// will add by default all connectors not defined in
NodeConnector nodeConnector = new NodeConnector(parentNode);
nodeConnector.setDefaultConnectionType(currentType);
nodeConnector.setName(currentType.getName());
nodeConnector.setBaseSchema(currentType.getName());
nodeConnector.addConnectionProperty(currentType, currentType.getRGB(), currentType.getDefaultLineStyle());
nodeConnector.setLinkName(currentType.getDefaultLinkName());
nodeConnector.setMenuName(currentType.getDefaultMenuName());
if ((currentType == EConnectionType.PARALLELIZE) || (currentType == EConnectionType.SYNCHRONIZE)) {
nodeConnector.setMaxLinkInput(1);
} else {
nodeConnector.setMaxLinkInput(0);
}
nodeConnector.setMaxLinkOutput(0);
nodeConnector.setMinLinkInput(0);
nodeConnector.setMinLinkOutput(0);
listConnector.add(nodeConnector);
}
}
return listConnector;
}
use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.
the class ComponentChooseDialog method updateConnectionCommand.
private void updateConnectionCommand(org.talend.designer.core.ui.editor.connections.Connection connection, Node node, CompoundCommand command) {
if (connection != null || node != null) {
Node originalTarget = (Node) connection.getTarget();
INodeConnector targetConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
for (INodeConnector connector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
if (connector.getMaxLinkOutput() != 0) {
targetConnector = connector;
break;
}
}
ConnectionCreateCommand.setCreatingConnection(true);
EConnectionType reconnectNewInputStyle = connection.getLineStyle();
if (ConnectionManager.canConnectToTarget(connection.getSource(), originalTarget, node, connection.getLineStyle(), connection.getName(), targetConnector.getName())) {
reconnectNewInputStyle = ConnectionManager.getNewConnectionType();
}
if (reconnectNewInputStyle.equals(EConnectionType.FLOW_MAIN)) {
connection.reconnect(connection.getSource(), node, EConnectionType.FLOW_MAIN);
} else if (reconnectNewInputStyle.equals(EConnectionType.FLOW_MERGE)) {
connection.reconnect(connection.getSource(), node, EConnectionType.FLOW_MERGE);
} else if (reconnectNewInputStyle.equals(EConnectionType.FLOW_REF)) {
connection.reconnect(connection.getSource(), node, EConnectionType.FLOW_REF);
}
INodeConnector nodeConnector = node.getConnectorFromName(targetConnector.getName());
nodeConnector.setCurLinkNbInput(nodeConnector.getCurLinkNbInput() + 1);
List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(connection, node);
ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
nodeCmd.setTarget(originalTarget);
INodeConnector originalNodeConnector = originalTarget.getConnectorFromName(connection.getTargetNodeConnector().getName());
originalNodeConnector.setCurLinkNbInput(originalNodeConnector.getCurLinkNbInput() - 1);
command.add(nodeCmd);
}
}
use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.
the class CreateComponentOnLinkHelper method canCreateNodeOnLink.
public static boolean canCreateNodeOnLink(org.talend.designer.core.ui.editor.connections.Connection connection, Node node) {
if (connection != null && node != null) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
if (camelService.isRouteBuilderNode(node)) {
return camelService.canCreateNodeOnLink(connection, node);
}
}
INode source = connection.getSource();
INodeConnector sourceConnector = connection.getSourceNodeConnector();
INode target = connection.getTarget();
INodeConnector targetConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
for (INodeConnector connector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
if (connector.getMaxLinkOutput() != 0) {
targetConnector = connector;
break;
}
}
EConnectionType outputConnectionType = node.getConnectorFromName(targetConnector.getName()).getDefaultConnectionType();
// only consider Flow connection
EConnectionType connectionType = source.getConnectorFromName(sourceConnector.getName()).getDefaultConnectionType();
if (connectionType.hasConnectionCategory(EConnectionType.FLOW)) {
boolean b1 = ConnectionManager.canConnectToTarget(source, null, node, connectionType, sourceConnector.getName(), null);
boolean b2 = ConnectionManager.canConnectToSource(source, node, target, outputConnectionType, targetConnector.getName(), null, true);
return b1 && b2;
}
}
return false;
}
Aggregations