@Override
  public void saveRepositories() {
    if (storage != null) {
      try {
        OutputStream output = storage.createOutputStream();
        try {
          repositoryRegistry.eResource().save(output, null);
        } finally {
          if (output != null) {
            IOUtil.closeSilent(output);
          }
        }
      } catch (IOException e) {
        Activator.log.error(
            "Failed to save model repositories to custom storage.", e); // $NON-NLS-1$
      }
    } else {
      try {
        repositoryRegistry.eResource().save(null);
      } catch (IOException e) {
        Activator.log.error("Failed to save model repositories.", e); // $NON-NLS-1$
      }
    }

    // save passwords, if any
    try {
      SecurePreferencesFactory.getDefault().flush();
    } catch (IOException e) {
      Activator.log.error(
          "Failed to save repository passwords to secure storage.", e); // $NON-NLS-1$
    }
  }
  private Map<String, IInternalPapyrusRepository> initializeRepositories() {
    Map<String, IInternalPapyrusRepository> result = Maps.newHashMap();

    for (Repository next : repositoryRegistry.getRepositories()) {
      result.put(next.getURL(), new PapyrusRepository(container, next));
    }

    return result;
  }
  @Override
  public IInternalPapyrusRepository createRepository(String url) {
    if (getRepository(url) != null) {
      throw new IllegalArgumentException("repository already exists"); // $NON-NLS-1$
    }

    Repository repository = RepositoriesFactory.eINSTANCE.createRepository();
    repository.setURL(url);
    repositoryRegistry.getRepositories().add(repository);

    PapyrusRepository result = new PapyrusRepository(container, repository);
    repositories.put(url, result);

    fireElementAddedEvent(result);

    return result;
  }