Interface ComponentManager
- All Known Implementing Classes:
ComponentManagerAppState
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)
Component
and Fragment
classes for more details on component lifecycle and
behavior.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addAndEnableComponent
(Component component, Object... deps) Adds and immediately enables a component.default void
addAndEnableComponent
(Component component, Object arg, Object... deps) Adds and immediately enables a component with the specified argument.void
addComponent
(Component component, Object... deps) Adds a component to the manager with optional dependencies.default void
disableComponent
(Class<? extends Component> type) Disables a component by its type.default void
Disables a component by its ID.void
disableComponent
(Component component) Disables a component.default void
enableComponent
(Class<? extends Component> type) Enables a component by its type without arguments.default void
enableComponent
(Class<? extends Component> type, Object arg) Enables a component by its type with the specified argument.default void
Enables a component by its ID without arguments.default void
enableComponent
(String id, Object arg) Enables a component by its ID.default void
enableComponent
(Component component) Enables a component without any specific arguments.<T> void
enableComponent
(Component component, T arg) Enables a component with the specified argument.Gets all registered components.<T extends Component>
TgetComponent
(Class<T> type) Retrieves a component by its type.Retrieves a component by its ID.getComponentBySlot
(Object slot) Retrieves all components assigned to a specific slot.default Component
Gets the currently enabled component in a slot.boolean
isComponentEnabled
(Component component) Checks if a component is currently enabled.void
removeComponent
(Component component) Removes a component from the manager.default Component
void
updateComponentDependencies
(Component component, Object... deps) Updates the dependencies of a component.
-
Method Details
-
getComponent
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
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
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
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
Gets all registered components.- Returns:
- A list of all components managed by this ComponentManager
-
addComponent
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 adddeps
- Zero or more dependencies for the component
-
removeComponent
Removes a component from the manager.If the component is enabled, it will be disabled before removal.
- Parameters:
component
- The component to remove
-
enableComponent
Enables a component without any specific arguments.This is a convenience method equivalent to
enableComponent(component, null)
.- Parameters:
component
- The component to enable
-
enableComponent
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 enablearg
- The argument to pass to the component's onEnable method
-
disableComponent
Disables a component.This will also disable any components that depend on this component.
- Parameters:
component
- The component to disable
-
updateComponentDependencies
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 fordeps
- The new dependencies for the component
-
isComponentEnabled
Checks if a component is currently enabled.- Parameters:
component
- The component to check- Returns:
- true if the component is enabled, false otherwise
-
enableComponent
Enables a component by its ID.- Parameters:
id
- The ID of the component to enablearg
- The argument to pass to the component's onEnable method
-
enableComponent
Enables a component by its ID without arguments.- Parameters:
id
- The ID of the component to enable
-
disableComponent
Disables a component by its ID.- Parameters:
id
- The ID of the component to disable
-
enableComponent
Enables a component by its type with the specified argument.- Type Parameters:
T
- The component type- Parameters:
type
- The class of the component to enablearg
- The argument to pass to the component's onEnable method
-
enableComponent
Enables a component by its type without arguments.- Type Parameters:
T
- The component type- Parameters:
type
- The class of the component to enable
-
disableComponent
Disables a component by its type.- Type Parameters:
T
- The component type- Parameters:
type
- The class of the component to disable
-
addAndEnableComponent
Adds and immediately enables a component.- Parameters:
component
- The component to add and enabledeps
- Zero or more dependencies for the component
-
addAndEnableComponent
Adds and immediately enables a component with the specified argument.- Parameters:
component
- The component to add and enablearg
- The argument to pass to the component's onEnable methoddeps
- Zero or more dependencies for the component
-
resolveDependency
-