Class SessionManager
java.lang.Object
com.nomagic.magicdraw.openapi.uml.SessionManager
The singleton manager for Elements editing in the model.
In order to edit some Element session with this manager must be created. After Element editing session must be closed. After that all changes will be applied to model and registered in command history(for undo/redo).
Only one session can be active at the time.
The sample of code is :
Class classA = ...;
SessionManager.getInstance().createSession("Edit class A");
classA.setName("nameB");
Operation operation = Project.getProject(classA).getElementsFactory().createOperationInstance();
ModelElementsManager.getInstance().addElement(operation, classA);
SessionManager.getInstance().closeSession();
Not editable(read only) Elements cannot be edited.
-
Method Summary
Modifier and TypeMethodDescription<V> V
callInsideSession
(Project project, String sessionName, Callable<V> callable) Calls given callable inside session.<V> V
callInsideSession
(String sessionName, Callable<V> callable) Deprecated.void
Deprecated.void
cancelSession
(Project project) Closes active session in a given project.void
checkReadOnly
(Element target) Tests if the given element is read only.void
Deprecated.void
checkSessionExistance
(Project project) Deprecated.typo.void
Deprecated.type.void
checkSessionExistence
(Project project) Checks if the session is created in a given project.void
Deprecated.void
closeSession
(Project project) Closes active session in a given project.void
createSession
(Project project, String sessionName) Creates new session in a given project.void
createSession
(String sessionName) Deprecated.void
executeInsideSession
(Project project, String sessionName, Runnable runnable) Executes given runnable inside session.void
executeInsideSession
(String sessionName, Runnable runnable) Deprecated.static SessionManager
Returns an instance of this manager.boolean
Deprecated.boolean
isSessionCreated
(Project project) Returns true if some session is created in a given project.void
runInSession
(String sessionName, Runnable runnable) Deprecated.<V> V
runInSession
(String sessionName, Callable<V> callable) <V> V
supplyInsideSession
(Project project, String sessionName, Supplier<V> supplier) Applies given supplier inside session.
-
Method Details
-
getInstance
Returns an instance of this manager.- Returns:
- instance of this manager.
-
closeSession
Deprecated.Closes active session in an active project. All changed made to registered ModelElements will be recorder in the command history. Session cannot be closed if it was not created with methodcreateSession
before that.- Throws:
IllegalStateException
- if session was not created.- See Also:
-
closeSession
Closes active session in a given project. All changed made to registered ModelElements will be recorder in the command history. Session cannot be closed if it was not created with methodcreateSession
before that.- Parameters:
project
- project- Throws:
IllegalStateException
- if session was not created.- See Also:
-
cancelSession
Deprecated.Closes active session. All changed made to registered ModelElements will be rolled back and command will be removed from the command history list. Session cannot be canceled if it was not created with methodcreateSession
before that.- Throws:
IllegalStateException
- if session was not created.- See Also:
-
cancelSession
Closes active session in a given project. All changed made to registered ModelElements will be rolled back and command will be removed from the command history list. Session cannot be canceled if it was not created with methodcreateSession
before that.- Parameters:
project
- project- Throws:
IllegalStateException
- if session was not created.- See Also:
-
checkSessionExistance
Deprecated.Checks if the session is created.- Throws:
IllegalStateException
- if session is not created at the current moment.- See Also:
-
checkSessionExistence
Deprecated.type. UsecheckSessionExistence(Project)
Checks if the session is created.- Throws:
IllegalStateException
- if session is not created at the current moment.- See Also:
-
checkSessionExistance
Deprecated.typo. UsecheckSessionExistence(Project)
Checks if the session is created in a given project.- Parameters:
project
- project- Throws:
IllegalStateException
- if session is not created at the current moment.- See Also:
-
checkSessionExistence
Checks if the session is created in a given project.- Parameters:
project
- project- Throws:
IllegalStateException
- if session is not created at the current moment.- See Also:
-
createSession
Deprecated.Creates new session in an active project. Session cannot be created if other session was not closed withcloseSession
method.- Parameters:
sessionName
- name of session which will be the name of command the command history(undo/redo).- Throws:
IllegalStateException
- if other session is already created and not closed.- See Also:
-
createSession
Creates new session in a given project. Session cannot be created if other session was not closed withcloseSession
method.- Parameters:
project
- projectsessionName
- name of session which will be the name of command the command history(undo/redo).- Throws:
IllegalStateException
- if other session is already created and not closed.- See Also:
-
isSessionCreated
Deprecated.Returns true if some session is created in an active project.- Returns:
- true, if session is created(active).
- See Also:
-
isSessionCreated
Returns true if some session is created in a given project.- Parameters:
project
- project- Returns:
- true, if session is created(active).
- See Also:
-
checkReadOnly
Tests if the given element is read only.- Parameters:
target
- element to check- Throws:
ReadOnlyElementException
- exception if given element is read only.
-
runInSession
Deprecated.Execute the given runnable in MD session. runInSession() will check whether a session has been already created. If not, it creates a new session. After executed, it closes its created session. The method never cancels the session even exception occurs. A runnable needs to cancel the session explicitly in case of exception.- Parameters:
sessionName
- session name if it needs to be createdrunnable
- runnable to run
-
executeInsideSession
Deprecated.Executes given runnable inside session. Creates new session if session is not created yet, after execution new session is closed (canceled if exception occurs on execution).- Parameters:
sessionName
- new session name.runnable
- runnable to execute.
-
runInSession
Deprecated.Execute the given callable in MD session. runInSession() will check whether a session has been already created. If not, it creates a new session. After executed, it closes its created session. The method never cancels the session even exception occurs. A callable needs to cancel the session explicitly in case of exception.- Type Parameters:
V
- the return type- Parameters:
sessionName
- the session namecallable
- the callable object- Returns:
- the return value from callable.
-
callInsideSession
@Deprecated public <V> V callInsideSession(String sessionName, Callable<V> callable) throws Exception Deprecated.Calls given callable inside session. Creates new session if session is not created yet, after execution new session is closed (canceled if exception occurs on calling).- Type Parameters:
V
- return type.- Parameters:
sessionName
- new session name.callable
- callable to call.- Throws:
Exception
-
callInsideSession
public <V> V callInsideSession(Project project, String sessionName, Callable<V> callable) throws Exception Calls given callable inside session. Creates new session if session is not created yet, after execution new session is closed (canceled if exception occurs on calling).- Type Parameters:
V
- return type.- Parameters:
project
- projectsessionName
- new session name.callable
- callable to call.- Throws:
Exception
-
supplyInsideSession
Applies given supplier inside session. Creates new session if session is not created yet, after execution new session is closed (canceled if exception occurs on calling).- Type Parameters:
V
- return type- Parameters:
project
- projectsessionName
- new session namesupplier
- supplier to apply
-
executeInsideSession
Executes given runnable inside session. Creates new session if session is not created yet, after execution new session is closed (canceled if exception occurs on execution).- Parameters:
project
- projectsessionName
- new session name.runnable
- runnable to execute.
-
callInsideSession(Project, String, Callable)