vaadin-miki / super-fields

Some extra Vaadin 14 / 24 components that support localisation, plus (hopefully) more.
Apache License 2.0
21 stars 7 forks source link

selecting a tab programmatically in SuperTabs #518

Closed jorgheymans closed 1 week ago

jorgheymans commented 1 month ago

I am keeping track of the Tab instances I am adding to my SuperTabs instance, and was hoping to programmatically call setSelected(true) on them when needed (my use case is direct link to a specific tab). However this does not seem to work. Maybe there is a mechanism in SuperTabs already that i'm overlooking to do this ?

jorgheymans commented 1 month ago

In the end, this works:

              Field field = ReflectionUtils.findField(SuperTabs.class, "tabs");
              ReflectionUtils.makeAccessible(field);
              final Object tabs = ReflectionUtils.getField(field, superTabs);
              final Method setSelectedTab =
                  ReflectionUtils.findMethod(tabs.getClass(), "setSelectedTab", Tab.class);
              ReflectionUtils.invokeMethod(setSelectedTab, tabs, tab);
vaadin-miki commented 1 month ago

hello @jorgheymans - thanks for using SuperFields and apologies for the delay (just ended the summer holiday and I am getting back to regular work)

SuperTabs is a select component, it is intented to be used e.g. as a replacement for a combo box - so the easiest way to select a tab is to setValue(value) with value associated with the tab; by using custom TabHeaderGenerator (that produces Tabs for a given value) and TabContentGenerator (that produces any component) it is possible to configure the looks and feel of the component, so there normally should not be any need for storing Tabs (just the values that were used to generate them)

however, yours is a valid use case, and I agree that it should be possible to just select a tab and be done with it ;) so I will make it work (selecting a tab programatically will change the value of SuperTabs to whatever is associated with the called Tab, or null) - so this goes to the backlog for 0.20

no promises on the release date, but I will do my best to have it in early September :)

jorgheymans commented 1 month ago

Thanks for the feedback, indeed using setValue one could achieve the same thing. Actually, the only reason we are using SuperTabs instead of regular tabs is .withMultiline(true), so our use case is closer to the 'tabs' side than the 'combobox' side. Thank you for taking into consideration this, for now the reflection hack works and it's not that terrible.

vaadin-miki commented 5 days ago

@jorgheymans fyi superfields 0.19.2 and 0.19.2-vaadin14 were just released with this feature in; please try it out and report any bugs and problems by reporting a new issue - thanks!

jorgheymans commented 5 days ago

@vaadin-miki ok will do, many thanks for this !