@Override
  public void disposeUIResources() {
    try {
      if (isExternalSystemsInvolved) {
        assert myOrphanProjectsCandidates != null;
        assert myProject != null;
        if (myExternalProjectsToRestore != null) {
          for (Pair<ProjectSystemId, ExternalProjectSettings> settingsPair : myExternalProjectsToRestore.values()) {
            AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(myProject, settingsPair.first);
            String rootProjectPath = settingsPair.second.getExternalProjectPath();
            if (settings.getLinkedProjectSettings(rootProjectPath) == null) {
              //noinspection unchecked
              settings.linkProject(settingsPair.second);
            }
            myOrphanProjectsCandidates.remove(rootProjectPath);
          }
        }

        ModulesConfigurator modulesConfigurator = getModulesConfigurator(myProject);
        if (modulesConfigurator != null) {
          for (Map.Entry<String, ProjectSystemId> entry : myOrphanProjectsCandidates.entrySet()) {
            String rootProjectPath = entry.getKey();
            if (StringUtil.isNotEmpty(rootProjectPath)) {
              unlinkProject(myProject, entry.getValue(), rootProjectPath);
            }
          }
        }
      }
    }
    catch (Throwable e) {
      LOG.warn(e);
    }
    finally {
      myProject = null;
      myExternalProjectsToRestore = null;
      myOrphanProjectsCandidates = null;
    }
  }
@Override
  public void disposeUIResources()