Class 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.

    • 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 method createSession 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 method createSession 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 method createSession 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 method createSession 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()
        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.
        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.
        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)
        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:
        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 with closeSession method.
        Parameters:
        project - project
        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()
      • 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)
      • runInSession

        @Deprecated
        public void runInSession​(java.lang.String sessionName,
                                 java.lang.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 needs to be created
        runnable - runnable to run
      • executeInsideSession

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

        @Deprecated
        public <V> V runInSession​(java.lang.String sessionName,
                                  java.util.concurrent.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​(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:
        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 - project
        sessionName - 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 - project
        sessionName - new session name.
        runnable - runnable to execute.