use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.
the class CreateComponentOnLinkHelper method getTargetArgs.
public static List<Object> getTargetArgs(Connection connection, Node node) {
List<Object> connArgs = new ArrayList<Object>();
IMetadataTable meta = null;
String connectName = null;
INodeConnector connector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
for (INodeConnector tconnector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
if (connector.getMaxLinkOutput() != 0) {
connector = tconnector;
break;
}
}
EConnectionType connectType = node.getConnectorFromName(connector.getName()).getDefaultConnectionType();
if (connectType.hasConnectionCategory(EConnectionType.FLOW)) {
// String name = "*New Output*" + " (" + connector.getMenuName() + ")";
if (node.getConnectorFromName(connector.getName()).isMultiSchema()) {
String tableName = connection.getMetaName();
meta = connection.getSource().getMetadataTable(tableName);
if (connector.isMultiSchema()) {
if (connection.getTarget().getConnectorFromName(node.getConnectorFromName(connector.getName()).getName()).isMultiSchema()) {
// Connection conn = (Connection) connection.getTarget().getIncomingConnections().get(0);
// node.getMetadataList().add(conn.getMetadataTable());
} else {
MetadataTable table = (MetadataTable) connection.getTarget().getMetadataList().get(0).clone();
table.setLabel(tableName);
node.getMetadataList().add(table);
}
}
} else {
if (node.getMetadataList().size() == 0) {
meta = null;
} else {
meta = node.getMetadataFromConnector(connector.getName());
}
connectName = node.getProcess().generateUniqueConnectionName(Process.DEFAULT_ROW_CONNECTION_NAME);
}
if (connectType.equals(EConnectionType.FLOW_MAIN) || connectType.equals(EConnectionType.FLOW_REF)) {
if (meta == null) {
connArgs.add(null);
} else {
connArgs.add(meta.getTableName());
}
} else {
connArgs.add(node.getUniqueName());
}
String baseName = node.getConnectionName();
String fromConnectionName = null;
if (node.getProcess().checkValidConnectionName(baseName)) {
fromConnectionName = node.getProcess().generateUniqueConnectionName(baseName);
}
if (fromConnectionName != null && connectType.hasConnectionCategory(IConnectionCategory.FLOW) && node.getProcess().checkValidConnectionName(fromConnectionName, false) && !connector.isMultiSchema()) {
connArgs.add(fromConnectionName);
} else {
connArgs.add(connectName);
}
connArgs.add(null);
}
return connArgs;
}
use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.
the class DummyNodeAnchor method getDirectionPosition.
private Point getDirectionPosition(Point figCenter, Point reference) {
Dimension nodeSize = this.source.getSize();
EConnectionCategory category = null;
EConnectionType lineStyle = null;
if (connection != null) {
lineStyle = connection.getLineStyle();
category = lineStyle.getCategory();
} else {
lineStyle = ConnectionManager.getNewConnectionType();
category = lineStyle.getCategory();
}
Point result = new Point(figCenter);
if (category == EConnectionCategory.MAIN && lineStyle != EConnectionType.FLOW_REF) {
if (!isTargetAnchor) {
result.x = figCenter.x + nodeSize.width / 2;
} else {
result.x = figCenter.x - nodeSize.width / 2;
}
return result;
} else if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.FLOW_REF || lineStyle == EConnectionType.TABLE_REF)) {
if (target != null) {
int sourceY = this.source.getPosY();
int targetY = this.target.getPosY();
Rectangle sourceBounds = new Rectangle(this.source.getLocation(), this.source.getSize());
Rectangle targetBounds = new Rectangle(this.target.getLocation(), this.target.getSize());
if (!isTargetAnchor) {
if (target.equals(source)) {
Point tempPoint = new Point(reference.x - nodeSize.width / 2, reference.y - nodeSize.height / 2);
targetBounds = new Rectangle(tempPoint, this.target.getSize());
targetY = reference.y - nodeSize.height / 2;
}
if (sourceY <= targetY) {
if ((targetBounds.getTopRight().y == sourceBounds.getBottomLeft().y)) {
result.y = figCenter.y - nodeSize.height / 2;
} else {
result.y = figCenter.y + nodeSize.height / 2;
}
} else {
if (targetBounds.getBottomLeft().y == sourceBounds.getTopRight().y) {
result.y = figCenter.y + nodeSize.height / 2;
} else {
result.y = figCenter.y - nodeSize.height / 2;
}
}
return result;
}
//
if (sourceY < targetY) {
result.y = figCenter.y - nodeSize.height / 2;
} else {
result.y = figCenter.y + nodeSize.height / 2;
}
return result;
}
}
return null;
}
use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createComponentOnLink.
private boolean createComponentOnLink(Node node, Point originalPoint) {
boolean executed = false;
RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
Point viewOriginalPosition = new Point();
if (rep instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
Viewport viewport = (Viewport) root.getFigure();
viewOriginalPosition = viewport.getViewLocation();
}
Point point = new Point(originalPoint.x + viewOriginalPosition.x, originalPoint.y + viewOriginalPosition.y);
point.x = (int) (point.x / AnimatableZoomManager.currentZoom);
point.y = (int) (point.y / AnimatableZoomManager.currentZoom);
org.talend.designer.core.ui.editor.connections.Connection targetConnection = null;
if (selectedConnectionPart != null) {
targetConnection = (org.talend.designer.core.ui.editor.connections.Connection) selectedConnectionPart.getModel();
}
if (targetConnection != null) {
IProcess2 p = editor.getProcess();
NodeContainer nodeContainer = ((Process) node.getProcess()).loadNodeContainer(node, false);
// TDI-21099
if (p instanceof Process) {
CreateNodeContainerCommand createCmd = new CreateNodeContainerCommand((Process) p, nodeContainer, point);
execCommandStack(createCmd);
// reconnect the node
Node originalTarget = (Node) targetConnection.getTarget();
EConnectionType connectionType = EConnectionType.FLOW_MAIN;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
if (camelService.isRouteBuilderNode(node)) {
connectionType = camelService.getTargetConnectionType(node);
}
}
INodeConnector targetConnector = node.getConnectorFromType(connectionType);
for (INodeConnector connector : node.getConnectorsFromType(connectionType)) {
if (connector.getMaxLinkOutput() != 0) {
targetConnector = connector;
break;
}
}
ConnectionCreateCommand.setCreatingConnection(true);
// bug 21411
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
if (targetConnection.getTarget() instanceof Node) {
NodeContainer jobletContainer = ((Node) targetConnection.getTarget()).getNodeContainer();
// remove the old connection in the container
jobletContainer.getInputs().remove(targetConnection);
}
}
}
ConnectionReconnectCommand cmd2 = new ConnectionReconnectCommand(targetConnection);
cmd2.setNewTarget(node);
execCommandStack(cmd2);
List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(targetConnection, node);
ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
nodeCmd.setTarget(originalTarget);
execCommandStack(nodeCmd);
// Setting,such as the target is TMap
if (node.getOutgoingConnections().size() > 0) {
if (node.getExternalNode() instanceof MapperExternalNode) {
CreateComponentOnLinkHelper.setupTMap(node);
}
if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
CreateComponentOnLinkHelper.updateTMap(originalTarget, targetConnection, node.getOutgoingConnections().get(0));
}
originalTarget.renameData(targetConnection.getName(), node.getOutgoingConnections().get(0).getName());
}
if (!ConnectionCreateCommand.isCreatingConnection()) {
return true;
}
executed = true;
}
}
return executed;
}
use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.
the class ConnectionAddUniqueNameMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
try {
uniqueConnectionNameList.clear();
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object o : processType.getConnection()) {
ConnectionType currentConnection = (ConnectionType) o;
ElementParameterType uniqueNameParam = null;
for (Object paramObject : currentConnection.getElementParameter()) {
ElementParameterType paramType = (ElementParameterType) paramObject;
if (UNIQUE_NAME.equals(paramType.getName())) {
uniqueNameParam = paramType;
}
}
if (uniqueNameParam == null) {
uniqueNameParam = TalendFileFactory.eINSTANCE.createElementParameterType();
uniqueNameParam.setName("UNIQUE_NAME");
uniqueNameParam.setField(EParameterFieldType.TEXT.getName());
uniqueNameParam.setContextMode(false);
currentConnection.getElementParameter().add(uniqueNameParam);
}
String value = uniqueNameParam.getValue();
String baseName = "";
if (value == null || "".equals(value)) {
modified = true;
EConnectionType connectionType = EConnectionType.getTypeFromId(currentConnection.getLineStyle());
if (connectionType.hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connectionType.hasConnectionCategory(IConnectionCategory.FLOW)) {
baseName = null;
} else if (connectionType.equals(EConnectionType.ITERATE)) {
baseName = "iterate";
} else if (connectionType.equals(EConnectionType.TABLE)) {
baseName = null;
} else if (connectionType.equals(EConnectionType.SYNCHRONIZE) || connectionType.equals(EConnectionType.PARALLELIZE)) {
baseName = null;
} else {
baseName = connectionType.getDefaultLinkName();
}
String uniqueName = "";
if (connectionType.equals(EConnectionType.TABLE)) {
uniqueName = currentConnection.getMetaname();
} else {
uniqueName = currentConnection.getLabel();
}
if (baseName != null && !"".equals(baseName)) {
uniqueName = generateUniqueConnectionName(baseName);
}
uniqueNameParam.setValue(uniqueName);
uniqueConnectionNameList.add(uniqueName);
}
}
}
if (modified) {
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.model.process.EConnectionType in project tdi-studio-se by Talend.
the class ConnectionCreateActionTest method testRun1.
private void testRun1() {
EConnectionType ct = EConnectionType.TABLE;
String text = "TALEND.JOBS (Table)";
int end = text.length() - 1;
//$NON-NLS-1$
int start = text.lastIndexOf("(") + 1;
String tableName = text.substring(start, end);
assertEquals("Table", tableName);
IMetadataTable meta = node.getMetadataTable("JOBS");
String connectionName = meta.getLabel();
assertEquals(connectionName, "JOBS");
}
Aggregations