Search in sources :

Example 81 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class ReconnectConnectionCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // confirm replacement?
    // check if old target node was executed
    WorkflowManager hostWFM = getHostWFM();
    NodeContainer oldTarget = hostWFM.getNodeContainer(m_oldTarget);
    NodeContainer newTarget = hostWFM.getNodeContainer(m_newTarget);
    if (oldTarget == null || newTarget == null) {
        // something is very wrong here
        return;
    }
    boolean oldExecuted = oldTarget.getNodeContainerState().isExecuted();
    boolean newExecuted = newTarget.getNodeContainerState().isExecuted();
    // or new target node is executed
    if (m_confirm && (oldExecuted || newExecuted)) {
        // create comprehensible and correct confirmation message
        StringBuffer message = new StringBuffer("Do you want to delete the existing connection? \n");
        if (oldExecuted || newExecuted) {
            message.append("This will reset ");
            if (oldExecuted) {
                message.append("the current destination node");
            }
            if (oldExecuted && newExecuted) {
                message.append(" and");
            }
            if (newExecuted) {
                message.append(" the new target node");
            }
            message.append('!');
        }
        MessageDialogWithToggle msgD = CreateConnectionCommand.openReconnectConfirmDialog(m_confirm, message.toString());
        m_confirm = !msgD.getToggleState();
        if (msgD.getReturnCode() != IDialogConstants.YES_ID) {
            return;
        }
    }
    // execute both commands
    m_deleteCommand.execute();
    m_createCommand.setConfirm(false);
    m_createCommand.execute();
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Example 82 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class UpdateMetaNodeLinkCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    LOGGER.debug("Undo: Reverting metanode links (" + m_newIDs.size() + " metanode(s))");
    WorkflowManager hostWFM = getHostWFM();
    for (int i = 0; i < m_newIDs.size(); i++) {
        NodeID id = m_newIDs.get(i);
        WorkflowPersistor p = m_undoPersistors.get(i);
        NodeContainerTemplate nodeToBeDeleted = (NodeContainerTemplate) hostWFM.findNodeContainer(id);
        WorkflowManager parent = nodeToBeDeleted.getParent();
        parent.removeNode(nodeToBeDeleted.getID());
        parent.paste(p);
    }
}
Also used : NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor)

Example 83 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class UpdateMetaNodeLinkCommand method canExecute.

/**
 * We can execute, if all components were 'non-null' in the constructor.
 * {@inheritDoc}
 */
@Override
public boolean canExecute() {
    if (!super.canExecute()) {
        return false;
    }
    if (m_ids == null) {
        return false;
    }
    boolean containsUpdateableMN = false;
    WorkflowManager hostWFM = getHostWFM();
    for (NodeID id : m_ids) {
        NodeContainer nc = hostWFM.findNodeContainer(id);
        if (nc instanceof NodeContainerTemplate) {
            NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
            final WorkflowManager parent = tnc.getParent();
            if (parent.hasUpdateableMetaNodeLink(id)) {
                containsUpdateableMN = true;
            }
            if (!parent.canUpdateMetaNodeLink(id)) {
                return false;
            }
        }
    }
    return containsUpdateableMN;
}
Also used : NodeContainerTemplate(org.knime.core.node.workflow.NodeContainerTemplate) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer)

Example 84 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class ReplaceHelper method reconnect.

/**
 * Connects new node with connection of the old node.
 *
 * @param container new node container
 */
public void reconnect(final NodeContainer container) {
    // reset node location
    NodeUIInformation uiInformation = m_oldNode.getUIInformation();
    int[] bounds = uiInformation.getBounds();
    NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], -1, -1).setHasAbsoluteCoordinates(true).setSnapToGrid(uiInformation.getSnapToGrid()).setIsDropLocation(false).build();
    container.setUIInformation(info);
    int inShift;
    int outShift;
    if (m_oldNode instanceof WorkflowManager && !(container instanceof WorkflowManager)) {
        inShift = 0;
        // replacing a metanode (no opt. flow var ports) with a "normal" node (that has optional flow var ports)
        if (m_oldNode.getNrInPorts() > 0 && container.getNrInPorts() > 1) {
            // shift ports one index - unless we need to use the invisible optional flow var port of new node
            if (!m_oldNode.getInPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
                inShift = 1;
            } else if (container.getInPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
                inShift = 1;
            }
        }
        outShift = 0;
        if (m_oldNode.getNrOutPorts() > 0 && container.getNrOutPorts() > 1) {
            if (!m_oldNode.getOutPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
                outShift = 1;
            } else if (container.getOutPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
                outShift = 1;
            }
        }
    } else if (!(m_oldNode instanceof WorkflowManager) && container instanceof WorkflowManager) {
        // replacing a "normal" node with a metanode
        inShift = -1;
        for (ConnectionContainer cc : m_incomingConnections) {
            if (cc.getDestPort() == 0) {
                inShift = 0;
                break;
            }
        }
        outShift = -1;
        for (ConnectionContainer cc : m_outgoingConnections) {
            if (cc.getSourcePort() == 0) {
                outShift = 0;
                break;
            }
        }
    } else {
        inShift = 0;
        outShift = 0;
    }
    // set incoming connections
    NodeID newId = container.getID();
    for (ConnectionContainer c : m_incomingConnections) {
        if (m_wfm.canAddConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift)) {
            m_wfm.addConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift);
        } else {
            break;
        }
    }
    // set outgoing connections
    for (ConnectionContainer c : m_outgoingConnections) {
        if (m_wfm.canAddConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort())) {
            m_wfm.addConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort());
        } else {
            break;
        }
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Example 85 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class ConnectionBendpointEditPolicy method getMoveBendpointCommand.

/**
 * {@inheritDoc}
 */
protected Command getMoveBendpointCommand(final BendpointRequest request) {
    // index of the bendpoint to move
    int index = request.getIndex();
    Point loc = request.getLocation();
    ConnectionContainerEditPart edit = (ConnectionContainerEditPart) getHost();
    ZoomManager zoomManager = (ZoomManager) getHost().getRoot().getViewer().getProperty(ZoomManager.class.toString());
    WorkflowManager m = getWorkflowManager();
    return new NewBendpointMoveCommand(edit, m, index, loc, zoomManager);
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Point(org.eclipse.draw2d.geometry.Point) NewBendpointMoveCommand(org.knime.workbench.editor2.commands.NewBendpointMoveCommand) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)88 NodeID (org.knime.core.node.workflow.NodeID)31 NodeContainer (org.knime.core.node.workflow.NodeContainer)20 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)12 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)12 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)10 ArrayList (java.util.ArrayList)9 MessageBox (org.eclipse.swt.widgets.MessageBox)9 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 IOException (java.io.IOException)8 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)8 Map (java.util.Map)7 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)7 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)7 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)7 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)7 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)6