Esempio n. 1
0
  private TransactionSettings processCanUndoDelete(TransactionSettings ts) {

    boolean bCanUndoDelete = false;
    Object selection = getSelection();

    if (selection instanceof ISelection) {
      ISelection iSelection = (ISelection) selection;
      if (!iSelection.isEmpty() && !isReadOnly() && canLegallyEditResource()) {
        if (SelectionUtilities.isSingleSelection(iSelection)) {
          Object o = SelectionUtilities.getSelectedEObject(iSelection);
          bCanUndoDelete = (o != null && ModelObjectEditHelperManager.canUndoCut(o));
        } else if (SelectionUtilities.isMultiSelection(iSelection)) {

          List sourceEObjects = SelectionUtilities.getSelectedEObjects(iSelection);
          bCanUndoDelete = true;

          if (sourceEObjects.size() > 0) {
            bCanUndoDelete = ModelObjectEditHelperManager.canUndoCut(sourceEObjects);
          }
        }

        ts.setIsUndoable(bCanUndoDelete);
      }
    }

    return ts;
  }
Esempio n. 2
0
  private TransactionSettings processDescription(TransactionSettings ts) {

    ts.setDescription(getUndoText(getSelectedEObjects()));

    return ts;
  }
Esempio n. 3
0
  private void executeCommand(
      final ObjectDeleteCommand odcDeleteCommand,
      final EObject[] eObjects,
      TransactionSettings ts) {

    if (odcDeleteCommand == null) {
      createObjectDeleteCommand();
    }

    String tempString = UiConstants.Util.getString(DELETE_ONE_TITLE_KEY);
    if (eObjects.length > 1) {
      tempString = UiConstants.Util.getString(DELETE_MANY_TITLE_KEY, eObjects.length);
    }
    final String deleteTitle = tempString;

    WorkspaceModifyOperation operation =
        new WorkspaceModifyOperation() {
          @Override
          public void execute(final IProgressMonitor monitor) {

            if (monitor instanceof SubProgressMonitor) {
              ((SubProgressMonitor) monitor).getWrappedProgressMonitor().setTaskName(deleteTitle);
            }

            monitor.beginTask(CoreStringUtil.Constants.EMPTY_STRING, 100);
            monitor.worked(5);
            // execute the command
            IStatus status = odcDeleteCommand.execute(monitor);

            setResult(status);
          }
        };

    // start the txn
    ts.setSource(this);
    boolean started =
        ModelerCore.startTxn(
            ts.isSignificant(), ts.isUndoable(), ts.getDescription(), ts.getSource());

    boolean succeeded = false;

    try {
      ProgressMonitorDialog progressDialog =
          new ProgressMonitorDialog(Display.getDefault().getActiveShell());

      // run the operation
      progressDialog.run(true, true, operation);
      if (!progressDialog.getProgressMonitor().isCanceled()) {
        succeeded = true;
      }

      if (!getStatus().isOK()) {
        UiConstants.Util.log(getStatus());
      }
    } catch (Exception e) {
      UiConstants.Util.log(IStatus.ERROR, e, e.getMessage());
    } finally {
      if (started) {
        if (succeeded) {
          ModelerCore.commitTxn();
        } else {
          ModelerCore.rollbackTxn();
        }
      }
    }
  }