Download MagicDraw Open API User Guide
Transcript
UML MODEL
Changing UML model
Also it helps to create different types of diagrams.
This manager can be used only if some session was created with SessionManager.
ModelElementsManager performs additional checks before modification if element is not read only. Also check
if element can be added to parent is performed. If ModelElementsManager is not used programmer must perform these checks in code explicitly.
Creating new model element
For creation of model element instances use ElementsFactory class.
create<model element type>Instance() method creates new model element instance .
To create model element, a session with SessionManager must be created.
All changes in UML model be registered and on session closing will be added into command history.
// creating new session
SessionManager.getInstance().createSession("Edit package A");
ElementsFactory f = Application.getInstance().getProject().getElementsFactory();
Package packageA = f.createPackageInstance();
…
// apply changes and add command into command history.
SessionManager.getInstance().closeSession();
Editing model element
To edit some ModelElement, a session with SessionManager must be created.
All changes in UML model will be registered and on session closing will be added into command history.
// creating new session
SessionManager.getInstance().createSession("Edit class A");
if (classA.isEditable())
{
classA.setName(newName);
}
...
// apply changes and add command into command history.
SessionManager.getInstance().closeSession();
It is programmer responsibility to ensure that modified model element is not read only. To check if model element is read only use Element.isEditable() method.
Adding new model element or moving it to another parent
For adding new model Element into a model, use addModelElement(child, parent) method provided by ModelElementsManager.
This manager can be used only if some session was created with SessionManager
ElementsFactory f = Application.getInstance().getProject().getElementsFactory();
Class classA = f.createClassInstance();
53
Copyright © 2003-2011 No Magic, Inc..