blob: c7a9d3af5ff6b423d5f72303a0a17c1d3aa6f496 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
<title>Components</title>
<link href="book.css" rel="stylesheet" type="text/css">
<link href="code.css" rel="stylesheet" type="text/css">
<link rel="home" href="00-Main.html" title="">
</head>
<body>
<a name="Components"></a>
<h1>Components</h1>
<p>
This section describes the components that are provided to be used out-of-the-box, that are the foundations for all parts built upon <em>EMF Parsley</em>.
Afetr a brief description, for each component we present a set of customizations, just to give an idea of how it works. You can refer
to <a href="06-Customization.html#Customizations" title="Go to &quot;Customizations&quot;">Customizations Section</a> for a complete list.
</p>
<p>
Components and viewers have to be created using the factories we provide
(e.g., for viewers we provide <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/parsley/viewers/ViewerFactory.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.viewers.ViewerFactory" >ViewerFactory</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/viewers/ViewerFactory.java" title="View Source Code" >(src)</a>);
such factories provide specific <em>create</em> methods that require all the needed parameters.
These factories must be injected.
</p>
<a name="FormComponent"></a>
<h2>Form Component</h2>
<p>
The <em>Form Component</em> can be used to rapresent an <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/ecore/EObject.html" title="View JavaDoc"><abbr title="org.eclipse.emf.ecore.EObject" >EObject</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EObject.java" title="View Source Code" >(src)</a> in a form,
like in the image above.
</p>
<p>
<div class="image" >
<img src="images/03-components-form.png" class=" "
/>
<div class="caption">
</div>
</div>
</p>
<p>
<em>EMF Parsley</em> provides a factory that can be used to create such a component, like in the code below.
Here you can see that a form can be configured in 2 lines, the constructor phase and the build&amp;fill phase.
</p>
<p>
<div class="literallayout">
<div class="incode">
<p class="code">
@Inject&nbsp;FormFactory&nbsp;formFactory;<br/>
<br/>
(...)<br/>
<br/>
formComposite&nbsp;=&nbsp;formFactory.createFormDetailComposite(parent,&nbsp;SWT.NONE);<br/>
formComposite.init(eObject);<br/>
</p>
</div>
</div>
</p>
<p>
Most of the job is done by the second line of code, which gets the list of <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.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_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EStructuralFeature.java" title="View Source Code" >(src)</a> defined
for the <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.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_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a>
(that is the type of the object to represent) and builds a row for each of them. Each row is composed
by a <em>caption</em> which defaults to the name of the feature and a <em>control</em> to access the data.
</p>
<p>
All these aspects can be customized in many ways, for example you can customize the feature list, the captions and the controls.
</p>
<a name="FormComponent_features"></a>
<h3>Feature List Customization</h3>
<p>
The <em>list of features</em> displayed on the form can be customized via the <a href="06-Customization.html#FeaturesProvider" title="Go to &quot;Features Provider&quot;">Feature Provider</a>
that returns the list of the features (in a given order).
</p>
<a name="FormComponent_captions"></a>
<h3>Caption Customization</h3>
<p>
The captions of the features shown in the form can be customizzed via the <a href="06-Customization.html#FormFeatureCaptionProvider" title="Go to &quot;Form and Dialog Feature Caption Provider&quot;">Form Feature Caption Provider</a>.
</p>
<a name="FormComponent_controls"></a>
<h3>Control Customization</h3>
<p>
The Controls in the form can be customized via the <a href="06-Customization.html#FormControlFactory" title="Go to &quot;Form Control Factory&quot;">Form Control Factory</a>.
</p>
<a name="FormComponent_proposals"></a>
<h3>Proposal Provider</h3>
<p>
Depending on the feature types, some fields can have predefined values (e.g. combo).
You can provide the exact proposal list via the <a href="06-Customization.html#ProposalProvider" title="Go to &quot;Proposal Provider&quot;">Proposal Provider</a>
</p>
<a name="TreeComponent"></a>
<h2>Tree Component</h2>
<p>
The <em>Tree Component</em> provides a tree representation of data that can be fed with an EResource, a
Resource URI, and a simple EObject. This component uses the EMF Meta-Model information to display objects in the tree.
</p>
<p>
<div class="image" >
<img src="images/03-components-tree.png" class=" "
/>
<div class="caption">
</div>
</div>
</p>
<p>
<em>EMF Parsley</em> provides a factory that can be used to create such a component, like in the code below:
</p>
<p>
<div class="literallayout">
<div class="incode">
<p class="code">
@Inject&nbsp;ViewerFactory&nbsp;viewerFactory;<br/>
<br/>
(...)<br/>
<br/>
treeViewer&nbsp;=&nbsp;<span class="keyword">new</span>&nbsp;TreeViewer(parent);<br/>
viewerFactory.initialize(treeViewer,&nbsp;element);<br/>
</p>
</div>
</div>
</p>
<p>
The <em>Tree Component</em>can be customized in several way via the standard EMF Edit facilities or with the EMF Parsley
codeinjection based mechanism. If you are familiar with Jface APIs, you can easily use the basic class with some facilties to define the specific implementation.
See the corrisponding sections for more details.
</p>
<a name="Tree_ContentProvider"></a>
<h3>Content Provider</h3>
<p>
An IContentProvider is used in Jface to retrieve the list of <em>elements</em> and <em>children</em> to be showed
in the tree viewer. The <a href="06-Customization.html#ViewerContentProvider" title="Go to &quot;Viewer Content Provider&quot;">Viewer Content Provider</a> is the <em>EMF Parsley</em> implementation of that interface,
and by default uses the containment mechanisms to provide children as in EMF Edit framework, but it can
be customized as weel.
</p>
<a name="Tree_LabelProvider"></a>
<h3>LabelProvider</h3>
<p>
The <a href="06-Customization.html#ViewerLabelProvider" title="Go to &quot;Viewer Label Provider&quot;">Viewer Label Provider</a> is the implementation of an ILabelProvider interface
and is responsible to provide the text and image representation for each EObject visualized.
</p>
<a name="Tree_MenuBuilder"></a>
<h3>Adding Menu</h3>
<p>
The contextual menu can be added to the viewer via an injected
<a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/parsley/menus/ViewerContextMenuHelper.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.menus.ViewerContextMenuHelper" >ViewerContextMenuHelper</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/menus/ViewerContextMenuHelper.java" title="View Source Code" >(src)</a>, as explained in the <a href="06-Customization.html#ContextualMenu" title="Go to &quot;Contextual Menu&quot;">Menu section</a>.
The <a href="06-Customization.html#MenuBuilder" title="Go to &quot;Menu Builder&quot;">Menu Builder</a> allows to fully customize the menus.
</p>
<a name="TreeFormComponent"></a>
<h2>Tree Form Component</h2>
<p>
The <em>Tree Form Component</em> contains a <a href="05-Components.html#TreeComponent" title="Go to &quot;Tree Component&quot;" >section TreeComponent</a> that provides a tree representation of data that can be fed with
an EResource, a Resource URI, and a simple EObject. This component uses the EMF Meta-Model information to display objects in
the tree. The component also combines a <a href="05-Components.html#FormComponent" title="Go to &quot;Form Component&quot;" >section FormComponent</a> detail that display the current selected object.
</p>
<p>
<div class="image" >
<img src="images/03-components-treeform.png" class=" "
/>
<div class="caption">
</div>
</div>
</p>
<p>
<em>EMF Parsley</em> provides a factory to create such a component.
</p>
<p>
<div class="literallayout">
<div class="incode">
<p class="code">
@Inject&nbsp;TreeFormFactory&nbsp;treeFormFactory;<br/>
<br/>
(...)<br/>
<br/>
treeFormComposite&nbsp;=&nbsp;treeFormFactory.createTreeFormComposite(parent,&nbsp;SWT.BORDER);<br/>
treeFormComposite.update(application);<br/>
</p>
</div>
</div>
</p>
<p>
Since <em>Tree Form Component</em> is a combination of <em>Tree Component</em> and <em>Form Component</em>, all their customizations
are avaible for it.
</p>
<a name="TableComponent"></a>
<h2>Table Component</h2>
<p>
The <em>Table Component</em> can rapresent data in a grid, once you have specified the type of objects to represent.
It uses metamodel information to build columns as needed, and a
<a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/parsley/edit/ui/provider/TableViewerContentProvider.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.edit.ui.provider.TableViewerContentProvider" >TableViewerContentProvider</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/edit/ui/provider/TableViewerContentProvider.java" title="View Source Code" >(src)</a> to retrieve
the contents of the specified type (see also <a href="06-Customization.html#TableViewerContentProvider" title="Go to &quot;Table Viewer Content Provider&quot;" >section TableViewerContentProvider</a>).
</p>
<p>
<div class="image" >
<img src="images/03-components-table.png" class=" "
/>
<div class="caption">
</div>
</div>
</p>
<p>
<div class="literallayout">
<div class="incode">
<p class="code">
@Inject&nbsp;ViewerFactory&nbsp;viewerFactory;<br/>
<br/>
(...)<br/>
<br/>
tableViewer&nbsp;=&nbsp;viewerFactory.createTableViewer(composite,&nbsp;SWT.BORDER&nbsp;|&nbsp;SWT.FULL_SELECTION,&nbsp;eClass);<br/>
</p>
</div>
</div>
</p>
<p>
The class <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/parsley/viewers/TableViewerColumnBuilder.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.viewers.TableViewerColumnBuilder" >TableViewerColumnBuilder</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/viewers/TableViewerColumnBuilder.java" title="View Source Code" >(src)</a> has the responsibility to
build the columns of the Table, by using the <a href="06-Customization.html#FeaturesProvider" title="Go to &quot;Features Provider&quot;">Features Provider</a> to get the list
of features and the <a href="06-Customization.html#FeatureCaptionProvider" title="Go to &quot;Feature Caption Provider&quot;">Feature Caption Provider</a> for the column headers.
The class <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.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_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/ui/provider/TableColumnLabelProvider.java" title="View Source Code" >(src)</a> can be used to specify
an implementation of ILabelProvider for each cell in the table.
</p>
<a name="Table_features"></a>
<h3>Feature List Customization</h3>
<p>
The <em>list fo features</em> displayed on the table can be customized via the <a href="06-Customization.html#TableFeaturesProvider" title="Go to &quot;Table Features Provider&quot;">Table Feature Provider</a>.
This list of features will be used for building the columns of the table.
</p>
<a name="Table_captions"></a>
<h3>Caption Customization</h3>
<p>
The headers of the table can be customizzed via the <a href="06-Customization.html#FeatureCaptionProvider" title="Go to &quot;Feature Caption Provider&quot;">Caption Provider</a>.
</p>
<a name="Table_columns_width"></a>
<h3>Column width Customization</h3>
<p>
All columns have the same size by default, but they can be customizzed via the <a href="06-Customization.html#Configurator" title="Go to &quot;Configurator&quot;">Configurator</a>
for instance in the DSL, like in the example below.
</p>
<p>
<div class="literallayout">
<div class="incode">
<p class="code">
<span class="keyword">bindings</span>{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">value</span>&nbsp;List&lt;Integer&gt;&nbsp;TableColumnWeights&nbsp;-&gt;&nbsp;#[10,20,30,40]<br/>
}<br/>
</p>
</div>
</div>
</p>
<a name="Table_MenuBuilder"></a>
<h3>Adding Menu</h3>
<p>
The contextual menu can be added to the viewer via an injected
<a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.0/org/eclipse/emf/parsley/menus/ViewerContextMenuHelper.html" title="View JavaDoc"><abbr title="org.eclipse.emf.parsley.menus.ViewerContextMenuHelper" >ViewerContextMenuHelper</abbr></a> <a class="srcLink" href="https://github.com/eclipse/emf/blob/R2_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/parsley/menus/ViewerContextMenuHelper.java" title="View Source Code" >(src)</a>, as explained in the <a href="06-Customization.html#ContextualMenu" title="Go to &quot;Contextual Menu&quot;">Menu section</a>.
The <a href="06-Customization.html#MenuBuilder" title="Go to &quot;Menu Builder&quot;">Menu Builder</a> allows to fully customize the menus.
</p>
<a name="TreeWithColumnsComponent"></a>
<h2>Tree With Columns Component</h2>
<p>
The <em>Tree With Columns Component</em> provides a tree representation just like <a href="05-Components.html#TreeComponent" title="Go to &quot;Tree Component&quot;">Tree Component</a>,
but it also shows table columns representing the features of the specified <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.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_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a>.
</p>
<p>
IMPORTANT: the <a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.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_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a> is used to retrieve the features to be shown, and
NOT to filter elements to be shown (as opposite to the <a href="05-Components.html#TableComponent" title="Go to &quot;Table Component&quot;">Table Component</a>). If a given
row in the tree represents an object whose class does not have the feature for a given column, then the
corresponding table cell for that object will be empty.
</p>
<p>
For example, the following screenshot shows a tree with columns representing a library; the specified
<a class="jdoc" href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.10.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_9_0/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java" title="View Source Code" >(src)</a> is the <em>Writer</em> so the columns show the features of the
<em>Writer</em>&apos;s class. Some of these features, e.g., <em>address</em>, <em>firstName</em> and <em>lastName</em>, are defined
in the superclasses of <em>Writer</em>. The objects of class <em>Employee</em> have these features as well, while
they don&apos;t have features that are specific of <em>Writer</em>, e.g., <em>name</em> and <em>books</em>, thus the corresponding
cells for employees will be empty.
</p>
<p>
<div class="image" >
<img src="images/03-components-treecolumns.png" class=" "
/>
<div class="caption">
</div>
</div>
</p>
<p>
<em>EMF Parsley</em> provides a factory that can be used to create such a component, like in the code below:
</p>
<p>
<div class="literallayout">
<div class="incode">
<p class="code">
@Inject&nbsp;ViewerFactory&nbsp;viewerFactory;<br/>
<br/>
(...)<br/>
<br/>
treeViewer&nbsp;=&nbsp;createTreeViewerWithColumns(parent,&nbsp;getEClass(),&nbsp;getContents());<br/>
</p>
</div>
</div>
</p>
<p>
Since this component mixes the features of a tree and a table, the customizations are basically the
same shown in the subsections of <a href="05-Components.html#TreeComponent" title="Go to &quot;Tree Component&quot;" >section TreeComponent</a> and <a href="05-Components.html#TableComponent" title="Go to &quot;Table Component&quot;" >section TableComponent</a>.
</p>
</body>
</html>