The com.nomagic.magicdraw.openapi.uml.SessionManager is a low-level API used to control model modification sessions manually.
All changes to model elements must be performed within an active session, defined by:
A session defines the scope of model changes and ensures that all modifications are:
- Grouped into a single command
- Recorded in the command history
- Available for undo/redo
Only one session can be active per project at a time.
When to Use This API
Use SessionManager only when you need explicit control over the session lifecycle, such as:
- Integrating with legacy APIs or existing code
- Performing advanced or conditional session handling
- Working outside of the
Editing API
For most use cases, prefer: Editing API
import com.nomagic.magicdraw.openapi.uml.SessionManager;
// Access singleton instance
SessionManager sessionManager = SessionManager.getInstance();
// Only one session can be active per project
if (!sessionManager.isSessionCreated(project)) {
sessionManager.createSession(project, "Edit");
}
JAVA
Completing a Session
After performing model changes, the session must be closed:
sessionManager.closeSession(project);
JAVA
Once closed:
- All changes are applied to the model
- They are recorded as a single command (using the session name)
- Undo/redo becomes available
Important Notes
- Only one session can be active at a time
- Calling
createSession(...) while a session is already active throws IllegalStateException - Failing to close a session may leave the model in an inconsistent state
Best Practices
- Always pair
createSession(...) with closeSession(...) - Use
try/finally to guarantee session closure
import com.nomagic.magicdraw.openapi.uml.SessionManager;
SessionManager sessionManager = SessionManager.getInstance();
sessionManager.createSession(project, "Edit");
try {
// perform model changes here
} finally {
sessionManager.closeSession(project);
}
JAVA
- Use meaningful session names (they appear in command history)
- Prefer the Editing API unless manual control is required