Create a plug-in project and we define a static profile, to do so see Help>Help Contents>Papyrus Guide>User Guide>Using UML Profiles sub-menu. As an example, we suppose that a static profile with 2 stereotyped classes named Stereotype_A , Stereotype_Band a "Metacalss" has been defined. We want to extend the Palette of a Class diagram to be able to create directly stereotyped elements from the Palette.
ElementTypes are used to manage the lifecycle (creation, deletion, move, ...) of an Element, see Help>Help Contents>Papyrus Guide>Papyrus Guide>Toolsmith Guide>ElementTypeConfigurations Framework sub-menu.
If we want to create a stereotyped class named Stereotype_A in a class diagram, there are two ways. Without any framework, we shall create manually a class and then we shall manually apply the stereotype Stereotype_A on it. With the ElementTypes Configuration framework, we will intercept the creation of the class and we will apply automatically the stereotype.
First, we need the Papyrus-development related software packages as shown in Figure 1 (we suppose that Papyrus 2020-12 has been installed, for further versions, see the list of update sites.
We select the profile model’s root and right-click on it. We select the "Generate Tooling Model">"Element Types..." sub-menu as shown in Figure 2.
The configuration menu pops up, as shown in Figure 3. We set the Identifier to org.eclipse.my_profile_test (i.e. the name of my profile) and let the other parts of the window as shown.
A new file named my_profile_test.elementtypesconfigurations has been created and looks like in Figure 4.
An ElementTypeConfiguration (noted 1 in Figure 4) has been created per stereotype of my profile. An ApplyStereotypeAdvice Configuration (noted 2 in Figure 4) has also been created. This Advice aims at applying the referenced stereotype of the ElementTypeConfiguration that has been created.
We add the following dependencies to the profile plugin (from org.eclipse.papyrus.infra.types core to org.eclipse.papyrus.uml.types.core):
We add the extension point org.eclipse.papyrus.infra.types.core.elementTypeSetConfiguration in the Extensions of the plugin:
Once installed, we setup the extension point’s clientContextID (Papyrus, i.e. org.eclipse.papyrus.infra.services.edit.TypeContext) and its path (by browsing the file named my_profile_test.elementtypesconfigurations that has been previously generated). See Figure 5.
We validate the Profile plug-in and the Element Types plugin by right-clicking on the profile project and selecting "Papyrus Developer"/"Validate Element Types plug-in..." as shown in Figure 6.
We launch an Eclipse run-time. We setup a Papyrus model with a class diagram. Via the sub-menu Window>Show View>Other, we select the Papyrus Dev/Registered Element Types view as below:
In the associated tab that has appeared, we select org.eclipse.papyrus.infra.services.edit.TypeContext and search for the Element Types (see 1 and 2 in the Figure 7) in the org.eclipse.papyrus.uml.Class element.
The fact that there are the two ElementTypes as expected (org.eclipse.my_profile_test.Stereotype_A and org.eclipse.my_profile_test.Stereotype_B) validates our configuration.
We want to extend the Palette with the new stereotypes based on Class. To do so for this diagram, we need to upload two plugins from the Papyrus git repository:
Do not forget to add org.eclipse.papyrus.uml.diagram.clazz to the dependencies of the profile plugin to be able to extend the Class Diagram Palette. If we want to extend another diagram than the Palette, this must be adapted to the given diagram.
We open the Palette files that correspond to the diagram:
We can see in PapyrusUMLClassDiagram.paletteconfiguration the fields that correspond to the Palette element Nodes/Class we want to “overload”, see Figure 8.
The element of the Palette named Class relies on 5 graphic ElementTypes (from "Class Component Nested Classifier Label" to "Class Shape"). Indeed, the graphical creation needs to be intercepted and it also needs to create UML elements. For example, Class Shape is the representation of the Class in the foreground of the diagram and it inherits from the ElementType UML::Class as shown in the file umldi.elementtypesconfiguration (Properties View, Specialized Types item), see below:
Now, we will create a new “graphical” ElementType that inherits from these “graphical” ElementTypes (e.g. Class Shape) and from our previously created ElementType associated to Stereotype_A. We create a new elementtypesconfiguration file. For this, we right-click on the my_profile_test/profile sub-folder, and we select the sub-menu File>New>Other>ElementTypesConfiguration Model. We name it my_profile_testdi.elementtypesconfiguration.
We select Element Type Set Configurations and its the Properties as shown in Figure 9. We set the Identifier to org.eclipse.papyrus.my_profile_testdi.elementtypeset.extension, the Metamodel Ns Uri shall be http://www.eclipse.org/uml2/5.0.0/UML and we set the name to my_profile_test_extension.
In this set, we create a new Child, by right clicking on Element Type Set Configuration my_profile_test_extension and selecting New Child/ Specialization Type Configuration, as shown in Figure 10.
Before filling the first "graphical" ElementType, we need to load 2 resources (right-click on the Resource Set>Load Resource sub-menu, item Browse Workspace):
ElementTypes associated to Class here);
ElementTypes associated to the stereotypes Stereotype_A and Stereotype_B). We then fill the created "graphical" ElementType as shown in Figure 11.
The Hint shall be Class_Shape and the Kind to org.eclipse.gmf.runtime.emf.type.core.IHintedType, as mentioned in the umldi.elementtypesconfigurations file/item Class Shape. The Hint is a filter to know if this graphical shall or shall not be displayed. By convention, the Identifier shall be set to "org.eclipse.papyrus.my_profile_test.Stereotype_A_Class_Shape" and the Name to "Stereotype_A (Class_Shape)". It is important to have a name with Class Shape as it will be what will appear on later selections. We then select the Specialized Type in this order: previously created ElementType associated to Stereotype_A and the basic "graphical" ElementType next, as shown in Figure 12.
We shall do so for each graphical element of the Palette, i.e. the 4 remaining ones as shown in Figure 8. We finally obtain what is shown in Figure 13.
We add the following extension point in the Extensions of the plugin
(
org.eclipse.papyrus.infra.core.elementTypeSetConfiguration):
We launch the Eclipse runtime and check in the Registered ElementTypes of a model if the 5 newly created ElementTypes exist in org.eclipse.my_profile_test_StereotypeA as shown in Figure 14.
We perform the same operations for the 5 “graphical” ElementTypes of Stereotype_B to be able to reference all these elements in the Palette.
We launch the Eclipse runtime and right-click on the Palette banner. We select the Customize menu as shown in Figure 15.
In the Available Palette buttons, we click on the Create a new local palette one. We set its name to an arbitrary one, like my_palette, and we add my_profile_test as Required profiles:
We click on Next and select Default in the Palette preview to rename it MyPalette. From UML tools, we add Class to the Palette preview and modify it. We click on Class in the Palette Preview and change its name to Stereotype_A. We select all associated ElementTypes, remove them and add the my_profile_extensions/Stereotype_A (Class Shape) ElementType. We then click on Finish. to create the 3 files:
We have to specify the export file option when we create the new palette
We double-click on the last file, select the Stereotype_A element and add the 4 missing ElementTypes shown in Figure 8 until obtaining Figure 16.
We finally copy the 3 files in the project my_profile/profile sub-folder.
First, we shall read and apply this to prepare an architecture framework that will host a new Class Diagram incorporating our Palette.
We add the Palette resource to the resources of the Architecture Framework as shown below:
We then add the Class Diagram that will use this Palette as shown below:
We add the Architecture extension 'org.eclipse.papyrus.infra.architecture.models' and its path (by browsing the file named 'my_test.architecture' that has been previously created).
In order to add the customized diagram in the "new diagram" list, a configuration of the architecture file is mandatory. to do this we can use the "org.eclipse.papyrus.infra.architecture" plug-in as a model.
We have also to add the profile to the diagram created on the the Eclipse runtime
After applying all the steps we have the following result