Using Proto Mediators

A proto mediator (class ) is a subclass of IlvGroupMediator and is used to dynamically create prototype instances of a given class and place them in a manager or container. The idea is to design a specific prototype for each main application class. When an object is created by the application, a corresponding prototype is instantiated and placed in the manager. This allows you to create a graphical user interface for a complete application, separating the user interface design from the functional core of the application. The following samples from the <ILVHOME>/samples/protos directory implement this design pattern: interact_synoptic to build an air-traffic control simulator, and synoptic to build a simulator for a manufacturing plant.

For example, assuming the same base application (Machines and Boilers), you want each Boiler instance to be represented and edited at the same time by the user. Create a subclass of IlvProtoMediator:

class BoilerUI: public IlvProtoMediator, public MachineObserver {

public:

BoilerUI(IlvManager*m,Boiler*b)

:IlvProtoMediator(m,"BoilerPrototype",b)

{

observe(b);

IlvSymbol* vals[2] = {

IlvGetSymbol( "x"), IlvGetSymbol("y") };

update(vals); // Sets the position of the current instance.

// The application must have a way of specifying where to place

// the object. Alternatively, you can handle the placement by

// explicitly setting the x and y values of the BGO.

install(m); // Place the prototype in the manager

}

// Other methods are the same as the BoilerUI using the GroupMediator.

};

Now, the application can have a global “user interface factory” responsible for generating prototype instances as soon as it creates its internal objects. The code of this factory may look like the following pseudo-code:

class myApplication {

list<Boiler*> boilers;

void initUI (IlvManager* m) {

for each machine in boilers

new BoilerUI(m, machine);

}

void add_boiler(Boiler* b) {

boilers.append(b);

new BoilerUI(getManager(), b);

}

};