How to add node extension into project? - pm4knime/pm4knime-document GitHub Wiki
How to add node extension into project?
In KNIME, the development unit is called a node. We extend pm4knime functions by creating corresponding nodes.
KNIME Architecture
The following picture shows us the running mode of KNIME.
NodeFactory
It is the entry point for the platform, bundles all necessary node classes: NodeModel, NodeDialogPane and NodeView (both optional). In addition, a NodeFactory.xml description is generated, an XML file is mandatory (with exactly the same name as the factory). which contains node properties such as a node description, node name, node type, icon, port and view descriptions, an explanation of all dialog options. These properties are shown inside the Node Description view in KNIME.
NodeModel
The functionality of a specific node implementation is defined by the following methods:
configure()
This method checka incoming data table specs and validate settings against them, and creates the resulting output sepcs w.r.t. user setting.
execute()
This method can be triggered only with all true conditions. The input data is available in the given array argument inData and is ensured to be neither null nor contain null elements.
saveSettingsTo(NodeSettingsWO)
In this method the current values of the user settings should be added to the NodeSettings object. The object provided is only accessible through a “write-only” interface, meaning you can only add values, and not read them back.
NodeDialog
A node that requires special user settings as input will need to provide a NodeDialog.
NodeDialogPane
A NodeDialogPane, which will be displayed by the platform whenever a user clicks on the node to configure it. In a NodeDialogPane, you can create JPanels, add Swing components to them, layout those components, and add these composite panels as tabs to the dialog pane. Use default method to create group in a tab, the components added later before the next group belong to this group. The layout of components can be changed by setHorizontalPlacement().
createNewGroup("Your choice");
setHorizontalPlacement(true);
addDialogComponent(new DialogComponentStringSelection(
selection, "Select one:", TestNodeModel.SELECTION));
Default Dialog Components
KNIME provides a couple of components that can be added to a default settings pane and that allow the user to enter values. They will automatically show in the dialog below each other (or next to each other).
- Each dialog pane must implement load and save methods to transfer settings values from and into the components.
- When you instantiate the component you must provide a settings model.
- when you want to load the entered value in your NodeModel, you use an instance of that same SettingsModel.
Relation with SettingsModel
Besides that each dialog component needs a SettingsModel. This settings model holds the actual value of the component and does the storing, loading and validation. When you instantiate the component you must provide a settings model - when you want to load the entered value in your NodeModel, you use an instance of that same SettingsModel. To identify the value handled by the settings model, you must provide a unique configName (i.e. a string ID).
Constructor
In the constructor you can create all the Swing components that you need for your user settings. After one panel is complete, add it to the dialog pane by calling addTab(String title, Component panel). Note that the title must be unique and it can be used as ID to retrieve this panel with getTab().
NodeView
A NodeView displays an internal view model or data structure generated by the underlying NodeModel. the view displays the result of the execute method and the reset method should set the node to its initial state, i.e. as it was before execution. In development, we need to pay attention to the following points.
- The constructor is called whenever the view is opened by clicking on the node.
- Only one component(usually it is a JPanel) can be set with this method, thus, if you have several components you have the make a composite by your own and set this composite.
- All operations related to the data of the model cannot be placed in the constructor.
- ModelChanged method . This method is called, whenever the underlying NodeModel has changed. in this method the data to be visualized is retrieved from the NodeModel. Then the data is interpreted by the view, i.e. converted in a component or drawn.
- To access NodeModel by using
getNodeModel()
. If you have to call this method frequently you can override this method and have your derived NodeModel as the return type of the overridden method.
KNIME Extension Environment
KNIME itself provides two extension points to which external providers can contribute to the functionality of KNIME. These extension points are
- the "Categories" extension point (org.knime.workbench.repository.categories). The "Categories" extension point allows you to introduce new category folders displayed in the node repository (accomplished by simply adding an entry to the plugin.xml file.)
- the "Nodes" extension point (org.knime.workbench.repository.nodes). The "Nodes" extension point enables you to contribute a new functional node to the node repository (accomplished by registering the corresponding NodeFactory in the plugin.xml file.)
KNIME Extension Wizard
all this infrastructure (especially the aforementioned files) is automatically created by the extension wizard. To use this wizard, we need to install it in Eclipse.
Installation
link to install it ...
Configuration
link is here
NodeType
By choosing different node type, it only changes the node color shown in KNIME platform. The node types in KNIME contain Source, Sink, Learner, Predictor, Manipulator, Visualizer, Meta, or Other node.
- Source: Read data into the KNIME
- Sink: Write data into hard disk
- Learner: input and output are different. So get some rules, models from the training set.
- Predictor: given trained model, input, and predict the output, like labels.
- Manipulator: procedure on the data, input and output are of the same type. like filter, split, and others.
- Visualizer: show figures from of results, sth with graph view.
Node Model
In XXNodeModel
constructor, the statement
super(i, j); // \(i, j \in N \), it is only used for DataTable type.
If we want to use customized PortObject, we need to list all the Type there, for example
super(new PortObjectType{XLogPortObject.TYPE} , new PortObjectType{PetriNetPortObject.TYPE, XLogPortObject.TYPE})
If there is no input data, like source, or output data like sink, we give it null to the PortObjectType
super(null , new PortObjectType{PetriNetPortObject.TYPE}) // or
super(new PortObjectType{PetriNetPortObject.TYPE} , new PortObjectType[0]) // or
In configure()
, correspondingly, there are different ways to create the new PortObject types.
- new generated types are known and consistent with constructor OutputSpec
new DataTableSpec[] { outSpec1, outSpec2};
- new generated types are not known but consistent with constructor OutputSpec
new DataTableSpec[5]; // or
new DataTableSpec[]{outSpec1, null}; // or
- new generated types are not consistent with constructor OutputSpec
throw Exception.
Generated Screenshot
image is here