Combo boxes for items with identical string representation [message #1852897] |
Thu, 09 June 2022 22:06 |
Louis Detweiler Messages: 100 Registered: August 2017 |
Senior Member |
|
|
Hello,
In our application we have EMF models, and we use NatTable to display the data.
These model elements all have ID and description fields, and when we display them in the NatTable their string representation is "ID: Description".
We are wanting to implement a user preference to not display the ID part of the string, however, while theoretically all of these model elements should have a unique description, this is not enforced. And in particular, when model elements are first created, we initialize their description with "Add a description"
This will present an issue because we use combo boxes in our tables, and if two items have the same display string in the combo box, if one is selected (in a multiselect combobox) then all of the items with the same display string is selected.
Would there be an easy way to circumvent this or would we have to customize the NatCombo pretty extensively? Would changing the selectionStateMap from a <String, boolean> map to a <ModelObject, boolean> map suffice?
Thanks for your time,
Louis
|
|
|
Re: Combo boxes for items with identical string representation [message #1852901 is a reply to message #1852897] |
Fri, 10 June 2022 04:41 |
Dirk Fauth Messages: 2902 Registered: July 2012 |
Senior Member |
|
|
Hi,
no just changing the selectionStateMap won't be sufficient. Actually you will need to create a new combo implementation. The reason is that the NatCombo is designed to handle String items, not Object items. The reason is the itemList. If you want to move from a simple String representation of data in the NatCombo to a Object one, and you at least need to have the Objects internally to achieve your idea. That also means you need to create another ComboBoxCellEditor, as the existing implementation that is using the NatCombo is taking the canonical values and transforms them into Strings to fill the NatCombo. The Object information is lost here, so the NatCombo doesn't know about the underlying object of the String representations. For your case you would need to operate totally on the canonical values. Not sure if there would be additional issues regarding conversion, but maybe that could be overcome with a custom ComboBoxCellEditor that avoids the data conversion.
From the usability point of view it would be also not optimal I guess. In a table with multiple entries that have different selections in the combo with the same representation, it would be not possible for a user to distinguish what is selected. For example, if all items are only created and the description would not be edited, every row in the table would show "Add a description" for any selected value.
So either create a new NatCombo and corresponding ComboBoxCellEditor that are able to operate on canonical values instead of String representations, or think about a smart converter mechanism that somehow knows if there are identical descriptions, and in that case avoid the drop of the description in the String representation or add some other information to be able to identify the real value from the String. This would probably even add more presure to the user to enter unique descriptions and might be less effort on your side. Although of course I don't know the whole structure, but I would probably go with such an approach as I only need to look at the converter rather than implementing a new editor control.
Hope that helps
|
|
|
|
Powered by
FUDForum. Page generated in 0.02619 seconds