Search in sources :

Example 11 with NodeModel

use of org.knime.core.node.NodeModel in project knime-core by knime.

the class SubNodeContainer method setHideNodeFromWizard.

/**
 * Sets a flag on a given {@link WizardNode}, whether or not it is hidden from wizard execution
 * @param id the node to set the flag on
 * @param hide true if the node is supposed to be hidden from WebPortal or wizard execution, false otherwise
 * @since 3.5
 * @noreference This method is not intended to be referenced by clients.
 */
public void setHideNodeFromWizard(final NodeID id, final boolean hide) {
    try (WorkflowLock lock = lock()) {
        NativeNodeContainer nnc = m_wfm.getNodeContainer(id, NativeNodeContainer.class, true);
        NodeModel model = nnc.getNodeModel();
        CheckUtils.checkArgument(model instanceof WizardNode, "Can't set hide in wizard flag on non-wizard nodes.");
        WizardNode<?, ?> wn = (WizardNode<?, ?>) model;
        if (hide != wn.isHideInWizard()) {
            wn.setHideInWizard(hide);
            nnc.saveNodeSettingsToDefault();
            nnc.setDirty();
        }
    }
}
Also used : VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) NodeModel(org.knime.core.node.NodeModel) WizardNode(org.knime.core.node.wizard.WizardNode)

Example 12 with NodeModel

use of org.knime.core.node.NodeModel in project knime-core by knime.

the class SubNodeContainer method checkInOutNodesAfterLoad.

/**
 * Fixes in- and output nodes after loading (in case they don't exist or have errors).
 */
private void checkInOutNodesAfterLoad(final SubNodeContainerPersistor subNodePersistor, final LoadResult loadResult) {
    /* Fix output node */
    NodeID virtualOutID = getVirtualOutNodeID();
    // non null in case not is not present of of wrong type
    String error = null;
    // settings of previous node if present or null
    NodeSettings outputSettings = null;
    // assigned with node insertion, used for node placement
    Pair<int[], int[]> minMaxCoordinates;
    if (m_wfm.containsNodeContainer(virtualOutID)) {
        NodeContainer virtualOutNC = m_wfm.getNodeContainer(virtualOutID);
        if (virtualOutNC instanceof NativeNodeContainer) {
            NodeModel virtualOutModel = ((NativeNodeContainer) virtualOutNC).getNodeModel();
            if (!(virtualOutModel instanceof VirtualSubNodeOutputNodeModel)) {
                // this is very likely a missing node (placeholder)
                error = String.format("Virtual output node is not of expected type (expected %s, actual %s)", VirtualSubNodeOutputNodeModel.class.getName(), virtualOutModel.getClass().getName());
                try {
                    NodeSettings temp = new NodeSettings("temp");
                    m_wfm.saveNodeSettings(virtualOutID, temp);
                    outputSettings = temp;
                } catch (InvalidSettingsException ise) {
                // silently ignore; this is minor given that the node is not there.
                }
            }
        } else {
            error = String.format("Virtual output node with ID %s is not a native node", virtualOutID);
        }
    } else {
        error = String.format("Virtual output node with ID %s does not exist", virtualOutID);
    }
    if (error != null) {
        minMaxCoordinates = getMinMaxCoordinates();
        m_virtualOutNodeIDSuffix = addVirtualOutNode(Output.getPortTypesNoFlowVariablePort(m_outputs), minMaxCoordinates).getIndex();
        error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualOutNodeIDSuffix));
        loadResult.addError(error);
        if (outputSettings != null) {
            try {
                m_wfm.loadNodeSettings(getVirtualOutNodeID(), outputSettings);
            } catch (InvalidSettingsException e) {
            // again, ignore as the node was missing, which is much more critical
            }
        }
    }
    /* Fix input node */
    NodeID virtualInID = getVirtualInNodeID();
    // non null in case not is not present of of wrong type
    error = null;
    // settings of previous node if present or null
    NodeSettings inputSettings = null;
    if (m_wfm.containsNodeContainer(virtualInID)) {
        NodeContainer virtualInNC = m_wfm.getNodeContainer(virtualInID);
        if (virtualInNC instanceof NativeNodeContainer) {
            NodeModel virtualInModel = ((NativeNodeContainer) virtualInNC).getNodeModel();
            if (!(virtualInModel instanceof VirtualSubNodeInputNodeModel)) {
                // this is very likely a missing node (placeholder)
                error = String.format("Virtual input node is not of expected type (expected %s, actual %s)", VirtualSubNodeInputNodeModel.class.getName(), virtualInModel.getClass().getName());
                try {
                    NodeSettings temp = new NodeSettings("temp");
                    m_wfm.saveNodeSettings(virtualInID, temp);
                    inputSettings = temp;
                } catch (InvalidSettingsException ise) {
                // silently ignore; this is minor given that the node is not there.
                }
            }
        } else {
            error = String.format("Virtual input node with ID %s is not a native node", virtualInID);
        }
    } else {
        error = String.format("Virtual input node with ID %s does not exist", virtualInID);
    }
    if (error != null) {
        minMaxCoordinates = getMinMaxCoordinates();
        // skip flow var port
        PortType[] inportTypes = new PortType[getNrInPorts() - 1];
        for (int i = 1; i < getNrInPorts(); i++) {
            inportTypes[i - 1] = getInPort(i).getPortType();
        }
        m_virtualInNodeIDSuffix = addVirtualInNode(inportTypes, minMaxCoordinates).getIndex();
        error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualInNodeIDSuffix));
        loadResult.addError(error);
        if (inputSettings != null) {
            try {
                m_wfm.loadNodeSettings(getVirtualInNodeID(), inputSettings);
            } catch (InvalidSettingsException e) {
            // again, ignore as the node was missing, which is much more critical
            }
        }
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) NodeModel(org.knime.core.node.NodeModel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) PortType(org.knime.core.node.port.PortType)

Example 13 with NodeModel

use of org.knime.core.node.NodeModel in project knime-core by knime.

the class CovarianceMatrixCalculatorTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    @SuppressWarnings({ "unchecked", "rawtypes" }) NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
    m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
}
Also used : NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) HashMap(java.util.HashMap) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) Node(org.knime.core.node.Node) PortType(org.knime.core.node.port.PortType) Before(org.junit.Before)

Example 14 with NodeModel

use of org.knime.core.node.NodeModel in project knime-core by knime.

the class JoinerTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
    m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
}
Also used : NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) HashMap(java.util.HashMap) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) Node(org.knime.core.node.Node) PortType(org.knime.core.node.port.PortType) Before(org.junit.Before)

Example 15 with NodeModel

use of org.knime.core.node.NodeModel in project knime-core by knime.

the class LiftChartNodeView method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
protected void modelChanged() {
    final NodeModel model = getNodeModel();
    m_liftChart.setDataProvider((DataProvider) model);
    m_gainChart.setDataProvider(new DataProvider() {

        public DataArray getDataArray(final int index) {
            return ((LiftChartNodeModel) model).getDataArray(1);
        }
    });
    m_liftChart.updatePaintModel();
    m_gainChart.updatePaintModel();
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) NodeModel(org.knime.core.node.NodeModel) DataArray(org.knime.base.node.util.DataArray)

Aggregations

NodeModel (org.knime.core.node.NodeModel)30 NodeFactory (org.knime.core.node.NodeFactory)9 HashMap (java.util.HashMap)6 ExecutionContext (org.knime.core.node.ExecutionContext)6 Node (org.knime.core.node.Node)6 PortType (org.knime.core.node.port.PortType)6 Before (org.junit.Before)5 DefaultNodeProgressMonitor (org.knime.core.node.DefaultNodeProgressMonitor)5 VirtualParallelizedChunkPortObjectInNodeFactory (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory)5 LinkedHashMap (java.util.LinkedHashMap)3 DataProvider (org.knime.base.node.viz.plotter.DataProvider)3 HiLiteHandler (org.knime.core.node.property.hilite.HiLiteHandler)3 VirtualParallelizedChunkPortObjectInNodeModel (org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeModel)3 IContainerObject (org.knime.workbench.repository.model.IContainerObject)3 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)3 MetaNodeTemplate (org.knime.workbench.repository.model.MetaNodeTemplate)3 NodeTemplate (org.knime.workbench.repository.model.NodeTemplate)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2