Difference between revisions of "Undo Mechanism"

From Developer Documents
Jump to navigation Jump to search
(Created page with "This page documents a mechanism for defining context specific undo/redo operations. == Mechanism == Client keeps context specifc lists of undoable/redoable operations. Operatio...")
 
Line 31: Line 31:
 
     });
 
     });
 
</pre>
 
</pre>
Use undo and redeo operations
+
Use undo and redo operations
  
 
     UndoRedoSupport support = session.getService(UndoRedoSupport.class);
 
     UndoRedoSupport support = session.getService(UndoRedoSupport.class);
 
     uctx.undo(support);
 
     uctx.undo(support);
 
     uctx.redo(support);
 
     uctx.redo(support);

Revision as of 07:20, 9 August 2011

This page documents a mechanism for defining context specific undo/redo operations.

Mechanism

Client keeps context specifc 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.

Procedure

Create context

    Session session = getSession();
    UndoContext uctx = new UndoContextEx();

Create request with context

    session.syncRequest(new UndoWriteRequest(uctx, true) {
        @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);
            graph.addMetadata(cm.add("Added connection " + cu));
        }
    });

Use undo and redo operations

   UndoRedoSupport support = session.getService(UndoRedoSupport.class);
   uctx.undo(support);
   uctx.redo(support);