2.2 Playing around with the Watch Example
To start the tour of the watch example, look at the Graph
Browser in the MetaEdit+ main launcher. All models related to the watch example
are shown on the Graphs
list (make sure ‘Watch’ is selected
in the Projects
list). Choose the ‘2008Models’ WatchFamily
diagram from the list and open it in the Diagram Editor by double-clicking it,
or by selecting Open
from the pop-up menu (as shown in Figure 2-1
Figure 2-1. Opening a WatchFamily diagram.
‘2008Models’ WatchFamily diagram (Figure 2-2
) presents a family of related
wristwatch models. In the diagram, the actual models are shown in the
group at the top of the diagram, while the logical watch
application and display components are presented in the two groups at the bottom
of the diagram. To access the properties of a model element, double-click it or
select it and choose Properties...
from its pop-up menu.
Figure 2-2. The ‘2008Models’ WatchFamily diagram.
further explore the watch example, let us take a look at how the logical watch
applications have been constructed. Choose the one called ‘TASTW’
from the Logical Watches
group, select Decomposition...
pop-up menu and Open
from the following dialog (or simply double-click
‘TASTW’ while holding down the Ctrl-key). This will open the
‘TASTW’ WatchApplication diagram as shown in Figure 2-3
(you could also have opened this
diagram from the Graph Browser).
Figure 2-3. The ‘TASTW’ WatchApplication diagram.
diagram shows the configuration of the logical watch application. It only
contains the top-level logical configuration of sub-applications, basically
showing which sub-applications have been included into this specific logical
watch and in which order they are invoked. When the logical watch application is
started (i.e. the watch is powered up), the basic Time sub-application will be
invoked. If this sub-application is exited, a Stopwatch sub-application will be
started. The cycle is completed when Time will be re-activated when exiting from
the WorldTime sub-application. The name ‘TASTW’ comes from these
sub-applications’ initials in order. To see how the sub-applications have
been defined, choose one and open its decomposition graph by selecting
Decompositions... from its pop-up menu and then Open from the
following dialog (or by double-clicking the sub-application element while
holding down the Ctrl-key).
Now we are ready to generate the code of the test
environment for our watch models. Close all WatchApplication diagrams and go
back to the WatchFamily diagram. Before we run the generation, we have to choose
the target platform for which the code will be generated. Select Graph |
in the WatchFamily Diagram Editor and choose the OS you are
running on (Windows or Linux) as the Generation target platform
dialog that opens (choices for MIDP and API are covered in Chapters 4
). Also make sure that you have the correct
version of the J2SE installed in the directory described at the beginning of
To invoke the code generation, select Graph |
(or press the Generate
button in the Diagram Editor
toolbar) and choose ‘Autobuild’ from the list that opens. Since this
generator is used frequently, it has also been given its own Build
on the toolbar. However you invoke it, this will generate the Java code for all
watch models, and compile and start the test environment in a web browser (as
shown in Figure 2-4
Figure 2-4. The watch test environment.
To test a watch
model, choose it from the web page to open its test environment. Depending on
your browser security settings, you may have to OK some queries or dialogs
before the selected watch model will start as shown in Figure 2-5
. If the watch model does not
start, please check you have installed Java according to the instructions in the
In the watch test environment you can test the watch as it
would appear in real life by pressing the buttons and observing the behavior of
the times and icons on the display. The current application is shown at the top
of the gray display area, and the current state is shown lower down on the page
for debugging purposes.
Figure 2-5. The test environment for a watch model.
also possible to generate a test environment for just some selected watch
models. To do this, open the graph properties dialog for the
‘2008Models’ WatchFamily diagram and add the desired watch models
into the Selected models list by selecting Add Existing... from
the pop-up menu of the list and choosing the appropriate watch models from the
dialog that opens. When the models have been added to the Selected models
list, run the ‘Autobuild’ generator as explained
Along with the Java code for the Watch test environment it
is also possible to generate the technical documentation directly from the Watch
models. To try this feature out, run the generator called ‘Watch family
documentation’. The output will be shown in your web browser with
clickable pictures and hypertext