How to create a customized SettingsModel

Hi,

I’d like to create a custom SettingsModelXX for a predefined parameter. It might happen in different situations.
Situation 1:
It is a composition of all defined SettingsModelYY in KNIME. To reuse it in another node, or simplify the cods, I want to wrap them together. How to create such a SettingsModel with a config name?

Situations 2:
It includes a predefined parameter object, which has no corresponding SettingsModelYY in KNIME, like javax.swing.table.TableModel, how to create a SettingsModelXX for this?

Sitautions 3:
It is a combination of situation 1 and 2.

I think, the most hard part is perhaps to save and load values for this SettingsModelXX. Because I couldn’t find a customized methods for NodeSettingsWO(RO) to handle a customized object.

It is very appreciated if some examples are given.

Regards
Kefang

Hi Kefang,

  1. Do you mean you want to create a SettingsModel that consists out of several SettingsModels? If they are distinct options in the node, they should be stored in separate SettingsModels, so that overriding them with FlowVariables works correctly.

  2. If you look at the implementation of a settings model, you can see that it wraps storing data to a SettingsWO object.
    https://github.com/knime/knime-core/blob/master/org.knime.core/src/eclipse/org/knime/core/node/defaultnodesettings/SettingsModelDuration.java

  3. You can only add a limited set of types to the NodeSettingsWO type, as the settings object is serialized to an XML file. You need to develop a way to decompose your custom datatype into the primitives supported to be stored into a settings object.

best,
Gabriel

2 Likes

Hi Gabriel,

thanks for your reply.

Do you mean you want to create a SettingsModel that consists out of several SettingsModels?

Yes, I mean this. Will apply your suggestion to store them in separate SettingsModels.

More questions:

  1. In the second way, a customized SettingsModel is created, however, when showing it in Dialog, it seems I have to create a corresponding DialogComponent to show them. Are there some ways around?
  2. I remembered the way to enable FlowVariable is to make this SettingsModel with saveSettingsTo and loadSettingsFrom methods. So, as you said

In separate way, overriding them with FlowVariables works correctly.

More details help a lot.

Regards
Kefang

You need to create a custom DialogComponent if you need a custom datatype input.
If you can express the input using already existing components, you could do that and construct the custom internal objects only at runtime.

best,
Gabriel

Also, if you want another layout option for DialogComponents, there is a class in the Vernalis core plugin, DialogComponentGroup which let’s you do nested grouping (like the result of createNewGroup(), but with arbitrary nesting). I was going to do a post in the Vernalis section on this after our next node release (hopefully towards the end of this week / early next week) when there will be a few more examples.

It is currently only available on the nightly build, but is hopefully reasonably well documented - https://community.knime.org/svn/nodes4knime/trunk/com.vernalis/com.vernalis.knime.core/src/com/vernalis/knime/dialog/components/DialogComponentGroup.java

(That package actually also contains a few other DialogComponents and corresponding SettingsModels, in case they happen to be useful)

Steve

3 Likes

@s.roughley that is neat :sunglasses:

2 Likes

Thanks @gab1one!

When I write the post, it will also show a workaround using it for the curse of the DialogComponentButtonGroup truncated title :slight_smile:

Steve

2 Likes