EMF Forms 1.19.0 Feature: Data Templates for EObject Creation

January 10, 2019 | 3 min Read

EMF Forms makes it easy to create forms that are capable of editing your data based on an EMF model. To get started with EMF Forms please refer to our tutorial. In this article, we would like to outline a new feature in the 1.19.0 release: The data template mechanism for creating new EObjects, which are based on templates, from within the UI.

There are several places in a UI, where you can create new instances, e.g. via right click in a tree, or in a table as shown below. In many applications, you want new objects to follow a specific template, e.g. by initializing some values or by adding some sub objects (e.g. an address to a person).

When providing such default templates, you ideally want to use some central mechanism, rather than customizing the logic directly in the UI. When using EMF, it is not a good idea to override the generated factories (see here why see why here). EMF allows to specify

default values, though, which are applied to new instances. This does not fulfil all requirements, that a typical data-centric application poses. As an example, you can only set one default value; there is no way to allow the user to choose between different templates when creating an object. Additionally, you can create sub objects using default values in EMF. Finally, you need to be a programmer to provide default values in EMF, the mechanism is not suited for end users.

Therefore, EMF Forms comes with explicit support for data templates. It addresses the shortcomings of plain EMF. Basically, you can register an arbitrary number of templates, which can be either static or created programmatically. The easiest way of providing a data template is to create it using a form-based UI, as shown in the screenshot below. This option can even be exposed to end users.

Once you have registered a data template, it will be used at any place in your UI, which allows to create a new object. If provide several data templates, the user can even choose between them (as shown below).

If you are interested in more details about this feature  or if you want to learn how to provide your own custom data templates, please have a look at this tutorial.

As for all EMF Forms features, the data template mechanism is of course adaptable to even more custom requirements. If there are any features you miss or ways you wish to adapt it, please provide feedback by submitting bugs or feature requests or contact us if you are interested in enhancements or support.

Jonas, Maximilian and Philip

Jonas, Maximilian and Philip

Jonas Helming, Maximilian Koegel and Philip Langer co-lead EclipseSource. They work as consultants and software engineers for building …