Interface ComponentManager

All Known Implementing Classes:
ComponentManagerAppState

public interface ComponentManager
The ComponentManager is responsible for managing the lifecycle of components within the application.

This interface provides methods to add, remove, enable, disable, and retrieve components. It also handles component dependencies and slots (for mutually exclusive components).

Key Concepts:

  • Components - Reusable pieces of functionality
  • Dependencies - Components a component depends on to function
  • Slots - Groups of mutually exclusive components (only one active at a time)
See the Component and Fragment classes for more details on component lifecycle and behavior.

  • Method Details

    • getComponent

      <T extends Component> T getComponent(Class<T> type)
      Retrieves a component by its type.
      Type Parameters:
      T - The component type
      Parameters:
      type - The class of the component to retrieve
      Returns:
      The component of the specified type, or null if not found
    • getComponentById

      Component getComponentById(String id)
      Retrieves a component by its ID.
      Parameters:
      id - The ID of the component to retrieve
      Returns:
      The component with the specified ID, or null if not found
    • getComponentBySlot

      List<Component> getComponentBySlot(Object slot)
      Retrieves all components assigned to a specific slot.
      Parameters:
      slot - The slot to get components from
      Returns:
      A list of components in the specified slot
    • getCurrentComponentInSlot

      default Component getCurrentComponentInSlot(Object slot)
      Gets the currently enabled component in a slot.

      Since slots are designed for mutually exclusive components, there should be only one enabled component per slot at any given time.

      Parameters:
      slot - The slot to check
      Returns:
      The currently enabled component in the slot, or null if none is enabled
    • getComponent

      List<Component> getComponent()
      Gets all registered components.
      Returns:
      A list of all components managed by this ComponentManager
    • addComponent

      void addComponent(Component component, Object... deps)
      Adds a component to the manager with optional dependencies.

      The component will be initialized but not enabled. Call enableComponent(Component) to enable it after adding.

      Parameters:
      component - The component to add
      deps - Zero or more dependencies for the component
    • removeComponent

      void removeComponent(Component component)
      Removes a component from the manager.

      If the component is enabled, it will be disabled before removal.

      Parameters:
      component - The component to remove
    • enableComponent

      default void enableComponent(Component component)
      Enables a component without any specific arguments.

      This is a convenience method equivalent to enableComponent(component, null).

      Parameters:
      component - The component to enable
    • enableComponent

      <T> void enableComponent(Component component, T arg)
      Enables a component with the specified argument.

      The component will only be enabled if all its dependencies are already enabled.

      Type Parameters:
      T - The type of argument to pass to the component
      Parameters:
      component - The component to enable
      arg - The argument to pass to the component's onEnable method
    • disableComponent

      void disableComponent(Component component)
      Disables a component.

      This will also disable any components that depend on this component.

      Parameters:
      component - The component to disable
    • updateComponentDependencies

      void updateComponentDependencies(Component component, Object... deps)
      Updates the dependencies of a component.

      This allows changing what components a particular component depends on at runtime.

      Parameters:
      component - The component to update dependencies for
      deps - The new dependencies for the component
    • isComponentEnabled

      boolean isComponentEnabled(Component component)
      Checks if a component is currently enabled.
      Parameters:
      component - The component to check
      Returns:
      true if the component is enabled, false otherwise
    • enableComponent

      default void enableComponent(String id, Object arg)
      Enables a component by its ID.
      Parameters:
      id - The ID of the component to enable
      arg - The argument to pass to the component's onEnable method
    • enableComponent

      default void enableComponent(String id)
      Enables a component by its ID without arguments.
      Parameters:
      id - The ID of the component to enable
    • disableComponent

      default void disableComponent(String id)
      Disables a component by its ID.
      Parameters:
      id - The ID of the component to disable
    • enableComponent

      default void enableComponent(Class<? extends Component> type, Object arg)
      Enables a component by its type with the specified argument.
      Type Parameters:
      T - The component type
      Parameters:
      type - The class of the component to enable
      arg - The argument to pass to the component's onEnable method
    • enableComponent

      default void enableComponent(Class<? extends Component> type)
      Enables a component by its type without arguments.
      Type Parameters:
      T - The component type
      Parameters:
      type - The class of the component to enable
    • disableComponent

      default void disableComponent(Class<? extends Component> type)
      Disables a component by its type.
      Type Parameters:
      T - The component type
      Parameters:
      type - The class of the component to disable
    • addAndEnableComponent

      default void addAndEnableComponent(Component component, Object... deps)
      Adds and immediately enables a component.
      Parameters:
      component - The component to add and enable
      deps - Zero or more dependencies for the component
    • addAndEnableComponent

      default void addAndEnableComponent(Component component, Object arg, Object... deps)
      Adds and immediately enables a component with the specified argument.
      Parameters:
      component - The component to add and enable
      arg - The argument to pass to the component's onEnable method
      deps - Zero or more dependencies for the component
    • resolveDependency

      default Component resolveDependency(Object d)