Skip to main content



      Home
Home » Modeling » Graphiti » Editor is dirty when create method returns EMPTY
Editor is dirty when create method returns EMPTY [message #902971] Tue, 21 August 2012 09:17 Go to next message
Eclipse UserFriend
Hello everyone,

Following graphiti tutorial:

public Object[] create(ICreateContext context) {
        // ask user for EClass name
        String newClassName = ExampleUtil.askString(TITLE, USER_QUESTION, "");
        if (newClassName == null || newClassName.trim().length() == 0) {
            return EMPTY;
        }
 
        // create EClass
        EClass newClass = EcoreFactory.eINSTANCE.createEClass();
        // Add model element to resource.
        // We add the model element to the resource of the diagram for
        // simplicity's sake. Normally, a customer would use its own
        // model persistence layer for storing the business model separately.
        getDiagram().eResource().getContents().add(newClass);
        newClass.setName(newClassName);
 
        // do the add
        addGraphicalRepresentation(context, newClass);
 
        // return newly created business object(s)
        return new Object[] { newClass };
    }


When this method returns EMPTY, the editor still gets dirty despite no object was added to the resource.

Is this the expected behaviour?

Is there anyway that I can avoid this?

Thanks,
Joao
Re: Editor is dirty when create method returns EMPTY [message #902978 is a reply to message #902971] Tue, 21 August 2012 09:51 Go to previous messageGo to next message
Eclipse UserFriend
You need to override hasDoneChanges() to return true or false depending on whether or not you changed the model. Returning false will keep the dirty flag from appearing.

Hope that helps.
Rob
Re: Editor is dirty when create method returns EMPTY [message #1852475 is a reply to message #902971] Tue, 17 May 2022 10:53 Go to previous message
Eclipse UserFriend
This seem to work on custom Features but not when you use a Pattern.
I noticed that the CreateFeatureForPattern object always returns true and the GFCommandStack only queries the top CreateFeatureForPattern and not the actual delegated class pattern (e.g. MyCustomPattern).

So even if I override the hasDoneChanges() in my custom pattern, it has no effect. Once the Command executes the create(), the Editor will always be dirty.

Is there are a good way around this?

I see two options
a. Use a custom Create Feature - but this defeats the purpose of using a pattern, no?
b. Create your own GFCommandStack and update the execute() logic to query the delegate pattern's hasDoneChanges().

Anyone ran into a similar issue on using Patterns?
Previous Topic:Select pictogram element in editor on add
Next Topic:Automated Test for Graphiti Diagrams
Goto Forum:
  


Current Time: Mon Apr 14 16:13:38 EDT 2025

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

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

Back to the top