private CommandResult createDiagram() throws ServiceException {
      Resource modelResource = UmlUtils.getUmlResource(modelSet);
      Resource notationResource = getNotationResource(modelSet, owner, element);
      if (notationResource == null) {
        return CommandResult.newErrorCommandResult(
            "Cannot create a diagram on the selected element (ReadOnly?)");
      }
      Resource diResource = DiModelUtils.getDiResource(modelSet);

      if (owner == null) {
        owner = getRootElement(modelResource);
        attachModelToResource(owner, modelResource);
      }

      service = ElementEditServiceUtils.getCommandProvider(owner);
      if (service == null) {
        // Something isn't right ...
        return null;
      }

      try {
        clientContext = TypeContext.getContext();
      } catch (ServiceException e) {
        Activator.log.error(e);
      }
      if (clientContext == null) {
        // Something isn't right ...
        return null;
      }

      rule = PolicyChecker.getCurrent().getOwningRuleFor(prototype, owner);
      if (rule == null) {
        // Something isn't right ...
        return null;
      }

      element = owner;
      if (rule.getNewModelPath() != null) {
        // We have a path for the root auto-creation
        for (ModelAutoCreate auto : rule.getNewModelPath()) {
          EReference ref = auto.getFeature();
          String type = auto.getCreationType();
          if (ref.isMany()) {
            element = create(element, ref, type);
          } else {
            EObject temp = (EObject) element.eGet(ref);
            if (temp != null) {
              element = temp;
            } else {
              element = create(element, ref, type);
            }
          }
        }
      }

      if (rule.getSelectDiagramRoot() != null) {
        // We have a path for the root auto-selection
        for (RootAutoSelect auto : rule.getSelectDiagramRoot()) {
          EReference ref = auto.getFeature();
          element = (EObject) element.eGet(ref);
        }
      }

      if (name == null) {
        name =
            openDiagramNameDialog(
                prototype.isNatural()
                    ? getDefaultDiagramName()
                    : "New" + prototype.getLabel().replace(" ", ""));
      }
      // canceled
      if (name == null) {
        return CommandResult.newCancelledCommandResult();
      }

      Diagram diagram = doCreateDiagram(notationResource, owner, element, prototype, name);

      if (diagram != null) {
        IPageManager pageManager =
            ServiceUtilsForResource.getInstance().getIPageManager(diResource);
        pageManager.addPage(diagram);
        return CommandResult.newOKCommandResult(diagram);
      }

      return CommandResult.newCancelledCommandResult();
    }