use of org.knime.core.node.workflow.ConnectionContainer in project knime-core by knime.
the class ChangeBendPointLocationCommand method changeBendpointsUIInfo.
private void changeBendpointsUIInfo(final boolean shiftBack) {
ConnectionContainer cc = getConnectionContainer();
ConnectionUIInformation ui = cc.getUIInfo();
if (ui == null) {
return;
}
int[][] bendpoints = ui.getAllBendpoints();
Point locationShift = m_locationShift.getCopy();
if (m_zoomManager != null) {
WorkflowEditor.adaptZoom(m_zoomManager, locationShift, false);
}
int length = bendpoints.length;
int shiftX = shiftBack ? locationShift.x * -1 : locationShift.x;
int shiftY = shiftBack ? locationShift.y * -1 : locationShift.y;
ConnectionUIInformation.Builder newUIBuilder = ConnectionUIInformation.builder();
for (int i = 0; i < length; i++) {
// get old
int x = ui.getBendpoint(i)[0];
int y = ui.getBendpoint(i)[1];
// set the new point
newUIBuilder.addBendpoint(x + shiftX, y + shiftY, i);
}
// must set explicitly so that event is fired by container
cc.setUIInfo(newUIBuilder.build());
}
use of org.knime.core.node.workflow.ConnectionContainer 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.core.node.workflow.ConnectionContainer in project knime-core by knime.
the class CreateConnectionCommand method undo.
/**
* {@inheritDoc}
*/
@Override
public void undo() {
WorkflowManager wm = getHostWFM();
wm.removeConnection(m_connection);
ConnectionContainer old = m_oldConnection;
if (old != null) {
ConnectionContainer newConn = wm.addConnection(old.getSource(), old.getSourcePort(), old.getDest(), old.getDestPort());
newConn.setUIInfo(old.getUIInfo());
}
}
use of org.knime.core.node.workflow.ConnectionContainer in project knime-core by knime.
the class CreateConnectionCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// check whether it is the same connection
ConnectionContainer conn = getHostWFM().getIncomingConnectionFor(m_targetNode.getNodeContainer().getID(), m_targetPortID);
if (conn != null && conn.getSource().equals(m_sourceNode.getNodeContainer().getID()) && conn.getSourcePort() == m_sourcePortID && conn.getDest().equals(m_targetNode.getNodeContainer().getID()) && conn.getDestPort() == m_targetPortID) {
// it is the very same connection -> do nothing
return;
}
WorkflowManager wm = getHostWFM();
// displayed to the user
try {
// if target nodeport is already connected
if (conn != null) {
// ask user if it should be replaced...
if (m_confirm && m_targetNode.getNodeContainer().getNodeContainerState().isExecuted()) {
// show confirmation message only if target node is executed
MessageDialogWithToggle msgD = openReconnectConfirmDialog(m_confirm, "Do you want to replace existing connection? \n" + "This will reset the target node!");
m_confirm = !msgD.getToggleState();
if (msgD.getReturnCode() != IDialogConstants.YES_ID) {
return;
}
}
// remove existing connection
wm.removeConnection(conn);
m_oldConnection = conn;
}
LOGGER.debug("adding connection from " + m_sourceNode.getNodeContainer().getID() + " " + m_sourcePortID + " to " + m_targetNode.getNodeContainer().getID() + " " + m_targetPortID);
m_connection = wm.addConnection(m_sourceNode.getNodeContainer().getID(), m_sourcePortID, m_targetNode.getNodeContainer().getID(), m_targetPortID);
NodeTimer.GLOBAL_TIMER.addConnectionCreation(unwrapNC(m_sourceNode.getNodeContainer()), unwrapNC(m_targetNode.getNodeContainer()));
if (m_newConnectionUIInfo != null) {
m_connection.setUIInfo(m_newConnectionUIInfo);
}
} catch (Exception e) {
LOGGER.error("Connection could not be created.", e);
m_connection = null;
m_oldConnection = null;
m_sourceNode = null;
m_targetNode = null;
m_sourcePortID = -1;
m_targetPortID = -1;
MessageDialog.openError(Display.getDefault().getActiveShell(), "Connection could not be created", "The two nodes could not be connected due to " + "the following reason:\n " + e.getMessage());
}
}
use of org.knime.core.node.workflow.ConnectionContainer in project knime-core by knime.
the class DeleteCommand method canExecute.
/**
* {@inheritDoc}
*/
@Override
public boolean canExecute() {
if (!super.canExecute()) {
return false;
}
boolean foundValid = false;
WorkflowManager hostWFM = getHostWFM();
for (NodeID id : m_nodeIDs) {
foundValid = true;
if (!hostWFM.canRemoveNode(id)) {
return false;
}
}
for (ConnectionContainer cc : m_connections) {
foundValid = true;
if (!hostWFM.canRemoveConnection(cc)) {
return false;
}
}
return foundValid || m_annotations.length > 0;
}
Aggregations