@startuml !include jb-plantuml-theme.puml :closeProject; note right Project closing executed in a dispatch thread. end note :canClose ""(ep=ProjectCloseHandler)""] if (canClose ""(ep=ProjectCloseHandler)"") then (yes) :Stop Service Preloading] :Fire ""projectClosingBeforeSave"" Event ""(l=ProjectManagerListener)""] note right In unit test mode in a light tests, light project is not closed and not disposed. end note :Save Project Files] if (Save Project Settings) then (Successfully or Error Ignored) :Fire ""projectClosing"" Event ""(l=ProjectManagerListener)""] partition "write action" { :Dispose everything that uses Project as parent disposable] note right If you incorrectly specify project for ""MessageBus.connect()"", it will be disconnected on this step. Do not specify ""parentDisposable"" unless needed. end note :Dispose Project Message Bus Connections without explicitly specified parent disposable] :Set Project State to ""DISPOSE_IN_PROGRESS""] note right Getting services and publishing to message bus is prohibited from now on. ""Project.isDisposed"" returns ""true"" (not changed in a read action, because state is set in a write action). end note :Dispose Project Message Bus Connection Disposable] note right Connecting to message bus is prohibited from now on. end note :Remove Project from List of Opened] note right Result of ""ProjectManager.getOpenProjects()"" is valid only in a read action. end note :Fire ""projectClosed"" Event ""(l=ProjectManagerListener)""] :Set Project State to ""DISPOSED""] :Dispose Services and Components] note right First created, last disposed. Children are disposed before parent. end note :Dispose Message Bus] :Set Project State to ""DISPOSE_COMPLETED""; } else (Error Occurred) :Close Cancelled; endif detach else (no) :Close Cancelled; detach endif @enduml