Class PresentationElementsManager
java.lang.Object
com.nomagic.magicdraw.openapi.uml.PresentationElementsManager
The utility class for ShapesElements and PathElement creating, moving and properties changing.
Works together with
SessionManager
.
This manager can be used only if some session was created with SessionManager. See code sample in SessionManager description for more details.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
changePathBreakPoints
(PathElement element, List newBreakPoints) Changes the break points of the given PathElement.void
changePathPoints
(PathElement element, Point supplierPoint, Point clientPoint, List<Point> newBreakPoints) Changes the points of the given PathElement.connectComment
(ShapeElement comment, PresentationElement target) Connects given comment with note anchor to the given presentation element.connectNote
(ShapeElement noteOrComment, PresentationElement target) Connects given note or comment shape with an anchor to the given presentation element.createContainmentLink
(PresentationElement parentView, PresentationElement childView) Connects given parent and child elements with containment link.createContentShape
(PresentationElement parent, Point location, Element pack) Creates a ContentShape in the given parent.createDurationConstraint
(DurationConstraint durationConstraint, PathElement firstConstrainedView, PathElement secondConstrainedView) Creates DurationConstraint presentation element between the given two end views, that can be either SeqMessageView or ActivationViewcreateFoundMessage
(Message message, ShapeElement from, Message insertAfter, int verticalGap) Creates a found message symbol for given message from the given shape element.createGenericView
(Element element, PresentationElement parent, String identifier) Creates Generic viewcreateImageShape
(PresentationElement parent, File imageFile) Creates an image shape in the given parent.createImageShape
(PresentationElement parent, File imageFile, Point location) Creates an image shape in the given parent.createLostMessage
(Message message, ShapeElement from, Message insertAfter, int verticalGap) Creates a lost message symbol for given message from the given shape element.createNote
(PresentationElement parent) Creates a note in the given parent.createNote
(PresentationElement parent, Point location) Creates a note in the given parent.createPartShape
(Property part, PresentationElement parent, List<Property> nestedPath, boolean createRelationships, Point location) Creates part shape on the diagram at a given coordinate.createPathElement
(Element relationship, PresentationElement client, PresentationElement supplier) Creates a PathElement for given relationship between given client and supplier PresentationElements.createPathToSelfShapeElement
(Element relationship, PresentationElement client) Creates a rectangular shape in the given parent.createRectangularShape
(PresentationElement parent, Point location) Creates a rectangular shape in the given parent.createSeparator
(PresentationElement parent) Creates a separator shape in the given parent.createSeparator
(PresentationElement parent, Point location) Creates a separator shape in the parent.createSequenceMessage
(Message message, MessageSort sort, ShapeElement from, ShapeElement to, boolean recursive, int diagonal, Message insertAfter, int verticalGap) Creates a PathElement for given message between given client (from) and supplier (to) PresentationElements.createShapeElement
(Element element, PresentationElement parent) Creates a ShapeElement for given ModelElement in the given diagram.createShapeElement
(Element element, PresentationElement parent, boolean createRelationships) Creates a ShapeElement for given ModelElement in the given diagram.createShapeElement
(Element element, PresentationElement parent, boolean createRelationships, Point location) Creates a ShapeElement for given ModelElement in the given diagram.createSwimlane
(List<? extends ActivityPartition> horizontal, List<? extends ActivityPartition> vertical, DiagramPresentationElement diagram) Creates a swimlane in a given diagram.createTextBox
(PresentationElement parent) Creates a text box in the given parent.createTextBox
(PresentationElement parent, Point location) Creates a text box in the given parent.createVirtualRelation
(PresentationElement clientView, PresentationElement supplierView, String ruleKey) Creates Virtual Relation viewvoid
Removes given element from the diagram.static PresentationElementsManager
Returns an instance of this manager.protected boolean
void
movePresentationElement
(PresentationElement view, PresentationElement parent, Point location) Moves a presentation element to the given parent and the specified location.void
movePresentationElement
(PresentationElement view, PresentationElement parent, Point location, boolean canChangeElementOwner) Moves a presentation element to the given parent and the specified location.void
movePresentationElement
(PresentationElement view, Point location) Moves a presentation element to the specified location.void
movePresentationElements
(List<PresentationElement> views, PresentationElement parent, Point location) Moves a list of presentation elements to the given parent and the specified location.void
movePresentationElements
(List<PresentationElement> views, PresentationElement parent, Point location, boolean canChangeElementOwner) Moves a list of presentation elements to the given parent and the specified location.void
movePresentationElements
(List<PresentationElement> views, Point location) Moves a list of presentation elements to the specified location.void
resetLabelPositions
(PathElement element) Moves all given PathElement's labels to the default position(for example default position for name label is a middle of the path).void
reshapeShapeElement
(ShapeElement element, Rectangle newBounds) Reshapes given ShapeElement.void
setConstraintForNote
(ShapeElement note, Constraint constraint) Shows given constraint in the given note.void
setPresentationElementProperties
(PresentationElement view, PropertyManager propertyManager) Changes symbol properties of a given presentation element.void
setText
(ShapeElement shape, String text) Sets text for given symbol.
-
Constructor Details
-
PresentationElementsManager
protected PresentationElementsManager()Private constructor. Do not allow to create instance outside this class.
-
-
Method Details
-
getInstance
Returns an instance of this manager.- Returns:
- instance of this manager.
-
createShapeElement
public ShapeElement createShapeElement(Element element, PresentationElement parent) throws ReadOnlyElementException Creates a ShapeElement for given ModelElement in the given diagram. The created shape location is (0,0). The relationships to other symbols are not created.- Parameters:
element
- the given ModelElement to create ShapeElement for.parent
- presentation element in which symbol should be created. In case created symbol is illegal in such parent method can produce unpredictable results. Valid combination is such as package in package, class in package etc.- Returns:
- created shape element.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createShapeElement
public ShapeElement createShapeElement(Element element, PresentationElement parent, boolean createRelationships, @CheckForNull Point location) throws ReadOnlyElementException Creates a ShapeElement for given ModelElement in the given diagram. The created shape location is (0,0).- Parameters:
element
- the given ModelElement to create ShapeElement for.createRelationships
- create relationships to other symbols or not.parent
- presentation element in which symbol should be created. In case created symbol is illegal in such parent method can produce unpredictable results. Valid combination is such as package in package, class in package etc.location
- the location where the new symbol is placed- Returns:
- created shape element.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createShapeElement
public ShapeElement createShapeElement(Element element, PresentationElement parent, boolean createRelationships) throws ReadOnlyElementException Creates a ShapeElement for given ModelElement in the given diagram. The created shape location is (0,0).- Parameters:
element
- the given ModelElement to create ShapeElement for.createRelationships
- create relationships to other symbols or not.parent
- presentation element in which symbol should be created. In case created symbol is illegal in such parent method can produce unpredictable results. Valid combination is such as package in package, class in package etc.- Returns:
- created shape element.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createPathElement
public PathElement createPathElement(Element relationship, PresentationElement client, PresentationElement supplier) throws ReadOnlyElementException Creates a PathElement for given relationship between given client and supplier PresentationElements. The PathElement will be created in the same diagram as client's and supplier's PresentationElements are.
ModelElement of client must be equal to relationship's client.
ModelElement of supplier must be equal to relationship's supplier.- Parameters:
relationship
- the given relationship.client
- a PresentationElement of relationship client.supplier
- a PresentationElement of relationship supplier.- Returns:
- created PathElement for given a relationship.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createPathToSelfShapeElement
public ShapeElement createPathToSelfShapeElement(Element relationship, PresentationElement client) throws ReadOnlyElementException - Throws:
ReadOnlyElementException
-
deletePresentationElement
Removes given element from the diagram.- Parameters:
element
- the element to remove.- Throws:
ReadOnlyElementException
- if diagram is read only.
-
isPresentationElementEditable
-
movePresentationElement
public void movePresentationElement(PresentationElement view, PresentationElement parent, Point location) throws ReadOnlyElementException Moves a presentation element to the given parent and the specified location. During this operation parent of the symbol can change both at the symbols and at the model level. If model is read-only, model element parent does not change, only symbol coordinates change.- Parameters:
view
- presentation element to move.parent
- parent to move into.location
- location to move to.- Throws:
ReadOnlyElementException
- if element permissions prohibited to perform this operation.
-
movePresentationElement
public void movePresentationElement(PresentationElement view, PresentationElement parent, Point location, boolean canChangeElementOwner) throws ReadOnlyElementException Moves a presentation element to the given parent and the specified location. During this operation parent of the symbol can change both at the symbols and at the model level. If model is read-only, model element parent does not change, only symbol coordinates change.- Parameters:
view
- presentation element to move.parent
- parent to move into.location
- location to move to.canChangeElementOwner
- allow to change Element owner if needed by symbols structure- Throws:
ReadOnlyElementException
- if element permissions prohibited to perform this operation.
-
movePresentationElement
public void movePresentationElement(PresentationElement view, Point location) throws ReadOnlyElementException Moves a presentation element to the specified location. During this operation parent of the symbol does not change, only geometrical position changes.- Parameters:
view
- symbol to move.location
- location to move to.- Throws:
ReadOnlyElementException
- if element permissions prohibited to perform this operation.
-
movePresentationElements
public void movePresentationElements(List<PresentationElement> views, PresentationElement parent, Point location) throws ReadOnlyElementException Moves a list of presentation elements to the given parent and the specified location. During this operation parent of symbols can change both at the symbols and at the model level. If model is read-only, model element parent does not change, only symbol coordinates change.- Parameters:
views
- presentation elements to move.parent
- parent to move into.location
- location to move to.- Throws:
ReadOnlyElementException
- if element permissions prohibited to perform this operation.
-
movePresentationElements
public void movePresentationElements(List<PresentationElement> views, PresentationElement parent, Point location, boolean canChangeElementOwner) throws ReadOnlyElementException Moves a list of presentation elements to the given parent and the specified location. During this operation parent of symbols can change both at the symbols and at the model level. If model is read-only, model element parent does not change, only symbol coordinates change.- Parameters:
views
- presentation elements to move.parent
- parent to move into.location
- location to move to.canChangeElementOwner
- allow to change Element owner if needed by symbols structure- Throws:
ReadOnlyElementException
- if element permissions prohibited to perform this operation.
-
movePresentationElements
public void movePresentationElements(List<PresentationElement> views, Point location) throws ReadOnlyElementException Moves a list of presentation elements to the specified location. During this operation parent of symbols does not change.- Parameters:
views
- presentation elements to move.location
- location to move to.- Throws:
ReadOnlyElementException
- if element permissions prohibited to perform this operation.
-
reshapeShapeElement
public void reshapeShapeElement(ShapeElement element, Rectangle newBounds) throws ReadOnlyElementException Reshapes given ShapeElement.- Parameters:
element
- the ShapeElement to reshape.newBounds
- a new bounds of the element.- Throws:
ReadOnlyElementException
- if element is read only.
-
changePathBreakPoints
public void changePathBreakPoints(PathElement element, List newBreakPoints) throws ReadOnlyElementException Changes the break points of the given PathElement. The order of break points is from supplier to client.- Parameters:
element
- the given PathElement.newBreakPoints
- a list of new PathElement break points- Throws:
ReadOnlyElementException
- if given element is read only and can't edit.IllegalArgumentException
- if given element is null or if given breakpoints are null
-
changePathPoints
public void changePathPoints(PathElement element, Point supplierPoint, Point clientPoint, List<Point> newBreakPoints) throws ReadOnlyElementException Changes the points of the given PathElement. The order of break points is from supplier to client.- Parameters:
element
- the given PathElement.supplierPoint
- new supplierclientPoint
- new client pointnewBreakPoints
- a list of new PathElement break points- Throws:
ReadOnlyElementException
- if given element is read only and can't editIllegalArgumentException
- if given element is null or if given breakpoints are null
-
resetLabelPositions
Moves all given PathElement's labels to the default position(for example default position for name label is a middle of the path).- Parameters:
element
- the given PathElement to reset labels for.- Throws:
ReadOnlyElementException
- if given element is read only and can not be editedIllegalArgumentException
- if given element is null.
-
setPresentationElementProperties
public void setPresentationElementProperties(PresentationElement view, PropertyManager propertyManager) throws ReadOnlyElementException Changes symbol properties of a given presentation element. Make sure to pass the newly created or cloned property manager, not the old one.Example:
PresentationElement view = // some view ChoiceProperty property = (ChoiceProperty) view.getProperty(PropertyID.TAGGED_VALUES_DISPLAY_MODE); // important to create a new property or clone the old one! Property clonedProperty = property.clone(); clonedProperty.setValue(ClassifierView.IN_COMPARTMENT); // important to create a new property manager or clone the old one! PropertyManager properties = new PropertyManager(); properties.addProperty(clonedProperty); PresentationElementsManager.getInstance().setPresentationElementProperties(view, properties);
- Parameters:
view
- symbol for which to change the property manager.propertyManager
- a newly created or cloned manager with new properties, do not reuse the old property manager.- Throws:
ReadOnlyElementException
- if given element is null and can not be edited.IllegalArgumentException
- if given element and properties is null and the element 's type can't have properties.
-
createNote
Creates a note in the given parent. The created shape location is (0,0).- Parameters:
parent
- the parent to create ShapeElement in- Returns:
- created shape element
- Throws:
ReadOnlyElementException
- if diagram is read only and cannot editIllegalArgumentException
- if given parent is null
-
createNote
public ShapeElement createNote(PresentationElement parent, @CheckForNull Point location) throws ReadOnlyElementException Creates a note in the given parent.- Parameters:
parent
- the parent to create Note inlocation
- location of created Note- Returns:
- created Note
- Throws:
ReadOnlyElementException
- if diagram is read only and can not be editedIllegalArgumentException
- if parent is null
-
createTextBox
Creates a text box in the given parent. The created shape location is (0,0).- Parameters:
parent
- the parent to create ShapeElement in.- Returns:
- created shape element
- Throws:
ReadOnlyElementException
- if diagram is read only and cannot editIllegalArgumentException
- if given parent is null
-
createImageShape
public ShapeElement createImageShape(PresentationElement parent, File imageFile, @CheckForNull Point location) throws ReadOnlyElementException Creates an image shape in the given parent.- Parameters:
parent
- the parent to create Image Shape inimageFile
- image filelocation
- location of created Image Shape- Returns:
- created Image Shape
- Throws:
ReadOnlyElementException
- if diagram is read only and can not be editedIllegalArgumentException
- if parent is null
-
createImageShape
public ShapeElement createImageShape(PresentationElement parent, File imageFile) throws ReadOnlyElementException Creates an image shape in the given parent. The created shape location is (0,0).- Parameters:
parent
- the parent to create Image Shape inimageFile
- image file- Returns:
- created shape element
- Throws:
ReadOnlyElementException
- if parent is read only and cannot editIllegalArgumentException
- if given parent is null
-
createTextBox
public ShapeElement createTextBox(PresentationElement parent, @CheckForNull Point location) throws ReadOnlyElementException Creates a text box in the given parent.- Parameters:
parent
- the parent to create TextBox inlocation
- location of TextBox- Returns:
- created TextBox
- Throws:
ReadOnlyElementException
- if diagram is read only and can not be editedIllegalArgumentException
- if given parent is null
-
createContentShape
public ContentShape createContentShape(PresentationElement parent, @CheckForNull Point location, Element pack) throws ReadOnlyElementException Creates a ContentShape in the given parent.- Parameters:
parent
- the parent to create ContentShape inlocation
- location of shapepack
- content shape root content- Returns:
- created TextBox
- Throws:
ReadOnlyElementException
- if diagram is read only and can not be editedIllegalArgumentException
- if given parent is null
-
createSeparator
Creates a separator shape in the given parent. The created shape location is (0,0).- Parameters:
parent
- the parent to create ShapeElement in- Returns:
- created shape element
- Throws:
ReadOnlyElementException
- if diagram is read only and cannot editIllegalArgumentException
- if given parent is null
-
createSeparator
public ShapeElement createSeparator(PresentationElement parent, @CheckForNull Point location) throws ReadOnlyElementException Creates a separator shape in the parent.- Parameters:
parent
- the parent to create Separator inlocation
- location of Separator- Returns:
- created Separator
- Throws:
ReadOnlyElementException
- if diagram is read only and can not be editedIllegalArgumentException
- if given parent is null
-
createRectangularShape
public ShapeElement createRectangularShape(PresentationElement parent) throws ReadOnlyElementException Creates a rectangular shape in the given parent. The created shape location is (0,0).- Parameters:
parent
- the parent to create ShapeElement in- Returns:
- created shape element
- Throws:
ReadOnlyElementException
- if diagram is read only and cannot editIllegalArgumentException
- if given parent is null
-
createRectangularShape
public ShapeElement createRectangularShape(PresentationElement parent, @CheckForNull Point location) throws ReadOnlyElementException Creates a rectangular shape in the given parent.- Parameters:
parent
- the parent to create Rectangular Shape inlocation
- location of shape- Returns:
- created shaped
- Throws:
ReadOnlyElementException
- if diagram is read only and can not be editedIllegalArgumentException
- if given parent is null
-
connectNote
public PathElement connectNote(ShapeElement noteOrComment, PresentationElement target) throws ReadOnlyElementException Connects given note or comment shape with an anchor to the given presentation element.- Parameters:
noteOrComment
- the given note or comment shape.target
- the presentation element to connect note (or comment) to.- Returns:
- created anchor.
- Throws:
ReadOnlyElementException
- if note (or comment) is read-only and cannot edit.IllegalArgumentException
- if given note is not instance of NoteView or comment is not instance of CommentView.
-
connectComment
public PathElement connectComment(ShapeElement comment, PresentationElement target) throws ReadOnlyElementException Connects given comment with note anchor to the given presentation element.- Parameters:
comment
- comment to connect.target
- the presentation element to connect comment to.- Returns:
- created shape element.
- Throws:
ReadOnlyElementException
- if comment is read-only and not editable.IllegalArgumentException
- if given comment is not an instance of CommentView.
-
setText
Sets text for given symbol. Given symbol can be note, text box or separator.- Parameters:
shape
- the given symbol.text
- a new text for a given symbol.- Throws:
ReadOnlyElementException
- if diagram is read only.IllegalArgumentException
- if given node is not instance of NoteView,TextBoxView,SeparatorView.
-
setConstraintForNote
public void setConstraintForNote(ShapeElement note, Constraint constraint) throws ReadOnlyElementException Shows given constraint in the given note. Constraint must be added into model already. Constraint must be assigned to ModelElement of symbol connected to the given note. If these conditions are not true, constraint may not be shown inside the note.- Parameters:
note
- the given note.constraint
- the given constraint.- Throws:
ReadOnlyElementException
- if note is read only and cannot edit.IllegalArgumentException
- if given node is not instance of NoteView.
-
createSwimlane
public SwimlaneView createSwimlane(List<? extends ActivityPartition> horizontal, List<? extends ActivityPartition> vertical, DiagramPresentationElement diagram) throws ReadOnlyElementException Creates a swimlane in a given diagram. Adds horizontal and vertical partitions to the created swimlane.- Parameters:
horizontal
- list of horizontal partitionsvertical
- list of vertical partitionsdiagram
- parent for swimlane- Returns:
- created swimlane
- Throws:
ReadOnlyElementException
- if given diagram is read only and cannot edit.IllegalArgumentException
- if given diagram is null.
-
createContainmentLink
public PathElement createContainmentLink(PresentationElement parentView, PresentationElement childView) throws ReadOnlyElementException Connects given parent and child elements with containment link.- Parameters:
parentView
- the presentation element of the parent element.childView
- the presentation element of the child element.- Returns:
- created link.
- Throws:
ReadOnlyElementException
- if diagram is read only.IllegalArgumentException
- if parent element does not contain child element.
-
createLostMessage
public PathElement createLostMessage(Message message, ShapeElement from, @CheckForNull Message insertAfter, int verticalGap) throws ReadOnlyElementException Creates a lost message symbol for given message from the given shape element. The given message is initialized (message ends are created and set, message sort is assigned) in this method.- Parameters:
message
- the given messagefrom
- a ShapeElement of message client lifelineinsertAfter
- the new message is inserted after this message, or null to insert before all messagesverticalGap
- vertical gap before the new message- Returns:
- created symbol for a given message
- Throws:
ReadOnlyElementException
- if diagram is read only
-
createFoundMessage
public PathElement createFoundMessage(Message message, ShapeElement from, @CheckForNull Message insertAfter, int verticalGap) throws ReadOnlyElementException Creates a found message symbol for given message from the given shape element. The given message is initialized (message ends are created and set, message sort is assigned) in this method.- Parameters:
message
- the given messagefrom
- a ShapeElement of message client lifelineinsertAfter
- the new message is inserted after this message, or null to insert before all messagesverticalGap
- vertical gap before the new message- Returns:
- created symbol for a given message
- Throws:
ReadOnlyElementException
- if diagram is read only
-
createSequenceMessage
public PathElement createSequenceMessage(Message message, MessageSort sort, ShapeElement from, ShapeElement to, boolean recursive, int diagonal, @CheckForNull Message insertAfter, int verticalGap) throws ReadOnlyElementException Creates a PathElement for given message between given client (from) and supplier (to) PresentationElements. The given message is initialized (message ends are created and set, message sort is assigned) in this method. The diagram should be opened to make the messages' layout correctly.- Parameters:
message
- the given message.sort
- message sort.from
- a ShapeElement of message client lifeline.to
- a ShapeElement of message supplier lifeline.recursive
- true if message is recursive (recursive message can be only when from == to).diagonal
- vertical size of diagonal message, or 0 if the message is not diagonal.insertAfter
- the new message is inserted after this message, or null to insert before all messages.verticalGap
- vertical gap before the new message.- Returns:
- created PathElement for given message.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createDurationConstraint
@CheckForNull public DurationConstraintView createDurationConstraint(DurationConstraint durationConstraint, PathElement firstConstrainedView, PathElement secondConstrainedView) throws ReadOnlyElementException Creates DurationConstraint presentation element between the given two end views, that can be either SeqMessageView or ActivationView- Parameters:
durationConstraint
- model element for the DurationConstraintViewfirstConstrainedView
- first endsecondConstrainedView
- second end- Throws:
ReadOnlyElementException
- if diagram is not editable
-
createPartShape
@CheckForNull public PartView createPartShape(Property part, PresentationElement parent, List<Property> nestedPath, boolean createRelationships, @CheckForNull Point location) throws ReadOnlyElementException Creates part shape on the diagram at a given coordinate. Parent symbol can be specified. If nested parts path is specified, nesting level is displayed in dot notation. It can be specified whether to create connected relationships.- Parameters:
part
- part for which to create a shape.parent
- parent symbol in which to add the part.nestedPath
- a list of nested parts in which to nest the given part symbol.createRelationships
- controls whether to display connected paths.location
- location on the diagram where to move the part.- Returns:
- created part symbol or null if it was not possible to create it.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createVirtualRelation
@CheckForNull public PathElement createVirtualRelation(PresentationElement clientView, PresentationElement supplierView, String ruleKey) throws ReadOnlyElementException Creates Virtual Relation view- Parameters:
clientView
- relation client viewsupplierView
- relation supplier viewruleKey
- Virtual relation rule key- Returns:
- created virtual relation symbol or null if it was not possible to create it.
- Throws:
ReadOnlyElementException
- if diagram is read only.
-
createGenericView
public ShapeElement createGenericView(Element element, PresentationElement parent, String identifier) throws ReadOnlyElementException Creates Generic view- Parameters:
element
- element for which the generic view is createdparent
- created view parent elementidentifier
- Generic view unique identifier, you can have different Generic views for same element when the identifier is different- Throws:
ReadOnlyElementException
- if diagram is read only.
-