Difference between revisions of "Undo Mechanism"

From Developer Documents
Jump to navigation Jump to search
Line 9: Line 9:
 
If '''org.eclipse.ui.edit.undo''' and '''org.eclipse.ui.edit.redo''' commands are bound to handlers Diagram{Undo,Redo}Handler then the undo/redo mechanism is activated. The handlers undo/redo one operation from the global undo/redo lists with each button press. It is desirable that each developer who develops requests that modify the graph comment their changes as shown by thefollowing example.
 
If '''org.eclipse.ui.edit.undo''' and '''org.eclipse.ui.edit.redo''' commands are bound to handlers Diagram{Undo,Redo}Handler then the undo/redo mechanism is activated. The handlers undo/redo one operation from the global undo/redo lists with each button press. It is desirable that each developer who develops requests that modify the graph comment their changes as shown by thefollowing example.
  
<pre>
+
<div style="background-color:#f8f8f8; border: 1px dashed #cccccc; padding: 1ex; margin-left:2em; margin-top: 1em; margin-bottom:1em;">
 +
<syntaxhighlight lang="java">
 
     session.syncRequest(new WriteRequest() {
 
     session.syncRequest(new WriteRequest() {
 
         @Override
 
         @Override
Line 24: Line 25:
 
         }
 
         }
 
     });
 
     });
</pre>
+
</syntaxhighlight>
 +
</div>
  
 
You can test your operations using the following procedure:
 
You can test your operations using the following procedure:

Revision as of 21:43, 15 September 2011

This page documents a simple global non contextual undo/redo mechanism.

Mechanism

Database client keeps a global list of undoable/redoable operations. Operations are added to undo list during commit. Each commit creates a change set to server which defines the changes to resource values and statements. Change set also contains metadata for interpreting the change. The metadata format is defined by client and the server can not read or interpret it. Each operation has unique change set identifier. Sequential operations are tagged as combined by giving them the same operation id. All operations with same id will be treated as single undoable/redoable operation. Database client groups all change sets created within one write request as one operation.

Undo and redo handling in the Simantics workbench

If org.eclipse.ui.edit.undo and org.eclipse.ui.edit.redo commands are bound to handlers Diagram{Undo,Redo}Handler then the undo/redo mechanism is activated. The handlers undo/redo one operation from the global undo/redo lists with each button press. It is desirable that each developer who develops requests that modify the graph comment their changes as shown by thefollowing example.

<syntaxhighlight lang="java">

   session.syncRequest(new WriteRequest() {
       @Override
       public void perform(WriteGraph graph) throws DatabaseException {
           // Do your modifications.
           Layer0 b = Layer0.getInstance(graph);
           Resource s = graph.newResource();
           graph.claim(s, b.InstanceOf, b.Entity);
           
           // Add comment to change set.
           CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
           cm.add("My comment.");
           graph.addMetadata(cm);
       }
   });

</syntaxhighlight>

You can test your operations using the following procedure:

  • Do the operation.
  • Check from Teamwork / Graph History view which change sets have been created and that they are commented properly.

Related Documents