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();
}
}
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
}
};
}
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);
}
}
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;
}
}
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);
}
Aggregations