The Guiliani DataPool Component for generic binding of UI Elements to arbitrary data sources. More...
Classes | |
class | CDataPoolConnector |
Connects a GUIObject to the DataPool. DataPoolConnectors are used to observe values within the DataPool. GUIObjects, which are observing entries in the datapool must have a DataPoolConnector. A DataPoolConnector will be notified of changes to the DataPool via the OnNotification(DataPoolEntry&) Interface, and will notify its observers via the NotifyObservers (const CGUIValue&, const CGUIObject* const, const eC_UInt, const eC_UInt) interface if the value of its GUIObject changes. More... | |
class | CDataPoolEntry |
A single entry in the DataPool. The DataPoolEntry class represents a single entry (unique id + a value/array of values) within the DataPool. DataPoolEntries are observed by DataPoolConnectors and will be notified of changes to the DataPoolConnector via the OnNotification(value, object, x, y) interface. In the opposite direction, a DataPooolEntry notifies its observers by calling their OnNotification(DataPoolEntry) interfaces. More... | |
class | CGUIDataPool |
The Guiliani DataPool Component for generic binding of UI Elements to arbitrary data sources.
The DataPool stores application specific data and allows objects within the user interface to get notified when data changes, for which they have registered themselves as observers.
The DataPool is meant to work as an interface between the GUI and the underlying application and is thus designed to be threadsafe. The CGUIDataPool::Set() and CGUIDataPool::Get() methods may therefore be accessed from both the UI-Thread, and application threads.
The following example shows how an object gets registered to an entry within the DataPool. In this example a DataPool entry named ID_OF_DATAPOOL_RESOURCE (which has been defined in UserDataPoolResource.h) gets connected to the object pkSlider. Note that this will always result in a two-way dependency, which means that the object within the GUI will get notified when the DataPool changes, but changing the GUI object's value (e.g. by dragging the slider) will also update the value within the DataPool.
Using pointers is not possible when streaming. In this case, use the CGUIDataPool::AutoRegister() method instead. It registers an Object Handle with an entry of the DataPool. If an object with this ID is constructed (or streamed) it will automatically be registered within the DataPool.
Manually changing a value within the DataPool (e.g. from application code) can be done via the CGUIDataPool::Set() interface.
The following example code demonstrates how to implement a custom DataPoolConnector, which observes a value within the DataPool. Its OnNotification() method will be called whenever the associated value within the DataPool gets updated.
It is possible to register callback functions to entries within the DataPool, which will automatically be called when their corresponding value gets changed. To work as a callback your function must accept a CDataPoolEntry& as a paramter and have void as return value. The DataPoolEntry parameter will contain the observed DataPoolEntry from which you can extract its current value.
The following is an example implementation of a customized Image-control, which will display one of three defineable images with regard of the value received from the DataPool.
It inherits from the standard CGUIImage base class, but extends it by a custom SetValue() method, which implements the communication with the DataPool.
The SetValue() implementation will interpret the value received from the DataPool as an integer. If the value lies in the range of 0-49 it will display the "GreenImage" supplied during construction. For values in the range of 50-74 it will display the "YellowImage", and for all others it will display the "RedImage".
In some ocassions it will be necessary to replace the standard DataPoolEntries within the DataPool with customized code, which does for instance access an external database to retrieve the requested data. For this purpose it is possible to..
The following example code gives a skeleton implementation of a customized DataPoolEntry.
A single DataPool entry can store more than a single CGUIValue. If you wish to store multiple values you can access these via the x,y parameters of the CGUIDataPool::Set() and CGUIDataPool::Get() interfaces. Most standard GUI elements will only make use of the first value (=which is the one at indices 0,0). But some - such as ListBoxes - will automatically know how to deal with arrays.
The following example shows how to set / get arrays of data in the DataPool: