Search in sources :

Example 1 with VirtualSubNodeOutputNodeFactory

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

the class SubNodeContainer method setOutPorts.

/**
 * @param portTypes Types of the new ports
 * @since 2.10
 */
public void setOutPorts(final PortType[] portTypes) {
    m_outputs = new Output[portTypes.length + 1];
    m_outports = new NodeContainerOutPort[portTypes.length + 1];
    for (int i = 0; i < portTypes.length; i++) {
        m_outputs[i + 1] = new Output(portTypes[i]);
        m_outports[i + 1] = new NodeContainerOutPort(this, portTypes[i], i + 1);
    }
    m_outputs[0] = new Output(FlowVariablePortObject.TYPE);
    m_outports[0] = new NodeContainerOutPort(this, FlowVariablePortObject.TYPE, 0);
    NodeContainer oldVNode = m_wfm.getNodeContainer(getVirtualOutNodeID());
    NodeSettings settings = new NodeSettings("node settings");
    try {
        m_wfm.saveNodeSettings(oldVNode.getID(), settings);
    } catch (InvalidSettingsException e) {
    // no valid settings available, skip
    }
    m_virtualOutNodeIDSuffix = m_wfm.createAndAddNode(new VirtualSubNodeOutputNodeFactory(portTypes)).getIndex();
    NodeContainer newVNode = m_wfm.getNodeContainer(getVirtualOutNodeID());
    newVNode.setUIInformation(oldVNode.getUIInformation());
    newVNode.setDeletable(false);
    // 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());
    getOutPort(0).setPortName("Variable Outport");
    newVNode.addNodeStateChangeListener(new RefreshPortNamesListener());
    refreshPortNames();
    m_wfm.setDirty();
    setDirty();
    notifyNodePropertyChangedListener(NodeProperty.MetaNodePorts);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) VirtualSubNodeOutputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeFactory)

Example 2 with VirtualSubNodeOutputNodeFactory

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

the class SubNodeContainer method addVirtualOutNode.

/**
 * Adds new/empty instance of a virtual output node and returns its ID.
 */
private NodeID addVirtualOutNode(final PortType[] outTypes, final Pair<int[], int[]> minMaxCoordinates) {
    NodeID outNodeID = m_wfm.createAndAddNode(new VirtualSubNodeOutputNodeFactory(outTypes));
    final NodeContainer outNodeNC = m_wfm.getNodeContainer(outNodeID);
    outNodeNC.setDeletable(false);
    int[] minCoordinates = minMaxCoordinates.getFirst();
    int[] maxCoordinates = minMaxCoordinates.getSecond();
    int x = maxCoordinates[0] + 100;
    int y = (minCoordinates[1] + maxCoordinates[1]) / 2;
    outNodeNC.setUIInformation(NodeUIInformation.builder().setNodeLocation(x, y, 0, 0).build());
    return outNodeID;
}
Also used : VirtualSubNodeOutputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeFactory)

Example 3 with VirtualSubNodeOutputNodeFactory

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

the class SelectionEventSourceTest method testProcessSelectionEventAsync.

/**
 * Tests the {@code async}-parameter of the
 * {@link SelectionEventSource#processSelectionEvent(NativeNodeContainer, SelectionEventMode, boolean, List)}-method.
 *
 * @throws Exception
 */
@Test
public void testProcessSelectionEventAsync() throws Exception {
    var wfm = WorkflowManagerUtil.createEmptyWorkflow();
    NativeNodeContainer nnc = WorkflowManagerUtil.createAndAddNode(wfm, new VirtualSubNodeOutputNodeFactory(new PortType[] { BufferedDataTable.TYPE }));
    var hiLiteHandler = nnc.getNodeModel().getInHiLiteHandler(0);
    var hiLiteListener = new TestHiLiteListener();
    hiLiteHandler.addHiLiteListener(hiLiteListener);
    // async call
    SelectionEventSource.processSelectionEvent(nnc, SelectionEventMode.ADD, true, List.of("1"));
    SelectionEventSource.processSelectionEvent(nnc, SelectionEventMode.REMOVE, true, List.of("1"));
    SelectionEventSource.processSelectionEvent(nnc, SelectionEventMode.REPLACE, true, List.of("1"));
    Awaitility.await().atMost(5, TimeUnit.SECONDS).pollInterval(200, TimeUnit.MILLISECONDS).untilAsserted(() -> assertThat(hiLiteListener.m_callerThreadName, notNullValue()));
    assertThat(hiLiteListener.m_callerThreadName, is(not("INVALID")));
    assertThat(hiLiteListener.m_callerThreadName, is(not(Thread.currentThread().getName())));
    hiLiteListener.m_callerThreadName = null;
    // sync call
    SelectionEventSource.processSelectionEvent(nnc, SelectionEventMode.ADD, false, List.of("2"));
    SelectionEventSource.processSelectionEvent(nnc, SelectionEventMode.REMOVE, false, List.of("2"));
    SelectionEventSource.processSelectionEvent(nnc, SelectionEventMode.REPLACE, false, List.of("2"));
    assertThat(hiLiteListener.m_callerThreadName, is(Thread.currentThread().getName()));
}
Also used : NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) VirtualSubNodeOutputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeFactory) PortType(org.knime.core.node.port.PortType) Test(org.junit.Test)

Aggregations

VirtualSubNodeOutputNodeFactory (org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeFactory)3 Test (org.junit.Test)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 NodeSettings (org.knime.core.node.NodeSettings)1 PortType (org.knime.core.node.port.PortType)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1