Empty preselection in DialogComponentStringListSelection


I started to work on a new Knime Node (Knime 3.1.0) a week ago and encountered a little challenge:

I use DialogComponentStringListSelection objects which are filled with column names from an input table. This works nicely but now some of these selections should be allowed to stay without selection.

Whenever I enter the configuration dialog, the first entry of all selection lists without previous selection is automatically selected which means that the user always has to unselect this preselection in each and every list where no selection is intended.

Normally I would now just manipulate the selection index of the underlying JList to ensure an empty selection but I have no access to this implementation detail of DialogComponentStringListSelection.

I cannot derive from the final DialogComponentStringListSelection class, so all solutions I can currently see involve quite ugly hacks.

Is there an elegant way to fix the behavior of DialogComponentStringListSelection for the case of a non-selection?

Did you already try the "required" argument in the constructor?

Yes, I did, This is required anyway because otherwise empty selections result in an error. Nevertheless this flag only influences the handling of the selection result, not the default initial selection by JList. From my understanding it would help if the setting of this flag would also disable the default initial selection but currently it doesn't.

What are you passing as SettingsModelStringArray (the first argument of the constructor)? If the array is empty, the component shouldn't select anything.

It's hard to debug this without any actual code. It's probably easier and faster for both of us, if you simply debug the code and check where the item is selected in the list component.

I pass an empty model as in

m_inputListSelection = new DialogComponentStringListSelection(
  new SettingsModelStringArray(someConfigurationKey, null),
  "myLabel", null, false, 10);

and later fill it up with the necessary list names:

m_inputListSelection.replaceListItems(listNames, (String[]) null);

In the end the problem is line 511 in DialogComponentStringListSelection.replaceListItems(), where you unconditionally select the first list element if the previous selection was empty (or something not found in the new list) and the new list is not empty. This should not be done if a selection is not required.

Ah, now I understand, the call to replaceListItems was the missing information. You are right, the component shouldn't pre-select anything in this case. This will be fixed in version 3.1.2.