Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EEF/User Guide/Custom Widget Generation"

(Creating Acceleo modules to generate a specific widget with EEF)
(Common service override)
Line 72: Line 72:
 
After this step, the spinnerGettersSetters is finished.
 
After this step, the spinnerGettersSetters is finished.
  
=== Common service override ===
+
=== Common module override ===
 +
 
 +
The common module provides a large set of services to the EEF generation. In our case, it provides a ''toJavaType'' service that define the Java Type to associate to a given widget. We must override this template to associate the ''Integer'' type to the ''Spinner''.
 +
 
 +
The first step is to create a spinnerCommon module. This module must extends the ''org::eclipse::emf::eef::codegen::services::common'' module for the EEF generation project.
 +
 
 +
In this module you have to override the ''toJavaType'' template:
 +
 
 +
[[Image:10 - EEF CostumGen CommonToJavaTypeOverride.png]]
 +
 
 +
For the Spinner case (don't forget to specify a guard), we must provide the ''Integer'' java type:
 +
 
 +
[[Image:11 - EEF CostumGen SpinnerToJavaType.png]]
 +
 
 +
This is all you have to do in this module.
 +
 
 +
=== PropertiesEditingComponent generation ===

Revision as of 11:44, 6 February 2012

Need to generate new widgets ?

In the CustomElementEditor guide, we saw how to ponctually include specific widgets in EEF generated editing forms. If this need is becoming common, EEF offers the ability to extend its generators to generate new widgets.

Environment initialization

As we will create acceleo generator, we need to install the Acceleo SDK. It can be done via the release train:

acceleo install

Next, in an empty workspace, we create an Acceleo Project. In the new project wizard, we can initialize our first template:

Acceleo project creation

Let's name it spinnerGettersSetter. It need two metamodels:

The other data are marginal, we will erase the generated body of this module.

We also have to add to the generator project a dependency to the EEF Codegen plugin : org.eclipse.emf.eef.codegen.

All generator projects extending EEF must have a dependency on its generation project

And finally, we add an Extension to the generator project. The org.eclipse.acceleo.engine.dynamic.templates defines a project as an dynamic module able to extend existing generators. In this extension, we must specify the folders containing dynamic modules. In our case, we can specify the folder org/eclipse/emf/samples/eef/gen/spinner/common.

All generator projects extending EEF must be defined as Acceleo dynamic modules

After these step, we can create our modules to generate spinner with EEF.

Creating Acceleo modules to generate a specific widget with EEF

In the CustomElementEditor guide, we modified 4 classes in the code generated by EEF in order to add manually a specific widget in an EEF editing form. To generate a specific widget, we have to create 4 generation modules and to override the existing common module.

Generating PropertiesEditionPart

The first module is the "GettersSetters" module defining the methods' signature for the views interfaces and their implementations in the PartImpls and the PartForms. In our case, we just have to override the generation in order to define the getters and setters implementations. We have to override two templates from the abstract module widgetGettersSetters :

  • getterSignatureImplementation
  • setterSignatureImplementation

To do that, you can use the override view in Acceleo :

6 - EEF CostumGen GettersSettersTemplateOverride.png

This view initialize the two templates to implement :

EEF CostumGen GettersSettersTemplateToOverride.png

The easiest way to defines your templates is to copy the code from an existing example and to copy it into the templates:

8 - EEF CostumGen GeterrsSettersTemplateCodeCopy.png

Then you can replace the dynamic part of this code by an Acceleo dynamic code area:

9 - EEF CostumGen GettersSettersDynamicCode.png

In this example, we've used the
getterSignature()
and the
setterSignature()
templates which generate the getter and setter signatures for the given ElementEditor. We've also used the
elementEditorName()
template which refers to the name of the field in the generated views. To find these services you can browse the services package in the EEF generation project or look at the generation modules for the existing widgets.

For the moment, this generation module override all the other generation module for view interface generation. We must reduce the overriding scope the the ElementEditor having a Spinner for representation. For that, in our two templates, we add a guard reducing the overriding scope :

[template public getterSignatureImplementation(elementEditor : ElementEditor) overrides getterSignatureImplementation 
   ? (elementEditor.representationName('Spinner'))] 
   ...
[/template]

[template public setterSignatureImplementation(elementEditor : ElementEditor) overrides setterSignatureImplementation 
   ? (elementEditor.representationName('Spinner'))]
   ...
[/template]

After this step, the spinnerGettersSetters is finished.

Common module override

The common module provides a large set of services to the EEF generation. In our case, it provides a toJavaType service that define the Java Type to associate to a given widget. We must override this template to associate the Integer type to the Spinner.

The first step is to create a spinnerCommon module. This module must extends the org::eclipse::emf::eef::codegen::services::common module for the EEF generation project.

In this module you have to override the toJavaType template:

10 - EEF CostumGen CommonToJavaTypeOverride.png

For the Spinner case (don't forget to specify a guard), we must provide the Integer java type:

11 - EEF CostumGen SpinnerToJavaType.png

This is all you have to do in this module.

PropertiesEditingComponent generation

Back to the top