/** @generated */
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {

    Enumeration newElement = UMLFactory.eINSTANCE.createEnumeration();

    EObject target = getElementToEdit();
    ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target, newElement);
    if (data.isPermitted()) {
      if (data.isPathDefined()) {
        if (!data.execute(target, newElement)) {
          return CommandResult.newErrorCommandResult(
              "Failed to follow the policy-specified for the insertion of the new element");
        }
      } else {

        Class qualifiedTarget = (Class) target;
        qualifiedTarget.getNestedClassifiers().add(newElement);
      }
    } else {
      return CommandResult.newErrorCommandResult(
          "The active policy restricts the addition of this element");
    }

    ElementInitializers.getInstance().init_Enumeration_3052(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
Example #2
0
  /**
   * Create a MessageOccurenceSpecification and the call event when a message is created
   *
   * @generated NOT
   */
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    if (!canExecute()) {
      throw new ExecutionException("Invalid arguments in create link command"); // $NON-NLS-1$
    }
    InteractionFragment sourceContainer =
        (InteractionFragment)
            getRequest().getParameters().get(SequenceRequestConstant.SOURCE_MODEL_CONTAINER);
    InteractionFragment targetContainer =
        (InteractionFragment)
            getRequest().getParameters().get(SequenceRequestConstant.TARGET_MODEL_CONTAINER);

    Message message =
        CommandHelper.doCreateMessage(
            container,
            MessageSort.SYNCH_CALL_LITERAL,
            getSource(),
            getTarget(),
            sourceContainer,
            targetContainer);
    if (message != null) {
      doConfigure(message, monitor, info);
      ((CreateElementRequest) getRequest()).setNewElement(message);
      return CommandResult.newOKCommandResult(message);
    }

    return CommandResult.newErrorCommandResult(
        "There is now valid container for events"); //$NON-NLS-1$
  }
 @Override
 protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   if (!getEditPartFromEditPartAdapter()) {
     if (!allChildren.isEmpty()) {
       getEditPartFromViewAdapter(allChildren.get(0));
     }
   }
   if (mainEditPart != null) {
     createdNotificationConfigurator = new ArrayList<ChooseChildrenNotificationConfigurator>();
     NotificationConfigurator configurator =
         PendingGroupNotificationsManager.getInstanceForDiagram(diagramPart)
             .getChooseChildrenPendingNotification(mainEditPart);
     ChooseChildrenNotificationConfigurator notificationConfigurator = null;
     if (configurator == null) {
       // If there is no a pending notification for this main edit part then it create one
       if (!allChildren.isEmpty() && isChildrenToChoose()) {
         notificationConfigurator =
             new ChooseChildrenNotificationConfigurator(
                 mainEditPart, allChildren, automaticChildren, host, manager);
         notificationConfigurator.runConfigurator();
       }
     } else {
       // Else update the old one if needed TODO TODO
       // 1 - Compare if there is any modification TODO
       if (configurator instanceof ChooseChildrenNotificationConfigurator) {
         notificationConfigurator = (ChooseChildrenNotificationConfigurator) configurator;
         if (notificationConfigurator.isThereAnyModification(
             mainEditPart, allChildren, automaticChildren, host)) {
           // 2 - There are some update the old notification TODO
           notificationConfigurator.closeNotification();
           if (!allChildren.isEmpty() && isChildrenToChoose()) {
             notificationConfigurator =
                 new ChooseChildrenNotificationConfigurator(
                     mainEditPart, allChildren, automaticChildren, host, manager);
             notificationConfigurator.runConfigurator();
           }
         }
       }
     }
     if (notificationConfigurator != null) {
       createdNotificationConfigurator.add(notificationConfigurator);
     }
     return CommandResult.newOKCommandResult();
   }
   return CommandResult.newErrorCommandResult(
       "The editPart of the adaptable element has not been found"); //$NON-NLS-1$
 }
    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();
    }