EMF Forms 1.11.0 Feature: Change Input Domain Object

January 23, 2017 | 3 min Read

With Neon.2, we released EMF Forms 1.11.0. EMF Forms makes it simple to create forms which will edit your data based on an EMF model. To get started with EMF Forms please refer to our tutorial. In this post, we want to outline a new feature in the 1.11.0 release: Changing the input of an already rendered view.

Rendering a form with EMF Forms has always been a single line of code:

renderedComposite = ECPSWTViewRenderer.INSTANCE.render(parent, eObject);

The parameter “parent” is an SWT composite used to render the form on the parameter “eObject”, which is the data object to be shown in the rendered form (i.e. input). With this call, EMF Forms will render the form and bind all controls to the input object, e.g. like this:

While this works well when you embed EMF Forms in a classic view or dialog, it has a flaw when using master-detail views. In this scenario, your view is split into a viewer (tree, table or list), in which you can select an element as well as the detail pane where you wish to render the selected object in a form. An example is shown in the following screenshot:

In this scenario, there would be a selection listener attached to the table on the right side. When the selection is changed, you render the selected object on the details form. As there can be a previously rendered form, you potentially need to dispose this first:

if (renderedComposite != null) {
renderedComposite.dispose();
}
renderedComposite = ECPSWTViewRenderer.INSTANCE.render(content, eObject);

While the call is still simple, it actually does more than required. In fact, it will completely dispose the UI including all controls and recreate them for the new input object. In our example, both UIs look exactly the same, it would be better to replace the input of the already rendered form. This would also improve the performance, as SWT controls do not have to be re-created. EMF Forms 1.11.0 supports this call from scratch. Instead of re-rendering the form, you can simply pass in a new input object (see following code example).

if (renderedComposite != null) {
renderedComposite.getViewModelContext().changeDomainModel(eObject);
} else {
renderedComposite = ECPSWTViewRenderer.INSTANCE.render(content, eObject);
}

Please note, that EMF Forms automatically binds all existing controls to the new input Object and refreshes the validation markers. Further, it will re-evaluate visibility and enablement rules, as they may have changed due to the new input object. So, while the usage of this feature is very simple, EMF Forms solves quite a few issues for you under the hood.

Please note that the described scenario was based on the simple scenario in which you only have to deal with one element type. When the left view contains multiple types, you can combine the input replacement with a view cache to deal with multiple types. This is also supported by EMF Forms. We will describe this in the next blog post.

So have fun with the new feature! If you miss any feature or ways 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 & Philip

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