Ejemplo n.º 1
0
 /** @generated NOT set appropriate parents */
 protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   DecisionNode newElement = UMLFactory.eINSTANCE.createDecisionNode();
   // set appropriate parents
   if (!CreateCommandUtil.setNodeParents(newElement, getRequest(), getElementToEdit())) {
     return CommandResult.newCancelledCommandResult();
   }
   //		Activity owner = (Activity)getElementToEdit();
   //		owner.getNodes().add(newElement);
   ElementInitializers.getInstance().init_DecisionNode_3038(newElement);
   doConfigure(newElement, monitor, info);
   ((CreateElementRequest) getRequest()).setNewElement(newElement);
   return CommandResult.newOKCommandResult(newElement);
 }
      protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
          throws ExecutionException {

        if (null == viewAdapter || null == newValue)
          return CommandResult.newCancelledCommandResult();

        View view = (View) viewAdapter.getAdapter(View.class);
        Point p = (Point) newValue.getAdapter(IPropertyValueDeferred.class);
        ViewUtil.setStructuralFeatureValue(
            view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(p.x));
        ViewUtil.setStructuralFeatureValue(
            view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(p.y));

        // clear for garbage collection
        viewAdapter = null;
        newValue = null;
        return CommandResult.newOKCommandResult();
      }
  /**
   *
   *
   * <pre>
   *  The method executes the creation :
   *  - opens a selection dialog to choose a {@link ConnectableElement} reference as a role by the {@link CollaborationUse} type
   *  - created a dependency between the selected role and the {@link ConnectableElement} that will be bind to it
   *
   * {@inheritDoc}
   * </pre>
   */
  @Override
  protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info)
      throws ExecutionException {

    if (!canExecute()) {
      throw new ExecutionException(Messages.RoleBindingCreateCommand_INVALID_ARGS_MSG);
    }

    // Retrieve the graphical source of the binding.
    // This differs from the semantic source of the binding which is a role of the
    // CollaborationUse type.
    CollaborationUse graphicalSource = (CollaborationUse) getSource();

    // Create and open the selection dialog
    ComposedAdapterFactory adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(
            currentShell,
            new AdapterFactoryLabelProvider(adapterFactory),
            new CollaborationRoleTreeContentProvider());

    try {
      // Set dialog parameters
      dialog.setTitle(Messages.RoleBindingRoleSelectionDialog_Title);
      dialog.setMessage(Messages.RoleBindingRoleSelectionDialog_Message);
      dialog.setAllowMultiple(false);
      dialog.setHelpAvailable(false);
      // The source CollaborationUse is set as input for the selection dialog,
      // the CollaborationRoleTreeContentProvider provides the roles that can possibly be
      // selected.
      dialog.setInput(graphicalSource);

      dialog.open();
    } finally {
      adapterFactory.dispose();
    }

    // If a ConnectableElement has been selected, complete command execution
    // using selection as the "newly created" element and make the edited
    // Collaboration reference it in the CollaborationRoles eReference.
    if (dialog.getReturnCode() == ElementTreeSelectionDialog.OK) {

      ConnectableElement roleToBind = (ConnectableElement) dialog.getFirstResult();
      // Create a Dependency (the binding) between selected role and a ConnectableElement
      // (the target)
      Dependency newBinding = UMLFactory.eINSTANCE.createDependency();
      getContainer().getPackagedElements().add(newBinding);
      newBinding.getClients().add(roleToBind);
      newBinding.setName("binding_" + roleToBind.getName() + "_" + getTarget().getName());
      newBinding.getSuppliers().add(getTarget());
      graphicalSource.getRoleBindings().add(newBinding);

      doConfigure(newBinding, monitor, info);

      ((CreateElementRequest) getRequest()).setNewElement(newBinding);

      return CommandResult.newOKCommandResult(newBinding);
    }

    // No role selected: abort element creation
    return CommandResult.newCancelledCommandResult();
  }
    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();
    }
  /**
   *
   *
   * <pre>
   *  The method executes the creation :
   *  - opens a selection dialog to choose {@link InformationItem} or {@link Classifier} reference as a convoyed Classifier
   *   by the {@link InformationFlow} type
   *  - create the InformationFlow between the source and the target
   *
   * {@inheritDoc}
   * </pre>
   */
  @Override
  protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info)
      throws ExecutionException {

    // Create and open the selection dialog
    ComposedAdapterFactory adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    InformationItemElementTreeSelectionDialog dialog =
        new InformationItemElementTreeSelectionDialog(
            currentShell,
            new AdapterFactoryLabelProvider(adapterFactory),
            new AdapterFactoryContentProvider(adapterFactory));

    try {
      // Set dialog parameters
      dialog.setTitle(Messages.InformationFlowSelectionDialog_Title);
      dialog.setMessage(Messages.InformationFlowSelectionDialog_Message);
      dialog.setAllowMultiple(true);
      dialog.setHelpAvailable(false);
      dialog.setInput(getSource().getModel());
      dialog.setValidator(new InformationItemValidator());

      ArrayList<Classifier> initialSelection = new ArrayList<Classifier>();

      // here the dialog.getReturnCode is IDialogConstants.OK_ID
      while (dialog.open() != IDialogConstants.CANCEL_ID) {

        /*
         * If classifiers have been selected, complete command execution and write the selection
         * in the conveyed:Classifief Association
         */
        if (dialog.getReturnCode() == ElementTreeSelectionDialog.OK) {
          Object[] conveyedClassified = dialog.getResult();

          InformationFlow newInformationFlow = UMLFactory.eINSTANCE.createInformationFlow();
          getContainer().getPackagedElements().add(newInformationFlow);
          newInformationFlow.getInformationSources().add(getSource());
          newInformationFlow.getInformationTargets().add(getTarget());

          // add the classifier in the list of conveyed Classifier
          for (int i = 0; i < conveyedClassified.length; i++) {
            newInformationFlow.getConveyeds().add((Classifier) conveyedClassified[i]);
          }

          ElementInitializers.getInstance().init_InformationFlow_4021(newInformationFlow);

          ((CreateElementRequest) getRequest()).setNewElement(newInformationFlow);
          return CommandResult.newOKCommandResult(newInformationFlow);

        } else if (dialog.getReturnCode()
            == InformationItemElementTreeSelectionDialog.newInformationItemButton_ID) {
          // create a new InformationItem
          initialSelection.add((Classifier) createNewInformationItem());
          dialog.setInitialElementSelections(initialSelection);
        }
      } // end of while()
    } finally {
      adapterFactory.dispose();
    }

    // No Classifier selected: abort element creation
    return CommandResult.newCancelledCommandResult();
  }