use of org.knime.core.node.NodeModel in project knime-core by knime.
the class AbstractColumnTableSorterTest method setUp.
/**
* @throws java.lang.Exception
*/
@SuppressWarnings("rawtypes")
@Before
public void setUp() throws Exception {
@SuppressWarnings("unchecked") 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>());
DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator(FEATURE1, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(FEATURE2, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(STRING_FEATURE, StringCell.TYPE).createSpec(), new DataColumnSpecCreator(CLASS, StringCell.TYPE).createSpec() };
DataTableSpec spec = new DataTableSpec(colSpecs);
final BufferedDataContainer container = m_exec.createDataContainer(spec);
int i = 0;
container.addRowToTable(creatRow(i++, 1, 8, "A", "AClass8"));
container.addRowToTable(creatRow(i++, 2, 2, "Z", "ZClass2"));
container.addRowToTable(creatRow(i++, 3, 5, "B", "BClass5"));
container.addRowToTable(creatRow(i++, 4, 0, "E", "EClass0"));
container.addRowToTable(creatRow(i++, 5, 1, "F", "FClass1"));
container.addRowToTable(creatRow(i++, 6, 7, "G", "GClass7"));
container.addRowToTable(creatRow(i++, 7, 9, "H", "HClass9"));
container.addRowToTable(creatRow(i++, 8, 8, null, "Class8"));
container.close();
testTable = container.getTable();
final BufferedDataContainer emptyContainer = m_exec.createDataContainer(spec);
emptyContainer.close();
emptyTestTable = emptyContainer.getTable();
MemoryAlertSystemTest.forceGC();
}
use of org.knime.core.node.NodeModel in project knime-core by knime.
the class HierarchicalClusterNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
public void modelChanged() {
if (getNodeModel() == null || ((DataProvider) getNodeModel()).getDataArray(0) == null || ((DataProvider) getNodeModel()).getDataArray(0).size() == 0) {
return;
}
NodeModel model = getNodeModel();
m_dendroPlotter.reset();
m_distancePlotter.reset();
m_dendroPlotter.setHiLiteHandler(model.getInHiLiteHandler(0));
m_dendroPlotter.setAntialiasing(false);
m_dendroPlotter.setDataProvider((DataProvider) model);
m_distancePlotter.setDataProvider((DataProvider) model);
m_distancePlotter.setHiLiteHandler(model.getInHiLiteHandler(0));
DendrogramNode rootNode = getNodeModel().getRootNode();
DataArray distanceTable = ((DataProvider) getNodeModel()).getDataArray(0);
m_dendroPlotter.setRootNode(rootNode);
m_distancePlotter.createXCoordinate(((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(0).getDomain().getLowerBound()).getDoubleValue(), ((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(0).getDomain().getUpperBound()).getDoubleValue());
m_distancePlotter.createYCoordinate(((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(1).getDomain().getLowerBound()).getDoubleValue(), ((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(1).getDomain().getUpperBound()).getDoubleValue());
((BasicDrawingPane) m_distancePlotter.getDrawingPane()).clearPlot();
m_distancePlotter.addLine(distanceTable, 0, 1, Color.BLACK, new BasicStroke(m_thickness));
// m_distancePlotter.getXAxis().getCoordinate().setPolicy(
// DescendingNumericTickPolicyStrategy.getInstance());
m_distancePlotter.updatePaintModel();
m_dendroPlotter.updatePaintModel();
}
use of org.knime.core.node.NodeModel in project knime-core by knime.
the class WorkflowManager method findNodes.
/**
* Find all nodes in this workflow, whose underlying {@link NodeModel} is of the requested type. Intended purpose is
* to allow certain extensions (reporting, web service, ...) access to specialized nodes.
*
* @param <T> Specific NodeModel derivation or another interface implemented by NodeModel instances.
* @param nodeModelClass The class of interest
* @param filter A non-null filter to apply.
* @param recurseIntoMetaNodes Whether to recurse into contained metanodes.
* @param recurseIntoSubnodes Whether to recurse into contained wrapped metanodes.
* @return A (unsorted) list of nodes matching the class criterion
* @since 3.3
*/
public <T> Map<NodeID, T> findNodes(final Class<T> nodeModelClass, final NodeModelFilter<T> filter, final boolean recurseIntoMetaNodes, final boolean recurseIntoSubnodes) {
try (WorkflowLock lock = lock()) {
Map<NodeID, T> result = new LinkedHashMap<NodeID, T>();
for (NodeContainer nc : m_workflow.getNodeValues()) {
if (nc instanceof NativeNodeContainer) {
NativeNodeContainer nnc = (NativeNodeContainer) nc;
NodeModel model = nnc.getNode().getNodeModel();
boolean included = nodeModelClass.isAssignableFrom(model.getClass()) && filter.include(nodeModelClass.cast(model));
if (included) {
result.put(nnc.getID(), nodeModelClass.cast(model));
}
}
}
if (recurseIntoMetaNodes || recurseIntoSubnodes) {
// do separately to maintain some sort of order
for (NodeContainer nc : m_workflow.getNodeValues()) {
if (recurseIntoMetaNodes && nc instanceof WorkflowManager) {
WorkflowManager child = (WorkflowManager) nc;
result.putAll(child.findNodes(nodeModelClass, filter, recurseIntoMetaNodes, recurseIntoSubnodes));
}
if (recurseIntoSubnodes && nc instanceof SubNodeContainer) {
WorkflowManager child = ((SubNodeContainer) nc).getWorkflowManager();
result.putAll(child.findNodes(nodeModelClass, filter, recurseIntoMetaNodes, recurseIntoSubnodes));
}
}
}
return result;
}
}
use of org.knime.core.node.NodeModel in project knime-core by knime.
the class DecTreeNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
protected void modelChanged() {
NodeModel model = this.getNodeModel();
DecisionTree dt = ((DecisionTreeLearnerNodeModel) 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 = (((DecisionTreeLearnerNodeModel) model).getInHiLiteHandler(DecisionTreeLearnerNodeModel.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 AbstractWizardNodeView method applyTriggered.
/**
* @param useAsDefault true if changed values are supposed to be applied as new node default, false otherwise
* @return true if apply was successful, false otherwise
* @since 3.4
*/
protected boolean applyTriggered(final boolean useAsDefault) {
if (!viewInteractionPossible() || !checkSettingsChanged()) {
return true;
}
boolean valid = validateCurrentValueInView();
if (valid) {
String jsonString = retrieveCurrentValueFromView();
try {
VAL viewValue = getModel().createEmptyViewValue();
viewValue.loadFromStream(new ByteArrayInputStream(jsonString.getBytes(Charset.forName("UTF-8"))));
setLastRetrievedValue(viewValue);
ValidationError error = getModel().validateViewValue(viewValue);
if (error != null) {
showValidationErrorInView(error.getError());
return false;
}
if (getModel() instanceof NodeModel) {
triggerReExecution(viewValue, useAsDefault, new DefaultReexecutionCallback());
} else {
getModel().loadViewValue(viewValue, useAsDefault);
}
return true;
} catch (Exception e) {
LOGGER.error("Could not set error message or trigger re-execution: " + e.getMessage(), e);
return false;
}
} else {
return false;
}
}
Aggregations