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);
}
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;
}
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;
}
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()]);
}
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()]);
}
Aggregations