Пример #1
0
  /** @generated */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {

    Comment newElement = UMLFactory.eINSTANCE.createComment();

    Element owner = (Element) getElementToEdit();
    owner.getOwnedComments().add(newElement);

    ElementInitializers.getInstance().init_Comment_2109(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
  /** @generated */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {

    PrimitiveType newElement = UMLFactory.eINSTANCE.createPrimitiveType();

    Class owner = (Class) getElementToEdit();
    owner.getNestedClassifiers().add(newElement);

    ElementInitializers.getInstance().init_PrimitiveType_3112(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
  /** @generated */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {

    OpaqueBehavior newElement = UMLFactory.eINSTANCE.createOpaqueBehavior();

    Package owner = (Package) getElementToEdit();
    owner.getPackagedElements().add(newElement);

    ElementInitializers.getInstance().init_OpaqueBehavior_2065(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
Пример #4
0
 /** @generated */
 protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   InformationItem newElement = UMLFactory.eINSTANCE.createInformationItem();
   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_InformationItem_3094(newElement);
   doConfigure(newElement, monitor, info);
   ((CreateElementRequest) getRequest()).setNewElement(newElement);
   return CommandResult.newOKCommandResult(newElement);
 }
  // TODO should be moved?
  private InformationItem createNewInformationItem() {
    // create the new InformationItem
    InformationItem infoItem = UMLFactory.eINSTANCE.createInformationItem();
    getContainer().getPackagedElements().add(infoItem);
    ElementInitializers.getInstance().init_InformationItem_2080(infoItem);

    // ask for the name of the new InformationItem
    // Create the editor
    Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    IDirectEditorConfiguration configuration; // = new DefaultDirectEditorConfiguration();
    String languagePreferred =
        Activator.getDefault()
            .getPreferenceStore()
            .getString(
                IDirectEditorsIds.EDITOR_FOR_ELEMENT + infoItem.eClass().getInstanceClassName());
    configuration =
        DirectEditorsUtil.findEditorConfiguration(
            languagePreferred, infoItem.eClass().getInstanceClassName());
    configuration.preEditAction(infoItem);
    configuration.setInputValidator(
        new NameLabelValidator(Messages.InformationItemGetNameDialog_Error_Message));
    ExtendedDirectEditionDialog dialog =
        new ExtendedDirectEditionDialog(currentShell, infoItem, infoItem.getName(), configuration);

    dialog.open();

    if (dialog.getReturnCode() == Window.CANCEL) {
      // We delete the newInformationItem
      int index = getContainer().getPackagedElements().indexOf(infoItem);
      getContainer().getPackagedElements().remove(index);
      return null;
    } else {
      infoItem.setName(dialog.getValue());
      ((CreateElementRequest) getRequest()).setNewElement(infoItem);
      return infoItem;
    }
  }
  /**
   *
   *
   * <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();
  }