Dynamic View Services > Implementing a Representation Model > Implementing a Tree Representation Model > Bridge Classes
 
Bridge Classes
To build a bridge between the generic representation protocol and the graphic classes, we declare two new classes: TreeR which makes up the bridge to TreeGadget and TreeItemR which makes up the bridge to TreeGadgetItem.
To be used as bridge classes, the classes TreeR and TreeItemR must:
*derive directly or transitively from the class IlsRpObject;
*include specific server declarations made via the macro ILS_RP_OBJECT_DECL.
*define a constructor that takes the following parameters:
*A reference to the representation (that is, to an instance of the class IlsRepresentation) to which the representation object belongs.
*A reference to the dynamic representation object model (that is, to an instance of the class IlsRpObjModel) to which the server refers when acting on this object.
*In addition to these general declarations, bridge classes define specific members, namely:
*The functions and data used to apply the updates requested by the server. For instance the class TreeR declares a function to set the root label. It also has a single data member with a pointer to the tree gadget, to which it delegates the graphical operations.
*The callback functions and, optionally, data in charge of notifying the server about the modifications directly performed by the component on the graphical object. For instance, the class TreeR declares a function onSetLabel that is activated by the graphic gadget through a mechanism of callbacks when the label of the gadget is modified.
Below is the synopsis of the class TreeR:
class TreeR : public IlsRpObject
{
public:
TreeR(IlsRepresentation& rp, const IlsRpObjModel& m)
: IlsRpObject(rp,m), _gadget(0) {}
~TreeR();
 
// update functions
void setLabel(IlsString label);
 
// callback functions
void onSetLabel(IlsString label);
void onDelete();
 
TreeGadget* getGadget(){return _gadget;}
private:
TreeGadget* _gadget;
 
ILS_RP_OBJECT_DECL(TreeR)
};
Note that TreeR does not maintain the tree structure locally.
Similarly, the class TreeItemR defines its own members. In particular, it defines two functions that attach a new item either to a tree or to another tree item. It also defines the symmetric callback functions and maintains a pointer to the TreeGadgetItem to which it delegates the graphical operation.
Below is the synopsis of the class TreeItemR:
class TreeItemR : public IlsRpObject
{
public:
TreeItemR(IlsRepresentation& rp, const IlsRpObjModel& m)
: IlsRpObject(rp,m), _gadgetItem(0) {}
~TreeItemR();
 
// update functions
void setLabel(IlsString l);
void setOwner(TreeR*);
void setOwner(TreeItemR*);
 
// callback functions
void onSetLabel(IlsString l);
void onSetOwner(TreeR*);
void onSetOwner(TreeItemR*);
void onDelete();
TreeGadgetItem* getGadgetItem();
private:
TreeGadgetItem* _gadgetItem;
 
ILS_RP_OBJECT_DECL(TreeItemR)
};

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.