Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Undo Command doesn't unset model attributes(Graphiti Undo Command not working)
Undo Command doesn't unset model attributes [message #1768480] Wed, 19 July 2017 10:42 Go to next message
Ken Mersado is currently offline Ken MersadoFriend
Messages: 19
Registered: October 2014
Junior Member
Hi All,

I have problem with Undo Command in Graphiti.
First of all, i have implemented default features (add, move, resize, etc..) and custom features of Graphiti.

The features when executed will update/set the attributes of the underlying models link to pictogram elements. My diagram editor then will detect changes via INotifyChangedListener and execute my custom update feature (which extends AbstractUpdateFeature) to update the shapes in the editor.

But, when i invoke the undo (ctrl+z), it only undo the changes made in the shapes/pictogram elements and not the changes in the model.

1. Is my way in handling/updating shapes correct?
2. If so, why does the undo (ctrl+z) doesn't work on my models?

Thanks,
Ken

[Updated on: Wed, 26 July 2017 06:40]

Report message to a moderator

Re: Undo Command doesn't unset model attributes [message #1770446 is a reply to message #1768480] Fri, 11 August 2017 13:05 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1932
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Ken,

undo/redo will work automatically for all changes you do to EMF objects within one resourceset. Can you share how you trigger the changes to your model from the features?

Michael
Re: Undo Command doesn't unset model attributes [message #1770881 is a reply to message #1770446] Fri, 18 August 2017 10:34 Go to previous messageGo to next message
Ken Mersado is currently offline Ken MersadoFriend
Messages: 19
Registered: October 2014
Junior Member
Hi Michael,

Thanks for your response.
I have this MoveFeature implemented and i set the model attributes under postMoveShape()
The element.setRowPosition() and element.ColumnPosition() updates my model

protected void postMoveShape(IMoveShapeContext context) {
	log.infoStart();

	int x = context.getX();
	int y = context.getY();

	// get the size of the parent shape
	ContainerShape parentShape = context.getSourceContainer();
	GraphicsAlgorithm ga = parentShape.getGraphicsAlgorithm();
	int pWidth = ga.getWidth();
	int pHeight = ga.getHeight();

	// force the shape to fit within the boundaries of the screen
	if (x > pWidth) {
		x = pWidth;
	}

	if (y > pHeight) {
		y = pHeight;
	}

	Object obj = getBusinessObjectForPictogramElement(context.getPictogramElement());
	if (obj instanceof Screen_Element) {
		Screen_Element element = (Screen_Element) obj;
		// compute the row and column position
		int rowPos = (y / editor.getHeight()) + 1;
		int colPos = (x / editor.getWidth()) + 1;

		element.setRowPosition(rowPos);
		element.setColumnPosition(colPos);
	}

	ArrayList<Shape> selectedShapes = new ArrayList<Shape>();

	PictogramElement[] currentSelection = getDiagramBehavior().getDiagramContainer().getSelectedPictogramElements();
	for (PictogramElement pe : currentSelection) {
		selectedShapes.add((Shape) pe);
	}
	log.infoEnd();
}


I also, tried execution it using CompundCommand. It doesn't undo as well.

What you mean to say is that i need to add the element into the editors resourceSet?

Thanks,
Ken
Re: Undo Command doesn't unset model attributes [message #1770886 is a reply to message #1770881] Fri, 18 August 2017 11:50 Go to previous messageGo to next message
Ken Mersado is currently offline Ken MersadoFriend
Messages: 19
Registered: October 2014
Junior Member
Hi Michael,

I tried adding the resources in the resourceSet and it the undo works!
But, when i tried to save the editor, i get an java.lang.IllegalStateException: Cannot modify resource set without a write transaction

Any thoughts?

Thanks,
Ken
Re: Undo Command doesn't unset model attributes [message #1770895 is a reply to message #1770886] Fri, 18 August 2017 13:46 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1932
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Ken,

can you share the stacktrace of that exception?

Michael
Re: Undo Command doesn't unset model attributes [message #1771111 is a reply to message #1770895] Tue, 22 August 2017 06:42 Go to previous messageGo to next message
Ken Mersado is currently offline Ken MersadoFriend
Messages: 19
Registered: October 2014
Junior Member
Hi Micheal,

Please see sample stack trace:
URI: myproject://mymodel1503383630999/User%20Interface%20(UI)%20Artifacts/GUI%20Artifacts/Screens/c155f909-dc2f-4ed1-a7e2-0bb64cf510cb#c155f909-dc2f-4ed1-a7e2-0bb64cf510cb, cause: 
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at com.mymodel.mkm.mymodel.domain.impl.BaseKeyClassImpl.setLastUpdate(BaseKeyClassImpl.java:253)
	at com.mymodel.mkm.myproject.resource.MyResourceImpl.save(MyResourceImpl.java:333)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior$1$1.run(DefaultPersistencyBehavior.java:331)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior$1.run(DefaultPersistencyBehavior.java:342)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2313)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2295)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior.save(DefaultPersistencyBehavior.java:349)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior$SaveOperation.run(DefaultPersistencyBehavior.java:448)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)

!STACK 0
java.lang.RuntimeException
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior.save(DefaultPersistencyBehavior.java:351)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior$SaveOperation.run(DefaultPersistencyBehavior.java:448)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)


Thanks,
Ken
Re: Undo Command doesn't unset model attributes [message #1771146 is a reply to message #1771111] Tue, 22 August 2017 13:04 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1932
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Ken,

this looks as if your EMF resource implementation (com.mymodel.mkm.myproject.resource.MyResourceImpl) tries to modify the resource (set last update) before saving. The save operation is triggered by the Graphiti editor within a runnable and not inside any EMF transaction:
at com.mymodel.mkm.mymodel.domain.impl.BaseKeyClassImpl.setLastUpdate(BaseKeyClassImpl.java:253)
at com.mymodel.mkm.myproject.resource.MyResourceImpl.save(MyResourceImpl.java:333)

You will need to trigger that change to the model within an EMF transaction, that should fix the exception.

Michael
Previous Topic:Changing image associated with Shape
Next Topic:ConnectionDecorator is updated only once
Goto Forum:
  


Current Time: Sat Nov 09 02:07:13 GMT 2024

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

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

Back to the top