Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Undo
Undo [message #892984] Mon, 02 July 2012 08:32 Go to next message
Miriam Baran is currently offline Miriam BaranFriend
Messages: 16
Registered: May 2012
Junior Member
Hi,
I am having trouble with undo: It doesn't work correctly on Connections. If I create a new Connection in the diagram and undo that step, the Connection will be deleted from .diagram file as expected, but it will stay in the view (until I close and open it again). Could someone explain me how the undo works, to help me debug (I did not override it)? Can this be due to the update feature?
Re: Undo [message #893443 is a reply to message #892984] Wed, 04 July 2012 07:59 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
I'm not sure what the issue behind could be, maybe it is indeed an update
feature not working correctly, or may a linking (or missing linking) to a
domain object that caises this...

Undo works by using EMF Transaction functionality. All Graphiti features are
executed within a RecordingCommand that ends up on the EMF command stack for
the editor/TransactionalEditingDomain. Undo and redo simply trigger the undo
of the EMF RecodingCommand and the changes to the graphical objects
(Pictogram Model) and/or your domain model will trigger an update of the
diagram using the EMF adapters registered along with the editor.

Not sure if this helps...

Michael
Re: Undo [message #893806 is a reply to message #893443] Thu, 05 July 2012 14:27 Go to previous messageGo to next message
Miriam Baran is currently offline Miriam BaranFriend
Messages: 16
Registered: May 2012
Junior Member
Thank you, I think it will be the command stack. In fact undo is not the only problem: the editor does not seem to realize i have done changes when they only concern adding new connections, i even can't save them unless i move around some other object (deleting and moving works fine). As i never touched the command stack (consciously), i suppose that i either forgot some command that does it implicitly or that something about my add(or create)Feature will disable it.
Re: Undo [message #893940 is a reply to message #893806] Fri, 06 July 2012 07:00 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Strange. As soon as you modify the diagram or any contained object, a
Graphiti EMF adapter should notify that. How do you create/add the
connections? Could you post the coding here?

Michael
Re: Undo [message #894092 is a reply to message #893940] Fri, 06 July 2012 15:22 Go to previous messageGo to next message
Miriam Baran is currently offline Miriam BaranFriend
Messages: 16
Registered: May 2012
Junior Member
here my add Methode of the a connection (there are different ones, but one will do, as it is always the same problem).

     /**
     * {@inheritDoc}
     */
    @Override
    public PictogramElement add(IAddContext context) {
        IAddConnectionContext addConContext = (IAddConnectionContext) context;
        // TODO: Domain object
        Rule addedDomainObject = (Rule) context.getNewObject();
        ISprayStyle style = new RuleStyle();
        ISprayConnection connection = new SimpleArrowShape(getFeatureProvider());
        Connection result = (Connection) connection.getConnection(getDiagram(), style, addConContext.getSourceAnchor(), addConContext.getTargetAnchor());

        // create link and wire it
        peService.setPropertyValue(result, PROPERTY_MODEL_TYPE, CorePackage.Literals.RULE.getName());
        link(result, addedDomainObject);
        for (ConnectionDecorator conDecorator : result.getConnectionDecorators()) {
            link(conDecorator, addedDomainObject);
        }

        setDoneChanges(true);
        updatePictogramElement(result);

        /*
         * My add:
         * add false connections to enable collapse/expand
         */
        CustomContext ccontext = new CustomContext();
        PictogramElement[] pea = new PictogramElement[2];
        pea[0] = addConContext.getSourceAnchor().getParent();
        pea[1] = addConContext.getTargetAnchor().getParent();
        ccontext.setPictogramElements(pea);
        ccontext.putProperty("type", "rule");
        ICustomFeature[] cfs = getFeatureProvider().getCustomFeatures(ccontext);
        for(ICustomFeature cf : cfs){
        	if(cf instanceof MyCreateFalseConnectionsFeature){
        		if(cf.canExecute(ccontext)){
        			cf.execute(ccontext);
        		}
        	}
        }
        
        return result;
    }


and here is how the connection is created (getConnection Method of DottedArrowShape)

@Override
public Connection getConnection(final Diagram diagram, final ISprayStyle sprayStyle, final Anchor startAnchor, final Anchor endAnchor) {
	final Connection newConnection = peCreateService.createFreeFormConnection(diagram);
	newConnection.setStart(startAnchor);
	newConnection.setEnd(endAnchor);
	
	final Polyline polyline = gaService.createPolyline(newConnection);
	polyline.setStyle(sprayStyle.getStyle(diagram));
	// Define general layout of connection
	polyline.setLineStyle(LineStyle.DASH);	
	
	// Set the Placings of the connection
	{
		ConnectionDecorator decorator = peCreateService.createConnectionDecorator(newConnection, false, 1.0, true);
		List<Point> pointList = new ArrayList<Point>();
		pointList.add(gaService.createPoint(-10, 10, 0, 0));
		pointList.add(gaService.createPoint(0, 0, 0, 0));
		pointList.add(gaService.createPoint(-10, -10, 0, 0));
		Polyline element = gaService.createPolyline(decorator, pointList);
		ISprayStyle style = sprayStyle;
		element.setStyle(style.getStyle(diagram));
	}
	
	return newConnection;
}
Re: Undo [message #894806 is a reply to message #892984] Tue, 10 July 2012 15:15 Go to previous messageGo to next message
Miriam Baran is currently offline Miriam BaranFriend
Messages: 16
Registered: May 2012
Junior Member
Fixed: it was a hasDoneChanges() method in a subclass that should not have been overridden Embarrassed . Thanks your help, this may have been a really stupid problem in the end, i still learned a lot while debugging.
Re: Undo [message #978235 is a reply to message #892984] Fri, 09 November 2012 23:28 Go to previous messageGo to next message
Rob Cernich is currently offline Rob CernichFriend
Messages: 40
Registered: September 2011
Member
I've experienced something similar in the past. If you have a feature that executes, but is not the first command and does not make changes, then the command stack replaces the last operation in the history with an undoable operation. This ends up nuking the operation that was executed prior to the current operation.

See if (!changesDone) in GFCommandStack.execute(). All you need to do to reproduce is invoke a feature that invokes another feature that makes no changes (e.g. an add followed by an update when one isn't needed). Since the current command is not a topLevelCommand, and since that top level command hasn't finished executing, the previous operation is mistakenly removed from the operation history, which horks the undo stack.

I can create a BZ if you like. I've been working around the problem by making sure I always do work or skip invoking features that won't do work.

Hope that helps.

Best,
Rob
Re: Undo [message #981562 is a reply to message #978235] Mon, 12 November 2012 14:16 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Rob,

did you see https://bugs.eclipse.org/bugs/show_bug.cgi?id=389379 ? This bug
has been fixed for Kepler M3 and might target what you mention.

Michael
Previous Topic:Contextual help F1 support
Next Topic:ReconnectionContext
Goto Forum:
  


Current Time: Thu Mar 28 21:33:02 GMT 2024

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

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

Back to the top