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.
Difference between revisions of "EEF/User Guide/Custom Element Editor"
(→Modifying the generated code) |
(→Modifying the generated code) |
||
Line 27: | Line 27: | ||
== Modifying the generated code == | == Modifying the generated code == | ||
− | By using CustomElementEditor, EEF generates user code areas in | + | By using CustomElementEditor, EEF generates user code areas in four classes. We need to complete these classe to includes our own widget and to bind it with the EMF model. The four classes to modify are : |
+ | * the IPropertiesEditionPart : '''XXXPropertiesEditionPart''' | ||
* the PropertiesEditionPartForm : '''XXXPropertiesEditionPartForm''' | * the PropertiesEditionPartForm : '''XXXPropertiesEditionPartForm''' | ||
* the PropertiesEditionPartImpl : '''XXXPropertiesEditionPartImpl''' | * the PropertiesEditionPartImpl : '''XXXPropertiesEditionPartImpl''' | ||
* the PropertiesEditionComponent : '''XXXPropertiesEditionComponent''' | * the PropertiesEditionComponent : '''XXXPropertiesEditionComponent''' | ||
+ | |||
+ | === Modifiying the IPropertiesEditionPart === | ||
+ | |||
+ | The IPropertiesEditionPart interfaces defines the view's getters and setters for each widget. As we used a CustomElementEditor, EEF has generated an user code area in the ''PersonPropertiesEditionPart'' : | ||
+ | |||
+ | [[Image:EEF_SampleCEE_PartModifying.png | CustomElementEditor : User code area for PropertiesEditionPart ]] | ||
+ | |||
+ | We must had getter and setter for our spinner : | ||
+ | |||
+ | <source lang="java"> | ||
+ | // Start of user code for age specific getters and setters declaration | ||
+ | /** | ||
+ | * @return the age | ||
+ | * | ||
+ | */ | ||
+ | public String getAge(); | ||
+ | |||
+ | /** | ||
+ | * Defines a new age | ||
+ | * @param newValue the new age to set | ||
+ | * | ||
+ | */ | ||
+ | public void setAge(String newValue); | ||
+ | // End of user code | ||
+ | </source> | ||
=== Modifiying the PropertiesEditionPartForm === | === Modifiying the PropertiesEditionPartForm === | ||
+ | |||
+ | The PropertiesEditionPartForm is the | ||
=== Modifiying the PropertiesEditionPartImpl === | === Modifiying the PropertiesEditionPartImpl === | ||
=== Modifiying the PropertiesEditionComponent === | === Modifiying the PropertiesEditionComponent === |
Revision as of 10:05, 5 January 2012
Contents
Need of new widget ?
EEF generators offer a set of widget to build EMF editing forms. Sometime other widget needs appear to create more efficient GUIs. In this case, EEF users can employ CustomElementEditor to generate user code areas inside the EEF properties code.
Let's start this sample with this sample Ecore model :
By following the first generation tutorial, EEF generates theses forms :
Now suppose we want to use a spinner instead of a Text for the age entry. Spinners aren't yet available in the EEF generation. We can, in this case use a CustomElementEditor.
CustomElementEditor in the EEF models
The first step is to replace the ElementEditor generated by the EEF Initializer with a CustomElementEditor. This must be done in the View associated to our EClass Person, the "Person" View.
The removed ElementEditor was defined as the view of the "age" PropertiesEditionElement of the "Person" PropertiesEditionComponent. We need to define our CustomElementEditor as the new "age" PropertiesEditionElement view.
These changes made, we can regenerate the EEF code.
Modifying the generated code
By using CustomElementEditor, EEF generates user code areas in four classes. We need to complete these classe to includes our own widget and to bind it with the EMF model. The four classes to modify are :
- the IPropertiesEditionPart : XXXPropertiesEditionPart
- the PropertiesEditionPartForm : XXXPropertiesEditionPartForm
- the PropertiesEditionPartImpl : XXXPropertiesEditionPartImpl
- the PropertiesEditionComponent : XXXPropertiesEditionComponent
Modifiying the IPropertiesEditionPart
The IPropertiesEditionPart interfaces defines the view's getters and setters for each widget. As we used a CustomElementEditor, EEF has generated an user code area in the PersonPropertiesEditionPart :
We must had getter and setter for our spinner :
// Start of user code for age specific getters and setters declaration /** * @return the age * */ public String getAge(); /** * Defines a new age * @param newValue the new age to set * */ public void setAge(String newValue); // End of user code
Modifiying the PropertiesEditionPartForm
The PropertiesEditionPartForm is the