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>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField>,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField>,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.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:
- Serialized Form
-
-
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
Fields Modifier and Type Field Description static Supplier<com.vaadin.flow.component.html.Div>DEFAULT_TAB_CONTENTS_CONTAINERDefault container for tab contents.static StringMULTILINE_THEME_NAMEName of the theme for multiline tabs.-
Fields inherited from interface org.vaadin.miki.markers.HasHelperPositionable
HELPER_ABOVE_THEME_VARIANT
-
-
Constructor Summary
Constructors Constructor Description SuperTabs()Creates the component with no tabs and defaultTabHandler,TabHeaderGeneratorandTabContentGenerator.SuperTabs(Supplier<C> mainContentSupplier, T... values)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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddNewTab(T value, boolean select)Adds 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.voidaddTab(T... values)This 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 TgenerateModelValue()TabContentGenerator<T>getTabContentGenerator()Returns 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.TabHandlergetTabHandler()Returns the currentTabHandler.Optional<com.vaadin.flow.component.tabs.Tab>getTabHeader(T value)Returns tab header that corresponds to the given value.TabHeaderGenerator<T>getTabHeaderGenerator()Returns the generator responsible for providing tabs (headers) for values.protected Optional<Map.Entry<T,com.vaadin.flow.component.tabs.Tab>>getValueAndTab(T value)Finds the value and tab entry corresponding to the givenvalue.List<T>getValues()Returns the values that correspond to tabs.booleanisCustomValueAllowed()Whether or not custom values may be set throughAbstractField.setValue(Object).booleanisMultiline()Checks 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.voidremoveTab(T value)Removes the tab for a given value, if found.voidsetCustomValueAllowed(boolean customValueAllowed)Allows or disallows creating new tabs when callingAbstractField.setValue(Object).voidsetId(String id)Sets this object's id.voidsetItems(Collection<T> collection)voidsetMultiline(boolean multiline)Sets whether or not tabs should overflow to next line.protected voidsetPresentationValue(T t)voidsetTabContentGenerator(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.SuperTabs<T>withCustomValueAllowed(boolean customValueAllowed)ChainssetCustomValueAllowed(boolean)and returns itself.SuperTabs<T>withMultiline(boolean multiline)ChainssetMultiline(boolean)and returns itself.SuperTabs<T>withTabContentGenerator(TabContentGenerator<T> tabContentGenerator)ChainssetTabContentGenerator(TabContentGenerator)and returns itself.SuperTabs<T>withTabHandler(TabHandler tabHandler)ChainssetTabHandler(TabHandler)and returns itself.SuperTabs<T>withTabHeaderGenerator(TabHeaderGenerator<T> tabHeaderGenerator)ChainssetTabHeaderGenerator(TabHeaderGenerator)and returns itself.-
Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getErrorMessage, getLabel, isInvalid, onAttach, remove, removeThemeVariants, setErrorMessage, setInvalid, setLabel, updateValue
-
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals
-
Methods 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, scrollIntoView, set, setElement, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
-
Methods inherited from interface org.vaadin.miki.markers.HasHelperPositionable
isHelperAbove, setHelperAbove, setHelperAbove, setHelperBelow
-
Methods 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, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipText
-
Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Methods inherited from interface org.vaadin.miki.markers.WithHelperMixin
withHelperComponent, withHelperText
-
Methods inherited from interface org.vaadin.miki.markers.WithHelperPositionableMixin
withHelperAbove, withHelperAbove, withHelperBelow
-
Methods inherited from interface org.vaadin.miki.markers.WithIdMixin
withId
-
Methods inherited from interface org.vaadin.miki.markers.WithItemsMixin
withItems, withItems, withItems
-
Methods inherited from interface org.vaadin.miki.markers.WithLabelMixin
withLabel
-
Methods inherited from interface org.vaadin.miki.markers.WithValueMixin
withValue
-
-
-
-
Field Detail
-
DEFAULT_TAB_CONTENTS_CONTAINER
public static final Supplier<com.vaadin.flow.component.html.Div> DEFAULT_TAB_CONTENTS_CONTAINER
Default container for tab contents.
-
MULTILINE_THEME_NAME
public static final String MULTILINE_THEME_NAME
Name of the theme for multiline tabs.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SuperTabs
public SuperTabs()
Creates the component with no tabs and defaultTabHandler,TabHeaderGeneratorandTabContentGenerator.
-
SuperTabs
@SafeVarargs public SuperTabs(Supplier<C> mainContentSupplier, T... values)
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
@SafeVarargs public SuperTabs(TabContentGenerator<T> tabContentGenerator, T... values)
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:
TabHandlers
-
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:
TabHandlers
-
-
Method Detail
-
addNewTab
protected void addNewTab(T value, boolean select)
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
@SafeVarargs public final void addTab(T... values)
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(Collection)
-
addTabs
public void addTabs(Collection<T> values)
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
protected void removeExistingTab(T value, com.vaadin.flow.component.tabs.Tab header)
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
public void removeTab(T value)
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
protected Optional<Map.Entry<T,com.vaadin.flow.component.tabs.Tab>> getValueAndTab(T value)
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
public Optional<com.vaadin.flow.component.tabs.Tab> getTabHeader(T value)
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
public Optional<com.vaadin.flow.component.Component> getTabContents(T value)
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
protected T generateModelValue()
- Specified by:
generateModelValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
setPresentationValue
protected void setPresentationValue(T t)
- Specified by:
setPresentationValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
getValues
public List<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:
getTabHeader(Object),getTabContents(Object)
-
size
public int size()
Returns the number of values that currently correspond to tabs.- Returns:
- A number of values.
-
setTabContentGenerator
public void setTabContentGenerator(TabContentGenerator<T> tabContentGenerator)
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
public TabContentGenerator<T> getTabContentGenerator()
Returns the generator responsible for providing content for selected tabs.- Returns:
TabContentGenerator.
-
withTabContentGenerator
public SuperTabs<T> withTabContentGenerator(TabContentGenerator<T> tabContentGenerator)
ChainssetTabContentGenerator(TabContentGenerator)and returns itself.- Parameters:
tabContentGenerator- ATabContentGenerator.- Returns:
- This.
- See Also:
setTabContentGenerator(TabContentGenerator)
-
setTabHeaderGenerator
public void setTabHeaderGenerator(TabHeaderGenerator<T> tabHeaderGenerator)
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
public TabHeaderGenerator<T> getTabHeaderGenerator()
Returns the generator responsible for providing tabs (headers) for values.- Returns:
TabContentGenerator.
-
withTabHeaderGenerator
public SuperTabs<T> withTabHeaderGenerator(TabHeaderGenerator<T> tabHeaderGenerator)
ChainssetTabHeaderGenerator(TabHeaderGenerator)and returns itself.- Parameters:
tabHeaderGenerator- ATabHeaderGenerator.- Returns:
- This.
- See Also:
setTabHeaderGenerator(TabHeaderGenerator)
-
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
public SuperTabs<T> withCustomValueAllowed(boolean customValueAllowed)
ChainssetCustomValueAllowed(boolean)and returns itself.- Parameters:
customValueAllowed- Whether or not to allow setting custom value.- Returns:
- This.
- See Also:
setCustomValueAllowed(boolean)
-
setTabHandler
public void setTabHandler(TabHandler tabHandler)
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
public TabHandler getTabHandler()
Returns the currentTabHandler.- Returns:
- A
TabHandler. Nevernull.
-
withTabHandler
public SuperTabs<T> withTabHandler(TabHandler tabHandler)
ChainssetTabHandler(TabHandler)and returns itself.- Parameters:
tabHandler- ATabHandler. Ifnullis passed,TabHandlers.REMOVING_HANDLERwill be used.- Returns:
- This.
- See Also:
setTabHandler(TabHandler)
-
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
public SuperTabs<T> withMultiline(boolean multiline)
ChainssetMultiline(boolean)and returns itself.- Parameters:
multiline- Whether or not wrap tabs into new line on overflow.- Returns:
- This.
- See Also:
setMultiline(boolean)
-
setItems
public void setItems(Collection<T> collection)
- Specified by:
setItemsin interfacecom.vaadin.flow.data.binder.HasItems<T>
-
-