// 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;
    }
  }
예제 #2
0
  /**
   * This methods is no more generated to handle the case of editing the name of a lifeline with a
   * directEdition when its properties represents and decomposedAs are null
   *
   * @generated NOT
   */
  protected void performDirectEditRequest(Request request) {

    final Request theRequest = request;

    Lifeline lifeline = (Lifeline) resolveSemanticElement();
    if (lifeline.getRepresents() != null || lifeline.getDecomposedAs() != null) {
      directEditionMode = IDirectEdition.NO_DIRECT_EDITION;
    }

    if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
      directEditionMode = getDirectEditionType();
    }
    switch (directEditionMode) {
      case IDirectEdition.NO_DIRECT_EDITION:
        // no direct edition mode => does nothing
        return;
      case IDirectEdition.EXTENDED_DIRECT_EDITOR:
        updateExtendedEditorConfiguration();
        if (configuration == null || configuration.getLanguage() == null) {
          performDefaultDirectEditorEdit(theRequest);
        } else {
          configuration.preEditAction(resolveSemanticElement());
          final ExtendedDirectEditionDialog dialog =
              new ExtendedDirectEditionDialog(
                  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                  resolveSemanticElement(),
                  configuration.getTextToEdit(resolveSemanticElement()),
                  configuration);
          if (Window.OK == dialog.open()) {
            TransactionalEditingDomain domain = getEditingDomain();
            RecordingCommand command =
                new RecordingCommand(domain, "Edit Label") {

                  @Override
                  protected void doExecute() {
                    configuration.postEditAction(resolveSemanticElement(), dialog.getValue());
                  }
                };
            domain.getCommandStack().execute(command);
          }
        }
        break;
      case IDirectEdition.DEFAULT_DIRECT_EDITOR:

        // initialize the direct edit manager
        try {
          getEditingDomain()
              .runExclusive(
                  new Runnable() {

                    public void run() {
                      if (isActive() && isEditable()) {
                        if (theRequest
                                .getExtendedData()
                                .get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR)
                            instanceof Character) {
                          Character initialChar =
                              (Character)
                                  theRequest
                                      .getExtendedData()
                                      .get(
                                          RequestConstants
                                              .REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
                          performDirectEdit(initialChar.charValue());
                        } else if ((theRequest instanceof DirectEditRequest)
                            && (getEditText().equals(getLabelText()))) {
                          DirectEditRequest editRequest = (DirectEditRequest) theRequest;
                          performDirectEdit(editRequest.getLocation());
                        } else {
                          performDirectEdit();
                        }
                      }
                    }
                  });
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        break;
      default:
        break;
    }
  }