Search in sources :

Example 6 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class MetaPortInfoTest method testCopyBuilder.

@Test
public void testCopyBuilder() {
    PortType portType = BufferedDataTable.TYPE;
    MetaPortInfo mpi = MetaPortInfo.builder().setIsConnected(false).setMessage("message").setNewIndex(1).setOldIndex(2).setPortType(portType).build();
    MetaPortInfo mpi2 = MetaPortInfo.builder(mpi).build();
    assertEquals(mpi2.isConnected(), false);
    assertEquals(mpi2.getMessage(), "message");
    assertEquals(mpi2.getNewIndex(), 1);
    assertEquals(mpi2.getOldIndex(), 2);
    assertEquals(mpi2.getType(), portType);
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo) PortType(org.knime.core.node.port.PortType) Test(org.junit.Test)

Example 7 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class Workflow method changeSourcePortsForMetaNode.

/**
 * @param metaNodeID ID of the metanode
 * @param newPorts The new ports
 * @param includeUnchanged If connections that will not change should be included
 * @return List of pairs of original (first) and changed (second) connections
 */
List<Pair<ConnectionContainer, ConnectionContainer>> changeSourcePortsForMetaNode(final NodeID metaNodeID, final MetaPortInfo[] newPorts, final boolean includeUnchanged) {
    // argument node is either a contained metanode or this wfm itself
    // (latter only when updating outgoing connections)
    List<Pair<ConnectionContainer, ConnectionContainer>> result = new ArrayList<Pair<ConnectionContainer, ConnectionContainer>>();
    final Set<ConnectionContainer> connectionsFromMetaNode = m_connectionsBySource.get(metaNodeID);
    for (ConnectionContainer cc : connectionsFromMetaNode) {
        int sourcePort = cc.getSourcePort();
        boolean hasBeenFound = false;
        for (MetaPortInfo mpi : newPorts) {
            if (mpi.getOldIndex() == sourcePort) {
                hasBeenFound = true;
                if (mpi.getNewIndex() != sourcePort || includeUnchanged) {
                    ConnectionContainer newConn = new ConnectionContainer(metaNodeID, mpi.getNewIndex(), cc.getDest(), cc.getDestPort(), cc.getType(), cc.isFlowVariablePortConnection());
                    newConn.setUIInfo(cc.getUIInfo());
                    result.add(new Pair<ConnectionContainer, ConnectionContainer>(cc, newConn));
                }
                break;
            }
        }
        if (!hasBeenFound) {
            throw new IllegalStateException("New meta port information array " + "does not include currently connected ports, unseen connection: " + cc);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) Pair(org.knime.core.util.Pair)

Example 8 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class Workflow method getMetanodeInputPortInfo.

/**
 * Implementation of {@link WorkflowManager#getMetanodeInputPortInfo(NodeID)}.
 * @param metaNodeID ...
 * @return ...
 */
MetaPortInfo[] getMetanodeInputPortInfo(final NodeID metaNodeID) {
    WorkflowManager wfm = (WorkflowManager) m_nodes.get(metaNodeID);
    Workflow wfmFlow = wfm.getWorkflow();
    MetaPortInfo[] result = new MetaPortInfo[wfm.getNrInPorts()];
    for (int i = 0; i < result.length; i++) {
        int insideCount = 0;
        for (ConnectionContainer cc : wfmFlow.getConnectionsBySource(metaNodeID)) {
            if (cc.getSourcePort() == i) {
                // could also be a through connection
                insideCount += 1;
            }
        }
        boolean hasOutsideConnection = false;
        for (ConnectionContainer outCC : getConnectionsByDest(metaNodeID)) {
            if (outCC.getDestPort() == i) {
                hasOutsideConnection = true;
                break;
            }
        }
        String message;
        boolean isConnected;
        PortType portType = wfm.getInPort(i).getPortType();
        if (hasOutsideConnection || insideCount > 0) {
            isConnected = true;
            if (hasOutsideConnection && insideCount > 0) {
                message = "Connected to one upstream node and " + insideCount + " downstream node(s)";
            } else if (hasOutsideConnection) {
                message = "Connected to one upstream node";
            } else {
                message = "Connected to " + insideCount + " downstream node(s)";
            }
        } else {
            isConnected = false;
            message = null;
        }
        result[i] = MetaPortInfo.builder().setPortType(portType).setIsConnected(isConnected).setMessage(message).setOldIndex(i).build();
    }
    return result;
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo) PortType(org.knime.core.node.port.PortType)

Example 9 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class SubNodeContainer method getOutputPortInfo.

/**
 * Implementation of {@link WorkflowManager#getSubnodeOutputPortInfo(NodeID)}.
 * @return ...
 */
MetaPortInfo[] getOutputPortInfo() {
    Workflow wfmFlow = m_wfm.getWorkflow();
    NodeContainer outNode = m_wfm.getNodeContainer(getVirtualOutNodeID());
    List<MetaPortInfo> result = new ArrayList<MetaPortInfo>(outNode.getNrInPorts());
    for (int i = 0; i < outNode.getNrInPorts(); i++) {
        boolean hasInsideConnection = false;
        for (ConnectionContainer cc : wfmFlow.getConnectionsByDest(getVirtualOutNodeID())) {
            if (cc.getDestPort() == i) {
                hasInsideConnection = true;
                break;
            }
        }
        int outsideCount = 0;
        for (ConnectionContainer outCC : getParent().getWorkflow().getConnectionsBySource(getID())) {
            if (outCC.getSourcePort() == i) {
                outsideCount += 1;
            }
        }
        String message;
        boolean isConnected;
        PortType portType = outNode.getInPort(i).getPortType();
        if (hasInsideConnection || outsideCount > 0) {
            isConnected = true;
            if (hasInsideConnection && outsideCount > 0) {
                message = "Connected to one upstream node and " + outsideCount + " downstream node(s)";
            } else if (hasInsideConnection) {
                // could also be a through conn but we ignore here
                message = "Connected to one upstream node";
            } else {
                message = "Connected to " + outsideCount + " downstream node(s)";
            }
        } else {
            isConnected = false;
            message = null;
        }
        result.add(MetaPortInfo.builder().setPortType(portType).setIsConnected(isConnected).setMessage(message).setOldIndex(i).build());
    }
    return result.toArray(new MetaPortInfo[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) PortType(org.knime.core.node.port.PortType)

Example 10 with MetaPortInfo

use of org.knime.core.node.port.MetaPortInfo in project knime-core by knime.

the class SubNodeContainer method getInputPortInfo.

/**
 * Implementation of {@link WorkflowManager#getSubnodeInputPortInfo(NodeID)}.
 * @return ...
 */
MetaPortInfo[] getInputPortInfo() {
    Workflow wfmFlow = m_wfm.getWorkflow();
    NodeContainer inNode = m_wfm.getNodeContainer(getVirtualInNodeID());
    List<MetaPortInfo> result = new ArrayList<MetaPortInfo>(inNode.getNrOutPorts());
    for (int i = 0; i < inNode.getNrOutPorts(); i++) {
        int insideCount = 0;
        for (ConnectionContainer cc : wfmFlow.getConnectionsBySource(getVirtualInNodeID())) {
            if (cc.getSourcePort() == i) {
                // could also be a through connection
                insideCount += 1;
            }
        }
        boolean hasOutsideConnection = false;
        for (ConnectionContainer outCC : getParent().getWorkflow().getConnectionsByDest(getID())) {
            if (outCC.getDestPort() == i) {
                hasOutsideConnection = true;
                break;
            }
        }
        String message;
        boolean isConnected;
        PortType portType = inNode.getOutPort(i).getPortType();
        if (hasOutsideConnection || insideCount > 0) {
            isConnected = true;
            if (hasOutsideConnection && insideCount > 0) {
                message = "Connected to one upstream node and " + insideCount + " downstream node(s)";
            } else if (hasOutsideConnection) {
                message = "Connected to one upstream node";
            } else {
                message = "Connected to " + insideCount + " downstream node(s)";
            }
        } else {
            isConnected = false;
            message = null;
        }
        result.add(MetaPortInfo.builder().setPortType(portType).setIsConnected(isConnected).setMessage(message).setOldIndex(i).build());
    }
    return result.toArray(new MetaPortInfo[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) PortType(org.knime.core.node.port.PortType)

Aggregations

MetaPortInfo (org.knime.core.node.port.MetaPortInfo)22 PortType (org.knime.core.node.port.PortType)9 ArrayList (java.util.ArrayList)8 List (org.eclipse.swt.widgets.List)3 Test (org.junit.Test)3 NodeContainer (org.knime.core.node.workflow.NodeContainer)2 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)2 Pair (org.knime.core.util.Pair)2 ReconfigureMetaNodeCommand (org.knime.workbench.editor2.commands.ReconfigureMetaNodeCommand)2 Point (org.eclipse.draw2d.geometry.Point)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 GC (org.eclipse.swt.graphics.GC)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1