Example #1
0
  @Override
  public IUndoableOperation commit() {
    final IUndoableOperation updateVisualOperation = super.commit();
    if (updateVisualOperation == null) {
      return null;
    }

    // commit changes to model
    final FXGeometricShapePart host = getHost();
    final FXGeometricShape hostContent = host.getContent();

    // determine transformation
    @SuppressWarnings("serial")
    Provider<Affine> affineProvider =
        host.getAdapter(
            AdapterKey.<Provider<? extends Affine>>get(
                new TypeToken<Provider<? extends Affine>>() {},
                FXTransformPolicy.TRANSFORMATION_PROVIDER_ROLE));
    AffineTransform tx = JavaFX2Geometry.toAffineTransform(affineProvider.get());
    final AffineTransform oldTransform = hostContent.getTransform();
    final AffineTransform newTransform =
        new AffineTransform(
            tx.getM00(),
            tx.getM10(),
            tx.getM01(),
            tx.getM11(),
            tx.getTranslateX(),
            tx.getTranslateY());

    // create operation to write the changes to the model
    final IUndoableOperation updateModelOperation =
        new AbstractOperation("Update Model") {

          @Override
          public IStatus execute(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            hostContent.setTransform(newTransform);
            return Status.OK_STATUS;
          }

          @Override
          public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            return execute(monitor, info);
          }

          @Override
          public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            hostContent.setTransform(oldTransform);
            return Status.OK_STATUS;
          }
        };
    // compose operations
    IUndoableOperation compositeOperation =
        new ForwardUndoCompositeOperation(updateVisualOperation.getLabel()) {
          {
            add(updateVisualOperation);
            add(updateModelOperation);
          }
        };

    return compositeOperation;
  }