Some people and me, we were creating a node for SOM.
The node itself is working perfectly fine, but we had issues concerning the view.
The problem is also explained on your site:
But I have trouble to implement it properly.
First, the parameters needed for the views were all saved/created in the NodeModel and then used by other classes which create the different views.
But when I try to use your way of saving Internals by “modelContent” I cant add them to the modelContent because of being Integers, Doubles, Colors, Buttons etc…
I also found “NodeSettings” to be able to save at least some of the needed types, but not Colors and JButtons for example.
Is there a way to save them all in one step? I also tried to make a completely new class called “ContantContainer” and save all calculated/given/configured parameters into it and work over the extra class.
Maybe there is a way to save/load that one class and rebuilding the view via that class?
Regards & Thanks for the help
I just found out, that everything is saved and loaded by itself if you simply gather all parameters in an extra class (like mentioned above: "ConstantContainer"). I saved them as public statics.
Can anyone tell me, WHY it is saved and loaded even it I didnt "tell" my code to do so??
I mean: Every single aspect like colors etc is saved just by creating a new class from where everything concerning the view is executed.
Just to make clear: Once I am closing KNIME itself, the problem still exists, but I can temporarily save it somehow just by working with parameters in another class except for NodeModel
The methods load/saveInternals are the right methods to save your view's model. As an argument you get a File object pointing to a directory where you are free to store whatever you want (as long as you can read it back in in the loadInternals method).
There are convenient objects (like ModelContent or NodeSettings) that could be used to save models and/or values. They have load and save methods. If they don't fit your needs, create your own object and either serialize it or just write it to disc somehow. You just need to be able to restore the information in the loadInternals method.
But I would guess that it doesn't make sense to store buttons or colors. You store the state of a button, or the RGB components of a color. And for that, you could use the NodeSettings object, if you like it.
With that, your view model is preserved and restored everytime you load in your flow. There are several drawbacks with your public static solution: you are only able to store the model of one view (if you have multiple instances of your node in your flow, the last one wins). Secondly, it is gone when you close KNIME. A static object lives as long as (and only as long as) KNIME is running.
Hope that helps,
P.S.: In the reset method, you should clear your view model.