EMF generating swing application

375 Views Asked by At

I'm developing simple desktop applications.

It's very useful to be capable to observe and modify model structure in UML-like form, and EMF allows that. I want to combine EMF code generation approach with existing GUI framework (namely Swing), but I haven't found any existing examples.

I wonder if that's because it's not a reasonable idea? May be there are other ways to grasp and edit model structure that lies behind the application and generate code for concrete GUI framework?

1

There are 1 best solutions below

0
On

One of the main ideas behind model driven development is the automatic generation of alternative representations of a system. These are more commonly referred to as model-to-model (m2m) and model-to-code (m2t) transformations (although in some scenarios code is just considered to be another model).

EMF is a framework for defining metamodels. A metamodel defines the semantics of a model. Simply said, a metamodel defines the classes and properties that you can use to model a specific domain. For example, the UML metamodel lets you create models to represent a software system. The model includes the structure (class diagram) and it can also include the behaviour (sequence diagram, state machine, etc.).

Perpendicular to EMF there are a bunch of frameworks and languages that are capable of reading, modifying and creating models. For example the Epsilon Framework provides various model management languages to work with models. The Epsilon Transformation Language (ETL) allows you to write programs to perform m2m transformations and the Epsilon Generation Language (EGL) allows you to write programs to perform m2t transformations.

Thus, to generate code from a UML model to a concrete GUI framework you could use EGL to directly generate code that uses the GUI framework's API. An alternative is to first generate a model of the GUI (you will need a metamodel of the framework) using a m2m transformation and the do the m2t. The latter approach might be preferred as the m2m transformation can help you better breach the semantic gaps between UML and the selected framework.

Since you mentioned EMF generation, this is also a feasible approach. However, note that EMF only generates Java code to represent the metamodel. In this approach, you would have to write all the GUI framework code which will use the EMF generated code underneath as the base model. Thus, I would recommend the m2m and m2t approach in which you will be able to generate most (if not all) of the code.

The Epsilon Framework has a simple tutorial on EGL that shows how to generate HTML from a model. It will help you get an idea of what is needed. If you GUI framework was HTML then this would be a nice starting point.

Going over the details of m2m and m2t would require more detail on the specific UML model you have and the target GUI framework you intend to use.