Altova UModel 2025

Undo / Redo and UMLData Transaction Handling

Inicio Anterior Inicio Siguiente

When modifying the UML data structure using the UModel API, there is no need to take care of Undo/Redo or transactions.

 

The following code makes three modifications:

 

      public void ChangeClass( IUMLClass iClass )
      {
          iClass.SetName("NewName");
          iClass.Visibility = ENUMUMLVisibilityKind.eVisibility_Public;
          iClass.IsAbstract = true;
      }

 

and for every modification, a new undo-step is created, in other words: the user will have to press the "Undo" button three times in UModel to undo these three changes.

 

This is not always the required behavior so the UModel API supports "transaction-handling" making it possible to execute multiple modifications in one step.

 

IDocument has the functionality to define when a group of modifications starts ( "BeginModification" ) and when it ends ( "EndModification" ):

 

      public void ChangeClass(IUMLClass iClass, IDocument iDoc)
      {
          try
          {
              // make all modifications within one UndoStep; start modification here
              if (!iDoc.BeginModification())
                  return;
 
              iClass.SetName("NewName");
              iClass.Visibility = ENUMUMLVisibilityKind.eVisibility_Public;
              iClass.IsAbstract = true;
 
              // do not forget to end modification and finish UndoStep
              iDoc.EndModification();
          }
          catch (System.Exception)
          {
              // rollback made changes
              iDoc.AbortModification();
 
              // add error handling
          }
      }

 

This kind of transaction handling may only be used for UML data modifications. Other functions, such as e.g. 'synchronize model from code', will create one single Undo step anyway.

© 2018-2024 Altova GmbH