use of org.knime.workbench.editor2.editparts.ConnectableEditPart 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.editparts.ConnectableEditPart in project knime-core by knime.
the class CreateConnectionCommand method canExecute.
/**
* @return <code>true</code> if the connection can be added (that is, all
* fields were set to valid values before and the corresponding edit
* parts are not locked
* @see org.eclipse.gef.commands.Command#canExecute()
*/
@Override
public boolean canExecute() {
if (!super.canExecute()) {
return false;
}
if (m_sourceNode == null || m_targetNode == null) {
return false;
}
WorkflowManager wm = getHostWFM();
if (m_targetPortID < 0) {
ConnectableEditPart target = getTargetNode();
if (target instanceof NodeContainerEditPart) {
m_targetPortID = ((NodeContainerEditPart) target).getFreeInPort(getSourceNode(), getSourcePortID());
}
}
// check whether an existing connection can be removed
ConnectionContainer conn = wm.getIncomingConnectionFor(m_targetNode.getNodeContainer().getID(), m_targetPortID);
boolean canRemove = conn == null || wm.canRemoveConnection(conn);
// let the workflow manager check if the connection can be created
// or removed
boolean canAdd = wm.canAddConnection(m_sourceNode.getNodeContainer().getID(), m_sourcePortID, m_targetNode.getNodeContainer().getID(), m_targetPortID);
return canRemove && canAdd;
}
use of org.knime.workbench.editor2.editparts.ConnectableEditPart 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;
}
Aggregations