use of org.knime.workbench.editor2.commands.CreateConnectionCommand in project knime-core by knime.
the class PortGraphicalRoleEditPolicy method getConnectionCompleteCommand.
/**
* This tries to complete the command to create a connection.
*
* {@inheritDoc}
*/
@Override
protected Command getConnectionCompleteCommand(final CreateConnectionRequest request) {
// get the previously started command
CreateConnectionCommand cmd = (CreateConnectionCommand) request.getStartCommand();
if (cmd == null) {
return null;
}
EditPart target = request.getTargetEditPart();
if ((target instanceof NodeOutPortEditPart) || target instanceof WorkflowInPortEditPart) {
return null;
} else if (target instanceof NodeInPortEditPart || target instanceof WorkflowOutPortEditPart) {
cmd.setTargetPortID(((AbstractPortEditPart) target).getIndex());
cmd.setTargetNode((ConnectableEditPart) target.getParent());
} else if (target instanceof NodeContainerEditPart) {
if (cmd.wasStartedOnOutPort()) {
cmd.setTargetPortID(-1);
cmd.setTargetNode((NodeContainerEditPart) target);
} else {
cmd.setSourcePortID(-1);
cmd.setSourceNode((NodeContainerEditPart) target);
}
} else {
return null;
}
return cmd;
}
use of org.knime.workbench.editor2.commands.CreateConnectionCommand in project knime-core by knime.
the class PortGraphicalRoleEditPolicy method getConnectionCreateCommand.
/**
* This tries to initialize the command to create a connection as far as
* possible. However, it is completed by
* <code>getConnectionCompleteCommand</code>
*
* {@inheritDoc}
*/
@Override
protected Command getConnectionCreateCommand(final CreateConnectionRequest req) {
if (!(getHost() instanceof AbstractPortEditPart)) {
return null;
}
ConnectableEditPart nodePart = (ConnectableEditPart) getHost().getParent();
WorkflowManagerUI wm;
// TODO: if NodeContainerEditPart -> getParent
if (nodePart instanceof NodeContainerEditPart) {
NodeContainerEditPart p = (NodeContainerEditPart) nodePart;
wm = p.getWorkflowManager();
} else if (nodePart instanceof WorkflowInPortBarEditPart) {
WorkflowInPortBarEditPart barEditPart = (WorkflowInPortBarEditPart) nodePart;
WorkflowPortBar model = (WorkflowPortBar) barEditPart.getModel();
wm = model.getWorkflowManager();
} else {
return null;
}
CreateConnectionCommand cmd = new CreateConnectionCommand(Wrapper.unwrapWFM(wm));
if (getHost() instanceof NodeOutPortEditPart || getHost() instanceof WorkflowInPortEditPart || getHost() instanceof MetaNodeOutPortEditPart) {
// request started on out port?
cmd.setSourceNode(nodePart);
cmd.setSourcePortID(((AbstractPortEditPart) getHost()).getIndex());
cmd.setStartedOnOutPort(true);
} else if (getHost() instanceof NodeInPortEditPart || getHost() instanceof WorkflowOutPortEditPart) {
return null;
}
// we need the manager to execute the command
// we must remember this partially initialized command in the request.
req.setStartCommand(cmd);
return cmd;
}
use of org.knime.workbench.editor2.commands.CreateConnectionCommand in project knime-core by knime.
the class NodeContainerEditPart method getTargetConnectionAnchor.
/**
* {@inheritDoc}
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(final Request request) {
if (!(request instanceof CreateConnectionRequest)) {
return null;
}
CreateConnectionRequest req = (CreateConnectionRequest) request;
Command cmd = req.getStartCommand();
if (!(cmd instanceof CreateConnectionCommand)) {
return null;
}
CreateConnectionCommand connCmd = (CreateConnectionCommand) cmd;
// find a free port that could take the connection
int portIdx = getFreeInPort(connCmd.getSourceNode(), connCmd.getSourcePortID());
if (portIdx < 0) {
return null;
}
for (Object part : getChildren()) {
if (part instanceof AbstractPortEditPart) {
AbstractPortEditPart port = (AbstractPortEditPart) part;
if (port.isInPort() && port.getIndex() == portIdx) {
return port.getTargetConnectionAnchor(request);
}
}
}
return null;
}
Aggregations