Skip to main content



      Home
Home » Modeling » Graphiti » How to implement the undo&redo functions?
How to implement the undo&redo functions? [message #1014598] Tue, 26 February 2013 01:04 Go to next message
Eclipse UserFriend
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 #1014651 is a reply to message #1014598] Tue, 26 February 2013 03:12 Go to previous messageGo to next message
Eclipse UserFriend
Sakopp,

undo/redo is implemented generically within the framework (for EMF domain
objects), so you don't need to implement anything unless you have non-EMF
domain objects. But that is not the case in the tutorial.

Seperating domain objects from graphical objects be be done best while
creating the domain objects: simply add them to another EMF resource. In
case non exists you can also create a new resource in your create feature.
There's a short snippet in an older forum entry:
http://www.eclipse.org/forums/index.php?t=msg&th=172247&start=0&S=acb08c1bf425f0ccb0106fb3a46a4bad

Michael
Re: How to implement the undo&redo functions? [message #1014664 is a reply to message #1014651] Tue, 26 February 2013 03:36 Go to previous messageGo to next message
Eclipse UserFriend
Thank you. So TransactionEditingDomain is only required when dealing with non-EMF object,isn't it?

Re: How to implement the undo&redo functions? [message #1015592 is a reply to message #1014664] Fri, 01 March 2013 05:15 Go to previous message
Eclipse UserFriend
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
Previous Topic:Graphiti fails to handle resize after custom feature addition
Next Topic:Separating domain and pictogram model
Goto Forum:
  


Current Time: Wed Jul 23 08:51:29 EDT 2025

Powered by FUDForum. Page generated in 0.05711 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top