public abstract class ConfigManager
extends java.lang.Object
On server-side, this class allows update of the widget configurations with the received
client-side changes
.
On client-side, this class allows the collection of all changes in widget configurations and package them to be sent to the remote side. This will only be done after the server-side is fully initialized and has informed the client-side that it can start sending the updates. Also, the client-side is responsible of pushing the widget config config definitions to the server-side, so that the field IDs are synced on both sides.
When new widget configuration classes are added, always add them to the
ClientConfigManager.CONFIG_CLASSES
list.
WidgetConfigDef
,
WidgetConfig
,
WidgetConfigUpdates
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<WidgetId,WidgetConfig> |
activeConfigs
Map of active, live, widget configurations.
|
protected java.util.Map<WidgetId,WidgetConfig> |
backupConfigs
Map of backup configuration (as when the control was last received by this side).
|
protected java.util.Map<WidgetId,java.util.Set<java.lang.String>> |
dirtyConfigs
A set of dirty widget configuration.
|
private static ContextLocal<ConfigManager> |
local
Context-local state holding the live widget configurations.
|
private boolean |
tracking
Flag indicating if config changes are tracked or not.
|
protected java.util.Map<WidgetId,WidgetConfigDef> |
widgetCfg
Map of widget ID to its
definition . |
Constructor and Description |
---|
ConfigManager() |
Modifier and Type | Method and Description |
---|---|
void |
addDirtyConfig(WidgetConfig cfg,
java.lang.String field)
Register the specified field in the configuration for the specified widget ID as being
dirty.
|
void |
addWidgetConfig(WidgetConfig config)
Add the given config (associated with a new widget) to the active and backup registries.
|
void |
addWidgetConfig(WidgetConfig activeConfig,
WidgetConfig backupConfig)
Add the given config (associated with a new widget) to the active and backup registries.
|
<T extends WidgetConfig> |
duplicate(T config)
Duplicate the given configuration.
|
<T extends WidgetConfig> |
getActiveConfig(WidgetId widgetId)
Get the active config associated with the given widget ID.
|
<T extends WidgetConfig> |
getBackupConfig(WidgetId widgetId)
Get the backup config associated with the given widget ID.
|
protected abstract WidgetConfigDef |
getConfigDef(java.lang.Class<? extends WidgetConfig> cls)
Get the
WidgetConfigDef instance associated with the given WidgetConfig
implementation. |
(package private) WidgetConfigDef |
getConfigDef(int wid)
Get the
WidgetConfigDef instance associated with the given widget. |
WidgetConfigUpdates[] |
getConfigUpdates()
Get the widget configuration updates, using the captured dirty configs.
|
(package private) <T> T |
getDynamicConfig(WidgetConfig cfg,
java.lang.String fname,
java.lang.Class<T> ftype,
T defVal)
Dynamically get a specific widget configuration field.
|
static <T extends ConfigManager> |
getInstance()
Get the config manager instance for this context.
|
protected abstract boolean |
isRegisteredWidget(WidgetId id)
Check if the given ID is associated with a registered widget.
|
(package private) void |
notifyWidgetDestroyed(WidgetId wid)
Remove this widget IDs from all the maps.
|
void |
removeWidgetConfig(WidgetId wid)
Remove the widget config associated with the given ID, unless there are shared instances
of this widget.
|
void |
replaceConfig(WidgetConfig dest,
WidgetConfig source)
Post all the widget configuration from the source to the destination.
|
(package private) abstract ConfigOwner<?> |
resolveConfigOwner(WidgetId widgetId)
The method attempts to resolve a
ConfigOwner reference from
widgetId . |
<T extends WidgetConfig> |
resolveWidgetConfig(WidgetId id,
java.lang.Class<T> cls)
Determine the active configuration for the given ID.
|
<T extends WidgetConfig> |
resolveWidgetConfig(WidgetId id,
T cfgInstance)
Determine the active configuration for the given ID.
|
(package private) <T> void |
setDynamicConfig(WidgetConfig cfg,
java.lang.String fname,
java.lang.Class<T> ftype,
T value)
Dynamically set a specific widget configuration field.
|
void |
setTracking(boolean enabled)
Enable or disable widget configuration changes.
|
(package private) <T extends WidgetConfig> |
setWidgetConfig(T cfg,
java.lang.Object value,
WidgetConfigDef wdef,
java.lang.String fname)
Set a widget configuration field to the specified value.
|
static <C extends WidgetConfig> |
syncConfigChanges(java.lang.Runnable code)
All the config changes performed during execution of
code
are synchronized with the associated config owners. |
boolean |
trackConfig(WidgetConfig cfg)
Determine if the specified config instance can be tracked.
|
private static ContextLocal<ConfigManager> local
protected final java.util.Map<WidgetId,WidgetConfigDef> widgetCfg
definition
.protected final java.util.Map<WidgetId,WidgetConfig> activeConfigs
protected final java.util.Map<WidgetId,WidgetConfig> backupConfigs
protected final java.util.Map<WidgetId,java.util.Set<java.lang.String>> dirtyConfigs
private boolean tracking
public static <T extends ConfigManager> T getInstance()
abstract ConfigOwner<?> resolveConfigOwner(WidgetId widgetId)
ConfigOwner
reference from
widgetId
.widgetId
- Widget Id.ConfigOwner
reference or null
if
such cannot be find.protected abstract boolean isRegisteredWidget(WidgetId id)
id
- The widget ID.true
if a widget exists in the registry, with the given ID.protected abstract WidgetConfigDef getConfigDef(java.lang.Class<? extends WidgetConfig> cls)
WidgetConfigDef
instance associated with the given WidgetConfig
implementation.cls
- The widget config class.public boolean trackConfig(WidgetConfig cfg)
The config can be tracked if tracking of the config fields is active at this moment and
if the widget is not a virtual widget
.
cfg
- The WidgetConfig
instace which needs to be tracked.public void setTracking(boolean enabled)
enabled
- true
to enable tracking, false
otherwise.public void addDirtyConfig(WidgetConfig cfg, java.lang.String field)
This is will exclude any negative widget ID and also any widget IDs for which there is no
WidgetConfigDef
instance associated (these are new widgets).
cfg
- The widget config.field
- The changed field.public <T extends WidgetConfig> T resolveWidgetConfig(WidgetId id, java.lang.Class<T> cls)
id
- The widget ID.cls
- The widget's configuration class.public <T extends WidgetConfig> T resolveWidgetConfig(WidgetId id, T cfgInstance)
This does not register the config as the active config. It is the caller's responsibility to decide if the config needs to be registered or not.
id
- The widget ID.cfgInstance
- The widget's configuration class.public WidgetConfigUpdates[] getConfigUpdates()
public void replaceConfig(WidgetConfig dest, WidgetConfig source)
dest
- The destination config, where the source will be copied.source
- The source config.public void removeWidgetConfig(WidgetId wid)
wid
- The widget ID.public void addWidgetConfig(WidgetConfig config)
config
- The widget configuration associated with a new widget.public void addWidgetConfig(WidgetConfig activeConfig, WidgetConfig backupConfig)
This method can be used in case when a widget is initialized and its config state is changed during the init process. The initial config passed to the created widget is in this case interpreted as the backup confing and the changed config as the active config. The difference ensures that the changes are properly synchronized with the other side (server/client).
activeConfig
- The active widget configuration associated with a new widget.backupConfig
- The widget configuration that will be used as a backup config.
If null, the activeConfig will be used as backup as well.public <T extends WidgetConfig> T getActiveConfig(WidgetId widgetId)
widgetId
- The widget ID.public <T extends WidgetConfig> T getBackupConfig(WidgetId widgetId)
widgetId
- The widget ID.public static <C extends WidgetConfig> void syncConfigChanges(java.lang.Runnable code)
code
are synchronized with the associated config owners.
The method opens new scope for config synchronization on the current
thread. When there is another scope already opened, this will join the
previously opened scope. If not, this opened scope will become the root
scope. The config changes performed during the scope are synchronized
with the config owner after code
finishes its execution.
For more details see ConfigSyncManager
.
code
- Code to be executed, must not be null.WidgetConfigDef getConfigDef(int wid)
WidgetConfigDef
instance associated with the given widget.wid
- The widget ID.<T> void setDynamicConfig(WidgetConfig cfg, java.lang.String fname, java.lang.Class<T> ftype, T value)
cfg
- The config instance which needs to be updated.fname
- The field name.ftype
- The field type.value
- The new field value.<T> T getDynamicConfig(WidgetConfig cfg, java.lang.String fname, java.lang.Class<T> ftype, T defVal)
cfg
- The config instance from where the field is retrieved.fname
- The field name.ftype
- The field type.defVal
- The default value.public <T extends WidgetConfig> T duplicate(T config)
Changes are not tracked during duplication.
config
- The configuration to be duplicated.java.lang.NullPointerException
- If the received config is null
or the associated
WidgetConfigDef
instance could not be found.<T extends WidgetConfig> void setWidgetConfig(T cfg, java.lang.Object value, WidgetConfigDef wdef, java.lang.String fname)
cfg
- The widget configuration to be updated.value
- The new field value.wdef
- The definition of the widget configuration.fname
- The ID of the changed field.void notifyWidgetDestroyed(WidgetId wid)
wid
- The widget ID to be removed.