Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Can not save changes when using an TransactionalEditingDomain(Can not save changes when using an TransactionalEditingDomain as no change is caught by the EContentAdapter)
Can not save changes when using an TransactionalEditingDomain [message #484505] Mon, 07 September 2009 19:33 Go to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: September 2009
Junior Member
Hi, I'm new to EMF programming, and am trying to isolate the changes to a object in a GUI from all other parts until I commit the changes.

For this purpose I use TransactionalEditingDomain follwing the example in the documentation for EMF transactions. However, as I succesfully hide the changes from other parts of the program, I also seem to hide it from my own listener, so that the GUI doesn't know that something has changed, and it is not possible to save the changes.

Can someone please tell me what I am missing?

See the code below to see what I do, I use Eclipse 3.5.
Regards
Tomas Wahlgren

In the Editor, init method, the object I work with is the Contact object:
TransactionalEditingDomain edDomain = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("capEditDomain");
Resource exclusiveRes = edDomain.getResourceSet().createResource(CMUtil.makeUri(getId(c.getId())));
        edDomain.getCommandStack().execute(new RecordingCommand(edDomain) {
            protected void doExecute() {
                exclusiveRes.getContents().add(mContact);

                setPartName(mContact.getFullName());
                mContact.eAdapters().add(new EContentAdapter() {
                    @Override           
                    public void notifyChanged(Notification msg) {
                        setPartName(mContact.getFullName());
                        isDirty = true;
                        firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
                    }
                });
            }
        });

I use the same mContact in the createPartControl:

      
bindingContext.bindValue(SWTObservables.observeText(first, SWT.Modify), EMFObservables.observeValue(mContact, CMPackage.Literals.CONTACT__FIRST_NAME), null, null);


I can the value in the GUI, but not save it as no changes are detected. If use it without a TransactionalEditingDomain it works fine, but all other parts of the program listening to changes get them before I want them to.

[Updated on: Mon, 07 September 2009 19:39]

Report message to a moderator

Re: Can not save changes when using an TransactionalEditingDomain [message #484608 is a reply to message #484505] Tue, 08 September 2009 13:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
tomaswahlgren@gmail.com wrote:
> Hi, I'm new to EMF programming, and am trying to isolate the changes
> to a object in a GUI from all other parts until I commit the changes.
> For this purpose I use TransactionalEditingDomain follwing the example
> in the documentation for EMF transactions. However, as I succesfully
> hide the changes from other parts of the program, I also seem to hide
> it from my own listener, so that the GUI doesn't know that something
> has changed, and it is not possible to save the changes.
All changes must be made with the command stack of the editing domain
used by the editor.
>
> Can someone please tell me what I am missing?
> See the code below to see what I do, I use Eclipse 3.5.
> Regards
> Tomas Wahlgren
>
> In the Editor, init method, the object I work with is the Contact object:
> TransactionalEditingDomain edDomain =
> TransactionalEditingDomain.Registry.INSTANCE.getEditingDomai n( "capEditDomain");
>
> Resource exclusiveRes =
> edDomain.getResourceSet().createResource(CMUtil.makeUri(getI d(c.getId())));
>
> edDomain.getCommandStack().execute(new
> RecordingCommand(edDomain) {
> protected void doExecute() {
> exclusiveRes.getContents().add(mContact);
>
> setPartName(mContact.getFullName());
> mContact.eAdapters().add(new EContentAdapter() {
> @Override public void
> notifyChanged(Notification msg) {
> setPartName(mContact.getFullName());
> isDirty = true;
>
> firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
> }
> });
> }
> });
I suppose there is logic to undo this? There should be no need to
directly notify the dirty state. Executing a command should be
sufficient because the editor listens to the command stack itself.
> I use the same mContact in the createPartControl:
>
> bindingContext.bindValue(SWTObservables.observeText(first,
> SWT.Modify), EMFObservables.observeValue(mContact,
> CMPackage.Literals.CONTACT__FIRST_NAME), null, null);
>
>
> I can the value in the GUI, but not save it as no changes are
> detected. If use it without a TransactionalEditingDomain it works
> fine, but all other parts of the program listening to changes get them
> before I want them to.
Shouldn't you be using EMFEditObservables so that a command stack is used?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can not save changes when using an TransactionalEditingDomain [message #484742 is a reply to message #484608] Wed, 09 September 2009 06:05 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: September 2009
Junior Member
Thanks for your help, now it works!
/ Tomas
Re: Can not save changes when using an TransactionalEditingDomain [message #484783 is a reply to message #484608] Wed, 09 September 2009 09:28 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: September 2009
Junior Member
One additional question Ed, using the EMFEditObservables as you suggested allows the editor to pick up that changes has been done, but when I want to save it I cant get to the object that is changed.

Any tip?

Today I try to use the Resource I created in the init method, but when I do getContent() on it it is empty, and there is no sign of the object I put into it in the init() method.

Regards
Tomas
Re: Can not save changes when using an TransactionalEditingDomain [message #484847 is a reply to message #484783] Wed, 09 September 2009 13:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Tomas,

Comments below.


tomaswahlgren@gmail.com wrote:
> One additional question Ed, using the EMFEditObservables as you
> suggested allows the editor to pick up that changes has been done, but
> when I want to save it I cant get to the object that is changed.
I'm not quite sure what you mean by "get to the object that is changed."
>
> Any tip?
>
> Today I try to use the Resource I created in the init method, but when
> I do getContent() on it it is empty, and there is no sign of the
> object I put into it in the init() method.
Did you add any objects to the resource? Typically in an editor a
resource is loaded and has existing contents that the editor is editing.
A wizard is used to create a new resource with initial contents. So I'm
not sure I understand the scenario you describe.
>
> Regards
> Tomas


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] locking question
Next Topic:[TENEO] Editors drag-drop functionality with GMF
Goto Forum:
  


Current Time: Thu Apr 25 02:31:19 GMT 2024

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

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

Back to the top