Class SessionManager
- java.lang.Object
-
- com.nomagic.magicdraw.openapi.uml.SessionManager
-
@OpenApiAll public class SessionManager extends java.lang.Object
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. 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.
-
-
Field Summary
Fields Modifier and Type Field Description private static SessionManager
instance
The instance of this manager.private boolean
wasEnvironmentLocked
-
Constructor Summary
Constructors Modifier Constructor Description private
SessionManager()
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <V> V
callInsideSession(Project project, java.lang.String sessionName, java.util.concurrent.Callable<V> callable)
Calls given callable inside session.<V> V
callInsideSession(java.lang.String sessionName, java.util.concurrent.Callable<V> callable)
Deprecated.void
cancelSession()
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
checkSessionExistance()
Deprecated.void
checkSessionExistance(Project project)
Deprecated.typo.void
checkSessionExistence()
Deprecated.type.void
checkSessionExistence(Project project)
Checks if the session is created in a given project.void
closeSession()
Deprecated.void
closeSession(Project project)
Closes active session in a given project.void
createSession(Project project, java.lang.String sessionName)
Creates new session in a given project.void
createSession(java.lang.String sessionName)
Deprecated.void
executeInsideSession(Project project, java.lang.String sessionName, java.lang.Runnable runnable)
Executes given runnable inside session.void
executeInsideSession(java.lang.String sessionName, java.lang.Runnable runnable)
Deprecated.static SessionManager
getInstance()
Returns an instance of this manager.boolean
isSessionCreated()
Deprecated.boolean
isSessionCreated(Project project)
Returns true if some session is created in a given project.void
runInSession(java.lang.String sessionName, java.lang.Runnable runnable)
Deprecated.<V> V
runInSession(java.lang.String sessionName, java.util.concurrent.Callable<V> callable)
Deprecated.
-
-
-
Field Detail
-
instance
private static final SessionManager instance
The instance of this manager.
-
wasEnvironmentLocked
private boolean wasEnvironmentLocked
-
-
Method Detail
-
getInstance
public static SessionManager getInstance()
Returns an instance of this manager.- Returns:
- instance of this manager.
-
closeSession
@Deprecated public void 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:
java.lang.IllegalStateException
- if session was not created.- See Also:
createSession(java.lang.String)
-
closeSession
public void closeSession(Project project)
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:
java.lang.IllegalStateException
- if session was not created.- See Also:
createSession(java.lang.String)
-
cancelSession
@Deprecated public void cancelSession()
Deprecated.Closes active session. All changed made to registered ModelElements will be roll backed and command will be removed from the command history list. Session cannot be canceled if it was not created with methodcreateSession
before that.- Throws:
java.lang.IllegalStateException
- if session was not created.- See Also:
createSession(java.lang.String)
-
cancelSession
public void cancelSession(@CheckForNull Project project)
Closes active session in a given project. All changed made to registered ModelElements will be roll backed 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:
java.lang.IllegalStateException
- if session was not created.- See Also:
createSession(java.lang.String)
-
checkSessionExistance
@Deprecated public void checkSessionExistance()
Deprecated.Checks if the session is created.- Throws:
java.lang.IllegalStateException
- if session is not created at the current moment.- See Also:
isSessionCreated()
-
checkSessionExistence
@Deprecated public void checkSessionExistence()
Deprecated.type. UsecheckSessionExistence(Project)
Checks if the session is created.- Throws:
java.lang.IllegalStateException
- if session is not created at the current moment.- See Also:
isSessionCreated()
-
checkSessionExistance
@Deprecated public void checkSessionExistance(@CheckForNull Project project)
Deprecated.typo. UsecheckSessionExistence(Project)
Checks if the session is created in a given project.- Parameters:
project
- project- Throws:
java.lang.IllegalStateException
- if session is not created at the current moment.- See Also:
isSessionCreated()
-
checkSessionExistence
public void checkSessionExistence(@CheckForNull Project project)
Checks if the session is created in a given project.- Parameters:
project
- project- Throws:
java.lang.IllegalStateException
- if session is not created at the current moment.- See Also:
isSessionCreated()
-
createSession
@Deprecated public void createSession(java.lang.String sessionName)
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:
java.lang.IllegalStateException
- if other session is already created and not closed.- See Also:
closeSession()
-
createSession
public void createSession(Project project, java.lang.String sessionName)
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:
java.lang.IllegalStateException
- if other session is already created and not closed.- See Also:
closeSession()
-
isSessionCreated
@Deprecated public boolean isSessionCreated()
Deprecated.Returns true if some session is created in an active project.- Returns:
- true, if session is created(active).
- See Also:
createSession(java.lang.String)
-
isSessionCreated
public boolean isSessionCreated(@CheckForNull Project project)
Returns true if some session is created in a given project.- Parameters:
project
- project- Returns:
- true, if session is created(active).
- See Also:
createSession(java.lang.String)
-
checkReadOnly
public void checkReadOnly(Element target) throws ReadOnlyElementException
Tests if the given element is read only.- Parameters:
target
- element to check- Throws:
ReadOnlyElementException
- exception if given element is read only.
-
runInSession
@Deprecated public void runInSession(java.lang.String sessionName, java.lang.Runnable runnable)
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 needs to be createdrunnable
- runnable to run
-
executeInsideSession
@Deprecated public void executeInsideSession(java.lang.String sessionName, java.lang.Runnable runnable)
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 public <V> V runInSession(java.lang.String sessionName, java.util.concurrent.Callable<V> callable)
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(java.lang.String sessionName, java.util.concurrent.Callable<V> callable) throws java.lang.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:
java.lang.Exception
-
callInsideSession
public <V> V callInsideSession(Project project, java.lang.String sessionName, java.util.concurrent.Callable<V> callable) throws java.lang.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:
java.lang.Exception
-
executeInsideSession
public void executeInsideSession(Project project, java.lang.String sessionName, java.lang.Runnable runnable)
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.
-
-