|
|
(3 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{MoDiscoFacetManagerTabs}}
| + | #REDIRECT [[MoDisco/Moved To Help Center]] |
− | | + | |
− | ==How to create a model facet set==
| + | |
− | The first step is to [[MoDisco/ProjectNature|create a MoDisco project]].
| + | |
− | | + | |
− | The second step is to [[MoDisco/QueryManager|create a query set]]. This query set will store boolean queries indicating if an
| + | |
− | object conforms to a facet.
| + | |
− | | + | |
− | Right-click on the MoDisco project and select '''New > Other...'''.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_NewOther.png]] | + | |
− | | + | |
− | Select '''Facet Model''' and press the '''Next''' button
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_NewFacetModel.png]]
| + | |
− | | + | |
− | Choose a name for your model facet set (My.facetSet in the example)
| + | |
− | and press '''Finish'''.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_NewFacetSet_name.png]]
| + | |
− | | + | |
− | | + | |
− | Open the "My.facetSet" file and open the '''Properties''' View.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_FacetSetPropertiesView.png]]
| + | |
− | | + | |
− | Set the name of the facet set and make sure that the facet set name
| + | |
− | is the same as the containing file name ("My" in the example). The
| + | |
− | nsURI and prefix must also be filled.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_FacetSetProperties2.png]]
| + | |
− | | + | |
− | Load the resources containing the meta-model extended by the
| + | |
− | facet set. To load a meta-model resource you must use the
| + | |
− | '''Load Meta-model Resource''' action.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_LoadMetamodelResource.png]]
| + | |
− | | + | |
− | In this example, we choose to use the Java meta-model.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_LoadMetamodelResourceJava.png]]
| + | |
− | | + | |
− | Fill the '''Extended Package''' field with the ePackage
| + | |
− | containing the virtually extended meta-model.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_ExtendedPackageJava.png]]
| + | |
− | | + | |
− | Right click on the FacetSet element and choose '''New Child > Facet''' to create a facet.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_NewChildFacet.png]]
| + | |
− | | + | |
− | Set the facet name and the class that the facet will extend.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_FacetSuperTypeAndName.png]]
| + | |
− | | + | |
− | To specify how to know if an object conforms to a facet, we have
| + | |
− | to provide a boolean query. To provide this query we have to load the
| + | |
− | model containing its description.
| + | |
− | | + | |
− | Right-click in the editor and choose '''Load MoDisco Resource''':
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_LoadMoDiscoResource.png]]
| + | |
− | | + | |
− | The query has to be referred to using the MoDisco protocol ("modisco:/query/<querySetName>").
| + | |
− | In the example, we use the "My" query set.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_LoadMyQuerySet.png]]
| + | |
− | | + | |
− | Once the query set resource is referenced, we just have to select the
| + | |
− | query describing the facet. In the example this query is named
| + | |
− | "isAbstract".
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_FacetSelectConditionQuery.png]]
| + | |
− | | + | |
− | At this step, if we save the model, the error marker should disappear
| + | |
− | from the file's icon, indicating that the facet set model is now valid.
| + | |
− | | + | |
− | If the facet has specific attributes or references which can be
| + | |
− | calculated, we can declare them. In this example, we will declare an
| + | |
− | attribute indicating the number of abstract methods contained in the
| + | |
− | abstract class. To create a new facet attribute right-click on the facet
| + | |
− | element and select the '''New Child > FacetAttribute'''.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_NewFacetAttribute.png]]
| + | |
− | | + | |
− | The attribute's type and name must be set. The "Value Query" field must
| + | |
− | be filled with a reference to a query which is used to calculate the
| + | |
− | attribute's value. This query must have the same type as the attribute
| + | |
− | and be applicable to the virtually extended class.
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_FacetProperties.png]]
| + | |
− | | + | |
− | | + | |
− | The facet set is now ready to be used.
| + | |
− | | + | |
− | == How to consult the MoDisco facet set catalog through the UI ==
| + | |
− | | + | |
− | If a facet set model is valid, it is registered in the facet set
| + | |
− | catalog. To consult the facet set catalog, we can use the "Facet Set"
| + | |
− | view.
| + | |
− | | + | |
− | To open this view select '''Windows > Show view > Other ...'''
| + | |
− | in the menu bar and choose '''Facet Sets''' in the list.
| + | |
− | | + | |
− | [[Image:MoDisco_ShowView_FacetSets.png]]
| + | |
− | | + | |
− | [[Image:MoDisco_FacetSetsView.png]]
| + | |
− | | + | |
− | The "Facet Sets" view presents the available facet sets and their
| + | |
− | facets. For each facet set the location of its description model is pointed out.
| + | |
− | | + | |
− | == How to programmatically use the MoDisco facet set catalog ==
| + | |
− | | + | |
− | Here is an example of using the MoDisco facet API. For more information please refer to the JavaDoc.
| + | |
− | | + | |
− | import org.eclipse.emf.ecore.EObject;
| + | |
− | import org.eclipse.gmt.modisco.infra.query.core.exception.ModelQueryException;
| + | |
− | import org.eclipse.gmt.modisco.infra.facet.Facet;
| + | |
− | import org.eclipse.gmt.modisco.infra.facet.FacetSet;
| + | |
− | import org.eclipse.gmt.modisco.infra.facet.core.FacetSetCatalog;
| + | |
− | import org.eclipse.gmt.modisco.infra.facet.core.exception.ModiscoFacetException;
| + | |
− |
| + | |
− | public class Example {
| + | |
− |
| + | |
− | public Integer getNbAbstractMethod(EObject eObject)
| + | |
− | throws ModelQueryException, ModiscoFacetException {
| + | |
− | FacetSet facetSet = FacetSetCatalog.getSingleton().getFacetSet("My");
| + | |
− | FacetContext context = new FacetContext();
| + | |
− | context.addFacetSet(facetSet);
| + | |
− | Facet facet = facetSet.getFacet("AbstractClassDeclaration");
| + | |
− | if (context.isInstance(eObject, facet)) {
| + | |
− | Object object = context.get(eObject, facet
| + | |
− | .getEStructuralFeature("nbAbstractMethod"));
| + | |
− | if (object instanceof Integer) {
| + | |
− | Integer nbAbstractMethod = (Integer) object;
| + | |
− | return nbAbstractMethod;
| + | |
− | }
| + | |
− | }
| + | |
− | return null;
| + | |
− | }
| + | |
− | }
| + | |
− | | + | |
− | == How to package a facet set in a plug-in ==
| + | |
− | | + | |
− | To package a facet set in a plug-in, an extension must be added in the plugin.xml file (contained by the facet set's project). The extension point to use is: org.eclipse.gmt.modisco.infra.facet.registration.
| + | |
− | Here is an example of a facet set declaration:
| + | |
− | | + | |
− | <plugin>
| + | |
− | <extension
| + | |
− | point="org.eclipse.gmt.modisco.infra.facet.registration">
| + | |
− | <facetset
| + | |
− | file="_example_jdkAndEclipseFacets.facetSet">
| + | |
− | </facetset>
| + | |
− | </extension>
| + | |
− | </plugin>
| + | |
− | | + | |
− | Thanks to this extension declaration, the MoDisco project is ready to be exported as a plug-in.
| + | |
− | | + | |
− | == Facet Meta-model Description ==
| + | |
− | | + | |
− | [[Image:MoDisco_Facet_metamodel.png]]
| + | |
− | | + | |
− | The facet meta-model extends the ecore meta-model and uses the query meta-model.
| + | |
− | | + | |
− | A FacetSet is a kind of EPackage. A FacetSet contains facets through
| + | |
− | the eClassifier reference. A facet is a kind of EClass.
| + | |
− | | + | |
− | For a facet instance, the eSuperType reference must be set to
| + | |
− | specify which class the facet virtually extends.
| + | |
− | | + | |
− | The facet class has one specific reference: conditionQuery. The
| + | |
− | conditionQuery reference points to the ModelQuery class. The model queries
| + | |
− | pointed to by the conditionQuery reference must return a Boolean. Those
| + | |
− | queries are used to specify how to decide whether an instance conforms to a
| + | |
− | facet. If the conditionQuery is empty then all the instances of the class
| + | |
− | referred to by the facet instance through the eSuperType reference conform
| + | |
− | to this facet.
| + | |
− | | + | |
− | A facet contains facetAttributes and facetReferences through the
| + | |
− | eStructuralFeature reference. The FacetAttribute and FacetReference
| + | |
− | classes have a common super class: FacetStructuralFeature. The
| + | |
− | FacetStructuralFeature has one reference named valueQuery pointing to
| + | |
− | the ModelQuery class. The valueQuery is used to compute the facet
| + | |
− | structural feature value. The facetAttribute and facetReference must have
| + | |
− | the same type as the query they refer to.
| + | |
− | | + | |
− | [[Category:MoDisco]]
| + | |