Search in sources :

Example 16 with NodeModel

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

the class DefaultVisualizationNodeView method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
protected void modelChanged() {
    NodeModel model = getNodeModel();
    if (model == null) {
        return;
    }
    if (!(model instanceof DataProvider)) {
        throw new IllegalArgumentException("Model must implement the DataProvider " + "interface!");
    }
    DataProvider provider = (DataProvider) model;
    HiLiteHandler hiliteHandler = model.getInHiLiteHandler(0);
    // do not care about antialias
    for (AbstractPlotter plotter : m_plotters) {
        plotter.reset();
        plotter.setHiLiteHandler(hiliteHandler);
        plotter.setDataProvider(provider);
        plotter.updatePaintModel();
    }
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) NodeModel(org.knime.core.node.NodeModel) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) AbstractPlotter(org.knime.base.node.viz.plotter.AbstractPlotter)

Example 17 with NodeModel

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

the class AutoHiLiteNodeFactory method createNodeModel.

/**
 * {@inheritDoc}
 */
@Override
public NodeModel createNodeModel() {
    return new NodeModel(1, 1) {

        private SettingsModelBoolean m_smClearHiLites = createClearHilitesModel();

        /**
         * {@inheritDoc}
         */
        @Override
        protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
            return inSpecs;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
            if (m_smClearHiLites.getBooleanValue()) {
                getInHiLiteHandler(0).fireClearHiLiteEvent();
            }
            final Set<RowKey> keys = new HashSet<RowKey>();
            final HiLiteHandler hlh = getInHiLiteHandler(0);
            long counter = 0;
            long numOfRows = inData[0].size();
            for (final DataRow row : inData[0]) {
                keys.add(row.getKey());
                if (keys.size() == NUMBER_OF_ROWS_HILITED_AT_ONCE) {
                    exec.setProgress(++counter * NUMBER_OF_ROWS_HILITED_AT_ONCE / (double) numOfRows, "HiLiting all rows...");
                    hlh.fireHiLiteEvent(keys);
                    keys.clear();
                }
            }
            hlh.fireHiLiteEvent(keys);
            // wait for hilite to propagate
            ViewUtils.invokeAndWaitInEDT(() -> {
            });
            return inData;
        }

        @Override
        protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
        }

        @Override
        protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
        }

        @Override
        protected void saveSettingsTo(final NodeSettingsWO settings) {
            m_smClearHiLites.saveSettingsTo(settings);
        }

        @Override
        protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
            m_smClearHiLites.validateSettings(settings);
        }

        @Override
        protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
            m_smClearHiLites.loadSettingsFrom(settings);
        }

        @Override
        protected void reset() {
        // no op
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) RowKey(org.knime.core.data.RowKey) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DataRow(org.knime.core.data.DataRow) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File) HashSet(java.util.HashSet)

Example 18 with NodeModel

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

the class DecTreeNodeView2 method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
protected void modelChanged() {
    NodeModel model = this.getNodeModel();
    DecisionTree dt = ((DecisionTreeLearnerNodeModel2) model).getDecisionTree();
    if (dt != null) {
        // set new model
        m_jTree.setModel(new DefaultTreeModel(dt.getRootNode()));
        // change default renderer
        m_jTree.setCellRenderer(new DecisionTreeNodeRenderer());
        // make sure no default height is assumed (the renderer's
        // preferred size should be used instead)
        m_jTree.setRowHeight(0);
        // retrieve HiLiteHandler from Input port
        m_hiLiteHdl = (((DecisionTreeLearnerNodeModel2) model).getInHiLiteHandler(DecisionTreeLearnerNodeModel2.DATA_INPORT));
        // and adjust menu entries for HiLite-ing
        m_hiLiteMenu.setEnabled(m_hiLiteHdl != null);
    } else {
        m_jTree.setModel(null);
    }
}
Also used : NodeModel(org.knime.core.node.NodeModel) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) DecisionTreeNodeRenderer(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeRenderer) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 19 with NodeModel

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

the class WorkflowManager method canReExecuteNode.

/**
 * @param id ...
 * @return true if node can be re-executed.
 * @throws IllegalArgumentException if node is not of proper type.
 * @since 2.8
 */
public boolean canReExecuteNode(final NodeID id) {
    try (WorkflowLock lock = lock()) {
        NodeContainer nc = getNodeContainer(id);
        if (!(nc instanceof NativeNodeContainer)) {
            throw new IllegalArgumentException("Can't reexecute sub- or metanodes.");
        }
        NativeNodeContainer snc = (NativeNodeContainer) nc;
        NodeModel nm = snc.getNodeModel();
        if (!(nm instanceof InteractiveNode)) {
            throw new IllegalArgumentException("Can't reexecute non interactive nodes.");
        }
        if (!(EXECUTED.equals(snc.getInternalState()))) {
            return false;
        }
        if (!canResetNode(id)) {
            return false;
        }
        return true;
    }
}
Also used : VirtualParallelizedChunkPortObjectInNodeModel(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeModel) NodeModel(org.knime.core.node.NodeModel) InteractiveNode(org.knime.core.node.interactive.InteractiveNode)

Example 20 with NodeModel

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

the class WorkflowManager method castNodeModel.

/**
 * Retrieves the node with the given ID, fetches the underlying {@link NodeModel} and casts it to the argument
 * class.
 *
 * @param id The node of interest
 * @param cl The class object the underlying NodeModel needs to implement
 * @param <T> The type the class
 * @return The casted node model.
 * @throws IllegalArgumentException If the node does not exist, is not a {@link NativeNodeContainer} or the model
 *             does not implement the requested type.
 */
public <T> T castNodeModel(final NodeID id, final Class<T> cl) {
    NodeContainer nc = getNodeContainer(id);
    if (!(nc instanceof NativeNodeContainer)) {
        throw new IllegalArgumentException("Node \"" + nc + "\" not a native node container");
    }
    NodeModel model = ((NativeNodeContainer) nc).getNodeModel();
    if (!cl.isInstance(model)) {
        throw new IllegalArgumentException("Node \"" + nc + "\" not instance of " + cl.getSimpleName());
    }
    return cl.cast(model);
}
Also used : VirtualParallelizedChunkPortObjectInNodeModel(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeModel) NodeModel(org.knime.core.node.NodeModel)

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