super-fields icon indicating copy to clipboard operation
super-fields copied to clipboard

selecting a tab programmatically in SuperTabs

Open jorgheymans opened this issue 1 year ago • 3 comments

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 avatar Jul 24 '24 14:07 jorgheymans

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);

jorgheymans avatar Jul 25 '24 08:07 jorgheymans

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 :)

vaadin-miki avatar Aug 08 '24 14:08 vaadin-miki

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.

jorgheymans avatar Aug 09 '24 08:08 jorgheymans

@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!

vaadin-miki avatar Sep 06 '24 12:09 vaadin-miki

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

jorgheymans avatar Sep 06 '24 12:09 jorgheymans