<br style="clear:both;height:1em;"> | |
<div id="leftcol"> | |
<div class="nav-logo"> | |
<a href="index.php"><img src="logo.png" style="margin-left:10px; width:155px"/></a> | |
</div> | |
<ul id="leftnav"> | |
<li class="partentry" > | |
Documentation | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; display:none" /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="01-Introduction.php">Introduction</a></div> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; " /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="02-GettingStarted.php">Getting Started</a></div> | |
<ul style="display: none;" id="subToc_02-GettingStarted.html"> | |
<li id="02-GettingStarted.html#Installation.html" ><a href="02-GettingStarted.php#Installation.php" >Installation</a></li> | |
<li id="02-GettingStarted.html#FirstExample.html" ><a href="02-GettingStarted.php#FirstExample.php" >First Example</a></li> | |
<li id="02-GettingStarted.html#RCPMail.html" ><a href="02-GettingStarted.php#RCPMail.php" >RCP Mail Example</a></li> | |
</ul> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; " /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="03-Components.php">Components</a></div> | |
<ul style="display: none;" id="subToc_03-Components.html"> | |
<li id="03-Components.html#FormComponent.html" ><a href="03-Components.php#FormComponent.php" >Form Component</a></li> | |
<li id="03-Components.html#TreeComponent.html" ><a href="03-Components.php#TreeComponent.php" >Tree Component</a></li> | |
<li id="03-Components.html#TreeFormComponent.html" ><a href="03-Components.php#TreeFormComponent.php" >Tree Form Component</a></li> | |
<li id="03-Components.html#TableComponent.html" ><a href="03-Components.php#TableComponent.php" >Table Component</a></li> | |
</ul> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; " /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="04-Customization.php">Customization</a></div> | |
<ul style="display: none;" id="subToc_04-Customization.html"> | |
<li id="04-Customization.html#ResourceManagers.html" ><a href="04-Customization.php#ResourceManagers.php" >Managing Resources</a></li> | |
<li id="04-Customization.html#Providers.html" ><a href="04-Customization.php#Providers.php" >Providers</a></li> | |
<li id="04-Customization.html#SelectionAndMenu.html" ><a href="04-Customization.php#SelectionAndMenu.php" >Selection And Menu</a></li> | |
<li id="04-Customization.html#Builders.html" ><a href="04-Customization.php#Builders.php" >Builders</a></li> | |
<li id="04-Customization.html#Factories.html" ><a href="04-Customization.php#Factories.php" >Factories</a></li> | |
<li id="04-Customization.html#Viewers.html" ><a href="04-Customization.php#Viewers.php" >Viewers</a></li> | |
</ul> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; " /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="05-DSL.php">EMF Parsley DSL</a></div> | |
<ul style="display: none;" id="subToc_05-DSL.html"> | |
<li id="05-DSL.html#xbase.html" ><a href="05-DSL.php#xbase.php" >Xbase features</a></li> | |
</ul> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; display:none" /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="06-AdvancedComponents.php">Advanced Components</a></div> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; " /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="07-Eclipse4.php">Eclipse 4</a></div> | |
<ul style="display: none;" id="subToc_07-Eclipse4.html"> | |
<li id="07-Eclipse4.html#GetFirstExample.html" ><a href="07-Eclipse4.php#GetFirstExample.php" >First Example Setup</a></li> | |
<li id="07-Eclipse4.html#PrepareForEclipse4Application.html" ><a href="07-Eclipse4.php#PrepareForEclipse4Application.php" >Preparing for a pure Eclipse 4 Application</a></li> | |
<li id="07-Eclipse4.html#CreateEclipse4Application.html" ><a href="07-Eclipse4.php#CreateEclipse4Application.php" >Create an Eclipse 4 Application</a></li> | |
<li id="07-Eclipse4.html#Eclipse4ApplicationAndEMFParsley.html" ><a href="07-Eclipse4.php#Eclipse4ApplicationAndEMFParsley.php" >Using an EMF Parsley TreeComposite into an Eclipse 4 Part</a></li> | |
<li id="07-Eclipse4.html#Eclipse4Save.html" ><a href="07-Eclipse4.php#Eclipse4Save.php" >Adding the dirty state and Save command</a></li> | |
</ul> | |
</li> | |
<li class="partentry" > | |
Appendix | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; display:none" /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="GettingSources.php">Getting Sources</a></div> | |
</li> | |
<li class="separator"><div class="separator"> | |
<img src="triangle.gif" style="height:12px; margin-right: 2px; display:none" /><img src="triangle-90.gif" style="display:none; margin-right: 2px" height="12px" /> | |
<a href="Downloads.php">EMF Parsley - Downloads</a></div> | |
</li> | |
</ul> | |
</div> | |
<div id="midcolumn"> | |
<a name="Eclipse4" ></a> | |
<h1>Eclipse 4</h1> | |
<div class="toc"> | |
<ul> | |
<li><a href="07-Eclipse4.php#GetFirstExample.php" >First Example Setup</a></li> | |
<li><a href="07-Eclipse4.php#PrepareForEclipse4Application.php" >Preparing for a pure Eclipse 4 Application</a></li> | |
<li><a href="07-Eclipse4.php#CreateEclipse4Application.php" >Create an Eclipse 4 Application</a></li> | |
<li><a href="07-Eclipse4.php#Eclipse4ApplicationAndEMFParsley.php" >Using an EMF Parsley TreeComposite into an Eclipse 4 Part</a></li> | |
<li><a href="07-Eclipse4.php#Eclipse4Save.php" >Adding the dirty state and Save command</a></li> | |
</ul> | |
</div> | |
<p> | |
Instead of using the Extension Point mechanism, EMF Parsley leverages from DSL and Google Guice Injection. | |
</p> | |
<p> | |
Because of this, it is very easy to use it with Eclipse 4. | |
</p> | |
<a name="GetFirstExample" ></a> | |
<span style="float:left; border-top: 1px dotted #d4d4dd; margin-left: 0; margin-top: 5px; | |
padding: 5px 0; | |
padding-top: 5px;"></span><a style="float: right" href="#">Top</a> | |
<br style="clear:both"></br> | |
<h1>First Example Setup</h1> | |
<p> | |
If you followed the steps described in section <a href="02-GettingStarted.php" title="Go to "Getting Started"">Getting Started</a> you will have already | |
what we need to begin. Otherwise the following wizard will bring you to that point. | |
</p> | |
<p> | |
<ol> | |
<li>File -> New... -> Example...</li> | |
<li>from Category "Emf Parsley Examples", select "Emf Parsley First Example"</li> | |
<li>press Next and Finish</li> | |
</ol> | |
</p> | |
<p> | |
You will end up with three plug-ins: | |
</p> | |
<p> | |
<ul> | |
<li>org.eclipse.emf.parsley.examples.firstexample (the EMF Parsley example plug-in)</li> | |
<li>org.eclipse.emf.examples.library (the model plug-in)</li> | |
<li>org.eclipse.emf.examples.library.edit (the model.edit plug-in)</li> | |
</ul> | |
</p> | |
<p> | |
As a reminder, in section <a href="02-GettingStarted.php" title="Go to "Getting Started"">Getting Started</a> we reached the point where we launched a second Eclipse | |
instance (but, of course, just defining a product you could have a standalone 3.x application) with a | |
view (called "My Library Tree Form") that allowed to manage the model. | |
</p> | |
<a name="PrepareForEclipse4Application" ></a> | |
<span style="float:left; border-top: 1px dotted #d4d4dd; margin-left: 0; margin-top: 5px; | |
padding: 5px 0; | |
padding-top: 5px;"></span><a style="float: right" href="#">Top</a> | |
<br style="clear:both"></br> | |
<h1>Preparing for a pure Eclipse 4 Application</h1> | |
<p> | |
What we will do now is starting from the previous step and create an Eclipse 4 Application (on top of | |
the previous plug-ins) that gets to the same result, but now with a pure Eclipse 4 Part. | |
</p> | |
<p> | |
In order to do this we need to export the <em>"org.eclipse.emf.parsley.examples.firstexample"</em> package from the first plug-in. | |
</p> | |
<a name="CreateEclipse4Application" ></a> | |
<span style="float:left; border-top: 1px dotted #d4d4dd; margin-left: 0; margin-top: 5px; | |
padding: 5px 0; | |
padding-top: 5px;"></span><a style="float: right" href="#">Top</a> | |
<br style="clear:both"></br> | |
<h1>Create an Eclipse 4 Application</h1> | |
<p> | |
Now let's create a new, empty, Eclipse 4 application, e.g. <em>"org.eclipse.emf.parsley.examples.firstexample.application"</em> | |
(you can find details on how to create Eclipse 4 applications in <a href="http://www.rcp-vision.com/?p=4694&lang=en" >our | |
tutorials</a>). | |
</p> | |
<p> | |
Create a Part and ensure that the application starts. | |
</p> | |
<a name="Eclipse4ApplicationAndEMFParsley" ></a> | |
<span style="float:left; border-top: 1px dotted #d4d4dd; margin-left: 0; margin-top: 5px; | |
padding: 5px 0; | |
padding-top: 5px;"></span><a style="float: right" href="#">Top</a> | |
<br style="clear:both"></br> | |
<h1>Using an EMF Parsley TreeComposite into an Eclipse 4 Part</h1> | |
<p> | |
In the just created plug-in we need dependencies from the previous plug-ins: so open the <em>org.eclipse.emf.parsley.examples.firstexample.application/MANIFEST.MF</em> file, go to <em>Dependencies</em> | |
tab and add the three previous plug-ins. Add also <em>"org.eclipse.emf.parsley"</em> plug-in. | |
Don't forget to add the previous, and the required plug-ins, also to the Product. | |
</p> | |
<p> | |
Open the Part java class and make the following changes: | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
<span class="comment">// Use these imports during Organizing Imports operation<br/> | |
</span><span class="keyword">import</span> org.eclipse.emf.common.util.URI;<br/> | |
<span class="keyword">import</span> org.eclipse.emf.ecore.resource.Resource;<br/> | |
<span class="keyword">import</span> org.eclipse.swt.widgets.Composite; | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
<span class="comment">// The part implements IMenuListener for context menu handling<br/> | |
</span>public class MyEclipse4Part implements IMenuListener | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
<span class="comment">//the parent composite<br/> | |
</span>private Composite parent;<br/> | |
<span class="comment">//the EMF Parley composite for showing a tree and a detail form<br/> | |
</span>private TreeFormComposite treeFormComposite;<br/> | |
<span class="comment">//the EMF Resource<br/> | |
</span>private Resource resource;<br/> | |
<br/> | |
<span class="comment">//Guice injected EMF Parsley component for contributing to the tree context menu<br/> | |
</span>private TreeActionBarContributor treeActionBarContributor = FirstexampleActivator.getDefault().getInjector()<br/> | |
<br/> | |
.getInstance(TreeActionBarContributor.class);<br/> | |
<br/> | |
<br/> | |
<span class="comment">//Guice injected EMF Parsley factory for the tree detail form<br/> | |
</span>private TreeFormFactory treeFormFactory = FirstexampleActivator.getDefault().getInjector()<br/> | |
<br/> | |
.getInstance(TreeFormFactory.class);<br/> | |
<br/> | |
<span class="comment">//Guice injected EMF Parsley Resource loader<br/> | |
</span>private ResourceLoader resourceLoader = FirstexampleActivator.getDefault().getInjector()<br/> | |
<br/> | |
.getInstance(ResourceLoader.class);<br/> | |
<br/> | |
<span class="comment">//Guice injected EMF Parsley editing domain<br/> | |
</span>private AdapterFactoryEditingDomain editingDomain = FirstexampleActivator.getDefault().getInjector()<br/> | |
<br/> | |
.getInstance(AdapterFactoryEditingDomain.class);<br/> | |
<br/> | |
<span class="comment">//Guice injected viewer initializer<br/> | |
</span>private ViewerInitializer viewerInitializer = (ViewerInitializer) FirstexampleActivator.getDefault().getInjector()<br/> | |
<br/> | |
.getInstance(ViewerInitializer.class);<br/> | |
<br/> | |
<span class="comment">//Guice injected save manager<br/> | |
</span>private ResourceSaveManager resourceSaveManager = FirstexampleActivator.getDefault().getInjector()<br/> | |
<br/> | |
.getInstance(ResourceSaveManager.class);<br/> | |
<br/> | |
<span class="comment">//URI for EMF Resource<br/> | |
</span>private URI uri = URI.createFileURI(System.getProperty(<span class="string">"user.home"</span>)<br/> | |
<br/> | |
+ <span class="string">"/MyLibrary.library"</span>); | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
Modify the <em>@PostConstruct</em> method with this code: | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
@PostConstruct<br/> | |
public void postConstruct(Composite parent) {<br/> | |
this.parent = parent;<br/> | |
<br/> | |
<span class="comment">// Initialize TreeFormFactory & ResourceLoader<br/> | |
</span> init(treeFormFactory, resourceLoader);<br/> | |
<br/> | |
<span class="comment">// Prepare the menu action bar contributor upon the selection<br/> | |
</span> treeFormComposite.getViewer().addSelectionChangedListener(treeActionBarContributor);<br/> | |
<br/> | |
} | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
and add the following methods: | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
public void init(TreeFormFactory treeFormFactory, ResourceLoader resourceLoader) {<br/> | |
<span class="comment">//create the tree-form composite<br/> | |
</span> treeFormComposite = treeFormFactory.createTreeFormMasterDetailComposite(parent, SWT.BORDER);<br/> | |
<span class="comment">//load the resource<br/> | |
</span> resource = resourceLoader.getResource(editingDomain, uri).getResource();<br/> | |
<span class="comment">//update the composite<br/> | |
</span> treeFormComposite.update(resource);<br/> | |
<span class="comment">//initialize and bind the context menu to the tree-form composite<br/> | |
</span> treeActionBarContributor.initialize(editingDomain);<br/> | |
viewerInitializer.addContextMenu(<br/> | |
treeFormComposite.getViewer(), treeActionBarContributor, editingDomain, this);<br/> | |
}<br/> | |
<br/> | |
<br/> | |
@Override<br/> | |
public void menuAboutToShow(IMenuManager manager) {<br/> | |
treeActionBarContributor.menuAboutToShow(manager);<br/> | |
} | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
If you now run the application you will be able to manage the model: | |
</p> | |
<p> | |
<div class="image" > | |
<a class="gallery" rel="prettyPhoto[all]" title="" href="images/07-eclipse4-part.png"> | |
<img src="images/07-eclipse4-part.png" | |
width="600px" | |
/> | |
</a> | |
<div class="caption"> | |
</div> | |
</div> | |
</p> | |
<p> | |
but you will notice that it is not possible to persist the changes to the model. | |
</p> | |
<a name="Eclipse4Save" ></a> | |
<span style="float:left; border-top: 1px dotted #d4d4dd; margin-left: 0; margin-top: 5px; | |
padding: 5px 0; | |
padding-top: 5px;"></span><a style="float: right" href="#">Top</a> | |
<br style="clear:both"></br> | |
<h1>Adding the dirty state and Save command</h1> | |
<p> | |
In order to allow persisting the model changes we have to add the dirty state handling to the part and | |
the Save command to the application. | |
Let's start with adding the following attribute to the part | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
@Inject<br/> | |
MDirtyable dirtyable; | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
initialize it in the <em>@PostConstruct</em> method | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
@PostConstruct<br/> | |
public void postConstruct(Composite parent, MDirtyable dirtyable) {<br/> | |
<br/> | |
this.dirtyable = dirtyable;<br/> | |
<br/> | |
this.dirtyable.setDirty(false); | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
add to <em>init</em> method the following code in order to update the dirty state | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
editingDomain.getCommandStack().addCommandStackListener(<br/> | |
new CommandStackListener() {<br/> | |
public void commandStackChanged(EventObject event) {<br/> | |
if (dirtyable != null)<br/> | |
dirtyable.setDirty(true);<br/> | |
}<br/> | |
}); | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
and add the <em>@Persist</em> method, which will be called when the part is saved | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
@Persist<br/> | |
public void save(MDirtyable dirty) throws IOException {<br/> | |
if (resourceSaveManager.save(resource)) {<br/> | |
<br/> | |
if (dirty != null) {<br/> | |
<br/> | |
dirty.setDirty(false);<br/> | |
<br/> | |
}<br/> | |
<br/> | |
}<br/> | |
} | |
</p> | |
</div> | |
</div> | |
</p> | |
<p> | |
and, in the end, add the <em>Save</em> handler along with the correspondent <em>Command</em> and <em>Menu</em> | |
(you can find how to create handlers, commands and menus in an Eclipse 4 applications in <a href="http://www.rcp-vision.com/?p=4972&lang=en" >our | |
tutorials</a>) | |
</p> | |
<p> | |
<div class="literallayout"> | |
<div class="incode"> | |
<p class="code"> | |
public class SaveHandler {<br/> | |
<br/> | |
@Execute<br/> | |
void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) {<br/> | |
<br/> | |
partService.savePart(part, false);<br/> | |
}<br/> | |
<br/> | |
} | |
</p> | |
</div> | |
</div> | |
</p> | |
<div id="disqus_thread"></div> | |
<script type="text/javascript" src="documentationRoot.js"></script> | |
<script type="text/javascript"> | |
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ | |
var disqus_shortname = 'xtext'; // required: replace example with your forum shortname | |
// The following are highly recommended additional parameters. Remove the slashes in front to use. | |
var disqus_identifier = 'Eclipse4'; | |
var disqus_url = documentationRoot+'07-Eclipse4.php'; | |
/* * * DON'T EDIT BELOW THIS LINE * * */ | |
(function() { | |
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | |
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; | |
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | |
})(); | |
</script> | |
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> | |
</div> | |
<br style="clear:both;height:1em;"> |