/**
   * {@inheritDoc}
   *
   * @see
   *     org.eclipse.sirius.diagram.business.api.componentization.DiagramMappingsManagerRegistry#getDiagramMappingsManager(Session,
   *     DDiagram)
   */
  @Override
  public DiagramMappingsManager getDiagramMappingsManager(
      final Session session, final DDiagram diagram) {
    if (diagram == null) {
      throw new IllegalArgumentException(
          Messages.DiagramMappingsManagerRegistryImpl_diagramParamErrorMsg);
    }
    if (diagramMappingsManagers.containsKey(diagram)) {
      return diagramMappingsManagers.get(diagram);
    } else {
      final DiagramDescription desc = diagram.getDescription();
      final DiagramDescriptionMappingsRegistry mappingsRegistry =
          DiagramDescriptionMappingsRegistry.INSTANCE;
      final DiagramDescriptionMappingsManager descManager =
          mappingsRegistry.getDiagramDescriptionMappingsManager(session, desc);

      final DiagramMappingsManager newManager =
          new DiagramMappingsManagerImpl(diagram, descManager);
      diagram.eAdapters().add(this);
      if (session != null) {
        newManager.computeMappings(session.getSelectedViewpoints(false), false);
      } else {
        newManager.computeMappings(null, false);
      }
      diagramMappingsManagers.put(diagram, newManager);
      return newManager;
    }
  }
  private void computeMappings(final DDiagram diagram, final Layer layer) {
    final DiagramMappingsManager manager = diagramMappingsManagers.get(diagram);
    if (manager != null) {

      boolean needToRecomputeDescMappings = false;
      if (layer != null && layer.eContainer() instanceof DiagramExtensionDescription) {
        needToRecomputeDescMappings = true;
      }
      Session sess = SessionManager.INSTANCE.getSession(((DSemanticDiagram) diagram).getTarget());
      if (sess != null) {
        manager.computeMappings(sess.getSelectedViewpoints(false), needToRecomputeDescMappings);
      } else {
        manager.computeMappings(null, needToRecomputeDescMappings);
      }
    }
  }