Undoing direct editing leads to multiple undos [message #1262338] |
Mon, 03 March 2014 09:27  |
Eclipse User |
|
|
|
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 #1384720 is a reply to message #1384688] |
Fri, 30 May 2014 13:19   |
Eclipse User |
|
|
|
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 17:15  |
Eclipse User |
|
|
|
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;
}
|
|
|
Powered by
FUDForum. Page generated in 0.12864 seconds