How to implement the undo&redo functions? [message #1014598] |
Tue, 26 February 2013 01:04  |
Eclipse User |
|
|
|
Hi,I am a newbie to Graphiti.
Last week,I finished the tutorial part by follwing the contents attached to the eclipse "help" menu.
However, there are still a big problem that is still haunting me,as the tutorial says nothing about this topic
How to implement "undo" and "redo" functions?
I tried to wrap several modifications into one RecordingCommand and invoked
command.execute(),the shape was drawn on the panel without any exception.
However,when I pressed "Ctrl+Z", an exception was thrown:
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
Below is the code of assertWriting,the first time tx is a valid object,however,it becomes null the second time this code is executed.
protected void assertWriting() {
InternalTransaction tx = domain.getActiveTransaction();
if ((tx == null) || tx.isReadOnly() || (tx.getOwner() != Thread.currentThread())) {
synchronized (domain) {
tx = domain.getActiveTransaction();
// the transaction could be null now if it completed before we
// synchronized on the domain
if (tx != null) {
tx.abort(new Status(
IStatus.ERROR,
EMFTransactionPlugin.getPluginId(),
EMFTransactionStatusCodes.CONCURRENT_WRITE,
Messages.concurrentWrite,
null));
}
}
IllegalStateException ise = new IllegalStateException(
Messages.noWriteTx);
Tracing.throwing(TransactionChangeRecorder.class, "assertWriting", ise); //$NON-NLS-1$
throw ise;
}
}
Can sb tell me how to do it(any simple examples will be fully appreciated!) or give a link to a more detailed tutorial.
Thanks!
[Updated on: Tue, 26 February 2013 02:41] by Moderator
|
|
|
|
|
Re: How to implement the undo&redo functions? [message #1015592 is a reply to message #1014664] |
Fri, 01 March 2013 05:15  |
Eclipse User |
|
|
|
Sakop,
the TransactionalEditingDoamin is used in Graphiti for all operations inside
the editor that deal with EMF objects. So, if you modify any EMF data (be it
graphical or part of your EMF domain objects) you will need to do this via a
TransactionalEditingDomain (more precisly the one used in the open editor).
In case you deal with non-EMF domain objects you cannot use a
TransactionalEditingDomain for modifications on your domain objects, because
the domain can only handle EMF objects. But still you would have to use the
domain for modifying your Graphiti diagram objects.
HTH,
Michael
|
|
|
Powered by
FUDForum. Page generated in 0.03506 seconds