use of org.knime.core.node.port.PortType in project knime-core by knime.
the class AddMetaNodeWizard method createMetaNode.
private void createMetaNode(final int nrInPorts, final int nrOutPorts) {
PortType[] inPorts = new PortType[nrInPorts];
for (int i = 0; i < nrInPorts; i++) {
inPorts[i] = BufferedDataTable.TYPE;
}
PortType[] outPorts = new PortType[nrOutPorts];
for (int i = 0; i < nrOutPorts; i++) {
outPorts[i] = BufferedDataTable.TYPE;
}
// removed the port "ratio" from the name
String name = "Metanode " + nrInPorts + " : " + nrOutPorts;
createMetaNodeFromPorts(inPorts, outPorts, name);
}
use of org.knime.core.node.port.PortType in project knime-core by knime.
the class AddMetaNodeWizard method performCustomizedFinish.
private void performCustomizedFinish() {
// create subworkflow with the number and types
// of the entered in- and out ports
PortType[] inPorts = new PortType[m_addPage.getInPorts().size()];
PortType[] outPorts = new PortType[m_addPage.getOutPorts().size()];
int i = 0;
for (MetaPortInfo p : m_addPage.getInPorts()) {
inPorts[i++] = p.getType();
}
i = 0;
for (MetaPortInfo p : m_addPage.getOutPorts()) {
outPorts[i++] = p.getType();
}
String name = "";
if (m_addPage.getMetaNodeName() != null && m_addPage.getMetaNodeName().length() > 0) {
name = m_addPage.getMetaNodeName();
}
createMetaNodeFromPorts(inPorts, outPorts, name);
}
use of org.knime.core.node.port.PortType in project knime-core by knime.
the class ReconfigureMetaNodeCommand method createReverseOperationList.
/**
* Creates a port list that can be applied - after the newPortList was applied to a metanode with the
* currentPortList - to get the metanode back to a port list like the curentPortList.
*
* @param currentPortList
* @param newPortList
* @return
*/
private List<MetaPortInfo> createReverseOperationList(final MetaPortInfo[] currentPortList, final List<MetaPortInfo> newPortList) {
MetaPortInfo[] reverse = new MetaPortInfo[currentPortList.length];
for (MetaPortInfo newInfo : newPortList) {
if (newInfo.getOldIndex() >= 0) {
int revOldIdx = newInfo.getNewIndex();
int revNewIdx = newInfo.getOldIndex();
PortType revType = currentPortList[newInfo.getOldIndex()].getType();
boolean revConn = currentPortList[newInfo.getOldIndex()].isConnected();
MetaPortInfo revInfo = MetaPortInfo.builder().setPortType(revType).setIsConnected(revConn).setOldIndex(revOldIdx).setNewIndex(revNewIdx).build();
reverse[revNewIdx] = revInfo;
}
}
// all array positions still null got deleted and must be filled from the current list
for (int i = 0; i < reverse.length; i++) {
if (reverse[i] != null) {
// that is a port that got moved back above
continue;
}
MetaPortInfo currentInfo = currentPortList[i];
MetaPortInfo revInfo = MetaPortInfo.builder(currentInfo).setIsConnected(false).setMessage(null).setOldIndex(-1).setNewIndex(i).build();
reverse[i] = revInfo;
}
return new ArrayList<MetaPortInfo>(Arrays.asList(reverse));
}
use of org.knime.core.node.port.PortType in project knime-core by knime.
the class FileNativeNodeContainerPersistor method guessPortTypesFromConnectedNodes.
/**
* {@inheritDoc}
*/
@Override
public void guessPortTypesFromConnectedNodes(final NodeAndBundleInformation nodeInfo, final NodeSettingsRO additionalFactorySettings, final ArrayList<PersistorWithPortIndex> upstreamNodes, final ArrayList<List<PersistorWithPortIndex>> downstreamNodes) {
if (m_node == null) {
/* Input ports from the connection table. */
// first is flow var port
PortType[] inPortTypes = new PortType[Math.max(upstreamNodes.size() - 1, 0)];
// default to BDT for unconnected ports
Arrays.fill(inPortTypes, BufferedDataTable.TYPE);
for (int i = 0; i < inPortTypes.length; i++) {
// first is flow var port
PersistorWithPortIndex p = upstreamNodes.get(i + 1);
if (p != null) {
PortType portTypeFromUpstreamNode = p.getPersistor().getUpstreamPortType(p.getPortIndex());
if (portTypeFromUpstreamNode != null) {
// null if upstream is missing, too
inPortTypes[i] = portTypeFromUpstreamNode;
}
}
}
/* Output ports from node settings (saved ports) -- if possible (executed) */
String nodeName = nodeInfo.getNodeNameNotNull();
PortType[] outPortTypes;
try {
LoadResult guessLoadResult = new LoadResult("Port type guessing for missing node \"" + nodeName + "\"");
NodeSettingsRO settingsForNode = loadSettingsForNode(guessLoadResult);
FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
outPortTypes = nodePersistor.guessOutputPortTypes(guessLoadResult, nodeName);
if (guessLoadResult.hasErrors()) {
getLogger().debug("Errors guessing port types for missing node \"" + nodeName + "\": " + guessLoadResult.getFilteredError("", LoadResultEntryType.Error));
}
} catch (Exception e) {
getLogger().debug("Unable to guess port types for missing node \"" + nodeName + "\"", e);
outPortTypes = null;
}
if (outPortTypes == null) {
// couldn't guess port types from looking at node settings (e.g. not executed)
// default to BDT for unconnected ports
outPortTypes = new PortType[Math.max(downstreamNodes.size() - 1, 0)];
}
for (int i = 0; i < outPortTypes.length; i++) {
PortType type = outPortTypes[i];
// output types may be partially filled by settings guessing above, list may be empty or too short
List<PersistorWithPortIndex> list = i < downstreamNodes.size() - 1 ? downstreamNodes.get(i + 1) : null;
if (list != null) {
assert !list.isEmpty();
for (PersistorWithPortIndex p : list) {
PortType current = p.getPersistor().getDownstreamPortType(p.getPortIndex());
if (current == null) {
// ignore, downstream node is also missing
} else if (type == null) {
type = current;
} else if (type.equals(current)) {
// keep type
} else {
// this shouldn't really happen - someone changed port types between versions
type = PortObject.TYPE;
}
}
outPortTypes[i] = type;
}
if (outPortTypes[i] == null) {
// might still be null if missing node is only connected to missing node, fallback: BDT
outPortTypes[i] = BufferedDataTable.TYPE;
}
}
MissingNodeFactory nodefactory = new MissingNodeFactory(nodeInfo, additionalFactorySettings, inPortTypes, outPortTypes);
if (getLoadVersion().ordinal() < FileWorkflowPersistor.VERSION_LATEST.ordinal()) {
nodefactory.setCopyInternDirForWorkflowVersionChange(true);
}
nodefactory.init();
m_node = new Node((NodeFactory) nodefactory);
}
}
use of org.knime.core.node.port.PortType in project knime-core by knime.
the class FileWorkflowPersistor method loadOutPortTemplate.
/**
* Sub class hook o read port settings.
*
* @param settings Ignored.
* @return null
* @throws InvalidSettingsException Not actually thrown here.
*/
WorkflowPortTemplate loadOutPortTemplate(final NodeSettingsRO settings) throws InvalidSettingsException {
if (getLoadVersion().isOlderThan(LoadVersion.V200)) {
throw new InvalidSettingsException("No ports for metanodes in version 1.x.x");
} else {
int index = settings.getInt("index");
String name = settings.getString("name");
NodeSettingsRO portTypeSettings = settings.getNodeSettings("type");
PortType type = PortType.load(portTypeSettings);
WorkflowPortTemplate result = new WorkflowPortTemplate(index, type);
result.setPortName(name);
return result;
}
}
Aggregations