Class ProjectsManager
- java.lang.Object
-
- com.nomagic.magicdraw.core.project.ProjectsManager
-
- All Implemented Interfaces:
ProjectPersistenceManager
@OpenApi public class ProjectsManager extends java.lang.Object implements ProjectPersistenceManager
Stores and manages multiple projects.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<Project>
activatedProjects
All activated projectsprivate Project
activeProject
Activated project.private java.util.Set<Project>
loadedProjects
Set of projects that were finished loading by ProjectLoaderprivate java.util.Collection<Project>
pendingToLoadProjects
private java.util.List<ProjectEventListener>
projectListeners
Listener support.private java.util.List<Project>
projects
All projects in their activation order (last= currently active).private SelectionProvider.SelectionChangedListener
selectionChangeListener
-
Constructor Summary
Constructors Constructor Description ProjectsManager()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.private void
addProject(Project project)
Adds project, does not set it as active, also adds tab into tab panel and activates that tab.void
addProjectListener(ProjectEventListener listener)
Adds new project listener.void
closeProject()
Closes current project.void
closeProject(Project project)
Closes given projectvoid
closeProjectNoSave()
Close project without trying to save it.boolean
contains(java.lang.String path)
Test if given path exists in projects list.Project
createProject()
Creates new project.Project
createProjectFromTemplate(java.lang.String templatePath)
Creates a new project from the given template.private void
deactivateProject(Project project)
Closes given project , does not activate previous.void
exportModule(Project prj, java.util.Collection packages, java.lang.String description, ProjectDescriptor module)
Export local (not teamwork) module into given descriptorIAttachedProject
findAttachedProject(Project project, ProjectDescriptor projectDescriptor)
Find used module according given project descriptor.Project
findProject(ProjectDescriptor projectDescriptor)
Find loaded project according given project descriptor.Project
findProjectToActivate()
Find project to activatevoid
fireProjectActivated(Project project)
Notifies project event listeners that the given project is activated.void
fireProjectActivatedFromGUI(Project project)
Method fires project activated.void
fireProjectClosed(Project project)
Method fires project closed event.void
fireProjectCreated(Project project)
Method fires event when project was created.void
fireProjectDeactivated(Project project)
Notifies project event listeners that the given project is deactivated.void
fireProjectModelLoaded(Project project)
Fire event when project model is loaded but diagrams are still not loaded.void
fireProjectOpened(Project project)
Method fires event when project was opened.void
fireProjectOpenedFromGUI(Project project)
Method fires project open.void
fireProjectPartAttached(ModuleUsage usage)
Fire event when project or module started using new module.void
fireProjectPartDetached(ModuleUsage usage)
Fire event when project or module stops using module.void
fireProjectPartLoaded(Project project, IProject storage)
Fire event when project model or its part is loaded with diagrams.void
fireProjectPartRemoved(IProject storage)
Fire event when project used project is removed from projectvoid
fireProjectPreActivated(Project project)
Notifies project event listeners about project pre activation.void
fireProjectPreClosed(Project project)
Method fires project pre closed event.void
fireProjectPreClosedFinal(Project project)
Method fires project pre closed final event.void
fireProjectPreDeactivated(Project project)
Notifies project event listeners about project pre deactivation.void
fireProjectPreSaved(Project project, boolean teamwork)
Method fires project pre saved event.void
fireProjectReplaced(Project oldProject, Project newProject)
Method fires the ProjectReplaced notificationvoid
fireProjectSaved(Project project, boolean teamwork)
Method fires ProjectSaved event.Project
getActiveProject()
Returns active open project.Project
getEsiProject(java.lang.String projectID, java.lang.String version)
Returns ESI project if it is opened and it meets search criteria.java.lang.String
getNameForProject()
Getter for unique project name : Untitled+numberjava.lang.String
getNameForProject(java.lang.String base, boolean avoidNumber)
Getter for unique project name : "base"+numberstatic java.lang.String
getPreferredProjectPath(java.lang.String projectName, Project relatedProject)
Looks for possible path for project with a given name.Project
getProject(java.lang.String path)
Searches for given path in projects list and returns the project.Project
getProject(java.util.function.Predicate<Project> filter)
Look for a project for a given predicate.Project
getProject(org.eclipse.emf.common.util.URI uri)
Searches for given uri in projects list and returns the project.Project
getProjectByFileName(java.lang.String fileName)
Look for a project with a given fileName.Project
getProjectByName(java.lang.String name)
Look for a project with a given name.java.util.List<Project>
getProjects()
Returns list of open projects.static java.lang.String
getRecentFilePath()
Returns recent file path or examples directory pathProject
getTeamworkProject(java.lang.String projectID, java.lang.String version)
Look for a teamwork project with a given id and versionProject
getTeamworkProject(java.lang.String projectID, java.lang.String version, boolean checkLatest)
Look for a teamwork project with a given id and versionvoid
importModule(Project project, ProjectDescriptor descriptor)
Import module into project from given descriptorboolean
importProject(ProjectDescriptor pd)
Import project.boolean
isProjectActive(Project project)
Method checks if given project is active at this time.boolean
isProjectLoaded(Project project)
Get if project is fully loaded.void
loadProject(ProjectDescriptor descriptor, boolean silent)
Loads project from location, described in a project descriptor.void
loadProject(ProjectDescriptor descriptor, ProgressStatus status)
Loads new project from given descriptor.void
reloadModule(Project project, ProjectDescriptor projectDescriptor)
Reloads module.void
removeProject(Project project)
Removes project from storage, does not activate previous one.void
removeProjectListener(ProjectEventListener listener)
Removes project listener.private void
reportError(java.lang.RuntimeException exception, java.lang.Object o)
void
reportError(java.lang.String message, java.lang.Exception ex)
boolean
saveModule(Project project, IAttachedProject module, boolean silent, boolean temporalSave)
Save module from current project into given location.boolean
saveModule(Project project, IAttachedProject module, boolean silent, ProgressStatus status)
Saves module without any additional dependencies checking.boolean
saveModule(Project project, IAttachedProject module, boolean silent, ProgressStatus status, boolean temporalSave)
Saves module without any additional dependencies checking.boolean
saveModule(Project project, IAttachedProject module, boolean silent, ProgressStatus status, java.net.URI saveTo)
Saves module without any additional dependencies checking.boolean
saveModule(Project project, IAttachedProject module, boolean silent, ProgressStatus status, java.net.URI saveTo, boolean temporalSave)
Saves module without any additional dependencies checking.boolean
saveProject(ProjectDescriptor descriptor, boolean silent)
Saves project into location specified by descriptor.boolean
saveProject(ProjectDescriptor descriptor, ProgressStatus status, boolean silent)
Saves or commits project.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.void
setActiveProject(Project project)
Sets given project as active.void
sharePackage(Project project, java.util.List<Package> packages)
void
sharePackage(Project project, java.util.List<Package> packages, java.lang.String description)
Share given list of packages in project.private void
triggerListeners(Project project, java.util.function.Consumer<ProjectEventListener> consumer)
void
unloadModule(Project project, ProjectDescriptor moduleDescriptor)
Unload modulevoid
updateEnvironment(Project project)
Updates GUI by given project.boolean
useModule(Project project, ProjectDescriptor module)
Use module in given project from given descriptor.
-
-
-
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
-
projectListeners
private java.util.List<ProjectEventListener> projectListeners
Listener support.
-
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
-
selectionChangeListener
private final SelectionProvider.SelectionChangedListener selectionChangeListener
-
-
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 nameversion
- 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 nameversion
- 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 nameavoidNumber
- 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
public void loadProject(ProjectDescriptor descriptor, @CheckForNull ProgressStatus status)
Loads new project from given descriptor.- Specified by:
loadProject
in interfaceProjectPersistenceManager
- Parameters:
descriptor
- descriptorstatus
- status monitor
-
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 interfaceProjectPersistenceManager
- 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 interfaceProjectPersistenceManager
- 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 interfaceProjectPersistenceManager
- 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();
Listdirectories = projectOptions.getModulesDirectories(true);
if (!directories.contains(moduleDir))
{
projectOptions.addModuleDirectory(moduleDir);
}- Specified by:
useModule
in interfaceProjectPersistenceManager
- Parameters:
project
- projectmodule
- module- Returns:
- true if module was used
-
reloadModule
@OpenApi public void reloadModule(Project project, ProjectDescriptor projectDescriptor)
Reloads module.- Specified by:
reloadModule
in interfaceProjectPersistenceManager
- Parameters:
project
- the project.projectDescriptor
- the ProjectDescriptor of the module.
-
importModule
@OpenApi public void importModule(Project project, ProjectDescriptor descriptor) throws ReadOnlyElementException
Import module into project from given descriptor- Specified by:
importModule
in interfaceProjectPersistenceManager
- Parameters:
project
- projectdescriptor
- descriptor- Throws:
ReadOnlyElementException
- if user has no rights to perform this action.
-
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 interfaceProjectPersistenceManager
- Parameters:
prj
- current projectpackages
- "shared" packages in projectdescription
- module descriptionmodule
- 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 interfaceProjectPersistenceManager
- Parameters:
project
- projectmodule
- module to savesilent
- do not show UI messagestemporalSave
- 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 interfaceProjectPersistenceManager
- Parameters:
project
- projectmodule
- module to savesilent
- save in silent modestatus
- 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 interfaceProjectPersistenceManager
- Parameters:
project
- projectmodule
- module to savesilent
- save in silent modestatus
- progress statustemporalSave
- 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
- projectmodule
- module to savestatus
- statussilent
- save in silent modesaveTo
- 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
- projectmodule
- module to savesilent
- save in silent modestatus
- progress statussaveTo
- where to save module, can be null, then module is saved to module.getURI() locationtemporalSave
- 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 namerelatedProject
- 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 managerdirectory
- directoryname
- project name- Returns:
- found file path or null
-
unloadModule
@OpenApi public void unloadModule(Project project, ProjectDescriptor moduleDescriptor)
Unload module- Specified by:
unloadModule
in interfaceProjectPersistenceManager
- Parameters:
project
- projectmoduleDescriptor
- module descriptor
-
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 @Deprecated public void sharePackage(Project project, java.util.List<Package> packages)
Share given list of packages in project.- Parameters:
project
- Project where packages will be shared.packages
- List of packaged, dedicated for sharing.
-
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
-
importProject
@OpenApi public boolean importProject(ProjectDescriptor pd)
Import project.- Specified by:
importProject
in interfaceProjectPersistenceManager
- Parameters:
pd
- project descriptor to import.- Returns:
- true if project was imported
-
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 projectstorage
- 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.
-
fireProjectReplaced
public void fireProjectReplaced(Project oldProject, Project newProject)
Method fires the ProjectReplaced notification- Parameters:
oldProject
- project, which was replacednewProject
- project, which replaced the old project- See Also:
ProjectEventListener.projectReplaced(Project, Project)
-
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.
-
triggerListeners
private void triggerListeners(Project project, java.util.function.Consumer<ProjectEventListener> consumer)
-
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)
-
-