Difference between revisions of "Undo Mechanism"

From Developer Documents
Jump to navigation Jump to search
Line 1: Line 1:
This page documents a mechanism for defining context specific undo/redo operations.
+
This page documents a simple global non contextual undo/redo mechanism.
  
 
== Mechanism ==
 
== Mechanism ==
  
Client keeps context specific lists of undoable/redoable operations. Operations are added to undo list during commit if committed request has an undo context. 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 can be 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 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.  
  
== Procedure ==
+
== Undo and redo handling ==
  
Create context
+
If crtl-z and crtl-y keys are mapped to call DiagramUndo/RedoHandler 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 them as the following example shows.
  
 
<pre>
 
<pre>
    Session session = getSession();
+
     session.syncRequest(new WriteRequest() {
    UndoContext uctx = new UndoContextEx();
 
</pre>
 
 
 
Create request with context
 
 
 
<pre>
 
     session.syncRequest(new UndoWriteRequest(uctx, true) {
 
 
         @Override
 
         @Override
 
         public void perform(WriteGraph graph) throws DatabaseException {
 
         public void perform(WriteGraph graph) throws DatabaseException {
Line 32: Line 25:
 
     });
 
     });
 
</pre>
 
</pre>
Use undo and redo operations
 
 
    UndoRedoSupport support = session.getService(UndoRedoSupport.class);
 
    uctx.undo(support);
 
    uctx.redo(support);
 
 
== Diagram undo and redo handling ==
 
  
Each diagram viewer has its own undo context which can be get with getAdapter call. Ctrl-z and Crtl-y keys are mapped to call DiagramUndo/RedoHandler which uses getAdapter call to get the undo context and then calls undo/redo operation. Each developer who develops diagram(s)) must check that wanted operations are undoable for the diagram undo to be consistent. This can be done by the following procedure:
+
This can be done by the following procedure:
  
 
* Do the operation.
 
* Do the operation.
* Check from local history view which change sets have been created.
+
* Check from graph history view which change sets have been created and that they are commented properly.
* Check from undo view that change sets are combined to operations and added to the undo context correctly.
 

Revision as of 11:20, 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

If crtl-z and crtl-y keys are mapped to call DiagramUndo/RedoHandler 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 them as the following example shows.

    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);
        }
    });

This can be done by the following procedure:

  • Do the operation.
  • Check from graph history view which change sets have been created and that they are commented properly.