Class SessionManager

java.lang.Object
com.nomagic.magicdraw.openapi.uml.SessionManager

@OpenApiAll public class SessionManager extends 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 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 Details

    • 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 method createSession before that.
      Throws:
      IllegalStateException - if session was not created.
      See Also:
    • 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 method createSession before that.
      Parameters:
      project - project
      Throws:
      IllegalStateException - if session was not created.
      See Also:
    • cancelSession

      @Deprecated public void 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 method createSession before that.
      Throws:
      IllegalStateException - if session was not created.
      See Also:
    • cancelSession

      public void cancelSession(@CheckForNull Project project)
      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 method createSession before that.
      Parameters:
      project - project
      Throws:
      IllegalStateException - if session was not created.
      See Also:
    • checkSessionExistance

      @Deprecated public void checkSessionExistance()
      Checks if the session is created.
      Throws:
      IllegalStateException - if session is not created at the current moment.
      See Also:
    • checkSessionExistence

      @Deprecated public void checkSessionExistence()
      Deprecated.
      Checks if the session is created.
      Throws:
      IllegalStateException - if session is not created at the current moment.
      See Also:
    • checkSessionExistance

      @Deprecated public void checkSessionExistance(@CheckForNull Project project)
      Deprecated.
      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

      public void checkSessionExistence(@CheckForNull Project 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:
    • createSession

      @Deprecated public void createSession(String sessionName)
      Creates new session in an active project. Session cannot be created if other session was not closed with closeSession 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

      public void createSession(Project project, String sessionName)
      Creates new session in a given project. Session cannot be created if other session was not closed with closeSession method.
      Parameters:
      project - project
      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:
    • 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:
    • 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:
    • 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(String sessionName, Runnable runnable)
      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 created
      runnable - runnable to run
    • executeInsideSession

      @Deprecated public void executeInsideSession(String sessionName, 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:
      sessionName - new session name.
      runnable - runnable to execute.
    • runInSession

      @Deprecated public <V> V runInSession(String sessionName, Callable<V> callable)
      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 name
      callable - the callable object
      Returns:
      the return value from callable.
    • callInsideSession

      @Deprecated public <V> V callInsideSession(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:
      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 - project
      sessionName - new session name.
      callable - callable to call.
      Throws:
      Exception
    • supplyInsideSession

      public <V> V supplyInsideSession(Project project, String sessionName, Supplier<V> supplier)
      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 - project
      sessionName - new session name
      supplier - supplier to apply
    • executeInsideSession

      public void executeInsideSession(Project project, String sessionName, 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 - project
      sessionName - new session name.
      runnable - runnable to execute.