use of org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand in project tdi-studio-se by Talend.
the class NodeGraphicalEditPolicy method getConnectionCreateCommand.
@Override
@SuppressWarnings("unchecked")
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
Node source = (Node) getHost().getModel();
if (source.isReadOnly()) {
return null;
}
String style = (String) request.getNewObjectType();
ConnectionCreateCommand cmd = new ConnectionCreateCommand(source, style, (List<Object>) request.getNewObject());
request.setStartCommand(cmd);
return cmd;
}
use of org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand 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.designer.core.ui.editor.cmd.ConnectionCreateCommand in project tdi-studio-se by Talend.
the class ProcessLayoutEditPolicy method getConnectionAndEndCommands.
protected Command getConnectionAndEndCommands(CreateConnectionRequest request) {
CompoundCommand cc = new CompoundCommand("CreateNodeCommand");
ProcessPart processPart = (ProcessPart) this.getHost();
final GraphicalViewer graphicalViewer = (GraphicalViewer) processPart.getViewer();
final CommandStack commandStack = processPart.getViewer().getEditDomain().getCommandStack();
final String categoryName = ComponentsFactoryProvider.getInstance().getComponentsHandler().extractComponentsCategory().getName();
final IProcess2 process = (IProcess2) processPart.getModel();
TalendEditorConnectionTargetAssist assist = new TalendEditorConnectionTargetAssist(categoryName, graphicalViewer, commandStack, process);
char start = '*';
assist.showComponentCreationAssist(start);
ConnectionCreateCommand cmd = (ConnectionCreateCommand) request.getStartCommand();
if (assist.getComponentName() == null) {
assist.releaseText();
return cmd;
}
IComponent component = TalendEditorComponentCreationUtil.getComponentsInCategory(categoryName).get(assist.getComponentName());
if (component == null) {
assist.releaseText();
return cmd;
}
assist.releaseText();
Node newNode = new Node(component);
NodeContainer nodeContainer = ((Process) newNode.getProcess()).loadNodeContainer(newNode, false);
CreateNodeContainerCommand command = new CreateNodeContainerCommand((org.talend.designer.core.ui.editor.process.Process) newNode.getProcess(), nodeContainer, request.getLocation());
cc.add(command);
cmd.setTarget(newNode);
cc.add(cmd);
return cc;
}
use of org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand in project tdi-studio-se by Talend.
the class NodeGraphicalEditPolicy method getConnectionCompleteCommand.
@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
ConnectionCreateCommand cmd = (ConnectionCreateCommand) request.getStartCommand();
cmd.setTarget((Node) getHost().getModel());
return cmd;
}
use of org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand 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;
}
Aggregations