Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Undoing direct editing leads to multiple undos((and editing through property view leads to same behavior))
Undoing direct editing leads to multiple undos [message #1262338] Mon, 03 March 2014 14:27 Go to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 168
Registered: September 2011
Senior Member
Hi all,

I implemented direct editing to change the name of a PE's underlying BO.
I can also change its name through the property view.
It works fine but I have to perform repeated undos if I want to cancel this single edition.

Undoing direct editing performed through the editor leads to 4 undos before I finally get back to the initial 'non dirty' editor :
- undo update
- undo update (previous name appears + PE with dashed line)
- undo direct editing
- undo update (editor dirty state disappears)

Undoing the same action performed through the property view also leads to 4 undos. Except that 'undo direct editing' is replaced by an 'undo set' in the context menu.

Is there a way to have only 'undo direct edit' / 'undo set' in each case ?

Reading another post with similar problem unfortunetaly did not help me much.

http://www.eclipse.org/forums/index.php/mv/msg/427888/972030/#msg_972030

I guess I did not manage to call AbstractFeature.updatePictogramElement the right way...
Calling updatePictogramElement or layoutPictogramElement at the end of my XXDirectEditingFeature.setValue or in XXDirectEditingFeature.execute makes no difference.

Moreover, is there something to be done in undo / redo methods ?

Kind regards,

Laurent
Re: Undoing direct editing leads to multiple undos [message #1262402 is a reply to message #1262338] Mon, 03 March 2014 15:50 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Laurent,

I have just checked in the Tutorial, there this seems to work with only one
entry in the undo stack. You might have a look into
TutorialDirectEditEClassFeature and TutorialUpdateEClassFeature to check how
it is done there.

The general rule is that each feature will be executed within its own EMF
transaction and each transaction is represented as an own entry in the
stack.

It might be that you really call your update feature in a wrong way, you
should ensure that all that needs to be updated is really done within the
call to updatePictogramElement .

Another possible reason is that the editor triggers further updates after
direct editing has finished. This happens because EMF objects have changed
(e.g. the name of the domain object). This again will trigger update
features (probably the same one you already triggered before). In that call
you have to ensure that updateNeeded returns false, otherwise the method
update will be called again in a new transaction, doing changes and is added
to the undo stack.

I hope this helps.

Michael
Re: Undoing direct editing leads to multiple undos [message #1263291 is a reply to message #1262402] Tue, 04 March 2014 10:47 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 168
Registered: September 2011
Senior Member
Hi Michael,

It helped a lot ! I had a look again to the tutorial and I added :
updatePictogramElement(((Shape) pe).getContainer()) in setValue as suggested.

And you were right, I also had to make a correction in XXUpdateFeature.updateNeeded.

It solves the problem for direct editing through the editor : all 'undo update' now disappear and only 'uno direct editing' remains as expected.

But, I still get an 'undo update' and an 'undo set' (?) when editing through the property view.

Do I have to add an 'updatePictogramElement(((Shape) pe).getContainer())' somewhere in a Set feature ? But, I found no getSetFeature that I could override in DefaultFeatureProvider or AbstractFeatureProvider.

Regards,

Laurent
Re: Undoing direct editing leads to multiple undos [message #1263580 is a reply to message #1263291] Tue, 04 March 2014 16:00 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Laurent,

from the property view you need to ensure that you do all needed changes
within one EMF transaction. The update needs to be triggered in that
transaction as well (best via your update feature). Otherwise the
automatical editor update will trigger your update and add a separate entry
in the command stack.

Graphit does not have s special set feature. You do the set yourself and in
the same transaction trigger the update.

Michael
Re: Undoing direct editing leads to multiple undos [message #1265952 is a reply to message #1262338] Thu, 06 March 2014 19:43 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 168
Registered: September 2011
Senior Member
Hi Michael,

I tried to figure out how to achieve what you adviced me to do.
I think - in my case - this would imply to override EMF ItemPropertyDescriptor.setPropertyValue to update both the BO and its PE as EMF objects (and not using the update feature that would cause a circular dependency between my plugins).
Well, setPropertyValue looked complicated Wink, so I finally found another solution which seems to work fine.

I override the GEF createActions method in my Graphiti editor to instanciate undo and redo actions that perform update and set commands at once when needed.

I still have one problem on the "editor side". I noticed that my direct editing feature doesn't cause the corresponding value to be refreshed in my property view.

I tried to call DiagramBehavior.refresh() or my BO notify() methods at the end of my XXDirectEditingFeature.setValue but none of them works...

Any idea why this happens ?

Regards,

Laurent
Re: Undoing direct editing leads to multiple undos [message #1266445 is a reply to message #1265952] Fri, 07 March 2014 13:23 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Laurent,

not sure why the property sheet update does not happen, that depends on how
you set the values there. E.g. using EMF databinding should automatically
update the values after the feature, but manually setting the UI fields will
need a manual update of the property sheet.

Michael
Re: Undoing direct editing leads to multiple undos [message #1266719 is a reply to message #1266445] Fri, 07 March 2014 21:54 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 168
Registered: September 2011
Senior Member
Hi Michael,

Notification through databinding is performed because XXItemProvider.notifyChanged() gets called but, for some reason, the emf extended property sheet page does not get refreshed.

Through my ToolBehaviorProvider implementation I get access to this page, so I called its refresh() method.
It now works perfectly...

Regards,

Laurent
Re: Undoing direct editing leads to multiple undos [message #1384119 is a reply to message #1266445] Wed, 28 May 2014 07:23 Go to previous messageGo to next message
Al B is currently offline Al B
Messages: 129
Registered: July 2009
Senior Member
I may be experiencing a similar problem. If I select Undo once, after
creating/adding multiple features; then multiple undos are triggered.
For instance, if I drag&drop 2 features individually each time and click
undo once, then the last feature added is removed. However, if I close
and reopen the editor after that, then both features are gone.
Re: Undoing direct editing leads to multiple undos [message #1384233 is a reply to message #1384119] Wed, 28 May 2014 13:33 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 168
Registered: September 2011
Senior Member
Hi Al,

Apparently your problem seems more to be the opposite of my former problem...

Nevertheless, if I remember right, I also faced your problem and it was because I was explicitly calling 'editingDomain.getCommandStack().undo()' in my XXDirectEditingFeature.undo() where the framework already does behind the scene...

And of course, I had to remove this irrelevant call also on redo side...

Hope it helps,

Laurent
Re: Undoing direct editing leads to multiple undos [message #1384423 is a reply to message #1384233] Thu, 29 May 2014 00:27 Go to previous messageGo to next message
Al B is currently offline Al B
Messages: 129
Registered: July 2009
Senior Member
Hi Laurent,

In our case, we are not calling editingDomain.getCommandStack().undo() at all so something else might be calling undo() twice. As you said, Graphiti already does things behind the scene so makes it a little bit difficult to trace the problem.
Re: Undoing direct editing leads to multiple undos [message #1384497 is a reply to message #1384423] Thu, 29 May 2014 06:04 Go to previous messageGo to next message
Al B is currently offline Al B
Messages: 129
Registered: July 2009
Senior Member
I noticed that the multiple undos occurs if I have not save the editor before I select undo. For instance, if I drag element "A" from the palette and drop it onto the editor and repeat the same step with element "B", then undo is available saying "Undo Create B" so if I select undo (without saving the editor), then both elements are removed from the editor and undo is disable (gray out). If I repeat the same steps, but I save the editor before I click on "Undo Create B"; then element B is removed and the context menu now shows "Undo Create A". It's strange since GFCommandStack::undo() is called once in both case scenarios.
Re: Undoing direct editing leads to multiple undos [message #1384601 is a reply to message #1384497] Thu, 29 May 2014 12:50 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 168
Registered: September 2011
Senior Member
Hi Al,

I tried your scenario but the undos just behave normally in my case...
I'm afraid I won't be of much help and hope a Graphiti expert will give you an hint...

Meanwhile, I suggest you debug / trace the execution of org.eclipse.gef.ui.parts.GraphicalEditor.createActions() and more specifically the registered UndoAction.

Regards,

Laurent
Re: Undoing direct editing leads to multiple undos [message #1384688 is a reply to message #1384497] Fri, 30 May 2014 12:21 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
That sounds strange.

Can you provide the code of your add features that are involved in these
steps here?

Michael
Re: Undoing direct editing leads to multiple undos [message #1384720 is a reply to message #1384688] Fri, 30 May 2014 17:19 Go to previous messageGo to next message
Al B is currently offline Al B
Messages: 129
Registered: July 2009
Senior Member
Hi Michael,

I can see that the problem is when a feature is created. For some reason the emf command stack only records the last created feature. For instance, if I drop two elements from the palette onto the diagram editor, then the command stack only shows the last one in the history list (see attached CreateTwice.png file). However, if I drop 2 elements and then I delete the last one, then you can see the two command operations listed in the stack (see CreateTwiceDeleteOne.png).

The problem seems to happen only with the create operation bacause if I execute 2 deletes, then the stack shows the 2 delete operations plus the last create operation. I expect it to show 2 delete operations plus 2 create operations though.

It's definitely strange since the code to create the feature is quite simple (see below) so I'm not sure where the emf command stack is being overridden with the last create operation.


public class CreateGoalFeature extends AbstractCreateNodeFeature {

	public static final String NAME = "Goal";

	public static final String DESCRIPTION = "Create Goal";
	
	public CreateGoalFeature(IFeatureProvider fp) {
		super(fp, NAME, DESCRIPTION);
	}

	@Override
	public Object[] create(ICreateContext context) {
		Goal goal = XxegsnFactory.eINSTANCE.createGoal();
		goal.setIdentifier(getUniqueId(IIdentifierConstants.GOAL));		
		getDiagram().eResource().getContents().add(goal);
		addGraphicalRepresentation(context, goal);

		return new Object[] { goal };
	}

	@Override
	public String getCreateImageId() {
		return IImageConstants.GOAL;
	}
}
Re: Undoing direct editing leads to multiple undos [message #1384897 is a reply to message #1384720] Mon, 02 June 2014 21:15 Go to previous message
Al B is currently offline Al B
Messages: 129
Registered: July 2009
Senior Member
Hi, Michael, Laurent,

I think I found out the problem. It's actually caused by the call to updatePictogramElement(containerShape); which is being called from the overridden AbstractAddShapeFeature::add() method as shown below. If I comment out the call to updatePictogramElement(), then undo works properly, but the shape doesn't look right. Any suggestions? Can updatePictogramElement() be called form add()?

	@Override
	public PictogramElement add(IAddContext context) {
		Diagram diagram = (Diagram) context.getTargetContainer();

		Goal goal = (Goal) context.getNewObject();

		IPeCreateService peCreateService = getPeCreateService();
		IGaService gaService = getGaService();

		// Container-shape
		ContainerShape containerShape = peCreateService.createContainerShape(diagram, true);
		peCreateService.createChopboxAnchor(containerShape);
		link(containerShape, goal);

		// Outer-rectangle
		Rectangle outerRectangle = gaService.createInvisibleRectangle(containerShape);
		gaService.setLocationAndSize(outerRectangle, context.getX(), context.getY(), context.getWidth(), context.getHeight());

		// Inner-rectangle
		Rectangle innerRectangle = gaService.createRectangle(outerRectangle);
		innerRectangle.setStyle(getStyle(IModelConstants.Goal));
		
		addIdentifier(containerShape);
		addDescription(containerShape);

		updatePictogramElement(containerShape);
		layoutPictogramElement(containerShape);
		
		activateDirectEdit(containerShape, IDiagramConstants.description);

		return containerShape;
	}
Previous Topic:MoveAnchorFeature - only vertically/horizontally
Next Topic:Problem with EReference
Goto Forum:
  


Current Time: Sat Oct 25 19:40:46 GMT 2014

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

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