Search in sources :

Example 1 with PortType

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);
}
Also used : Point(org.eclipse.draw2d.geometry.Point) PortType(org.knime.core.node.port.PortType)

Example 2 with PortType

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);
}
Also used : MetaPortInfo(org.knime.core.node.port.MetaPortInfo) Point(org.eclipse.draw2d.geometry.Point) PortType(org.knime.core.node.port.PortType)

Example 3 with PortType

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));
}
Also used : ArrayList(java.util.ArrayList) MetaPortInfo(org.knime.core.node.port.MetaPortInfo) PortType(org.knime.core.node.port.PortType)

Example 4 with PortType

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);
    }
}
Also used : Node(org.knime.core.node.Node) FileNodePersistor(org.knime.core.node.FileNodePersistor) LoadResult(org.knime.core.node.workflow.WorkflowPersistor.LoadResult) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeFactoryUnknownException(org.knime.core.node.workflow.WorkflowPersistor.NodeFactoryUnknownException) IOException(java.io.IOException) NodeFactory(org.knime.core.node.NodeFactory) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) MissingNodeFactory(org.knime.core.node.missing.MissingNodeFactory) PortType(org.knime.core.node.port.PortType)

Example 5 with PortType

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;
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) PortType(org.knime.core.node.port.PortType)

Aggregations

PortType (org.knime.core.node.port.PortType)40 MetaPortInfo (org.knime.core.node.port.MetaPortInfo)9 HashMap (java.util.HashMap)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 IOException (java.io.IOException)7 ExecutionContext (org.knime.core.node.ExecutionContext)7 Node (org.knime.core.node.Node)7 NodeFactory (org.knime.core.node.NodeFactory)7 NodeModel (org.knime.core.node.NodeModel)6 PortObject (org.knime.core.node.port.PortObject)6 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)6 VirtualParallelizedChunkPortObjectInNodeFactory (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Before (org.junit.Before)5 DefaultNodeProgressMonitor (org.knime.core.node.DefaultNodeProgressMonitor)5 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)5 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)5 LinkedHashMap (java.util.LinkedHashMap)4 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)4