Search in sources :

Example 11 with MetaPortInfo

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

the class Workflow method changeDestinationPortsForMetaNode.

/**
 * @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>> changeDestinationPortsForMetaNode(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> connectionsToMetaNode = m_connectionsByDest.get(metaNodeID);
    for (ConnectionContainer cc : connectionsToMetaNode) {
        int destPort = cc.getDestPort();
        boolean hasBeenFound = false;
        for (MetaPortInfo mpi : newPorts) {
            if (mpi.getOldIndex() == destPort) {
                hasBeenFound = true;
                if (mpi.getNewIndex() != destPort || includeUnchanged) {
                    ConnectionContainer newConn = new ConnectionContainer(cc.getSource(), cc.getSourcePort(), metaNodeID, mpi.getNewIndex(), 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 12 with MetaPortInfo

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

the class Workflow method getMetanodeOutputPortInfo.

/**
 * Implementation of {@link WorkflowManager#getMetanodeOutputPortInfo(NodeID)}.
 * @param metaNodeID ...
 * @return ...
 */
MetaPortInfo[] getMetanodeOutputPortInfo(final NodeID metaNodeID) {
    WorkflowManager wfm = (WorkflowManager) m_nodes.get(metaNodeID);
    Workflow wfmFlow = wfm.getWorkflow();
    MetaPortInfo[] result = new MetaPortInfo[wfm.getNrOutPorts()];
    for (int i = 0; i < result.length; i++) {
        boolean hasInsideConnection = false;
        for (ConnectionContainer cc : wfmFlow.getConnectionsByDest(metaNodeID)) {
            if (cc.getDestPort() == i) {
                hasInsideConnection = true;
                break;
            }
        }
        int outsideCount = 0;
        for (ConnectionContainer outCC : getConnectionsBySource(metaNodeID)) {
            if (outCC.getSourcePort() == i) {
                outsideCount += 1;
            }
        }
        String message;
        boolean isConnected;
        PortType portType = wfm.getOutPort(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[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 13 with MetaPortInfo

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

the class MetaPortInfoTest method testBuilderAndGetters.

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

Example 14 with MetaPortInfo

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

the class MetaPortInfoTest method testUIDNotSet.

@Test
public void testUIDNotSet() throws IllegalArgumentException {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("No port type set");
    MetaPortInfo mpi = MetaPortInfo.builder().build();
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo) Test(org.junit.Test)

Example 15 with MetaPortInfo

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

the class ConfigureMetaNodePortsPage method removeSelPort.

private void removeSelPort(final boolean inPort) {
    java.util.List<MetaPortInfo> infoList = inPort ? m_inPortList : m_outPortList;
    List portList = inPort ? m_inPorts : m_outPorts;
    int idx = portList.getSelectionIndex();
    if (idx < 0) {
        return;
    }
    if (idx >= infoList.size()) {
        LOGGER.coding("Selected port index is too big for internal port info list");
        return;
    }
    infoList.remove(idx + m_offset);
    populateSelectionlistFromInfolist(portList, infoList, inPort ? "in_" : "out_");
    updateStatus();
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo) ArrayList(java.util.ArrayList) List(org.eclipse.swt.widgets.List)

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