Session management

com.nomagic.magicdraw.openapi.uml.SessionManager is the singleton manager used for editing model Elements. All modifications to model elements should be performed between the createSession(Project, java.lang.String) and closeSession(Project) method calls.

To edit some com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element, a session with this manager must be created. After editing a model element, a session must be closed. After that, all changes will be applied to the model and registered in the command history (for undo/redo) as one command with a session name. Only one session can be active.

The following code can be used for accessing, checking, and creating the session:

// access a singleton instance by using getInstance()
// only one session can be active, so check this.
if (!SessionManager.getInstance().isSessionCreated(project))
{
// create a new session.
SessionManager.getInstance().createSession(project, "Edit");
}

If other session is already created and not closed, the createSession(Project, java.lang.String) method throws the java.lang.IllegalStateException runtime exception.