Package org.vaadin.miki.superfields.tabs
Class SuperTabs<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<T>,T>
com.vaadin.flow.component.customfield.CustomField<T>
org.vaadin.miki.superfields.tabs.SuperTabs<T>
- Type Parameters:
T- Type of value.
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.shared.HasTooltip,com.vaadin.flow.component.shared.HasValidationProperties,com.vaadin.flow.data.binder.HasItems<T>,Serializable,HasHelperPositionable,HasId,WithHelperMixin<SuperTabs<T>>,WithHelperPositionableMixin<SuperTabs<T>>,WithIdMixin<SuperTabs<T>>,WithItemsMixin<T,,SuperTabs<T>> WithLabelMixin<SuperTabs<T>>,WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>, T, SuperTabs<T>>
@Tag("super-tabs")
@CssImport(value="./styles/super-tabs-multiline.css",
themeFor="vaadin-tabs")
public class SuperTabs<T>
extends com.vaadin.flow.component.customfield.CustomField<T>
implements com.vaadin.flow.component.HasStyle, WithItemsMixin<T,SuperTabs<T>>, WithIdMixin<SuperTabs<T>>, WithHelperMixin<SuperTabs<T>>, WithHelperPositionableMixin<SuperTabs<T>>, WithLabelMixin<SuperTabs<T>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T,SuperTabs<T>>
Configurable tab sheet component that also is a field.
- Since:
- 2020-04-10
- Author:
- miki
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Supplier<com.vaadin.flow.component.html.Div>Default container for tab contents.static final StringName of the theme for multiline tabs.Fields inherited from interface org.vaadin.miki.markers.HasHelperPositionable
HELPER_ABOVE_THEME_VARIANT -
Constructor Summary
ConstructorsConstructorDescriptionCreates the component with no tabs and defaultTabHandler,TabHeaderGeneratorandTabContentGenerator.Creates the component with no tabs and defaultTabHandler,TabHeaderGeneratorandTabContentGenerator, overriding default main layout component for the tab contents.SuperTabs(TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabContentGeneratorand tabs, but with defaultTabHeaderGeneratorandTabHandler.SuperTabs(TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabHeaderGenerator,TabContentGeneratorand tabs, but defaultTabHandler.SuperTabs(T defaultValue, Supplier<C> mainContentSupplier, TabHandler tabHandler, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabHandler,TabHeaderGenerator,TabContentGeneratorand tabs, overriding the default value fromnullto the one provided and overriding default layout component for tab contents.SuperTabs(T defaultValue, TabHandler tabHandler, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabHandler,TabHeaderGenerator,TabContentGeneratorand tabs, overriding the default value fromnullto the one provided.SuperTabs(T defaultValue, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with defaultTabHandler, givenTabHeaderGenerator,TabContentGeneratorand tabs, overriding the default value fromnullto the one provided. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds a new tab and content for given value, usinggetTabHeaderGenerator()andgetTabContentGenerator()to produce components.protected voidaddNewTab(T value, com.vaadin.flow.component.tabs.Tab tab, com.vaadin.flow.component.Component content, boolean select) Adds a new tab and content for given value.final voidThis method adds one or more tabs.voidaddTab(T value, com.vaadin.flow.component.tabs.Tab tabHeader, com.vaadin.flow.component.Component tabContents) Adds a tab for a given value.voidaddTabs(Collection<T> values) Adds a tab for each of the given values.protected TReturns the generator responsible for providing content for selected tabs.Optional<com.vaadin.flow.component.Component>getTabContents(T value) Returns contents that corresponds to the given value.Returns the currentTabHandler.Optional<com.vaadin.flow.component.tabs.Tab>getTabHeader(T value) Returns tab header that corresponds to the given value.Returns the generator responsible for providing tabs (headers) for values.getValueAndTab(T value) Finds the value and tab entry corresponding to the givenvalue.Returns the values that correspond to tabs.booleanWhether or not custom values may be set throughAbstractField.setValue(Object).booleanChecks whether tabs wrap to a new line.protected voidremoveExistingTab(T value, com.vaadin.flow.component.tabs.Tab header) Removes an existing tab, its header and contents.voidRemoves the tab for a given value, if found.voidsetCustomValueAllowed(boolean customValueAllowed) Allows or disallows creating new tabs when callingAbstractField.setValue(Object).voidSets this object's id.voidsetItems(Collection<T> collection) voidsetMultiline(boolean multiline) Sets whether or not tabs should overflow to next line.protected voidvoidsetTabContentGenerator(TabContentGenerator<T> tabContentGenerator) Sets the generator responsible for providing content for selected tabs.voidsetTabHandler(TabHandler tabHandler) Sets the newTabHandlerto use.voidsetTabHeaderGenerator(TabHeaderGenerator<T> tabHeaderGenerator) Sets the generator responsible for providing tabs (headers) for values.intsize()Returns the number of values that currently correspond to tabs.withCustomValueAllowed(boolean customValueAllowed) ChainssetCustomValueAllowed(boolean)and returns itself.withMultiline(boolean multiline) ChainssetMultiline(boolean)and returns itself.withTabContentGenerator(TabContentGenerator<T> tabContentGenerator) ChainssetTabContentGenerator(TabContentGenerator)and returns itself.withTabHandler(TabHandler tabHandler) ChainssetTabHandler(TabHandler)and returns itself.withTabHeaderGenerator(TabHeaderGenerator<T> tabHeaderGenerator) ChainssetTabHeaderGenerator(TabHeaderGenerator)and returns itself.Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabel, updateValueMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface org.vaadin.miki.markers.HasHelperPositionable
isHelperAbove, setHelperAbove, setHelperAbove, setHelperBelowMethods inherited from interface com.vaadin.flow.data.binder.HasItems
setItems, setItemsMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisibleMethods inherited from interface org.vaadin.miki.markers.WithHelperMixin
withHelperComponent, withHelperTextMethods inherited from interface org.vaadin.miki.markers.WithHelperPositionableMixin
withHelperAbove, withHelperAbove, withHelperBelowMethods inherited from interface org.vaadin.miki.markers.WithIdMixin
withIdMethods inherited from interface org.vaadin.miki.markers.WithItemsMixin
withItems, withItems, withItemsMethods inherited from interface org.vaadin.miki.markers.WithLabelMixin
withLabelMethods inherited from interface org.vaadin.miki.markers.WithValueMixin
withValue
-
Field Details
-
DEFAULT_TAB_CONTENTS_CONTAINER
Default container for tab contents. -
MULTILINE_THEME_NAME
Name of the theme for multiline tabs.- See Also:
-
-
Constructor Details
-
SuperTabs
public SuperTabs()Creates the component with no tabs and defaultTabHandler,TabHeaderGeneratorandTabContentGenerator. -
SuperTabs
Creates the component with no tabs and defaultTabHandler,TabHeaderGeneratorandTabContentGenerator, overriding default main layout component for the tab contents.- Type Parameters:
C- Generic type to ensure the supplier gives a validComponentthat implementsHasComponents.- Parameters:
mainContentSupplier- A callback to construct an instance of a component into which tab contents is put.
-
SuperTabs
Creates the component with givenTabContentGeneratorand tabs, but with defaultTabHeaderGeneratorandTabHandler.- Parameters:
tabContentGenerator-TabContentGeneratorto construct content for tabs.values- Values to use.
-
SuperTabs
@SafeVarargs public SuperTabs(TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabHeaderGenerator,TabContentGeneratorand tabs, but defaultTabHandler.- Parameters:
tabHeaderGenerator-TabHeaderGeneratorto construct tab headers.tabContentGenerator-TabContentGeneratorto construct content for tabs.values- Values to use.
-
SuperTabs
@SafeVarargs public SuperTabs(T defaultValue, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with defaultTabHandler, givenTabHeaderGenerator,TabContentGeneratorand tabs, overriding the default value fromnullto the one provided.- Parameters:
defaultValue- Default value that corresponds to no tab selected.tabHeaderGenerator-TabHeaderGeneratorto construct tab headers.tabContentGenerator-TabContentGeneratorto construct content for tabs.values- Values to use.
-
SuperTabs
@SafeVarargs public SuperTabs(T defaultValue, TabHandler tabHandler, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabHandler,TabHeaderGenerator,TabContentGeneratorand tabs, overriding the default value fromnullto the one provided.- Parameters:
defaultValue- Default value that corresponds to no tab selected.tabHandler-TabHandlerto use.tabHeaderGenerator-TabHeaderGeneratorto construct tab headers.tabContentGenerator-TabContentGeneratorto construct content for tabs.values- Values to use.- See Also:
-
SuperTabs
@SafeVarargs public SuperTabs(T defaultValue, Supplier<C> mainContentSupplier, TabHandler tabHandler, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values) Creates the component with givenTabHandler,TabHeaderGenerator,TabContentGeneratorand tabs, overriding the default value fromnullto the one provided and overriding default layout component for tab contents.- Type Parameters:
C- Generic type to ensure the supplier gives a validComponentthat implementsHasComponents.- Parameters:
defaultValue- Default value that corresponds to no tab selected.mainContentSupplier- A callback to construct an instance of a component into which tab contents is put.tabHandler-TabHandlerto use.tabHeaderGenerator-TabHeaderGeneratorto construct tab headers.tabContentGenerator-TabContentGeneratorto construct content for tabs.values- Values to use.- See Also:
-
-
Method Details
-
addNewTab
Adds a new tab and content for given value, usinggetTabHeaderGenerator()andgetTabContentGenerator()to produce components.- Parameters:
value- A new value, not yet present in the component. Warning: no check are made to make sure this value is not used.select- Whether or not to select newly added tab.
-
addNewTab
protected void addNewTab(T value, com.vaadin.flow.component.tabs.Tab tab, com.vaadin.flow.component.Component content, boolean select) Adds a new tab and content for given value.- Parameters:
value- A new value, not yet present in the component. Warning: no check are made to make sure this value is not used.tab- Tab corresponding to the value.content- Content corresponding to the value.select- Whether or not to select newly added tab.
-
addTab
This method adds one or more tabs. It converts the values into aCollectionand callsaddTabs(Collection).- Parameters:
values- Values to add tabs and contents for.- See Also:
-
addTabs
Adds a tab for each of the given values. Selects the tab if it was already present, otherwise just adds it. Will usegetTabHeaderGenerator()andgetTabContentGenerator()to produce components. If there were no tabs prior to calling this method, the first tab added this way will be selected.- Parameters:
values- Values to add tabs and contents for.
-
addTab
public void addTab(T value, com.vaadin.flow.component.tabs.Tab tabHeader, com.vaadin.flow.component.Component tabContents) Adds a tab for a given value. Selects the tab if it was already present, otherwise just adds it. This will *not* overwrite the existing tab. If you want that, remove the tab first. If this is the first tab added, it will be selected.- Parameters:
value- A value that corresponds to provided tab header and tab contents.tabHeader- Header.tabContents- Contents.
-
removeExistingTab
Removes an existing tab, its header and contents. Makes no check on whether the tab is really there.- Parameters:
value- Value to remove.header- Header being removed.
-
removeTab
Removes the tab for a given value, if found. If the tab was selected, there will be no selection active.- Parameters:
value- Value to remove the tab for.
-
getValueAndTab
Finds the value and tab entry corresponding to the givenvalue.- Parameters:
value- A value to look for.- Returns:
- Value and its matching
Tab, if any.
-
getTabHeader
Returns tab header that corresponds to the given value.- Parameters:
value- Value to look for.- Returns:
- A
Tabthat corresponds to the value, if any.
-
getTabContents
Returns contents that corresponds to the given value. Note:Component.setVisible(boolean)calls on the result are discouraged ;)- Parameters:
value- Value to look for.- Returns:
- A
Componentthat corresponds to the value, if any.
-
generateModelValue
- Specified by:
generateModelValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
setPresentationValue
- Specified by:
setPresentationValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
getValues
Returns the values that correspond to tabs.- Returns:
- A collection of values. Modifying the returned collection has no effect on this component.
- See Also:
-
size
public int size()Returns the number of values that currently correspond to tabs.- Returns:
- A number of values.
-
setTabContentGenerator
Sets the generator responsible for providing content for selected tabs. It is called first time a tab is displayed. When the generator is changed, the new one has no effect on previously generated content.- Parameters:
tabContentGenerator-TabContentGenerator. Ifnull, it will be replaced with a default function.
-
getTabContentGenerator
Returns the generator responsible for providing content for selected tabs.- Returns:
TabContentGenerator.
-
withTabContentGenerator
ChainssetTabContentGenerator(TabContentGenerator)and returns itself.- Parameters:
tabContentGenerator- ATabContentGenerator.- Returns:
- This.
- See Also:
-
setTabHeaderGenerator
Sets the generator responsible for providing tabs (headers) for values. It is called first time a tab is created. When the generator is changed, the new one has no effect on previously generated tabs.- Parameters:
tabHeaderGenerator-TabHeaderGenerator. Ifnull, it will be replaced with a default function.
-
getTabHeaderGenerator
Returns the generator responsible for providing tabs (headers) for values.- Returns:
TabContentGenerator.
-
withTabHeaderGenerator
ChainssetTabHeaderGenerator(TabHeaderGenerator)and returns itself.- Parameters:
tabHeaderGenerator- ATabHeaderGenerator.- Returns:
- This.
- See Also:
-
isCustomValueAllowed
public boolean isCustomValueAllowed()Whether or not custom values may be set throughAbstractField.setValue(Object).- Returns:
truewhen selecting a value that does not have a corresponding tab results in adding a new tab,falseotherwise (and by default).
-
setCustomValueAllowed
public void setCustomValueAllowed(boolean customValueAllowed) Allows or disallows creating new tabs when callingAbstractField.setValue(Object).- Parameters:
customValueAllowed- whentrue, selecting a value that does not have a corresponding tab will result in adding and selecting a new tab;falsewill ignore setting the value.
-
withCustomValueAllowed
ChainssetCustomValueAllowed(boolean)and returns itself.- Parameters:
customValueAllowed- Whether or not to allow setting custom value.- Returns:
- This.
- See Also:
-
setTabHandler
Sets the newTabHandlerto use. Causes all current tab contents to be removed with the currentTabHandler, then added and (de)selected with the new one. Does not trigger value change events nor generating tab headers/contents, as only the handling of tabs is changed.- Parameters:
tabHandler- ATabHandler. Ifnullis passed,TabHandlers.REMOVING_HANDLERwill be used.
-
getTabHandler
Returns the currentTabHandler.- Returns:
- A
TabHandler. Nevernull.
-
withTabHandler
ChainssetTabHandler(TabHandler)and returns itself.- Parameters:
tabHandler- ATabHandler. Ifnullis passed,TabHandlers.REMOVING_HANDLERwill be used.- Returns:
- This.
- See Also:
-
isMultiline
public boolean isMultiline()Checks whether tabs wrap to a new line.- Returns:
- When
trueand tabs would overflow current viewport, the extra ones will drop to the next line;falseotherwise and by default.
-
setMultiline
public void setMultiline(boolean multiline) Sets whether or not tabs should overflow to next line.- Parameters:
multiline- Whentrueand tabs overflow current viewport, the extra ones will drop to the next line;falsewhen all should be displayed in one line (with navigation buttons if needed).
-
withMultiline
ChainssetMultiline(boolean)and returns itself.- Parameters:
multiline- Whether or not wrap tabs into new line on overflow.- Returns:
- This.
- See Also:
-
setItems
- Specified by:
setItemsin interfacecom.vaadin.flow.data.binder.HasItems<T>
-
setId
Description copied from interface:HasIdSets this object's id.
-