public class Components extends Registry<ComponentType>
Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
logger |
Constructor and Description |
---|
Components() |
Modifier and Type | Method and Description |
---|---|
java.util.stream.Stream<ComponentType<?>> |
allComponents() |
java.util.stream.Stream<WidgetType> |
allWidgets() |
java.util.List<java.lang.String> |
componentNamesForSource(DataSource<?> source)
Gets the names of all the possible components than can display the data in a given source.
|
java.util.List<java.lang.String> |
componentNamesForType(DataType type)
Gets the names of all the possible components that can display the given type, sorted alphabetically.
|
java.util.Optional<? extends Component> |
createComponent(java.lang.String name)
Tries to create an arbitrary component.
|
java.util.Optional<? extends Component> |
createComponent(java.lang.String name,
DataSource<?> source)
Creates a new component with the given name.
|
java.util.Optional<Widget> |
createWidget(java.lang.String name)
Tries to create a widget from a known widget name, without an initial source.
|
java.util.Optional<Widget> |
createWidget(java.lang.String name,
java.util.Collection<DataSource> sources)
Tries to create a widget from a known widget with the given name.
|
<T> java.util.Optional<Widget> |
createWidget(java.lang.String name,
DataSource<T> source)
Tries to create a widget from a known widget with the given name.
|
java.util.Optional<java.lang.String> |
defaultComponentNameFor(DataType type)
Gets the name of the default component for the given data type, or
Optional.empty() if there is no default
component for that type. |
java.util.List<Widget> |
getActiveWidgets()
Gets a list of the active widgets in the application.
|
static Components |
getDefault()
Gets the default widget registry.
|
java.util.Optional<java.lang.reflect.Type> |
javaTypeFor(java.lang.String name) |
java.util.Optional<java.lang.String> |
pickComponentNameFor(DataType type)
Gets the name of a component that can handle data of the given type.
|
<T extends Widget> |
register(java.lang.Class<T> widgetClass)
Convenience overload for registering annotated widgets.
|
void |
register(ComponentType type)
Registers an item with this registry.
|
static void |
setDefault(Components instance)
Sets the default instance to use.
|
void |
setDefaultComponent(DataType dataType,
ComponentType<?> widgetType)
Sets the default component to use for a given data type.
|
void |
unregister(ComponentType type)
Unregisters an item from this registry.
|
static <T extends Component> |
validateAnnotatedComponentClass(java.lang.Class<T> componentClass)
Validates a component class.
|
static <T> java.util.Optional<T> |
viewFor(java.lang.Class<T> annotatedClass)
Create an instance for a ParametrizedController annotated class.
|
addItem, getItems, isRegistered, registerAll, registerAll, registerIfAbsent, removeItem, unregisterAll, unregisterAll
public static Components getDefault()
public static void setDefault(Components instance)
java.lang.IllegalStateException
- if not called from a testpublic void register(ComponentType type)
Registry
unregistered
.register
in class Registry<ComponentType>
type
- the item to registerpublic <T extends Widget> void register(java.lang.Class<T> widgetClass)
public static <T extends Component> void validateAnnotatedComponentClass(java.lang.Class<T> componentClass)
@Description
annotation, or if its name is empty.InvalidWidgetException
- if the component class is not validpublic void unregister(ComponentType type)
Registry
unregister
in class Registry<ComponentType>
type
- the item to unregisterpublic java.util.stream.Stream<ComponentType<?>> allComponents()
public java.util.stream.Stream<WidgetType> allWidgets()
public <T> java.util.Optional<Widget> createWidget(java.lang.String name, DataSource<T> source)
name
- the name of the widget to createsource
- the data source for the widget to usepublic java.util.Optional<Widget> createWidget(java.lang.String name, java.util.Collection<DataSource> sources) throws IncompatibleSourceException
IncompatibleSourceException
will be
thrown.name
- the name of the widget to createsources
- the data sources for the widget to useIncompatibleSourceException
- if the widget for the given name is incompatible with any of the given sourcespublic java.util.Optional<Widget> createWidget(java.lang.String name)
public java.util.Optional<? extends Component> createComponent(java.lang.String name)
public java.util.Optional<? extends Component> createComponent(java.lang.String name, DataSource<?> source)
Sourced
),
its source will be set to the one provided.name
- the name of the component to createsource
- the source for the created component to use, if the component accepts onepublic java.util.Optional<java.lang.reflect.Type> javaTypeFor(java.lang.String name)
public java.util.List<Widget> getActiveWidgets()
Do not keep references to elements in this list. It prevents garbage collection of widget instances.
public java.util.List<java.lang.String> componentNamesForType(DataType type)
createWidget
.type
- the type of data to get possible widgets for.public void setDefaultComponent(DataType dataType, ComponentType<?> widgetType)
dataType
- the type to set the default widget forwidgetType
- the type of widget to set as the defaultpublic java.util.Optional<java.lang.String> defaultComponentNameFor(DataType type)
Optional.empty()
if there is no default
component for that type.public java.util.Optional<java.lang.String> pickComponentNameFor(DataType type)
componentNamesForType(DataType)
is used.public java.util.List<java.lang.String> componentNamesForSource(DataSource<?> source)
public static <T> java.util.Optional<T> viewFor(java.lang.Class<T> annotatedClass)