Class ProjectsManager

    • Field Detail

      • projects

        private final java.util.List<Project> projects
        All projects in their activation order (last= currently active).
      • activatedProjects

        private final java.util.Set<Project> activatedProjects
        All activated projects
      • loadedProjects

        private final java.util.Set<Project> loadedProjects
        Set of projects that were finished loading by ProjectLoader
      • activeProject

        @CheckForNull
        private Project activeProject
        Activated project. From projects list there is no information is current project activated or not.
      • pendingToLoadProjects

        private final java.util.Collection<Project> pendingToLoadProjects
    • Constructor Detail

      • ProjectsManager

        public ProjectsManager()
        Constructor.
    • Method Detail

      • getProjects

        @OpenApi
        public java.util.List<Project> getProjects()
        Returns list of open projects.
        Returns:
        list of open projects.
      • deactivateProject

        private void deactivateProject​(@CheckForNull
                                       Project project)
        Closes given project , does not activate previous.
        Parameters:
        project - project project
      • updateEnvironment

        public void updateEnvironment​(@CheckForNull
                                      Project project)
        Updates GUI by given project.
        Parameters:
        project - project project
      • isProjectActive

        @OpenApi
        public boolean isProjectActive​(@CheckForNull
                                       Project project)
        Method checks if given project is active at this time.
        Parameters:
        project - project to check.
        Returns:
        true if given project is active.
      • setActiveProject

        @OpenApi
        public void setActiveProject​(@CheckForNull
                                     Project project)
        Sets given project as active. Updates GUI.
        Parameters:
        project - the project to be set as active.
      • addCreatedProject

        public void addCreatedProject​(Project project)
        Adds just created project to this manager, but this project activation event will not be fired, because it is still not loaded or initialized from template.
        Parameters:
        project - created project
      • addProject

        private void addProject​(Project project)
        Adds project, does not set it as active, also adds tab into tab panel and activates that tab.
        Parameters:
        project - project project
      • getActiveProject

        @OpenApi
        @CheckForNull
        public Project getActiveProject()
        Returns active open project.
        Returns:
        active project.
      • findProjectToActivate

        @CheckForNull
        public Project findProjectToActivate()
        Find project to activate
        Returns:
        active project.
      • removeProject

        public void removeProject​(Project project)
        Removes project from storage, does not activate previous one.
        Parameters:
        project - project project
      • getProjectByName

        @CheckForNull
        public Project getProjectByName​(java.lang.String name)
        Look for a project with a given name.
        Parameters:
        name - the project name
        Returns:
        found project with given name or a null
      • getProjectByFileName

        @CheckForNull
        public Project getProjectByFileName​(java.lang.String fileName)
        Look for a project with a given fileName.
        Parameters:
        fileName - the project fileName
        Returns:
        found project with given fileName or a null
      • getProject

        @CheckForNull
        public Project getProject​(java.util.function.Predicate<Project> filter)
        Look for a project for a given predicate.
        Parameters:
        filter - predicate
        Returns:
        found project or a null
      • getProject

        @CheckForNull
        public Project getProject​(java.lang.String path)
        Searches for given path in projects list and returns the project.
        Parameters:
        path - path
        Returns:
        found project or null
      • getProject

        @CheckForNull
        public Project getProject​(org.eclipse.emf.common.util.URI uri)
        Searches for given uri in projects list and returns the project.
        Parameters:
        uri - uri
        Returns:
        found project or null
      • getTeamworkProject

        @CheckForNull
        public Project getTeamworkProject​(java.lang.String projectID,
                                          @CheckForNull
                                          java.lang.String version)
        Look for a teamwork project with a given id and version
        Parameters:
        projectID - the project name
        version - project version (-1 if not specified)
        Returns:
        found project
      • getTeamworkProject

        @CheckForNull
        public Project getTeamworkProject​(java.lang.String projectID,
                                          @CheckForNull
                                          java.lang.String version,
                                          boolean checkLatest)
        Look for a teamwork project with a given id and version
        Parameters:
        projectID - the project name
        version - project version (-1 if not specified)
        checkLatest - flag if to check latest version or not, if version is null, it is not counted as other version if flag is false
        Returns:
        found project
      • getEsiProject

        @CheckForNull
        public Project getEsiProject​(java.lang.String projectID,
                                     java.lang.String version)
        Returns ESI project if it is opened and it meets search criteria.
        Parameters:
        projectID - remote project id.
        version - project version.
        Returns:
        project or null.
      • contains

        public boolean contains​(java.lang.String path)
        Test if given path exists in projects list.
        Parameters:
        path - path
        Returns:
        true if exists
      • getNameForProject

        public java.lang.String getNameForProject()
        Getter for unique project name : Untitled+number
        Returns:
        unique project name
      • getNameForProject

        public java.lang.String getNameForProject​(java.lang.String base,
                                                  boolean avoidNumber)
        Getter for unique project name : "base"+number
        Parameters:
        base - base part of unique name
        avoidNumber - avoid numbers
        Returns:
        unique name
      • addProjectListener

        @OpenApi
        public void addProjectListener​(ProjectEventListener listener)
        Adds new project listener.
        Parameters:
        listener - listener to be added.
      • removeProjectListener

        @OpenApi
        public void removeProjectListener​(ProjectEventListener listener)
        Removes project listener.
        Parameters:
        listener - listener to be removed.
      • loadProject

        @OpenApi
        public void loadProject​(ProjectDescriptor descriptor,
                                boolean silent)
        Loads project from location, described in a project descriptor. Loading is done on EDT.
        Specified by:
        loadProject in interface ProjectPersistenceManager
        Parameters:
        descriptor - the project descriptor.
        silent - if true, loads without GUI interruptions.
      • saveProject

        @OpenApi
        public boolean saveProject​(ProjectDescriptor descriptor,
                                   boolean silent)
        Saves project into location specified by descriptor.
        Specified by:
        saveProject in interface ProjectPersistenceManager
        Parameters:
        descriptor - the project descriptor.
        silent - if true, saves without GUI interruptions.
      • saveProject

        public boolean saveProject​(ProjectDescriptor descriptor,
                                   ProgressStatus status,
                                   boolean silent)
        Description copied from interface: ProjectPersistenceManager
        Saves or commits project.
        Specified by:
        saveProject in interface ProjectPersistenceManager
        Parameters:
        descriptor - descriptor of project to save.
        status - status to display operation status.
        silent - true if no gui should be shown durring save/commmit
        Returns:
        false if saving fails.
      • createProject

        @OpenApi
        public Project createProject()
        Creates new project.
        Returns:
        created project.
      • createProjectFromTemplate

        @OpenApi
        @CheckForNull
        public Project createProjectFromTemplate​(java.lang.String templatePath)
        Creates a new project from the given template.
        Parameters:
        templatePath - absolute template path
        Returns:
        created project.
      • closeProjectNoSave

        public void closeProjectNoSave()
        Close project without trying to save it.
      • closeProject

        @OpenApi
        public void closeProject()
        Closes current project.
      • closeProject

        @OpenApi
        public void closeProject​(Project project)
        Closes given project
        Parameters:
        project - project to close
      • useModule

        @OpenApi
        public boolean useModule​(Project project,
                                 ProjectDescriptor module)
        Use module in given project from given descriptor.

        Need to update ProjectOptions before using local module:
        String moduleDir = moduleFile.getParent();
        ProjectOptions projectOptions = project.getOptions();
        List directories = projectOptions.getModulesDirectories(true);
        if (!directories.contains(moduleDir))
        {
            projectOptions.addModuleDirectory(moduleDir);
        }

        Specified by:
        useModule in interface ProjectPersistenceManager
        Parameters:
        project - project
        module - module
        Returns:
        true if module was used
      • exportModule

        @OpenApi
        public void exportModule​(Project prj,
                                 java.util.Collection packages,
                                 java.lang.String description,
                                 ProjectDescriptor module)
        Export local (not teamwork) module into given descriptor
        Specified by:
        exportModule in interface ProjectPersistenceManager
        Parameters:
        prj - current project
        packages - "shared" packages in project
        description - module description
        module - module location descriptor
      • saveModule

        @OpenApi
        public boolean saveModule​(Project project,
                                  IAttachedProject module,
                                  boolean silent,
                                  boolean temporalSave)
        Save module from current project into given location.
        Specified by:
        saveModule in interface ProjectPersistenceManager
        Parameters:
        project - project
        module - module to save
        silent - do not show UI messages
        temporalSave - do not change module location after save
        Returns:
        true if module was saved
      • saveModule

        @OpenApi
        public boolean saveModule​(Project project,
                                  IAttachedProject module,
                                  boolean silent,
                                  ProgressStatus status)
        Saves module without any additional dependencies checking.
        Specified by:
        saveModule in interface ProjectPersistenceManager
        Parameters:
        project - project
        module - module to save
        silent - save in silent mode
        status - progress status
        Returns:
        true if operation was successful
      • saveModule

        @OpenApi
        public boolean saveModule​(Project project,
                                  IAttachedProject module,
                                  boolean silent,
                                  ProgressStatus status,
                                  boolean temporalSave)
        Saves module without any additional dependencies checking.
        Specified by:
        saveModule in interface ProjectPersistenceManager
        Parameters:
        project - project
        module - module to save
        silent - save in silent mode
        status - progress status
        temporalSave - do not change module location after save
        Returns:
        true if operation was successful
      • saveModule

        @OpenApi
        public boolean saveModule​(Project project,
                                  IAttachedProject module,
                                  boolean silent,
                                  ProgressStatus status,
                                  java.net.URI saveTo)
        Saves module without any additional dependencies checking.
        Parameters:
        project - project
        module - module to save
        status - status
        silent - save in silent mode
        saveTo - where to save module, can be null, then module is saved to module.getURI() location
        Returns:
        true if operation was successful
      • saveModule

        @OpenApi
        public boolean saveModule​(Project project,
                                  IAttachedProject module,
                                  boolean silent,
                                  @CheckForNull
                                  ProgressStatus status,
                                  @CheckForNull
                                  java.net.URI saveTo,
                                  boolean temporalSave)
        Saves module without any additional dependencies checking.
        Parameters:
        project - project
        module - module to save
        silent - save in silent mode
        status - progress status
        saveTo - where to save module, can be null, then module is saved to module.getURI() location
        temporalSave - do not change module location after save
        Returns:
        true if operation was successful
      • getRecentFilePath

        public static java.lang.String getRecentFilePath()
        Returns recent file path or examples directory path
        Returns:
        recent file path
      • getPreferredProjectPath

        @CheckForNull
        public static java.lang.String getPreferredProjectPath​(java.lang.String projectName,
                                                               Project relatedProject)
        Looks for possible path for project with a given name. Searches among recent projects for project with a given name. Also looks in given project (if not null) dir and modules path for a file with a given name.
        Parameters:
        projectName - the given project name
        relatedProject - related project. Maybe be null
        Returns:
        preferred path to save a project
      • searchForMDFileIn

        @CheckForNull
        private static java.lang.String searchForMDFileIn​(com.nomagic.magicdraw.utils.FileManager fileManager,
                                                          java.lang.String directory,
                                                          java.lang.String name)
        Looks for a MD project with a given name in the given directory. Analyzes existing files with all possible MD extensions.
        Parameters:
        fileManager - file manager
        directory - directory
        name - project name
        Returns:
        found file path or null
      • isProjectLoaded

        public boolean isProjectLoaded​(Project project)
        Get if project is fully loaded. We can not work with data while project is loading. Since project does not provide synchronization mechanism, we may get concurrent modification exceptions. Once project becomes "loaded" it stays loaded until closed.
        Parameters:
        project - project
        Returns:
        true when particular project is loaded and open - when PROJECT_OPENED event is fired.
      • findAttachedProject

        @OpenApi
        @CheckForNull
        public IAttachedProject findAttachedProject​(Project project,
                                                    ProjectDescriptor projectDescriptor)
        Find used module according given project descriptor.
        Parameters:
        project - project using module.
        projectDescriptor - project descriptor of module.
        Returns:
        found attached project or null
      • findProject

        @OpenApi
        @CheckForNull
        public Project findProject​(ProjectDescriptor projectDescriptor)
        Find loaded project according given project descriptor.
        Parameters:
        projectDescriptor - project descriptor.
        Returns:
        null if project not found.
      • sharePackage

        @OpenApi
        public void sharePackage​(Project project,
                                 java.util.List<Package> packages,
                                 @CheckForNull
                                 java.lang.String description)
        Share given list of packages in project. On CTS decomposition must be locked before sharing.
        Parameters:
        project - Project where packages will be shared.
        packages - List of packaged, dedicated for sharing.
        description - share description, null if do not change/set the description.
        Throws:
        java.lang.RuntimeException - if either some being shared package becomes invalid in the main project (that is, has been deleted or moved to a module) or is locked by another user
      • fireProjectModelLoaded

        public void fireProjectModelLoaded​(Project project)
        Fire event when project model is loaded but diagrams are still not loaded.
        Parameters:
        project - project which model is loaded.
      • fireProjectPartLoaded

        public void fireProjectPartLoaded​(Project project,
                                          IProject storage)
        Fire event when project model or its part is loaded with diagrams. Event is fired when part of model is loaded and after teamwork update part is loaded and elements is removed.
        Parameters:
        project - the project
        storage - the part of project is loaded..
      • fireProjectPartRemoved

        public void fireProjectPartRemoved​(IProject storage)
        Fire event when project used project is removed from project
        Parameters:
        storage - the part of project which is removed
      • fireProjectPartAttached

        public void fireProjectPartAttached​(ModuleUsage usage)
        Fire event when project or module started using new module.
        Parameters:
        usage - added usage.
      • fireProjectPartDetached

        public void fireProjectPartDetached​(ModuleUsage usage)
        Fire event when project or module stops using module.
        Parameters:
        usage - removed usage.
      • reportError

        public void reportError​(java.lang.String message,
                                java.lang.Exception ex)
      • fireProjectActivated

        public void fireProjectActivated​(Project project)
        Notifies project event listeners that the given project is activated.
        Parameters:
        project - project that is activated.
      • fireProjectPreActivated

        public void fireProjectPreActivated​(Project project)
        Notifies project event listeners about project pre activation.
        Parameters:
        project - project that will be activated.
      • fireProjectDeactivated

        public void fireProjectDeactivated​(Project project)
        Notifies project event listeners that the given project is deactivated.
        Parameters:
        project - project that is deactivated.
      • fireProjectPreDeactivated

        public void fireProjectPreDeactivated​(Project project)
        Notifies project event listeners about project pre deactivation.
        Parameters:
        project - project that will be deactivated.
      • fireProjectOpened

        public void fireProjectOpened​(Project project)
        Method fires event when project was opened.
        Parameters:
        project - project which was opened.
      • fireProjectCreated

        public void fireProjectCreated​(Project project)
        Method fires event when project was created.
        Parameters:
        project - project which was created.
      • fireProjectSaved

        public void fireProjectSaved​(Project project,
                                     boolean teamwork)
        Method fires ProjectSaved event.
        Parameters:
        project - saved project.
        teamwork - true if project saved in teamwork.
      • fireProjectPreSaved

        public void fireProjectPreSaved​(Project project,
                                        boolean teamwork)
        Method fires project pre saved event.
        Parameters:
        project - saved project.
        teamwork - true if project saved in teamwork.
      • fireProjectClosed

        public void fireProjectClosed​(Project project)
        Method fires project closed event.
        Parameters:
        project - closed project.
      • fireProjectPreClosed

        public void fireProjectPreClosed​(Project project)
        Method fires project pre closed event.
        Parameters:
        project - closed project.
      • fireProjectPreClosedFinal

        public void fireProjectPreClosedFinal​(Project project)
        Method fires project pre closed final event.
        Parameters:
        project - closed project.
      • fireProjectOpenedFromGUI

        public void fireProjectOpenedFromGUI​(Project project)
        Method fires project open.
        Parameters:
        project - closed project.
      • fireProjectActivatedFromGUI

        public void fireProjectActivatedFromGUI​(Project project)
        Method fires project activated.
        Parameters:
        project - closed project.
      • reportError

        private void reportError​(java.lang.RuntimeException exception,
                                 java.lang.Object o)