|
|
|
Re: A newbie question of EMF transaction [message #1014406 is a reply to message #1014163] |
Mon, 25 February 2013 18:56 |
|
Hi,
I'm mildly surprised that you didn't get some kind of exception in
trying to run this stand-alone test application. The Transaction API
wasn't designed to work without the Eclipse framework running; I might
have expected the transaction in which the RecordingCommand executes to
fail to commit because of a problem validating it (the Validation API
also wasn't designed to work without Eclipse).
Can you confirm in the debugger that the top command on the undo stack
is the RecordingCommand? That is, is "stack.undo()" actually undoing
what you think it's undoing?
If so, then what does the ChangeDescription look like that
RecordingCommand.undo() is undoing?
As far as examples are concerned, the EMF Transaction SDK includes
tutorial documentation in the Eclipse Help centre and also an Examples
wizard that installs one or more example projects in your workspace.
These examples are documented in the help.
HTH,
Christian
On 2013-02-25 09:29:52 +0000, sakop qq said:
> 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
|
|
|
|
Re: A newbie question of EMF transaction [message #1014800 is a reply to message #1014595] |
Tue, 26 February 2013 13:38 |
|
OK, that makes sense.
So, the problem is resolved? Or it still occurs but now there are no
errors in the log?
cW
On 2013-02-26 05:53:06 +0000, sakop qq said:
> Yes,an error was thrown saying that the "EvaluationContext.class" is
> not found,so I added "org.eclipse.core.expressions" to the dependecy
> list and the error was suppressed
|
|
|
|
Powered by
FUDForum. Page generated in 0.01953 seconds