Class ViewElementMode

java.lang.Object
com.foreach.across.modules.entity.views.ViewElementMode

public class ViewElementMode extends Object
Represents the mode for which a ViewElementBuilder is being requested. A mode is essentially represented by a string, so it is easy to add custom modes.

A mode has a single and multiple variant, in the latter the suffix _MULTIPLE is present in the mode string. Multiple modes are mainly used on entity level to configure default element types for either a single or collection representation of that entity.

A ViewElementMode can optionally have child modes configured (withChildMode(String, ViewElementMode). These are named sub-modes which can be used for more complex control rendering.

Author:
Arne Vandamme
  • Field Details

    • LABEL

      public static final ViewElementMode LABEL
      Only the label text of the descriptor.
    • VALUE

      public static final ViewElementMode VALUE
      Only the (readonly) value of the descriptor.
    • CONTROL

      public static final ViewElementMode CONTROL
      Form control for modifying the descriptor.
    • LIST_LABEL

      public static final ViewElementMode LIST_LABEL
      Only the label text of the descriptor - for use in list view (usually tabular).
    • LIST_VALUE

      public static final ViewElementMode LIST_VALUE
      Only the (readonly) value of the descriptor - for use in list view (usually tabular).
    • LIST_CONTROL

      public static final ViewElementMode LIST_CONTROL
      Form control for modifying the descriptor - for use in list view (usually tabular).
    • FORM_READ

      public static final ViewElementMode FORM_READ
      Control for detail (form) view.
    • FORM_WRITE

      public static final ViewElementMode FORM_WRITE
      Control for modifying form view.
    • FILTER_FORM

      public static final ViewElementMode FILTER_FORM
      Wrapper for the control for filtering on the property or entity. Usually a form group with holds the FILTER_CONTROL.
    • FILTER_CONTROL

      public static final ViewElementMode FILTER_CONTROL
      Control for filtering on the property or entity.
  • Constructor Details

  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • withoutChildMode

      public ViewElementMode withoutChildMode(@NonNull @NonNull String childModeName)
      Creates a new element mode without the child mode configured.
      Parameters:
      childModeName - child mode name
      Returns:
      new mode instance
    • withChildMode

      public ViewElementMode withChildMode(@NonNull @NonNull String childModeName, ViewElementMode viewElementMode)
      Creates a new element mode with the additional child mode configured. If the viewElementMode argument is null, the child mode will be removed.
      Parameters:
      childModeName - child mode name
      viewElementMode - mode to apply for the child mode
      Returns:
      new mode instance
    • withoutChildModes

      public ViewElementMode withoutChildModes()
      Creates a new element mode without any child modes configured.
      Returns:
      new mode instance
    • forMultiple

      public ViewElementMode forMultiple()
      Converts the current mode to the multiple variant. If the current mode is already a multiple (ends with _MULTIPLE), the current reference will be returned.
      Returns:
      new instance or same if already a multiple
    • forSingle

      public ViewElementMode forSingle()
      Converts the current mode to the single variant. If the current mode is not a multiple variant, the current reference will be returned.
      Returns:
      new instance or same if not a multiple
    • isForMultiple

      public boolean isForMultiple()
      Returns:
      true if this mode corresponds to multiple
    • getChildMode

      public ViewElementMode getChildMode(@NonNull @NonNull String childModeName)
      Get the child mode.
      Parameters:
      childModeName - name of the child mode
      Returns:
      mode
      See Also:
    • hasChildModes

      public boolean hasChildModes()
      Returns:
      true if a child mode is set
    • getChildMode

      public ViewElementMode getChildMode(@NonNull @NonNull String childModeName, ViewElementMode defaultIfNotSet)
      Get the child mode or return the default value if not set.
      Parameters:
      childModeName - name of the child mode
      defaultIfNotSet - default value
      Returns:
      mode
    • matchesTypeOf

      public boolean matchesTypeOf(ViewElementMode viewElementMode)
      Check if this view element mode has the same base type as the arguments. This ignores any child modes set on the view element modes. This check requires the plurality to match, use matchesSingleTypeOf(ViewElementMode) if you want to ignore the plural indicator.
      Parameters:
      viewElementMode - to compare with
      Returns:
      true if any element mode matches
    • matchesSingleTypeOf

      public boolean matchesSingleTypeOf(ViewElementMode viewElementMode)
      Check if this view element mode has the same single type as the argument. This ignores any child modes set on the view element modes.
      Parameters:
      viewElementMode - to compare with
      Returns:
      true if any element mode matches
    • matchesTypeOfAny

      public boolean matchesTypeOfAny(ViewElementMode... viewElementModes)
      Check if this view element mode has the same base type as any of the arguments. This ignores any child modes set on the view element modes. This check requires the plurality to match, use matchesSingleTypeOfAny(ViewElementMode...) if you want to ignore the plural indicator.
      Parameters:
      viewElementModes - to compare with
      Returns:
      true if any element mode matches
    • matchesSingleTypeOfAny

      public boolean matchesSingleTypeOfAny(ViewElementMode... viewElementModes)
      Check if this view element mode has the same single type as any of the arguments. This ignores any child modes set on the view element modes.
      Parameters:
      viewElementModes - to compare with
      Returns:
      true if any element mode matches
    • of

      public static ViewElementMode of(@NonNull @NonNull String viewElementModeString)
      Parses a string into a valid mode.
      Parameters:
      viewElementModeString - representation
      Returns:
      view element mode
    • isList

      public static boolean isList(@NonNull @NonNull ViewElementMode mode)
    • isLabel

      public static boolean isLabel(@NonNull @NonNull ViewElementMode mode)
    • isValue

      public static boolean isValue(@NonNull @NonNull ViewElementMode mode)
    • isControl

      public static boolean isControl(@NonNull @NonNull ViewElementMode mode)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getChildModes

      public Map<String,ViewElementMode> getChildModes()
      Get the child modes attached.