Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selecting a tab programmatically in SuperTabs #518

Closed
jorgheymans opened this issue Jul 24, 2024 · 5 comments · Fixed by #520
Closed

selecting a tab programmatically in SuperTabs #518

jorgheymans opened this issue Jul 24, 2024 · 5 comments · Fixed by #520
Assignees
Labels
enhancement New feature or request

Comments

@jorgheymans
Copy link

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
Copy link
Author

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
Copy link
Owner

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 vaadin-miki self-assigned this Aug 8, 2024
@vaadin-miki vaadin-miki added the enhancement New feature or request label Aug 8, 2024
@vaadin-miki vaadin-miki added this to the Next release milestone Aug 8, 2024
@jorgheymans
Copy link
Author

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 added a commit that referenced this issue Aug 29, 2024
vaadin-miki added a commit that referenced this issue Aug 29, 2024
@vaadin-miki vaadin-miki mentioned this issue Aug 29, 2024
vaadin-miki added a commit that referenced this issue Aug 29, 2024
vaadin-miki added a commit that referenced this issue Sep 6, 2024
@vaadin-miki
Copy link
Owner

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants