-
Notifications
You must be signed in to change notification settings - Fork 1
Creating an EEF editor
This tutorial covers the instalation of Extended Editing Framework (EEF) and the creation of a model editor.
- Eclipse IDE for Java Developeers, version 3.6.2 (Helios SR2 release).
Available at: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliossr2 - EEF (version 3.1.0)
Install "Extended Editing Framework - Extension" from the "EEF 1.0 update site" (http://download.eclipse.org/modeling/emft/eef/updates/releases/1.0)
fa3d3728795139903b49a3293d0a0389402c75cd
This is an optional part of the "Building the Droid DSL editor with Xtext" tutorial, but is a required part of this tutorial. The metamodel generated in the previous tutorial will be used in this tutorial.
File > New > Project...
- Choose
Eclipse Modeling Framework > Empty EMF Project
- Set the project name "org.emf.example.droid"
- Finish the wizard.
Make sure you have generated the Xtext language artifacts (by running the MWE2 Workflow). It will update the generated Ecore metamodel.
- Locate the file
Droid.ecore
in theorg.xtext.example.droid
project (the Xtext project). It is located at thesrc-gen
folder, inside theorg.xtext.example.droid
package. - Move the file to the
org.emf.example.droid
project (the EMF project). Place it under themodel
folder. - Create a new Genmodel file in the EMF project
- In the
model
folder, select theDroid.ecore
file and go to menu File > New > Other... - Eclipse Modeling Framework > EMF Generator Model
- Name the file
Droid.genmodel
and place it inside themodel
folder - Select
Ecore model
-
Browse workspace
and chose theDroid.ecore
file.
83b29c9f2d4c9f1e8e55393b750cc3d43c739efe
A genmodel is ...
To generate the code you must:
- Open the created
Droid.genmodel
file. - Click the menu
Generator > Generate All
We will not use the org.emf.example.droid.tests
. We will use only the editor related projects (org.emf.example.droid.edit
and org.emf.example.droid.editor
).
b41560c359e8aa695d7a9bf96be0d784e221fa07
- Create a folder named
model
inside theorg.emf.example.droid.edit
project - In the
org.emf.example.droid.emf
project, right-click theDroid.genmodel
file - Choose
EEF > Initialize EEF models
- As a destination folder, choose the
model
folder inside theorg.emf.example.droid.edit
project
This will create two files:
Droid.components
Droid.eefgen
f08d242e05a91b1c504fd8bc50191538bbf23915
In order to generate code from the EEF model, we need to prepare the Edit project (org.emf.example.droid.edit
).
The code generated by the EEF models will be placed in a src-gen
folder inside the project where the models reside. So we need to create this folder and add it to the build path.
- Right-click the
org.emf.example.droid.edit
project - Choose
Build Path > New Source Folder...
- Create a
src-gen
folder
Next step is adding the EEF runtime plugin as a dependency in the Edit plugin:
- Open
plugin.xml
file - Click the
Dependencies
tab - Click
Add
button and chooseorg.eclipse.emf.eef.runtime
plugin - Select the recently added
org.eclipse.emf.eef.runtime
plugin and clickProperties...
- Check
Reexport this dependency
option - Save the file
b9747e38780749a280ef146f40f94281899bec65
- Right click the
Droid.eefgen
file (in themodel
folder underorg.emf.example.droid.edit
project) - Choose
EEF > Generate EEF Architecture
Then you need to configure the plugin to export the generated package to the Editor plugin:
- Open
plugin.xml
- Click the
Runtime
tab - Click
Add
- Choose
droid.providers
package and clickOk
- Save the file
0bb04a1c2cbe6d9e4d9eaa599cc2d741e38c697b
In the Edit project (org.emf.example.droid.edit
):
- Open the
src-gen/droid_properties.plugin.xml
- Click the
Source
tab - Copy the content inside the
<plugin>
node - Open the
plugin.xml
- Paste the content inside the
<plugin>
node.
Note that you should not replace its content.
Now we need to replace the grid-based editor to a tab-based editor.
Open DroidEditor.java
in the Editor project (org.emf.example.droid.editor
)
- Add the
org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor
interface toDroidEditor
class.
Caution: You need to add@implements ITabbedPropertySheetPageContributor
inside the user section in the Javadoc in order to keep the code generation from reverting the changes.
//...
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
//...
/**
* This is an example of a Droid model editor.
* <!-- begin-user-doc -->
* @implements ITabbedPropertySheetPageContributor
* <!-- end-user-doc -->
* @generated
*/
public class DroidEditor
extends MultiPageEditorPart
implements IEditingDomainProvider, ISelectionProvider, IMenuListener, IViewerProvider, IGotoMarker, ITabbedPropertySheetPageContributor {
//...
- Implement the method
getContributorId()
/** (non-Javadoc)
* @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor#getContributorId()
* @generated NOT
*/
@Override
public String getContributorId() {
return PROPERTIES_CONTRIBUTOR;
}
and define your contributor ID
/**
* @generated NOT
*/
private static final String PROPERTIES_CONTRIBUTOR = "droid.properties";
finally we will replace the declaration of the Eclipse standard properties view by a tabbed properties view:
- Replace
/**
* This is the property sheet page.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected PropertySheetPage propertySheetPage;
with
/**
* This is the property sheet page.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
protected TabbedPropertySheetPage propertySheetPage;
- Replace
/**
* This accesses a cached version of the property sheet.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IPropertySheetPage getPropertySheetPage() {
if (propertySheetPage == null) {
propertySheetPage =
new ExtendedPropertySheetPage(editingDomain) {
@Override
public void setSelectionToViewer(List<?> selection) {
DroidEditor.this.setSelectionToViewer(selection);
DroidEditor.this.setFocus();
}
@Override
public void setActionBars(IActionBars actionBars) {
super.setActionBars(actionBars);
getActionBarContributor().shareGlobalActions(this, actionBars);
}
};
propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(adapterFactory));
}
return propertySheetPage;
}
with
/**
* This accesses a cached version of the property sheet.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public IPropertySheetPage getPropertySheetPage() {
if (propertySheetPage == null || propertySheetPage.getControl().isDisposed()) {
propertySheetPage = new TabbedPropertySheetPage(DroidEditor.this);
}
return propertySheetPage;
}
- Right-click the Editor project (
org.emf.example.droid.editor
) - Choose
Run As > Eclipse Application
- Create a new .droid file (or use an existing one)
- Open the .droid file with the generated Editor.
If you have the Xtext plugin installed, right-click the .droid file and chooseOpen With > Droid Model Editor
. If you have not installed the Xtext plugin, just double-click the .droid file.