Projects are saved and loaded by using two methods in the com.nomagic.magicdraw.core.project.ProjectsManager class.

  • saveProject(ProjectDescriptor, boolean)
  • loadProject(ProjectDescriptor, boolean)

“Save” means “Commit” for the server project.

A project cannot be saved using a descriptor, if the project isn’t specified, and a project cannot be loaded, if the file isn’t specified. In such cases java.lang.IllegalStateException is thrown.

The silent mode means that during the saving or load process no GUI interruptions for a user input is used, for example, there is no the Commit Project dialog box while committing a server project or there is no the Save dialog box while saving a new project (a project is saved into the last used directory).

Save participant

Use com.nomagic.magicdraw.core.SaveParticipant to plugin into a save/commit operation. 

Register it using com.nomagic.magicdraw.core.Application.addSaveParticipant(SaveParticipant)

Implementing SaveParticipant.isReadyForSave(Project, ProjectDescriptor) you can "disable" the save/commit operation until some conditions are met.

Example #1. Saving an active project

    ProjectsManager projectsManager = Application.getInstance().getProjectsManager();
    // An active project
    Project project = projectsManager.getActiveProject();
 
    // Get a project descriptor
    ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.getDescriptorForProject(project);
    
    // Save a project 
    projectsManager.saveProject(projectDescriptor, true);

Example #2. Loading a project from the file

The project can be loaded, if the project’s file name is known:

    ProjectsManager projectsManager = Application.getInstance().getProjectsManager(); 
    File file = new File(projectFilePath);
    // Create a project descriptor 
    ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.createProjectDescriptor(file.toURI()); 
    projectsManager.loadProject(projectDescriptor, true);

Example #3. Importing another project file

The project can be imported, if the project's file name is known:

    ProjectsManager projectsManager = Application.getInstance().getProjectsManager(); 
    File file = new File(projectFilePath);
    // Create a project descriptor 
    ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.createProjectDescriptor(file.toURI()); 
    projectsManager.importProject(projectDescriptor);

Example #4. Loading a server project

The project can be loaded, if the project’s qualified name is known:

    ProjectsManager projectsManager = Application.getInstance().getProjectsManager();
    // Create a project descriptor
    ProjectDescriptor projectDescriptor = TeamworkUtils.getRemoteProjectDescriptorByQualifiedName(remoteProjectQualifiedName);
    if (projectDescriptor != null)
    {
        projectsManager.loadProject(projectDescriptor, true);
    }
Related pages