Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.