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