Package com.storedobject.ui
Class Card<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
com.storedobject.ui.Card<T>
- Type Parameters:
T- The type of object associated with the card.
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasComponents,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasStyle,Serializable
- Direct Known Subclasses:
ObjectCard
public class Card<T>
extends com.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
implements com.vaadin.flow.component.HasComponents
Represents a styled container with configurable layout and styling options.
The Card class embeds a component and provides a pre-defined style for creating card-like components.
It supports alignment, justification, and grid span configuration.
- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a flex container that manages its child components with a customizable layout.static classRepresents a column-based layout container that arranges its child components vertically with an optional gap between them.static classThe Line class represents a styled horizontal line component with customizable properties.static classRepresents a container component designed to arrange child components in a horizontal row layout with customizable gap spacing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAligns the component content to the bottom of the container.voidAligns the content of the component to the center by setting the `align-items` style property to "center".voidalignTop()Aligns the content of the card to the top of the container.final TRetrieves the object of type T stored in this card.getView()Retrieves the associated view of the card from its containing grid's dashboard.voidDisables card selection in the associated grid.protected final com.vaadin.flow.component.ComponentbooleanChecks whether card selection is currently being ignored in the associated grid.booleanChecks whether the card is currently selected.voidAligns the content of the component to the center horizontally within its container.voidAdjusts the horizontal alignment of items within the card to the left.voidAdjusts the alignment of the item's content within its grid cell to the right.protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) voidsetColumnSpan(int span) Sets the column span for the grid layout of the component.voidSets the object of type T for this card.voidsetRowSpan(int span) Sets the number of rows that the component should span in a CSS Grid layout.voidsetSelected(boolean selected) Updates the selection state of the card and applies corresponding visual styles.voidToggles the selection state of the card.Methods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElementMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, 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.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, getChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll, replaceMethods 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.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
Card
public Card()Default constructor for the Card component. Initializes the card with a default content component (a Div) and applies predefined styles for appearance and layout.The following styles are typically applied by default: - Rounded corners (e.g., 12px border radius). - Padding for internal spacing (e.g., 16px). - Background color and subtle shadow effect for better visibility. - Flexbox layout with vertical stacking of child elements. - Stretch alignment to fill the available space. - Gap between child elements for improved readability.
-
Card
public Card(com.vaadin.flow.component.Component root) Default constructor for the Card component. It initializes the card with a predefined set of styles for appearance and layout.The following styles are applied by default: - Border radius set to 12px for rounded corners. - Padding set to 16px for internal spacing. - Background color set to white. - Box shadow set to create a subtle shadow effect. - Flex display for layout management. - Column-based flex-direction for stacking elements vertically. - No margin. - Alignment set to stretch to occupy available space. - Gap set to 8px between child elements.
- Parameters:
root- The root component to be displayed within the card.
-
-
Method Details
-
initContent
protected final com.vaadin.flow.component.Component initContent()- Overrides:
initContentin classcom.vaadin.flow.component.Composite<com.vaadin.flow.component.Component>
-
alignTop
public void alignTop()Aligns the content of the card to the top of the container. Sets the "align-items" style property to "start". -
alignBottom
public void alignBottom()Aligns the component content to the bottom of the container. This method sets the CSS style property "align-items" to "end", effectively positioning child elements at the bottom within a flex container. -
alignCenter
public void alignCenter()Aligns the content of the component to the center by setting the `align-items` style property to "center". This method applies a CSS style to center the alignment of child elements vertically within the component's layout. It is typically used in flexbox or grid layouts where centering content is needed. -
justifyLeft
public void justifyLeft()Adjusts the horizontal alignment of items within the card to the left. This method sets the CSS `justify-items` property to `start`, ensuring that the content aligns along the left side of the container. -
justifyRight
public void justifyRight()Adjusts the alignment of the item's content within its grid cell to the right. This method sets the "justify-items" CSS property to "end", ensuring the content is aligned to the end (right) of the grid cell it resides in. -
justifyCenter
public void justifyCenter()Aligns the content of the component to the center horizontally within its container. This method sets the `justify-items` CSS property to `center`. -
setColumnSpan
public void setColumnSpan(int span) Sets the column span for the grid layout of the component. The span determines how many columns the component will occupy.- Parameters:
span- The number of columns to span must be a positive integer.
-
setRowSpan
public void setRowSpan(int span) Sets the number of rows that the component should span in a CSS Grid layout.- Parameters:
span- the number of rows the component should span
-
toggleSelection
public void toggleSelection()Toggles the selection state of the card. If the card is currently selected, it will be deselected. If it is not selected, it will be marked as selected. Internally, this method callssetSelected(boolean selected)with the negated value of the current selection state. -
setSelected
public void setSelected(boolean selected) Updates the selection state of the card and applies corresponding visual styles. If the new selection state differs from the current state, this method updates the card's appearance, including the visibility of the check icon, and notifies the associated data grid (if any) of the selection change.- Parameters:
selected- The new selection state. If true, the card is marked as selected; otherwise, it is unselected.
-
isSelected
public boolean isSelected()Checks whether the card is currently selected.- Returns:
trueif the card is selected,falseotherwise
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
getObject
Retrieves the object of type T stored in this card.- Returns:
- the object of type T stored in this card
-
setObject
Sets the object of type T for this card. Display attributes of the card should be set based on the object's property values. If this method is overridden, the object must be set by invoking the superclass implementation.- Parameters:
object- the object to be associated with this card must be of type T where T is a subclass of StoredObject
-
ignoreSelection
public void ignoreSelection()Disables card selection in the associated grid. When this method is invoked, it prevents the grid from processing any card selection events, effectively ignoring selection input or state changes. This can be useful in scenarios where card selection functionality needs to be temporarily suspended without altering the grid's selection state. Use case: When you have clickable components inside the cards, you may not want to fire the selection events when the user clicks on them. In such cases, you can temporarily suspend card selection to avoid unintended behavior. This is typically achieved by invoking this method from within your click-handlers. It will be automatically enabled again when your click-handlers complete their execution. -
isIgnoreSelection
public boolean isIgnoreSelection()Checks whether card selection is currently being ignored in the associated grid. When this method returnstrue, card selection events are not processed, effectively disabling selection functionality for the grid.- Returns:
trueif card selection is being ignored;falseotherwise
-
getView
Retrieves the associated view of the card from its containing grid's dashboard. If the card is not part of a grid or the associated grid does not have a dashboard, the method returnsnull.- Returns:
- the view associated with the card's grid dashboard, or
nullif the grid or its dashboard is not available
-