# Combining SettingsModels

**URL:** <https://forum.knime.com/t/combining-settingsmodels/7164>\
**Category:** Node Development\
**Created:** [December 18, 2014, 11:16am UTC](https://forum.knime.com/t/combining-settingsmodels/7164 "2014-12-18T11:16:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [December 18, 2014, 11:16am UTC](https://forum.knime.com/t/combining-settingsmodels/7164/1 "2014-12-18T11:16:40Z")

</div>

Hi,

I'm currently working on an enhanced version of the _Number to String_ node with formating options. For that, I want to present the possible settings in a radio group with sub elements. Those sub elements would then be activated when the corresponding radio button is active. This seems to be a recurring pattern, yet there's nothing suitable in the _DialogComponent_s yet. No problem, I thought, let's just create it then.

One of the components of that would be to create a _SettingsModel_ that more or less just contains the current selection and a mapping from choices to sets of child-_SettingsModel_s. This way I could free the user from dealing with many of the details while reusing as much as possible.

The thing is: I can't seem to create a combining _SettingsModel_, because all the _loadSettings_- and _saveSettings_- methods of the children are invisible to the parent. I could use reflection, but normally that's a red flag that I'm thinking in the wrong direction... Are _SettingModel_s not meant to be combined, is that an option that just hasn't occured to anyone yet, am I using the elements wrong, or am I just missing something?

---

<div class="post-metadata">

**Author:** ![Iris](https://forum-cdn.knime.com/user_avatar/forum.knime.com/iris/32/14_2.png) [@Iris](https://forum.knime.com/u/Iris)\
**Post date:** [December 18, 2014, 11:55am UTC](https://forum.knime.com/t/combining-settingsmodels/7164/2 "2014-12-18T11:55:51Z")

</div>

I did something similiar with the SettingsModelDisactableLong. Maybe helps taking a look at.

Iris

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [December 18, 2014, 1:40pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/3 "2014-12-18T13:40:51Z")

</div>

Thanks for the hint, Iris, but I think we're talking about slightly different things here. Your SettingsModelDisactableLong is "just" an extension of the existing SettingsModelLong, and as such has access to the methods and the configName of its base class.

What I'm after is more of a composite pattern, a SettingsModel that can contain other SettingsModels that are only specified later on. If the loadSettings- and saveSettings-methods where not protected, they might look something like this in my class:

```
protected void loadSettingsForDialog(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    try {
        setSelection(settings.getString(m_configName, m_selection));
    } catch (IllegalArgumentException e) {
        // if the value is not accepted, keep the old value.
    }
    for (SettingsModel childModel : m_childModels.values()) {
        childModel.loadSettingsForDialog(settings,specs); // doesn't work :(
    }
}
```

---

<div class="post-metadata">

**Author:** ![Iris](https://forum-cdn.knime.com/user_avatar/forum.knime.com/iris/32/14_2.png) [@Iris](https://forum.knime.com/u/Iris)\
**Post date:** [December 18, 2014, 1:49pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/4 "2014-12-18T13:49:53Z")

</div>

It is very easy to implement an own SettingsModel. Making a collection of old SettingsModels sounds quite inefficient.

---

<div class="post-metadata">

**Author:** ![aborg](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@aborg](https://forum.knime.com/u/aborg)\
**Post date:** [December 18, 2014, 2:27pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/5 "2014-12-18T14:27:45Z")

</div>

Marlin, I think you miss the fact that many KNIME dialogs do not extend the [DefaultNodeSettingsPane](https://forum.knime.com/docs/api/org/knime/core/node/defaultnodesettings/DefaultNodeSettingsPane.html). In those cases they usually use custum settings objects instead of the predefined SettingsModels.

In case you stay on the path of DefaultNodeSettingsPane (and want to disable enable certain options based on other properties), I would suggest adding a custom DialogComponent after all other DialogComponents to set initial state. [Here](https://code.google.com/p/hits/source/browse/ie.tcd.imm.hits/trunk/ie.tcd.imm.hits/src/ie/tcd/imm/hits/knime/ranking/RankNodeDialog.java?r=268#83) is an example.

Cheers, gabor

PS.: Using custom NodeDialogs are not too hard either, but a bit repetitive.

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [December 18, 2014, 3:09pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/6 "2014-12-18T15:09:13Z")

</div>

Gabor, of course I can implement my own dialog, of course I can create a complex settings object or use a workaround that is not especially user friendly or in compliance with the noding guidelines. But that's not what this question is about. This question is about composeability of SettingsModels. They are a good idea, because they simplify the layouting and because they encourage reuse, that's why I want to use them. I thought that maybe I could create something with more than a single use case. (And without reinventing the wheel.) But if the system can't handle anything beyond the simplest tasks (which is supported by the facts in your first two sentences), that sounds like they're simply not good enough yet... Which is an answer to my initial questions, too.

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [December 18, 2014, 3:26pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/7 "2014-12-18T15:26:42Z")

</div>

Well, the default dialog components were never intended for complex dialogs, they were explicitly designed for simple tasks only. All our dialogs that are a bit more complex actually don't use the default dialog components.

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [December 19, 2014, 8:00am UTC](https://forum.knime.com/t/combining-settingsmodels/7164/8 "2014-12-19T08:00:43Z")

</div>

Mh... I suppose one of the reasons for introducing the default components was that you saw a possibility to reduce repetitions and human errors. The focus should be on other parts, after all.

So, what tools do you recommend for this end instead, when you go beyond their capabilities? Are there any other tricks in the system, or are you using something like generator scripts yourself? Of course there's no magic solution for every use case, but after developing a lot of dialogs you probably weren't satisfied with having to write everything by hand yourself.

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [December 19, 2014, 10:22am UTC](https://forum.knime.com/t/combining-settingsmodels/7164/9 "2014-12-19T10:22:00Z")

</div>

Sure, this is what we do. This gives you the most flexibility. Usually finding an easy to use solution that is generic enough for almost all use cases is impossible.

We are thinking about using annotation to simplify dialog creation and settings handling, but then again this won't be flexible enough to solve all problems.

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [December 19, 2014, 11:30am UTC](https://forum.knime.com/t/combining-settingsmodels/7164/10 "2014-12-19T11:30:50Z")

</div>

Sure, nothing is applicable to everything. If the problem were simple, we would all be using java beans or something now. I was just wondering about that (perceived) large jump from the defaults to completly manual, without anything in between. Giving "us" something to start off of is a good idea, it's just that a big enough step can feel like a wall if you're running. Also, I'm still learning how not to run. ;)

Annotations do sound like a good way to go to smooth that step, though. I'm still not entirely unconvinced of my idea, but I'll just chalk it up as a suggestion for an alternative/additional possibility.

On a side note: Some of the walls I'm running into while trying to find my way around the code are created by restrictive access rules, including this one. Many of these might be necessary or required, but certainly not all of them. Just food for thought.

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [December 19, 2014, 12:06pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/11 "2014-12-19T12:06:22Z")

</div>

The more API you make public the harder it is to change it lateron without breaking 3rd party code. Therefore being as restrictive as possible isn't a bad approach. If it's of general use and has already matured, then we may make it public API.

Another reason for having a restrictive API is to prevent developers from making accidental errors or abusing methods. This quite often leads to problems that are hard to debug. Especially if you are working in a highly extensible framework such as Eclipse.

---

<div class="post-metadata">

**Author:** ![aborg](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@aborg](https://forum.knime.com/u/aborg)\
**Post date:** [December 19, 2014, 3:16pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/12 "2014-12-19T15:16:40Z")

</div>

For the first problem it might be a solution to expose the API through [x-internal](http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fbundle_manifest.html). That way the usage will not be forbidden (by default error and does not work at runtime), just discouraged (by default warning, works at runtime).

Though this would work against the second concern, so that might be not so useful afterall.

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [December 19, 2014, 3:26pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/13 "2014-12-19T15:26:58Z")

</div>

Yeah, I get that, that's why I said it's just food for thought. You don't have an easy job there.

Just consider that walls can not only channel water away from your shed, but also towards your house. If I want to reuse something and can't do it directly, I'm more prone to abuse something else to get there. Like using a foreign NodeFactory to get access to a constructor or manually copying configNames, hoping they wont get changed too often. Or worse, I could give up, leaving even more work for you to do. ;)

On the other hand, water in your cellar can keep your boiler from blowing up in your face, so that's that...

I wish you all warm, un-blown-up holidays.  
&nbsp;

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 23, 2023, 8:24pm UTC](https://forum.knime.com/t/combining-settingsmodels/7164/14 "2023-06-23T20:24:20Z")

</div>


