Search in sources :

Example 1 with VirtualSubNodeInputNodeFactory

use of org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory in project knime-core by knime.

the class SubNodeContainer method setInPorts.

/**
 * @param portTypes Types of the new ports
 * @since 2.10
 */
public void setInPorts(final PortType[] portTypes) {
    m_inports = new NodeInPort[portTypes.length + 1];
    for (int i = 0; i < portTypes.length; i++) {
        m_inports[i + 1] = new NodeInPort(i + 1, portTypes[i]);
    }
    NodeContainer oldVNode = m_wfm.getNodeContainer(getVirtualInNodeID());
    m_inports[0] = new NodeInPort(0, FlowVariablePortObject.TYPE_OPTIONAL);
    NodeSettings settings = new NodeSettings("node settings");
    try {
        m_wfm.saveNodeSettings(oldVNode.getID(), settings);
    } catch (InvalidSettingsException e) {
    // no valid settings available, skip
    }
    m_virtualInNodeIDSuffix = m_wfm.addNode(new VirtualSubNodeInputNodeFactory(this, portTypes)).getIndex();
    NodeContainer newVNode = m_wfm.getNodeContainer(getVirtualInNodeID());
    newVNode.setUIInformation(oldVNode.getUIInformation());
    // copy settings from old to new node
    try {
        m_wfm.loadNodeSettings(newVNode.getID(), settings);
    } catch (InvalidSettingsException e) {
    // ignore
    }
    oldVNode.setDeletable(true);
    m_wfm.removeNode(oldVNode.getID());
    getInPort(0).setPortName("Variable Inport");
    newVNode.addNodeStateChangeListener(new RefreshPortNamesListener());
    refreshPortNames();
    m_wfm.setDirty();
    setDirty();
    notifyNodePropertyChangedListener(NodeProperty.MetaNodePorts);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) VirtualSubNodeInputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 2 with VirtualSubNodeInputNodeFactory

use of org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory in project knime-core by knime.

the class SubNodeContainer method addVirtualInNode.

/**
 * Adds new/empty instance of a virtual input node and returns its ID.
 */
private NodeID addVirtualInNode(final PortType[] inTypes, final Pair<int[], int[]> minMaxCoordinates) {
    NodeID inNodeID = m_wfm.addNode(new VirtualSubNodeInputNodeFactory(this, inTypes));
    final NodeContainer inNodeNC = m_wfm.getNodeContainer(inNodeID);
    inNodeNC.setDeletable(false);
    int[] minCoordinates = minMaxCoordinates.getFirst();
    int[] maxCoordinates = minMaxCoordinates.getSecond();
    int x = minCoordinates[0] - 100;
    int y = (minCoordinates[1] + maxCoordinates[1]) / 2;
    inNodeNC.setUIInformation(NodeUIInformation.builder().setNodeLocation(x, y, 0, 0).build());
    return inNodeID;
}
Also used : VirtualSubNodeInputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory)

Aggregations

VirtualSubNodeInputNodeFactory (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettings (org.knime.core.node.NodeSettings)1