Skip to content

Instantly share code, notes, and snippets.

@mbarbero
Created March 27, 2013 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbarbero/6ffe6b88ee61ce7e2e57 to your computer and use it in GitHub Desktop.
Save mbarbero/6ffe6b88ee61ce7e2e57 to your computer and use it in GitHub Desktop.
package fr.obeo.emf.edit.econ2013.live;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.ecore.change.util.ChangeRecorder;
import org.eclipse.emf.edit.command.ChangeCommand;
import org.eclipse.emf.examples.extlibrary.Book;
import org.eclipse.emf.examples.extlibrary.EXTLibraryFactory;
import org.eclipse.emf.examples.extlibrary.Library;
import org.eclipse.emf.examples.extlibrary.Writer;
public class ChangeRecorderExample {
/**
* @param args
*/
public static void main(String[] args) {
BasicCommandStack commandStack = new BasicCommandStack();
final Library library = EXTLibraryFactory.eINSTANCE.createLibrary();
library.setName("My Library");
ChangeRecorder recorder = new ChangeRecorder();
ChangeCommand command = new ChangeCommand(recorder, library) {
@Override
protected void doExecute() {
Book book = EXTLibraryFactory.eINSTANCE.createBook();
book.setTitle("The two towers");
library.getBooks().add(book);
Writer writer = EXTLibraryFactory.eINSTANCE.createWriter();
writer.setName("JRR Tolkien");
library.getWriters().add(writer);
book.setAuthor(writer);
}
};
commandStack.execute(command);
System.out.println("book title: " + library.getBooks().get(0).getTitle());
commandStack.undo();
System.out.println("books.isEmpty?: " + library.getBooks().isEmpty());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment