Chapter 8. Event System

Table of Contents
Introduction
RFG to OpenCAGE Model Events
Events within the OpenCAGE Model
OpenCAGE Model to OpenCAGE GUI Events
Events within the OpenCAGE GUI
Example: Creating a node

Introduction

Motivation

After a part of the model has been loaded from the graph (e.g. from the RFG) into the OpenCAGE Model there must be a mechanism that keeps the OpenCAGE Model consistent to the graph. Additionally a mechanism is needed that keeps the OpenCAGE Model and the OpenCAGE Display consistent.

The Observer (the Section called Observer in Chapter 9) Pattern emerges as a proper solution for this problem.

Concept

There are basically three events that can happen to an object:

  • Creation

  • Change

  • Destruction

How these events are dealt with is shown at the example of a node in the RFG and the corresponding objects in OpenCAGE:

Figure 8-1. Event example

Event example

After the creation of the node in the RFG, a "Childe_Added" Message is passed to the RFG_View_Node_Model representing the view the new node belongs to. Therefore an observer is used that has been attached earlier to the view in the RFG. The RFG_View_Node_Model then creates a new RFG_Node_Model which attaches an observer to the node in the RFG. The RFG_View_Node_Model also attaches an observer to the RFG_Node_Model.

If the node changes (i.e. changes its attributes) or is destroying itself, it passes a "Changed" Message resp. a "Destroying" Message to the RFG_Node_Model.

If the RFG_Node_Model receives a destroying message, it sends the RFG_View_Node_Model also a destroying message by using the observer mentioned above. So the RFG_View_Node_Model can update the list of its children, i.e. remove the RFG_Node_Model from the list of its children.

Because this is only meant to show the basic concept of the events, details have been omitted. They are going to be explained in the following sections.

This concept also applies to the communication between the OpenCAGE Model and the OpenCAGE Display. I.e. Creating an object always leads to sending a message to the superior object (in case of a created edge, the superior object is a node). Changing and destroying an object always results in sending a message to the corresponding object to the one changed resp. destroying.