h1. Specifying Viewpoints

{toc:style=disc|minLevel=2|maxLevel=3}

<div style="display: none">
  TODO Add a few screenshots to make the document less dry.
</div>

This document gives a general overview of how viewpoints are specified, tested and deployed.

h2(#introduction). Introduction

_Sirius_ is a modeling tool which has been originally created in the context of complex systems modeling. The complexity of those systems makes necessary the collaboration of people with different concerns. For the same domain and on the same data, there are different levels of analysis, different roles and different concerns possible. Each of these correspond to a different _viewpoint_ on the same _domain  model_, and Sirius (the system) gives you all the tools to specify the viewpoints which are relevant to your business domain, whatever it is.

More pragmatically, Sirius assumes that you _domain model_ is defined using _EMF_ (Eclipse Modeling Framework), which is an industry standard with a rich eco-system. Many existing standards like UML (for software systems) or TOGAF (for Enterprise Architecture) have an implementation based on EMF. You can also easily define your own _Domain-Specific Model_ (sometimes called _Domain-Specific Language_) to more precisely suit your specific needs and avoid unnecessary complexities. While this part (the domain specification) is not strictly in the scope of Sirius, the system provides a graphical modeler to ease the creation of your own _DSM_ (Domain-Specific Model).

Given such a domain model, which defines concepts and their relations in the abstract, Sirius will allow you to easily specify _concrete representations_ of these models. Representations can be diagrams, tables, matrices (cross-tables) or hierarchies (trees). You can define as many of them as you need, some more detailed than others, some customized for certain tasks or roles (e.g. initial design, review, certification, etc.). These representations are not just static: provided you specify the appropriate tools (see below), they can be complete modeling environments where users can create, modify and validate their designs. Representations can be logically organized in _viewpoints_, and end-users can enable or disable viewpoints at will to work on the same model through different, but logically consistent, points of view.

The main strengths of the Sirius platform can be summarized as is:
* it is based on an open and widely used _industry standard_ (the Eclipse Modeling Framework);
* it can _adapt itself_ to any EMF-compatible DSM: it can use standards like UML if they suit your needs, but it does not force you to do so, and you can easily create your own DSM which can thus be simpler and better suited to your specific needs;
* it provides a _strong separation_ between the semantic models it manipulates, where your business value resides, and the representation models (which deal with, for example, the size and location of graphical shapes on a diagram). This means your domain models have no adherence to Sirius itself, and can be manipulate with any of the other tools in the EMF eco-system (e.g. Acceleo to generate source code or other textual artifacts);
* it allows you to define many _different representations_ on your domain models: diagrams, tables, trees, showing different levels of details and offering different edition capabilities depending on their usage;
* it is _easy to use_ and supports _very fast_ development. Once you become familiar with the tool, you will be able to get a simple diagram in a matter of minutes, a prototype suited for a client demonstration in a few hours, and a fully-functional and customized modeler in a few days of work;
* it is _extensible_: by integrating in the Eclipse platform and offering open APIs, you can extend and integrate your Sirius modelers with other tools to provide a fully-customized modeling workbench to your users.

h2(#concepts). Philosophy and Concepts

As explained in introduction, _Sirius_ allows you to specify dedicated representations and associated tooling. As a _specifier_, your role will be to configure the generic Sirius platform to provide these representations to your users. This is done by creating and configuring a "_Viewpoint Specification Model_":../../Glossary.html#VSM which describes the structure, appearance and behavior of your modelers. This document does not deal with the definition of your domain model; you can use a standard one like UML, SysML, BPMN or TOGAF, or create a custom one. The only assumptions Sirius makes is that your model is based on EMF.

The main concepts you will work with as a specifier are:
* *Viewpoint* A viewpoint is one of the core elements that a specifier defines: it is a logical set of *representation specifications* and *representation extension specifications*.
* *Representation* A _representation_ is a group of *graphical construction which represent domain data*. A representation describes the structure, appearance and behavior of your modelers. By default, Sirius supports four kinds of representations (called _dialects_): diagrams, tables, matrices (aka cross-tables), and trees. All follow the same basic principles in their definitions.
* *Mapping* A _mapping_ identifies a sub-set of the semantic model's element that should appear in a representation and indicates how they should be represented. Each dialect offers different kinds of mappings. For example, diagrams provide _container mappings_, which can be used to represent semantic elements with graphical containers, where other elements (specified by other mappings) can appear. A mapping exists inside the _Viewpoint Specification Model_, but on a concrete representation it will produce _instances_. If you specify a container mapping to represent, say, divisions in an enterprise, and the model of your enterprise contains four divisions, a concrete diagram will show four containers, each an instance of the same mapping, but associated to a different semantic element.
* *Style* Each mapping can have one or several _styles_ associated to it, which are used to configure the visual appearance of the elements they represent. For example, for diagram elements this would include their shape and colors.
* *Tool* Without tools, your representations would be only visualizations, with no edition capabilities. While this can be sometimes useful, most representations will allow users to create, edit and delete elements. Tools are associated to mappings to describe their behaviors. Each kind of user interaction supported by _Sirius_ (e.g. creation or deletion, label editing, edge reconnection...) is specified by a different kind of tool, but they all follow the same principles in their definition. 

h2(#vsp). Viewpoint Specification Projects

Note: When working as a Sirius specifier, it is recommended to use the _Sirius_ perspective, which provides some additional shortcuts and views. The _Modeling_ perspective is simpler and oriented towards end-users.

Viewpoints are specified as models (see below) inside _Viewpoint Specification Projects_. These "_VSPs_":../../Glossary.html#VSP are normal Eclipse plug-in project, which happen to contain one or several @*.odesign@ files (the extension used for "_Viewpoint Specification Models_":../../Glossary.html#VSM ). You can create such a project using the supplied wizard: _New > Viewpoint Specification Project_.

By convention, the VSM (or VSMs) defined in your project are stored inside a @description@ folder. If you want to place them in a different location, make sure to add this location into the plug-in's @build.properties@ so that it is included in the deployed version.

The VSM name is given according to the project name defined when using the previous wizard. If the project name is suffixed with "design", the VSM name is provided by the last word before this suffix. Otherwise, the VSM name is given by the last word of the project name.

Other than that, the project is a normal Java plug-in project. You can add "service classes":Writing_Queries.html#service_methods into it if the query language you use support it, and any other Java code, including Eclipse views, actions, etc. 

Note that it is recommended to add your domain meta-model(s) plug-ins as dependencies of the project. Java services and some features of query language (like the use of type literals in AQL filter() operations) might require them. 

*Important:* Any VSM you place in the Eclipse workspace will be immediately available for use and testing, with no deployment. This is to facilitate dynamic and iterative development of viewpoints. However, when you *deploy* your VSMs, they *must* be part of a _VSP_, and they *must* be registered in the plug-in's activator class. The activator generated by the _VSP_ wizard is properly configured, but if you rename your _VSM_ or add new ones, be sure to edit the activator class so that all your _VSMs_ are correctly registered inside the Sirius platform when deployed.

h2(#vsm). Viewpoint Specification Models

The core part of a _VSP_ is the _Viewpoint Specification Model_ (or models) it contains. These are stored in @*.odesign@ files, usually in the @description@ folder of the project. A _VSM_ specifies a set of _Viewpoints_ and their representations (diagrams, trees...).

To edit a _VSM_, simply double-click on it, and a tree editor will open. The editor follows the conventions of standard EMF editors: selecting an element will show its properties in the _Properties_ view, where you can edit them. To create new elements, simply right-click on its parent and choose from one one the _New XXX_ menus. To delete an element and all its sub-elements, simply select it and hit the _Delete_ key or right-click and choose _Delete_.

h3(#vsm_organization). Organization

The top-level element of a _VSM_ is a _Group_ element. It has no specific semantics and serves only as a container for the other elements. Note however that once you define its _Name_, you should never change it as it becomes part of the identification of all the elements inside the _VSM_. If you change it, any concrete representations created using that _VSM_ will be broken.

Inside a _Group_, you can create an optional _User Colors Palette_, with shared "color definitions":Colors.html; this is useful to define a uniform color palette for all your viewpoints and representations. You can also, and more importantly, define _Viewpoint_ elements.

Besides its _Id_ and _Label_ (see below), a _Viewpoint_ can be associated to one or more _Model File Extensions_, separated by space. This can be used to restrict the availability of the viewpoint only to modeling projects which contain semantic models of the specified types. For example, to make your viewpoint available to UML and SysML models, you can specify @uml sysml@ (note that the syntax specifies only the file extension, @uml@, not a pattern like @*.uml@). You can use a star, @*@, to make your viewpoint available for *all* models, but it is normally prefered be as specific as possible so as not to interfere with unrelated models and projects.

Inside a _Viewpoint_ element, you can create:
* _Representation Descriptions_, for "diagrams":../diagrams/Diagrams.html, "sequence diagrams":../sequences/Sequence%20Diagrams.html, "tables and cross-tables":../tables/Tables.html, and "trees":../trees/Trees.html.
* _Representation Extensions_, currently supported only for "diagrams":../diagrams/Diagrams.html#diagram_extension.
* "_Validation Rules_":../diagrams/Diagrams.html#validation, which will apply to all representations defined inside this viewpoint.
* And finally _Java Extensions_. These refer (through its fully qualified name), to a Java class defined in the _Viewpoint Specification Project_ which defines "service methods":Writing_Queries.html#service_methods and make these services available inside all the representations defined in the viewpoint. If you "use Acceleo 3 to write your expressions":Writing_Queries.html#acceleo, you can also use these elements to declare Acceleo modules in the project that define MTL queries you want to use in your expressions.

To discover all elements in the _VSM_, it is possible to use the button <img src="images/specifier-guide/expandall.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/>, at the top right corner of the editor to expand the _VSM_ tree. Obviously, it is possible to collapse this tree by using the button <img src="images/specifier-guide/collapseall.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/>, at the top right corner of the editor.

h3(#common_attributes). Common attributes

Many of the elements used to specify viewpoint share some common configuration attributes. They are described in general terms in this section, and referenced from the specific element's sections which used them (sometimes with additional details only relevant for this element).

<img src="images/common_attributes.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/>

* _Id_: The mandatory identifier of the element. This identifier is mostly visible to the specifier in the description editor. It must be unique in the context of the viewpoint it is part of. The _Id_ is used internally to identify the element, and must be kept stable across different versions of the VSM (or it will make representations created with the old _Id_ unusable).
* _Label_: The label of the element. It's used to display this element to the end-user. By default, if this label is blank, the _Id_ is used to display this element to the end user. It can be changed with no impact on existing representation files.

<img src="images/documentation_attributes.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/>
* _Documentation_: All the elements in a description file contain a *Documentation* attribute available in the *Documentation* category. This attribute can be used by the specifier to add comments and documentation to these elements. The content of this attribute is not visible to the end users of the viewpoints.
* _End-user documentation_: This attribute describes this element for the end-user. It's available in the *Documentation* category. This attribute can be used by the specifier to add comments and documentation to these elements bounds for the end-user.

<img src="images/tricks.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/> _use the <img src="images/questionMarque.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/> icon to access the available fields tooltips._

h3(#type_names). Type Names

Some _VSM_ elements will need you to specify one or more _Type Names_ to configure them, usually types from the semantic domain model being represented (for example the _Domain Class_ for mapping definitions). You can easily identify _Type Name_ fields by their green background in the _Properties_ sheet of an element.

!images/domain_class.png!
The syntax for type names are the following:
* *minimal syntax:* it is the basic name, like @Class@,
* *AQL/OCL syntax:* a qualified name using name of the EMF EPackage which defines the type with the separator @::@ like  @uml::Class@. It is the default and *recommended* syntax, consistent with how qualified type names are written in AQL
* *legacy qualified name like syntax:* it is a qualified name using name of the EMF EPackage which defines the type, like @uml.Class@.
* *fully qualified URI*: like @http://www.eclipse.org/uml2/3.0.0/UML#//Class@.

Auto-completion is available in these fields using the _Ctrl+Space_ shortcut. It is recommended to explicitly associate a meta-model (or more) to your representations definitions to allow for smarter completion. Otherwise by default it will include all types from any EMF meta-model available.

h3(#interpreted_expressions). Interpreted Expressions

Many _VSM_ elements require you to specify _Interpreted Expressions_ to configure them. These can be queries to select elements (as in mappings for example), or more general expressions to compute value (like the text to use for the elements' labels).

You can easily identify _Interpreted Expressions_ by their yellow background in the _Properties_ sheet of an element. For all such field, you can use any of the supported languages to write the expression. Refer to the "queries documentation":Writing_Queries.html for more details.

!images/interpreted_expressions.png!

Also, by clicking on the button next to the text field, you can open a dialog with a bigger text area (providing auto-completion too) to type your expression more comfortably. Note that you can add line feeds or tabulations if you want, since they are removed when clicking on the "OK" button.

!images/textAreaDialog.png!

h3(#feature_name). Feature Name

Some _VSM_ elements will need you to specify a _Feature Name_ (or _Reference Name_ on _Create Instance_) to configure them (Create Instance, Set, Unset, etc.). You can easily identify _Feature Name_ fields by their light green background in the _Properties_ sheet of an element.

!images/featureName.png!

Auto-completion is available in these fields using the _Ctrl+Space_ shortcut except if the current element type cannot be inferred, usually in the case of a generic tool where the target element will be known only at runtime.
Note that for _Create Instance_  _Reference Name_ field, the completion will display only features that have a type consistent with the one specified in the _Type Name_ field. If no type is specified, all available features will be displayed. In the same way, if a valid _Reference Name_ is set, the completion for the _Type Name_ field will display only types consistent with the feature type.

h3(#translatable_messages). Translatable Messages

Many _VSM_ elements provide text fields that will be displayed when end-users reference the _VSM_ in a modeling project (Viewpoint name, tools...). Starting from Sirius 4.0, the value shown to the end users can be localized according to the user's language.  Fields which support this feature are called _Translatable_ _Messages_ and can be easily identified by their blue background in the _Properties_ sheet of an element. 

!images/common_attributes.png!

Note that on the previous screenshot, the text in the label field is grayish because no label have been set and the ID is used instead.

This feature is available for almost every _VSM_ elements defined in the VSMs which are visible to the end-user of the modeler, like viewpoint and tools names, can now be internationalized, but not to interpreted expressions. Note also that this feature is only available to modelers which are deployed as proper Eclipse plug-ins; it will not work for plain VSMs defined directly in the runtime workspace.

To make use of this feature in your modeler, simply replace the names with a _translation key_ reference of the form @%myUniqueKey@  in the VSM, and define the value in the _Viewpoint Specification Project_'s @plugin.properties@ (for the default value), or @plugin_XX.properties@ for locale @XX@. Note that the key chosen must be globally unique in the context of a whole _Viewpoint Specification Project_.

!images/translatable_message1.png!

The key must be added to the @plugin.properties@ file for each language with the translated message. The default properties file is named @plugin.properties@ and the localized version are identified with a postfixed with the corresponding language code (e.g. for US english @plugin_en_US.properties@, for french @plugin_fr.properties@).  The underlying mechanism is the same as for Eclipse/OSGi plug-ins, so translations can even be contributed by physically separate plug-in fragments. For the message values to be found at runtime, do not forget to:
* include all the @plugin*.properties@ files in the binary build (i.e. check them in the plug-in's @build.properties@ file);
* set the @Bundle-Localization: plugin@ header in your project's @MANIFEST.MF@.

!images/translatable_message2.png!

An Eclipse with localization in english will get the localized messages from @plugin_en.properties@, while an Eclipse with localization in french will get the localized messages from @plugin_fr.properties@.

table(table table-striped table-condensed).
|!images/translatable_message4.png!|!images/translatable_message3.png!|
|_. English locale|_. French locale (with corresponding translation in @plugin_fr.properties@ |

Note that an Eclipse with localization in a language that has no dedicated properties file, will get the localized message from the default @plugin.properties@.

If the ID is not found in the localized properties file or if there is no properties file, the ID will be directly displayed.

!images/translatable_message5.png!

As the internationalization is optional, if a _Translatable_ _Message_ does not start with a _%_ it will be directly displayed without consideration of the localization.

!images/translatable_message6.png!

It is still possible to display a non localized label starting with a _%_ however the character needs to be doubled.

!images/translatable_message8.png!
!images/translatable_message9.png!

_Warning_: _Translatable_ _Messages_ concern only labels set in the _VSM_ that are displayed to the end-users. Sirius is prepared for internationalization but is only available in English. Therefore, the _VSM_ labels can be available in another language but the labels coming from Sirius will stay in English. Moreover, some labels come from some other frameworks (such as EMF or GMF) and if the localization feature (if existing) is not installed, then the labels will stay in English.  

h3(#model_operations). Model Operations

Whenever a _VSM_ requires you to specify a behavior, for example inside any _Tool_ definition, you can use any of the available _Model Operations_ to do so. Refer to the "Model Operations documentation":Model_Operations.html for more details.

h3(#quick_outline). Quick Outline

When defining your _VSM_, a quick outline is available with the shortcut @Ctrl@ + @O@. This allows you to rapidly search text in the displayed name or the contained String attributes of your _VSM_ elements.

The star, @*@, is a joker character, allowing you to search with more complicated patterns. Regarding this, an element is found if there is a word in its name or one of its attributes that match with the text in the filter, so if you want to search within words too, add @*@ at the start of your pattern. Also, you can navigate along the matching elements with @↑@ and @↓@, and go to the selected element in your _VSM_ with @Enter@.

!images/quick_outline.png!

h3(#validation). VSM Validation

It is possible to validate your "_Viewpoint Specification Model_":../../Glossary.html#VSM , to check that your Representations, Mappings and Tools are correctly specified. It will help you to find missing element or erroneous one (e.g. missing required expression).

To validate your VSM, open your @odesign@ file, right-click on the top-level _Group_ element and select _Viewpoint specification Editor > Validate_. A dialog Box will appear and indicate if the validation succeeded. If not, it will give you details about the detected problems (click on the 'details' button of the dialog box). If problems are detected, they will also be added to the Eclipse _Problems_ view. Double-clicking on one of these problems will select the concerned element in the "_Viewpoint Specification Model_":../../Glossary.html#VSM editor.

You can also validate one specific element by right-clicking on it in the "_Viewpoint Specification Models_":../../Glossary.html#VSM and launching the validation process. All the children of the selected element will be validated too. This fine-grained validation is useful to localize issues in the Specification Model, especially when it contains a lot of elements.

It is also possible to use the button <img src="images/specifier-guide/complete_task.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/>, at the top right corner of the editor to launch the validation. This icon changes (<img src="images/specifier-guide/validate_model.png" style="box-shadow:none;display:inline;margin:0px;padding:0px;"/>) when we change the VSM to encourage the user to validate the VSM before saving.

h3(#dynamic). Dynamic Development

Sirius supports dynamic development of your _VSM_ with no need for deployment of your project to test it. If the domain model definition (the EMF meta-model plug-in) is installed in your development environment, and as long as your VSM does not use advanced features which require a deployment (like the definition of new _External Java Actions_ for example), you can test your representations while you are developing them. It is the recommended way to work, especially in the initial development phases, to easily experiment different approaches and see the results immediately.

To do this, simply create a modeling project in your development environment, alongside the Viewpoint Specification Project, and add a sample domain model to it. When you open the _Viewpoints Selection_ dialog on the sample project, you will see that all the viewpoints which are being developed in the same workspace are also made available, in addition to the ones installed as plug-ins. Select the ones you want and create sample representations.

Keep both your representations and the VSM that define them open at the same time. Whenever you change some definition or add new elements into your VSM, simply save it. Sirius will automatically detect the change, reload the new definition and apply it to your existing representations. This way you can develop your representations iteratively, for example starting from an empty diagram and adding more elements, styles and tools while and testing them immediately.

<div style="display: none">
  TODO Add a screenshot with both a VSM (on the left) and the corresponding diagram (on the right) opened at the same time. Make sure the "Model Explorer" is also visible to show both the VSP and the Modeling project they correspond to.
</div>

Note that Sirius does its best to take into account any change in the VSM, even for existing and opened representations. Sometimes, if the changes are too complex or in some corner cases not yet supported, you may need to close and reopen your representation, or in extreme case delete it and create a new one, in order to take the VSM changes into account properly.

h4(#reloadVSM). Reload installed VSM

Even though having your VSP in the runtime environment workspace is the best way to do dynamic development of your VSM, if your VSP is in the installed runtime plug-ins (that is the VSP plug-in is in the development environment workspace), you have the ability the reload it from your runtime to take external changes into account.
This is done with the _Reload installed VSM_ action from the main Eclipse tool bar. 
Click on _Reload installed VSM_ will have automatically effects in opened representations(depending on refresh options).

_Limitations_:
* The action is available only if specifier plug-ins are installed.
* The action is available only if the Eclipse Runtime is a started from PDE (that is, is not a stand alone application).
* Only the VSM is reloaded. The Java classes that may have been changed in the VSP are updated as normal Java classes managed in debug mode.
* If you delete the VSP in the host Eclipse, you may encounter unexpected exceptions.

h3(#migration). Migration from Previous Versions

The _Viewpoint Specification Model_ can evolve between two versions of Sirius. The migration process is done automatically. That means all VSM are migrated at loading time without any action from the user. While a VSM is not saved, the automatic migration will be replayed at the next opening.

