Copying Cutting Pasting in Papyrus
Introduction
Papyrus's policy is to ensure consistency between models and diagrams, so by default the cut/copy/paste functionalities act both on diagram and model elements.
The Copy/Cut/Paste functionalities are available between models and diagrams but not between eclipse instances.
The Cut/Paste functionalities are disable on root and read only elements.
User Interface
Right click on a model explorer element
Model Explorer KeyBinding
- Type M1+C for Papyrus copy
- Type M1+X for Papyrus cut
- Type M1+V for Papyrus paste
M1 is the COMMAND key on MacOS X, and the CTRL key on most other platforms.
M2 is the SHIFT key.
On a Diagram element
Right Click>EDIT
Diagram KeyBinding
- Type M1+C for Papyrus copy
- Type M1+X for Papyrus cut
- Type M1+V for Papyrus paste
- Type M1+M2+C for Graphical copy
- Type M1+M2+X for Graphical cut
- Type M1+M2+V for Graphical paste
Preferences
Papyrus copy/paste/cut preferences is accessible on
Window>Preferences>Papyrus>Paste
The preference page lists all the available strategies and the checkbox to select whether the references should be kept.
List of Paste strategies
Common Strategies
Default Paste Strategy
The strategy paste all copied elements in the selected place.
It is required for all other strategies.
SterotypeStrategy
The strategy reapplies profiles and stereotypes on the newly copied elements.
Concerning the stereotype itself, several cases are possible for its properties:
- the property is typed with a primitive type
- we copy the values in the stereotype applied on the pasted element
- the property is typed with a UML Element or a Stereotype
- if the value of the property references an element included in the copied UML Tree, we update the fields with the corresponding copied element,
- if the value of the property references an element not included in the copied UML Tree, we keep the initial value.
Here, an illustration of this strategy, in the next model, we use the following profile.
Here, the initial state of the model.
Now the user selects these elements (
ClassToCopy,
ClassRef1,
ClassRef3,
StereotypedClass1 and
StereotypedClass3.
and paste them in the
TargetPackage. The stars indicate the copied elements
As we can see in the previous image, the 5 elements have been copied in the
TargetPackage and the required stereotypes have been applied.
The values of the
StereotypeWithReferences have been updated to reference the pasted elements. The updated element
Preferences
- Always apply missing profiles: missing profiles will be applied to the root of the target model
- Never apply missing profiles: stereotypes referencing missing profiles will not be paste
Rename Strategy
- Only the duplications of the
roots elements will be renamed
- An element is renamed only if there is already an element with the
same name on the paste selection
- The element will be renamed in CopyOf_NameOfTheElement_id. The id will be incremented for each
same copy/paste. Example: a Class1 will become CopyOf_Class1_1 then CopyOf_Class1_2
Diagram in Model Explorer Strategy
The strategy allows copy/paste for diagrams in model explorer.
Several usecases have been implemented. The first thing to know is that a Diagram has 2 contexts:
- the
root element (known as semantic context) - it represents the background of the diagram. The UML Elements created on the background will be owned by the
root element.
- in the implementation, we use the field
Diagram#element to reference the
root element displayed in the UI.
- the
owner (as known as graphical context) - is used to display the Diagram in the ModelExplorer
- this field is not directly owned by the
Diagram, in the implementation, we use an intermediate element, a
PapyrusDiagramStyle, owned by the diagram, to reference the
owner
The copy/paste of diagram follows these rules:
- when an UML Element is copied,
- if elements referenced by
Diagram#owner and
Diagram#rootElement are included in the copied UML Tree, we update the fields with the corresponding copied element,
- if one element referenced by
Diagram#owner or
Diagram#rootElement is not included in the copied UML Tree, we don't update the concerned field.
- when the diagram itself is copied, we only update its
Diagram#owner
- when a UML Element is copied, we update the fields
Diagram#owner and
Diagram#rootElement with the copy of the initial values, when these values are included in the copied UML Tree. When one of these values is not included in the copy, we don't have to update the concerned field.
Here, the implemented usecases for a Copy/Paste in the ModelExplorer, with the previous model in snapshot as initial values:
Diagram#rootElement=
Class1 and
Diagram#owner=
Package1.
- Copy/Paste of the Diagram itself in the Package
Package2
- this copy preserves the
rootElement and update the
owner, so the copy of the Diagram has these values:
Diagram#rootElement=
Class1 and Diagram#owner=
Package2.
- Copy/Paste of the Diagram#owner
Package1 in the Model
ModelRoot
-
Package1 is copied as
CopyOf_Package1_2 with its contents
Class1 and
InnerClass
- The diagram is also copied and we update the fields as follow :
Diagram#rootElement=
Class1 (
ModelRoot::CopyOf_Package1_2::Class1) and Diagram#owner=
CopyOf_Package1_2.
- Copy/Paste of the Diagram#rootElement
Class1 in the Package
Package1
-
Class1 is copied as
CopyOf_Class1_2 in the Package
Package1
- The diagram is also copied. The
owner is not changed in the copy, but the
rootElement is updated. So we update the fields as follow :
Diagram#rootElement=
CopyOf_Class1_1
Table in model Explorer Strategy
The strategy allows copy/paste for tables in model explorer.
Uml Strategies
The following strategies will only apply on uml models
Constraint Paste Strategy
This strategy works only on uml class diagrams. It draws the constraint "context" link after a paste.
Sysml Strategies
The following strategies will only apply on sysml models
Part Paste Strategy
This strategy duplicates the linked association for each property pasted.