Search in sources :

Example 11 with ConnectionContainer

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());
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with ConnectionContainer

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;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 13 with ConnectionContainer

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());
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 14 with ConnectionContainer

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());
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 15 with ConnectionContainer

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;
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Aggregations

ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)28 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)14 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)9 NodeID (org.knime.core.node.workflow.NodeID)8 Point (org.eclipse.draw2d.geometry.Point)6 NodeContainer (org.knime.core.node.workflow.NodeContainer)6 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)5 ConnectionID (org.knime.core.node.workflow.ConnectionID)4 Map (java.util.Map)3 Builder (org.knime.core.node.workflow.ConnectionUIInformation.Builder)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)2 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)2 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 List (java.util.List)1 Set (java.util.Set)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 EditPartViewer (org.eclipse.gef.EditPartViewer)1