-
-
Save mbarbero/6ffe6b88ee61ce7e2e57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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