Dynamic View Services > Implementing a Representation Model > Implementing a Table Representation Model > Bridge Classes
 
Bridge Classes
For our application, we need to implement table representations. These tables are used to display the properties of the employees in a department or the properties of the contributions to a project. Therefore, we have defined a table-oriented representation model, based on the matrix gadget and on two bridge classes: TableR and RowR. We have also decided to support two types of values for the column items: integer and string.
Here is the code declaring the class TableR:
class TableR : public IlsRpObject
{
public:
TableR(IlsRepresentation& rp, const IlsRpObjModel& m);
 
// update functions
void setTitle(IlsString title);
void setColumnHeader(int index,IlsString header);
 
// callback functions
void onSetColumnHeader(int index,IlsString value);
void onDelete();
// utilities
void addRow(RowR&);
void removeRow(RowR&);
void setValue(int row,int col, int Value);
void setValue(int row,int col, IlsString value);
void setColor(int row,string color);
private:
  int row2Index(RowR&)
  RowR* index2Row(int index);
 
MatrixGadget * _gadget;
 
ILS_RP_OBJECT_DECL(TableR) // mandatory
};
 
 
class RowR : public IlsRpObject
{
public:
RowR(IlsRepresentation& rp, const IlsRpObjModel& m);
 
// update functions
void setValue(int index, IlsString value);
void setValue(int index, long value);
  void setColor(string color);
void setParent(TableR*);
 
// callback functions
void onSetValue(int index,IlsString value);
void onSetValue(int index,int value);
void onDelete();
private:
TableR* _table;
 
ILS_RP_OBJECT_DECL(RowR)
};
Since the only graphical object is the matrix gadget, the rows (instances of the class RowR) have no graphic object counterparts. Each row forms an “indirect bridge” to the matrix gadget through its parent table. All update operations on a RowR object are forwarded to the table, which delegates them to the matrix gadget, passing the relevant row index as an argument. Conversely, the editing events occurring on the matrix are fed back to the RowR object through the table. In other words, the table maintains the mapping between the RowR instances and the row numbers in the matrix gadget.

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