public class WidgetRegistry<O extends OutputManager<?>>
extends java.lang.Object
This class holds all widgets (frames and their inner widgets) which were pushed from server to client. Also, this class is responsible for building client side widgets from widget definition.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<Frame<O>,java.util.Set<WidgetId>> |
editableFramesList
We need to maintain the list of currently editable frames.
|
private java.util.concurrent.locks.ReadWriteLock |
lock
Guard lock for access to the widgetList
|
private static java.util.logging.Logger |
LOG
Logger.
|
private java.util.LinkedHashMap<WidgetId,Widget<O>> |
widgetList
The list of the widgets in the current screen.
|
Constructor and Description |
---|
WidgetRegistry()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addEditableFrameForWidget(Widget widToCheck)
Possibly add the frame with given widget to the editable frames list if it is not already
there.
|
void |
addFrame(Frame<O> frame)
Add pre-built frame.
|
void |
addWidget(Widget<O> widget)
Add the specified widget to the registry.
|
void |
addWidget(WidgetId id,
Widget<O> widget)
Add the widget with the specified ID to the registry.
|
void |
addWidgetsRecursive(java.lang.Iterable<Widget<O>> widgets)
Add the specified widgets and all the children recursively to the
registry, immediately.
|
void |
addWidgetsRecursive(Widget<O> widget)
Add the specified widget and all its children recursively to the
registry, immediately.
|
void |
addWidgetsRecursive(Widget<O>[] widgets)
Add the specified widgets and all the children recursively to the
registry, immediately.
|
private void |
addWidgetsToFrame(int frameID,
ScreenDefinition screen)
Add widgets to the frame which is identified by the given frame ID.
|
private void |
addWidgetsToMenu(int menuID,
MenuDescription descr)
Add widgets to the menu which is identified by the given menu ID.
|
static Widget |
findAncestor(Widget w,
java.util.function.Predicate<Widget> filter)
Returns a nearest widget's ancestor that satisfies the target filter condition.
|
static Widget |
findDescendant(Widget w,
java.lang.Class type)
Returns a nearest widget's descendant having a given type.
|
Widget<O> |
getComponent(int id)
Return
Component instance for the given ID. |
Widget<O> |
getComponent(WidgetId id)
Return
Component instance for the given ID. |
Widget<O>[] |
getComponents()
Get all components defined in the screen.
|
Frame<O>[] |
getEditableFrames()
Get all currently existed editable frames in the screen.
|
WidgetId[] |
getIDs(int frameId)
Get IDs of all widgets in the current screen belonging to the given frame.
|
int |
lookupFrameIdFromWidgetId(int widgetId)
Retrieve the ID of the frame containing the widget with a given ID.
|
void |
pushDefinition(ScreenDefinition[] sd)
Instantiate screen from the given array of definitions.
|
void |
pushMenuDescription(MenuDescription[] md)
Instantiate menus from the given array of descriptions.
|
private void |
reconstructSideLabel(WidgetConfig config)
Reconstruct the side-label with the specified config.
|
void |
reconstructWidget(WidgetConfig config)
Recreates the widget based on the information can be taken from the
source widget snapshot.
|
void |
removeEditableFrameForWidget(Widget widToCheck)
Possibly remove the frame with given widget from the editable frames list if there is no
more enabled focused widgets in a frame left.
|
void |
removeFrame(Frame<O> frame)
Remove the given frame and all contained components from the master
list of components.
|
Widget<?> |
removeWidget(WidgetId id)
Remove the specified widget from the registry, immediately.
|
void |
removeWidgetsRecursive(java.lang.Iterable<Widget<O>> widgets)
Remove the specified widgets and all the children recursively from the
registry, immediately.
|
void |
removeWidgetsRecursive(Widget<O> widget)
Remove the specified widget and all its children recursively from
the registry, immediately.
|
void |
removeWidgetsRecursive(Widget<O>[] widgets)
Remove the specified widgets and all the children recursively from the
registry, immediately.
|
void |
removeWidgetsRecursive(Widget<O> widget,
java.util.function.Predicate<Widget<O>> check)
Remove the specified widget and all its children recursively from the registry, immediately.
|
private static final java.util.logging.Logger LOG
private java.util.LinkedHashMap<WidgetId,Widget<O extends OutputManager<?>>> widgetList
private java.util.Map<Frame<O extends OutputManager<?>>,java.util.Set<WidgetId>> editableFramesList
private final java.util.concurrent.locks.ReadWriteLock lock
public static Widget findAncestor(Widget w, java.util.function.Predicate<Widget> filter)
w
- The target widget that can have an ancestor of a given type.filter
- The target filter condition.public static Widget findDescendant(Widget w, java.lang.Class type)
w
- The target widget that can have a descendant of a given type.type
- The specified type condition.public void reconstructWidget(WidgetConfig config)
config
- Widget snapshot taken from the server.public void addFrame(Frame<O> frame)
frame
- Frame reference.public Widget<O>[] getComponents()
public void removeFrame(Frame<O> frame)
frame
- The frame to remove.public void addEditableFrameForWidget(Widget widToCheck)
widToCheck
- The widget to check.public void removeEditableFrameForWidget(Widget widToCheck)
widToCheck
- The widget to check.public Frame<O>[] getEditableFrames()
public Widget<O> getComponent(WidgetId id)
Component
instance for the given ID.id
- Component ID.Component
or null
if no such component exists.public Widget<O> getComponent(int id)
Component
instance for the given ID.
If the widget is part of a frame and the frame's down body is initialized, then return the widget associated with the current frame line.
id
- Component ID.Component
or null
if no such component exists.public int lookupFrameIdFromWidgetId(int widgetId)
widgetId
- The widget ID.public void pushDefinition(ScreenDefinition[] sd)
sd
- Array of data containers.public void pushMenuDescription(MenuDescription[] md)
md
- Array of data containers.public WidgetId[] getIDs(int frameId)
frameId
- Frame ID whose widget ID info should be returned.public void addWidget(Widget<O> widget)
widget
- The new widget which needs to be registered.public void addWidget(WidgetId id, Widget<O> widget)
id
- The widget ID.widget
- The new widget which needs to be registered.public Widget<?> removeWidget(WidgetId id)
id
- The widget ID.public void addWidgetsRecursive(Widget<O> widget)
widget
- The root widget.public void addWidgetsRecursive(Widget<O>[] widgets)
widgets
- The root widgets.public void addWidgetsRecursive(java.lang.Iterable<Widget<O>> widgets)
widgets
- The root widgets.public void removeWidgetsRecursive(Widget<O>[] widgets)
widgets
- The root widgets.public void removeWidgetsRecursive(Widget<O> widget)
widget
- The root widget.public void removeWidgetsRecursive(Widget<O> widget, java.util.function.Predicate<Widget<O>> check)
The widgets are filtered and removed based on the specified predicate.
widget
- The root widget.check
- Condition to be satisfied by a widget, so that it will be removed.public void removeWidgetsRecursive(java.lang.Iterable<Widget<O>> widgets)
widgets
- The root widgets.private void addWidgetsToFrame(int frameID, ScreenDefinition screen)
frameID
- The index of the frame to be populated.screen
- List of widget configurations.private void addWidgetsToMenu(int menuID, MenuDescription descr)
menuID
- The index of the menu to be populated.descr
- List of widget configurations.private void reconstructSideLabel(WidgetConfig config)
This will not create a new Label
instance. It will only register the widget
configuration with the ConfigManager
, so that changes to the label instance can be
tracked and sent back to the server.
Note that the registered widget configuration must be "linked" to the related label widget.
This is because the widget takes care of unregistering the label configuration. The link
is established in Label.linkTo(int, int)
.
config
- Widget snapshot taken from the server.