| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" > |
| <title>Customization</title> |
| |
| <link href="book.css" rel="stylesheet" type="text/css"> |
| <link href="code.css" rel="stylesheet" type="text/css"> |
| <link rel="home" href="xtext.html" title=""> |
| </head> |
| <body> |
| <a name="Customization"></a> |
| <h1>Customization</h1> |
| <a name="ResourceManagers"></a> |
| <h2>Managing Resources</h2> |
| <a name="ResourceLoader"></a> |
| <h3>Resource Loader</h3> |
| <p> |
| The class <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/resource/ResourceLoader.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.resource.ResourceLoader" >ResourceLoader</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/resource/ResourceLoader.java" title="View Source Code" >(src)</a> can be used to handle resource loading. |
| This class uses internally the <a href="04-Customization.html#EmptyResourceInitializer" title="Go to "Empty Resource Initializer"">Empty Resource Initializer</a>. |
| </p> |
| <a name="EmptyResourceInitializer"></a> |
| <h3>Empty Resource Initializer</h3> |
| <p> |
| If you need to initialize your model, for the first use, you can define an implementation of <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/resource/EmptyResourceInitializer.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.resource.EmptyResourceInitializer" >EmptyResourceInitializer</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/resource/EmptyResourceInitializer.java" title="View Source Code" >(src)</a>. |
| When the main resource will be found empty, your code will be executed. |
| </p> |
| <a name="EditingDomainFinder"></a> |
| <h3>Editing Domain Finder</h3> |
| <p> |
| The class <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/edit/EditingDomainFinder.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.edit.EditingDomainFinder" >EditingDomainFinder</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/edit/EditingDomainFinder.java" title="View Source Code" >(src)</a> can be inherited to provide a specific |
| way to find the editign domain. |
| </p> |
| <a name="ResourceSaveManager"></a> |
| <h3>Resource Save Manager</h3> |
| <p> |
| Resource saving is delegated to <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/edit/ResourceSaveManager.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.edit.ResourceSaveManager" >ResourceSaveManager</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/edit/ResourceSaveManager.java" title="View Source Code" >(src)</a> |
| which, by defaults only saves the passed <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/ecore/resource/Resource.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.resource.Resource" >Resource</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/Resource.java" title="View Source Code" >(src)</a>. |
| You can inject your own save manager and implement the method <span class="inlinecode">precondition(Resource)</span>, for |
| instance, you may want to validate the resource before saving, and in case the validation |
| fails to return <span class="inlinecode">false</span>. If the precondition is <span class="inlinecode">false</span> the default implementation |
| will not save the resource (and in turn will return <span class="inlinecode">false</span>). |
| </p> |
| <a name="ValidateResourceSaveManager"></a> |
| <h4>Validate Resource Save Manager</h4> |
| <p> |
| We provide an example of custom resource save manager: <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/edit/ValidateResourceSaveManager.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.edit.ValidateResourceSaveManager" >ValidateResourceSaveManager</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/edit/ValidateResourceSaveManager.java" title="View Source Code" >(src)</a>, |
| we show here only relevant parts to give an example: |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> <span class="keyword">class</span> ValidateResourceSaveManager <span class="keyword">extends</span> ResourceSaveManager { |
| <br/> |
| @Override |
| <br/> |
| <span class="keyword">protected</span> <span class="keyword">boolean</span> precondition(Resource resource) { |
| <br/> |
| <span class="keyword">return</span> <span class="keyword">super</span>.precondition(resource) && validateModel(resource); |
| <br/> |
| } |
| <br/> |
| <span class="keyword">protected</span> <span class="keyword">boolean</span> validateModel(Resource resource) { |
| <br/> |
| <span class="keyword">for</span> (EObject eObject : resource.getContents()) { |
| <br/> |
| Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject); |
| <br/> |
| <span class="keyword">if</span> (diagnostic.getSeverity() == Diagnostic.ERROR) { |
| <br/> |
| <span class="comment">// SKIPPED: present the errors |
| <br/> |
| </span> <span class="keyword">return</span> false; |
| <br/> |
| } <span class="keyword">else</span> <span class="keyword">if</span> (diagnostic.getSeverity() == Diagnostic.WARNING) { |
| <br/> |
| <span class="comment">// SKIPPED: present the warnings |
| <br/> |
| </span> } |
| <br/> |
| } |
| <br/> |
| <span class="keyword">return</span> true; |
| <br/> |
| } |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <a name="Providers"></a> |
| <h2>Providers</h2> |
| <a name="FeaturesProvider"></a> |
| <h3>Features Provider</h3> |
| <p> |
| <em>This can be done with Parsley DSL too!</em> |
| |
| <div class="todo" > |
| TODO: merge delle 2 versioni |
| </div> |
| </p> |
| <a name="FeatureProvider1"></a> |
| <h4>Prima versione</h4> |
| <p> |
| To customize the <em>feature list</em> it can be injected a <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/FeaturesProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.FeaturesProvider" >FeaturesProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/FeaturesProvider.java" title="View Source Code" >(src)</a>. |
| The default is to return the list of all the features in the EClass, but the programmer can customize it (for instance, |
| by returning only a superset, or using a different order) on an EClass-based strategy. The customization can be done |
| redefining buildMap and adding mappings. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">protected</span> <span class="keyword">void</span> buildMap(EClassToEStructuralFeatureMap map) { |
| <br/> |
| <span class="keyword">super</span>.buildMap(map); |
| <br/> |
| map.mapTo(LIBRARY,LIBRARY__NAME, ADDRESSABLE__ADDRESS); |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <p> |
| In the example we specify that for the EClass <em>Library</em> the feature that are to be displayed are <em>name</em> |
| and <em>address</em>. |
| </p> |
| <a name="FeatureProvider2"></a> |
| <h4>Seconda versione</h4> |
| <p> |
| When the framework builds components according to the |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/ecore/EStructuralFeature.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.EStructuralFeature" >EStructuralFeature</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EStructuralFeature.java" title="View Source Code" >(src)</a>s of a given |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/ecore/EClass.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.EClass" >EClass</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a> it relies on an injected |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/FeaturesProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.FeaturesProvider" >FeaturesProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/FeaturesProvider.java" title="View Source Code" >(src)</a>. |
| The default behavior is to simply return all the features of the a given EClass, |
| in the order they are defined in the EClass; |
| you may want to provide a custom implementation by redefining |
| the method <span class="inlinecode">List<EStructuralFeature> getFeatures(EClass)</span>, or |
| <span class="inlinecode">List<EStructuralFeature> getFeatures(EObject)</span>, |
| for instance by returning the features ordered according to their name |
| (the following snippet uses an utility class from the framework) |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> <span class="keyword">class</span> OrderedEStructuralFeaturesProvider |
| <br/> |
| <span class="keyword">extends</span> FeaturesProvider { |
| <br/> |
| @Inject |
| <br/> |
| EStructuralFeatureNameComparator comparator; |
| <br/> |
| <br/> |
| @Override |
| <br/> |
| <span class="keyword">public</span> List<EStructuralFeature> getFeatures(EClass eClass) { |
| <br/> |
| List<EStructuralFeature> features = <span class="keyword">super</span>.getFeatures(eClass); |
| <br/> |
| Collections.sort(features, |
| <br/> |
| <span class="keyword">new</span> EStructuralFeatureNameComparator()); |
| <br/> |
| <span class="keyword">return</span> features; |
| <br/> |
| } |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <p> |
| Alternatively, you can set the mappings, i.e., specify the structural |
| features you want to be used given an EClass, by implementing |
| the method <span class="inlinecode">buildMap</span>, which receives the |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/FeaturesProvider.EClassToEStructuralFeatureMap.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.FeaturesProvider.EClassToEStructuralFeatureMap" >FeaturesProvider.EClassToEStructuralFeatureMap</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/FeaturesProvider.java" title="View Source Code" >(src)</a> |
| that can be filled with the method <span class="inlinecode">mapTo</span>; |
| for instance, using the EMF extended library |
| example, this customization will return only the <em>name</em> and <em>address</em> features |
| for <span class="inlinecode">Library</span>, the <em>firstName</em>, <em>lastName</em> and <em>address</em> for |
| <span class="inlinecode">Person</span>, and the <em>firstName</em>, <em>lastName</em> and <em>books</em> (but |
| not <em>address</em>) for <span class="inlinecode">Writer</span> (which inherits from <span class="inlinecode">Person</span>). |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">import</span> <span class="keyword">static</span> org.eclipse.emf.examples.extlibrary.EXTLibraryPackage.Literals.*; |
| <br/> |
| <span class="keyword">import</span> org.eclipse.emf.parsley.ui.provider.EStructuralFeaturesProvider; |
| <br/> |
| <span class="keyword">public</span> <span class="keyword">class</span> LibraryEStructuralFeaturesProvider <span class="keyword">extends</span> |
| <br/> |
| FeaturesProvider { |
| <br/> |
| @Override |
| <br/> |
| <span class="keyword">protected</span> <span class="keyword">void</span> buildMap(EClassToEStructuralFeatureMap map) { |
| <br/> |
| <span class="keyword">super</span>.buildMap(map); |
| <br/> |
| map.mapTo(LIBRARY, |
| <br/> |
| LIBRARY__NAME, ADDRESSABLE__ADDRESS); |
| <br/> |
| map.mapTo(PERSON, |
| <br/> |
| PERSON__FIRST_NAME, PERSON__LAST_NAME, |
| <br/> |
| ADDRESSABLE__ADDRESS); |
| <br/> |
| map.mapTo(WRITER, |
| <br/> |
| PERSON__FIRST_NAME, PERSON__LAST_NAME, |
| <br/> |
| WRITER__BOOKS); |
| <br/> |
| } |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <p> |
| Another possibility is to build a map which relies on Strings |
| both for the <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/ecore/EClass.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.EClass" >EClass</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a> and for |
| the list of <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/ecore/EStructuralFeature.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.EStructuralFeature" >EStructuralFeature</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EStructuralFeature.java" title="View Source Code" >(src)</a>; |
| note that the name of the <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/ecore/EClass.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.EClass" >EClass</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a> should |
| be obtained by using <span class="inlinecode">getInstanceClassName()</span>; you can also |
| combine the two approaches (in that case the map built with |
| <span class="inlinecode">buildMap</span> has the precedence): |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">import</span> <span class="keyword">static</span> org.eclipse.emf.examples.extlibrary.EXTLibraryPackage.Literals.*; |
| <br/> |
| <span class="keyword">import</span> org.eclipse.emf.parsley.ui.provider.FeaturesProvider; |
| <br/> |
| <span class="keyword">public</span> <span class="keyword">class</span> LibraryEStructuralFeaturesAsStringsProvider <span class="keyword">extends</span> |
| <br/> |
| FeaturesProvider { |
| <br/> |
| @Override |
| <br/> |
| <span class="keyword">protected</span> <span class="keyword">void</span> buildMap(EClassToEStructuralFeatureMap map) { |
| <br/> |
| <span class="keyword">super</span>.buildMap(map); |
| <br/> |
| map.mapTo(LIBRARY, LIBRARY__NAME, ADDRESSABLE__ADDRESS); |
| <br/> |
| } |
| <br/> |
| @Override |
| <br/> |
| <span class="keyword">protected</span> <span class="keyword">void</span> buildStringMap( |
| <br/> |
| EClassToEStructuralFeatureAsStringsMap stringMap) { |
| <br/> |
| <span class="keyword">super</span>.buildStringMap(stringMap); |
| <br/> |
| stringMap.mapTo(PERSON.getInstanceClassName(), <span class="string">"firstName"</span>, <span class="string">"lastName"</span>, |
| <br/> |
| <span class="string">"address"</span>); |
| <br/> |
| stringMap.mapTo(WRITER.getInstanceClassName(), <span class="string">"firstName"</span>, <span class="string">"lastName"</span>, |
| <br/> |
| <span class="string">"books"</span>); |
| <br/> |
| } |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <a name="FeaturesColumnProvider"></a> |
| <h4>Features Column Provider</h4> |
| <p> |
| As an extension, you can use the <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/FeaturesColumnProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.FeaturesColumnProvider" >FeaturesColumnProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/FeaturesColumnProvider.java" title="View Source Code" >(src)</a>: |
| the customizations will be applied only to <a href="03-Components.html#TableComponent" title="Go to "Table Component"">tables</a>, not to <a href="03-Components.html#FormComponent" title="Go to "Form Component"">Forms</a>. |
| </p> |
| <a name="PropertyDescriptionProvider"></a> |
| <h3>Property Description Provider</h3> |
| <p> |
| <em>This can be done with Parsley DSL too!</em> |
| |
| The <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/PropertyDescriptionProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.PropertyDescriptionProvider" >PropertyDescriptionProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/PropertyDescriptionProvider.java" title="View Source Code" >(src)</a> provides labels for |
| the features. It can be customized, with injection (see Injection paragraph), to customize the label on the |
| left of each control. The framework use a polimorphic mechanism to find customizations, so that It can |
| be written a method with a specific signature build by the keyword <em>'text'</em> followed by the EClass and the EStructuralFeature. |
| All parts of the name are separated by an underscore character and the method must accept a parameter of type EStructuralFeature. |
| </p> |
| <p> |
| In the following example we specify the label text for the feature 'Author' of Book and the feature 'Name' for |
| Writer. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> String text_Book_author(<span class="keyword">final</span> EStructuralFeature feature) { |
| <br/> |
| <span class="keyword">return</span> <span class="string">"Wrote by:"</span>; |
| <br/> |
| } |
| <br/> |
| |
| <br/> |
| <span class="keyword">public</span> String text_Writer_name(<span class="keyword">final</span> EStructuralFeature feature) { |
| <br/> |
| <span class="keyword">return</span> <span class="string">"Name:"</span>; |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <p> |
| Another chance of customization is to define a method the returns directly the control, like in the example |
| below. In this case there is another parameter that is the parent composite. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> Label label_Writer_name(Composite parent, EStructuralFeature feature) { |
| <br/> |
| Label label = defaultLabel(parent, feature); |
| <br/> |
| label.setBackground(getFormToolkit().getColors().getColor(IFormColors.TITLE)); |
| <br/> |
| <span class="keyword">return</span> label; |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <a name="FormPropertyDescriptionProvider"></a> |
| <h4>Form Property Description Provider</h4> |
| <p> |
| The <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/FormPropertyDescriptionProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.FormPropertyDescriptionProvider" >FormPropertyDescriptionProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/FormPropertyDescriptionProvider.java" title="View Source Code" >(src)</a> can be used if you want |
| to define the description only for the form. For example using the <a href="03-Components.html#TreeFormComponent" title="Go to "Tree Form Component"">Tree |
| Form</a> your definition will not be used in the tree. |
| </p> |
| <a name="ViewerLabelProvider"></a> |
| <h3>Viewer Label Provider</h3> |
| <p> |
| The Label Provider can be customized by providing a specific implementation of <a class="jdoc" href="http://help.eclipse.org/helios/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/viewers/ILabelProvider.html" title="View JavaDoc"><abbr title="org.eclipse.jface.viewers.ILabelProvider" >ILabelProvider</abbr></a> |
| and injecting it in the spefic module <em>(TODO)</em>. |
| EMF Components provides such an implementation with the class <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/ViewerLabelProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.ViewerLabelProvider" >ViewerLabelProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/ViewerLabelProvider.java" title="View Source Code" >(src)</a> |
| that is inteded to be surclassed by the programmer to provides specific implementations like in the example below. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> <span class="keyword">class</span> CustomLibraryLabelProvider <span class="keyword">extends</span> ViewerLabelProvider { |
| <br/> |
| |
| <br/> |
| @Inject |
| <br/> |
| <span class="keyword">public</span> CustomLibraryLabelProvider(AdapterFactoryLabelProvider delegate) { |
| <br/> |
| <span class="keyword">super</span>(delegate); |
| <br/> |
| } |
| <br/> |
| |
| <br/> |
| <span class="keyword">public</span> String text(Book book) { |
| <br/> |
| <span class="keyword">return</span> <span class="string">"Book: "</span> + book.getTitle(); |
| <br/> |
| } |
| <br/> |
| |
| <br/> |
| <span class="keyword">public</span> String image(Book book) { |
| <br/> |
| <span class="keyword">return</span> <span class="string">"book2.png"</span>; |
| <br/> |
| } |
| <br/> |
| |
| <br/> |
| <span class="keyword">public</span> String text(Borrower b) { |
| <br/> |
| <span class="keyword">return</span> <span class="string">"Borrower: "</span> + b.getFirstName(); |
| <br/> |
| } |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <a name="ViewerContentProvider"></a> |
| <h3>Viewer Content Provider</h3> |
| <p> |
| The programmer can provide a specific implementation of <a class="jdoc" href="http://help.eclipse.org/helios/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/viewers/IContentProvider.html" title="View JavaDoc"><abbr title="org.eclipse.jface.viewers.IContentProvider" >IContentProvider</abbr></a> |
| by injecting it in the spefic module <em>(TODO)</em>. EMF Components provides an implementation with the class |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/edit/ui/provider/ViewerContentProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.edit.ui.provider.ViewerContentProvider" >ViewerContentProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/edit/ui/provider/ViewerContentProvider.java" title="View Source Code" >(src)</a> that can be easily used to |
| specify the children of all object on the tree, like in the example below. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> <span class="keyword">class</span> CustomLibraryViewerContentProvider <span class="keyword">extends</span> ViewerContentProvider { |
| <br/> |
| |
| <br/> |
| @Inject |
| <br/> |
| <span class="keyword">public</span> CustomLibraryViewerContentProvider(AdapterFactory adapterFactory) { |
| <br/> |
| <span class="keyword">super</span>(adapterFactory); |
| <br/> |
| } |
| <br/> |
| |
| <br/> |
| <span class="keyword">public</span> Object children(Library library) { |
| <br/> |
| <span class="keyword">return</span> library.getBooks(); |
| <br/> |
| } |
| <br/> |
| |
| <br/> |
| <span class="keyword">public</span> Object children(Book book) { |
| <br/> |
| ArrayList<Object> children = <span class="keyword">new</span> ArrayList<Object>(); |
| <br/> |
| Writer author = book.getAuthor(); |
| <br/> |
| <span class="keyword">if</span> (author != null) { |
| <br/> |
| children.add(author); |
| <br/> |
| } |
| <br/> |
| children.addAll(book.getBorrowers()); |
| <br/> |
| <span class="keyword">return</span> children; |
| <br/> |
| } |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <a name="ProposalProvider"></a> |
| <h3>Proposal Provider</h3> |
| <p> |
| <em>This can be done with Parsley DSL too!</em> |
| |
| Some controls use a list of proposal to help the end user experince: for example the combo box has a |
| list of proposal, but also the simple text can use the proposal to assist and correct the hand-writed |
| values. For each feature it can be specified a list of proposals using a method that starts with the |
| keyword <em>'proposals'</em> followed byt the EClass and Feature undescore-character-separated. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> List<?> proposals_Book_author(Book book) { |
| <br/> |
| List<Object> proposals = <span class="keyword">new</span> LinkedList<Object>(); |
| <br/> |
| Writer writer = EXTLibraryFactory.eINSTANCE.createWriter(); |
| <br/> |
| writer.setFirstName(<span class="string">"Fake"</span>); |
| <br/> |
| writer.setLastName(<span class="string">"Writer"</span>); |
| <br/> |
| proposals.add(writer); |
| <br/> |
| writer = EXTLibraryFactory.eINSTANCE.createWriter(); |
| <br/> |
| writer.setFirstName(<span class="string">"Fake"</span>); |
| <br/> |
| writer.setLastName(<span class="string">"Writer2"</span>); |
| <br/> |
| proposals.add(writer); |
| <br/> |
| <span class="keyword">return</span> proposals; |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <a name="ViewerContextMenuFactory"></a> |
| <h3>Viewer Context Menu Factory</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/menus/ViewerContextMenuFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.menus.ViewerContextMenuFactory" >ViewerContextMenuFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/menus/ViewerContextMenuFactory.java" title="View Source Code" >(src)</a> |
| </p> |
| <a name="TableColumnLabelProvider"></a> |
| <h3>Table Column Label Provider</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/ui/provider/TableColumnLabelProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.ui.provider.TableColumnLabelProvider" >TableColumnLabelProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/TableColumnLabelProvider.java" title="View Source Code" >(src)</a> |
| </p> |
| <a name="SelectionAndMenu"></a> |
| <h2>Selection And Menu</h2> |
| <a name="EmfSelectionHelper"></a> |
| <h3>Emf Selection Helper</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/util/EmfSelectionHelper.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.util.EmfSelectionHelper" >EmfSelectionHelper</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/util/EmfSelectionHelper.java" title="View Source Code" >(src)</a> |
| </p> |
| <a name="Builders"></a> |
| <h2>Builders</h2> |
| <a name="TableViewerBuilder"></a> |
| <h3>Table Viewer Builder</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/builders/TableViewerBuilder.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.builders.TableViewerBuilder" >TableViewerBuilder</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/builders/TableViewerBuilder.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#TableViewerColumnBuilder" title="Go to "Table Viewer Column Builder"">TableViewerColumnBuilder</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#ViewerInitializer" title="Go to "Viewer Initializer"">ViewerInitializer</a> |
| </li> |
| </ul> |
| </p> |
| <a name="TableViewerColumnBuilder"></a> |
| <h3>Table Viewer Column Builder</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/builders/TableViewerColumnBuilder.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.builders.TableViewerColumnBuilder" >TableViewerColumnBuilder</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/builders/TableViewerColumnBuilder.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#JfaceProviderFactory" title="Go to "Jface Provider Factory"">JfaceProviderFactory</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#PropertyDescriptionProvider" title="Go to "Property Description Provider"">PropertyDescriptionProvider</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#FeaturesProvider" title="Go to "Features Provider"">FeaturesProvider</a> |
| </li> |
| </ul> |
| </p> |
| <a name="TableViewerEditableColumnBuilder"></a> |
| <h4>Table Viewer Editable Column Builder</h4> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/builders/TableViewerEditableColumnBuilder.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.builders.TableViewerEditableColumnBuilder" >TableViewerEditableColumnBuilder</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/builders/TableViewerEditableColumnBuilder.java" title="View Source Code" >(src)</a> |
| </p> |
| <a name="Factories"></a> |
| <h2>Factories</h2> |
| <a name="FormFactory"></a> |
| <h3>Form Factory</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/factories/FormFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.factories.FormFactory" >FormFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/factories/FormFactory.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#FormPropertyDescriptionProvider" title="Go to "Form Property Description Provider"">FormPropertyDescriptionProvider</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#FormControlFactory" title="Go to "Form Control Factory"">Form Control Factory</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#EditingDomainFinder" title="Go to "Editing Domain Finder"">EditingDomainFinder</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#JfaceProviderFactory" title="Go to "Jface Provider Factory"">JfaceProviderFactory</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#FeaturesProvider" title="Go to "Features Provider"">FeaturesProvider</a> |
| </li> |
| </ul> |
| </p> |
| <a name="JfaceProviderFactory"></a> |
| <h3>Jface Provider Factory</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/factories/ColumnLabelProviderFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.factories.ColumnLabelProviderFactory" >ColumnLabelProviderFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/factories/ColumnLabelProviderFactory.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#ViewerLabelProvider" title="Go to "Viewer Label Provider"">ViewerLabelProvider</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#TableColumnLabelProvider" title="Go to "Table Column Label Provider"">TableColumnLabelProvider</a> |
| </li> |
| </ul> |
| </p> |
| <a name="FormControlFactory"></a> |
| <h3>Form Control Factory</h3> |
| <p> |
| <em>This can be done with Parsley DSL too!</em> |
| |
| If you want to customize the controls on the right, it can be injected a specification of the class <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/binding/FormControlFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.binding.FormControlFactory" >FormControlFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/binding/FormControlFactory.java" title="View Source Code" >(src)</a>. |
| Using the same polimorphic mechanism of the labels, the programmer can write a method with the keyword <em>'control'</em> |
| followed by the EClass and EStructuralFeature undescore-character-separated. In the signature of the |
| method must be both the <em>DataBinding Context</em> and the <em>Feature Observable</em> that can be used for databinding. |
| </p> |
| <p> |
| <div class="literallayout"> |
| <div class="incode"> |
| <p class="code"> |
| <span class="keyword">public</span> Control control_Writer_name(DataBindingContext dbc,IObservableValue featureObservable) { |
| <br/> |
| <span class="comment">//Creating the control |
| <br/> |
| </span> Text text = getToolkit().createText(getParent(), <span class="string">""</span>); |
| <br/> |
| text.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); |
| <br/> |
| text.setBackground(getToolkit().getColors().getColor(IFormColors.TITLE)); |
| <br/> |
| <span class="comment">//Binding the control to the feature observable |
| <br/> |
| </span> dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), featureObservable); |
| <br/> |
| <span class="keyword">return</span> text; |
| <br/> |
| } |
| <br/> |
| </p> |
| </div> |
| </div> |
| </p> |
| <p> |
| For more info, see the other parts that are used internally by the <em>Form Control Factory</em>: |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#JfaceProviderFactory" title="Go to "Jface Provider Factory"">JfaceProviderFactory</a> |
| </li> |
| </ul> |
| </p> |
| <a name="TreeFormFactory"></a> |
| <h3>Tree Form Factory</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/factories/TreeFormFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.factories.TreeFormFactory" >TreeFormFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/factories/TreeFormFactory.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#ViewerInitializer" title="Go to "Viewer Initializer"">ViewerInitializer</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#FormFactory" title="Go to "Form Factory"">FormFactory</a> |
| </li> |
| </ul> |
| </p> |
| <a name="ViewerFactory"></a> |
| <h3>Viewer Factory</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/factories/ViewerFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.factories.ViewerFactory" >ViewerFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/factories/ViewerFactory.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <a href="04-Customization.html#TableViewerBuilder" title="Go to "Table Viewer Builder"">TableViewerBuilder</a> |
| </li> |
| <li> |
| <a href="04-Customization.html#ViewerInitializer" title="Go to "Viewer Initializer"">ViewerInitializer</a> |
| </li> |
| </ul> |
| </p> |
| <a name="AdapterFactoryEditingDomain"></a> |
| <h3>Viewer Factory</h3> |
| <p> |
| AdapterFactoryEditingDomain |
| </p> |
| <p> |
| AdapterFactory |
| </p> |
| <a name="Viewers"></a> |
| <h2>Viewers</h2> |
| <a name="ViewerInitializer"></a> |
| <h3>Viewer Initializer</h3> |
| <p> |
| <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/org/eclipse/emf/parsley/viewers/ViewerInitializer.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.viewers.ViewerInitializer" >ViewerInitializer</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_8_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/viewers/ViewerInitializer.java" title="View Source Code" >(src)</a> |
| </p> |
| <p> |
| <ul> |
| <li> |
| <em>AdapterFactoryEditingDomain</em> |
| </li> |
| <li> |
| <a href="04-Customization.html#ViewerContextMenuFactory" title="Go to "Viewer Context Menu Factory"">AdapterFactory</a> |
| </li> |
| <li> |
| <em>ILabelProvider</em> |
| </li> |
| <li> |
| <em>IContentProvider</em> |
| </li> |
| </ul> |
| |
| </p> |
| </body> |
| </html> |