A newbie question of EMF transaction [message #1014163] |
Mon, 25 February 2013 04:29  |
Eclipse User |
|
|
|
The RecordingCommand is said to support the undo function.
below is the code that makes me confused.
package test;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalCommandStack;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.example.library.Book;
import org.eclipse.example.library.BookCategory;
import org.eclipse.example.library.Library;
import org.eclipse.example.library.LibraryFactory;
import org.eclipse.example.library.Writer;
public class TransactionalEditingDomainTest {
public static void main(String[] args) {
LibraryFactory factory = LibraryFactory.eINSTANCE;
final Library library = factory.createLibrary();
final Writer sakop = factory.createWriter();
ResourceSet rset = new ResourceSetImpl();
rset.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("xmi", new XMIResourceFactoryImpl());
final Resource file1 = rset.createResource(URI.createFileURI("test.xmi"));
TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE
.createEditingDomain(rset);
TransactionalCommandStack stack = (TransactionalCommandStack) domain.getCommandStack();
RecordingCommand command = new RecordingCommand(domain) {
@Override
protected void doExecute() {
file1.getContents().add(library);
library.getWriters().add(sakop);
}
public boolean canUndo(){
return true;
}
};
System.out.println(library.getWriters());
stack.execute(command);
System.out.println(library.getWriters());
stack.undo();
System.out.println(library.getWriters());//still prints the writer list
}
}
I suppose that after undo library.getWriters() should be an empty EList,can sb tell me why?
Thanks
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07541 seconds