Class MasterDetailLayout

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.masterdetaillayout.MasterDetailLayout
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, HasStyle, RouterLayout, Serializable

@Tag("vaadin-master-detail-layout") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.8.3") @NpmPackage(value="@vaadin/master-detail-layout",version="24.8.3") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/master-detail-layout/src/vaadin-master-detail-layout.js") public class MasterDetailLayout extends Component implements HasSize, RouterLayout
MasterDetailLayout is a component for building UIs with a master (or primary) area and a detail (or secondary) area that is displayed next to, or overlaid on top of, the master area, depending on configuration and viewport size.
Author:
Vaadin Ltd
See Also:
  • Field Details

  • Constructor Details

    • MasterDetailLayout

      public MasterDetailLayout()
      Creates an empty Master Detail Layout.
  • Method Details

    • getMaster

      public Component getMaster()
      Gets the component currently in the master area.
      Returns:
      the component in the master area, or null if there is no component in the master area
    • setMaster

      public void setMaster(Component component)
      Sets the component to be displayed in the master area.
      Parameters:
      component - the component to display in the master area, not null
    • getDetail

      public Component getDetail()
      Gets the component currently in the detail area.
      Returns:
      the component in the detail area, or null if there is no component in the detail area
    • setDetail

      public void setDetail(Component component)
      Sets the component to be displayed in the detail area. The details area is automatically shown when the detail component is set, and hidden when the detail component is removed by setting it to null.
      Parameters:
      component - the component to display in the detail area, or null to clear the detail area
    • onAttach

      protected void onAttach(AttachEvent attachEvent)
      Description copied from class: Component
      Called when the component is attached to a UI.

      This method is invoked before the AttachEvent is fired for the component.

      Make sure to call super.onAttach when overriding this method.
      Overrides:
      onAttach in class Component
      Parameters:
      attachEvent - the attach event
    • onDetach

      protected void onDetach(DetachEvent detachEvent)
      Description copied from class: Component
      Called when the component is detached from a UI.

      This method is invoked before the DetachEvent is fired for the component.

      Make sure to call super.onDetach when overriding this method.

      Overrides:
      onDetach in class Component
      Parameters:
      detachEvent - the detach event
    • getMasterSize

      public String getMasterSize()
      Gets the size of the master area.
      Returns:
      the size of the master area in CSS length units, or null if the size is not set
    • setMasterSize

      public void setMasterSize(String size)
      Sets the size of the master area in CSS length units. When specified, it prevents the master area from growing or shrinking. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      size - the size of the master area in CSS length units
    • setMasterSize

      public void setMasterSize(float size, Unit unit)
      Sets the size of the master area in CSS length units. When specified, it prevents the master area from growing or shrinking. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      size - the size of the master area
      unit - the unit
    • getMasterMinSize

      public String getMasterMinSize()
      Gets the minimum size of the master area.
      Returns:
      the minimum size of the master area in CSS length units, or null if the minimum size is not set
    • setMasterMinSize

      public void setMasterMinSize(String minSize)
      Sets the minimum size of the master area in CSS length units. When specified, it prevents the master area from shrinking below this size. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      minSize - the minimum size of the master area in CSS length units
    • setMasterMinSize

      public void setMasterMinSize(float minSize, Unit unit)
      Sets the minimum size of the master area in CSS length units. When specified, it prevents the master area from shrinking below this size. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      minSize - the minimum size of the master area
      unit - the unit
    • getDetailSize

      public String getDetailSize()
      Gets the size of the detail area.
      Returns:
      the size of the detail area in CSS length units, or null if the size is not set
    • setDetailSize

      public void setDetailSize(String size)
      Sets the size of the detail area in CSS length units. When specified, it prevents the detail area from growing or shrinking. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      size - the size of the detail area in CSS length units
    • setDetailSize

      public void setDetailSize(float size, Unit unit)
      Sets the size of the detail area in CSS length units. When specified, it prevents the detail area from growing or shrinking. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      size - the size of the detail area
      unit - the unit
    • getDetailMinSize

      public String getDetailMinSize()
      Gets the minimum size of the detail area.
      Returns:
      the minimum size of the detail area in CSS length units, or null if the minimum size is not set
    • setDetailMinSize

      public void setDetailMinSize(String minSize)
      Sets the minimum size of the detail area in CSS length units. When specified, it prevents the detail area from shrinking below this size. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      minSize - the minimum size of the detail area in CSS length units
    • setDetailMinSize

      public void setDetailMinSize(float minSize, Unit unit)
      Sets the minimum size of the detail area in CSS length units. When specified, it prevents the detail area from shrinking below this size. If there is not enough space to show master and detail areas next to each other, the details are shown in an overlay, using the mode defined by setOverlayMode(OverlayMode).
      Parameters:
      minSize - the minimum size of the detail area
      unit - the unit
    • getOrientation

      public MasterDetailLayout.Orientation getOrientation()
      Gets the orientation of the layout. Defaults to MasterDetailLayout.Orientation.HORIZONTAL.
      Returns:
      the orientation
    • setOrientation

      public void setOrientation(MasterDetailLayout.Orientation orientation)
      Sets the orientation of the layout. Defines how master and detail areas are shown next to each other, and whether size and min-size are applied as width or height.
      Parameters:
      orientation - the orientation
    • getContainment

      public MasterDetailLayout.Containment getContainment()
      Gets the containment of the layout. Defaults to MasterDetailLayout.Containment.LAYOUT.
      Returns:
      the containment
    • setContainment

      public void setContainment(MasterDetailLayout.Containment containment)
      Sets the containment of the layout.When set to MasterDetailLayout.Containment.LAYOUT, the overlay is confined to the layout. When set to MasterDetailLayout.Containment.VIEWPORT, the overlay is confined to the browser's viewport.
      Parameters:
      containment - the containment
    • getOverlayMode

      public MasterDetailLayout.OverlayMode getOverlayMode()
      Gets the overlay mode of the layout. Defaults to MasterDetailLayout.OverlayMode.DRAWER.
      Returns:
      the overlay mode
    • setOverlayMode

      public void setOverlayMode(MasterDetailLayout.OverlayMode mode)
      Sets the overlay mode of the layout. When set to MasterDetailLayout.OverlayMode.DRAWER, the detail area is positioned on top of master area and there is a backdrop that covers the remaining part of the master area. When set to MasterDetailLayout.OverlayMode.STACK, the detail area fully covers the master area.
      Parameters:
      mode - the overlay mode
    • isForceOverlay

      public boolean isForceOverlay()
      Gets whether the layout overlay mode is enforced. The way how the overlay is rendered is defined by setOverlayMode(OverlayMode).
      Returns:
      true if the overlay mode is enforced, false otherwise
    • setForceOverlay

      public void setForceOverlay(boolean forceOverlay)
      Sets whether the layout overlay mode is enforced. The way how the overlay is rendered is defined by setOverlayMode(OverlayMode).
      Parameters:
      forceOverlay - true if the overlay mode is enforced, false otherwise
    • isAnimationEnabled

      public boolean isAnimationEnabled()
      Gets whether the layout animation is enabled.
      Returns:
      true if the animation is enabled, false otherwise
    • setAnimationEnabled

      public void setAnimationEnabled(boolean enabled)
      Sets whether the layout animation is enabled.
      Parameters:
      enabled - true if the animation is enabled, false otherwise
    • addBackdropClickListener

      public Registration addBackdropClickListener(ComponentEventListener<MasterDetailLayout.BackdropClickEvent> listener)
      Adds a listener for when the backdrop of the details overlay is clicked. The backdrop is the area outside the detail area when it is shown in drawer mode. Can be used to hide the details when the backdrop is clicked.
      Parameters:
      listener - the listener to add, not null
      Returns:
      a registration for removing the listener
    • addDetailEscapePressListener

      public Registration addDetailEscapePressListener(ComponentEventListener<MasterDetailLayout.DetailEscapePressEvent> listener)
      Adds a listener for when the Escape key is pressed within the details area. Can be used to hide the details when the Escape key is pressed.
      Parameters:
      listener - the listener to add, not null
      Returns:
      a registration for removing the listener
    • showRouterLayoutContent

      public void showRouterLayoutContent(HasElement content)
      Description copied from interface: RouterLayout
      Shows the content of the layout which is the router target component annotated with a @Route.

      Note implementors should not care about old @Route content, since it's handled separately by RouterLayout.removeRouterLayoutContent(HasElement) which by default simply removes the old content.

      Specified by:
      showRouterLayoutContent in interface RouterLayout
      Parameters:
      content - the content component or null if the layout content is to be cleared.
    • removeRouterLayoutContent

      public void removeRouterLayoutContent(HasElement oldContent)
      Description copied from interface: RouterLayout
      Removes content that should no longer be shown in this router layout. If RouterLayout.showRouterLayoutContent(HasElement) was previously called with a non-null parameter, then this method will be called with the same parameter immediately before calling RouterLayout.showRouterLayoutContent(HasElement) again.

      By default, the old content is removed from its parent using Element.removeFromParent().

      Specified by:
      removeRouterLayoutContent in interface RouterLayout
      Parameters:
      oldContent - the old content to remove, not null