Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Updating editor after modify an emf model programatically
Updating editor after modify an emf model programatically [message #508991] Thu, 21 January 2010 03:49 Go to next message
R.Afonso is currently offline R.AfonsoFriend
Messages: 10
Registered: December 2009
Junior Member
I have an EMF model´s editor opened and I´m inserting programatically some elements into the model.
Everything is ok, elements are shown but the editor doesn´t realized the model has changed, (the typical asterix besides the filename doesn´t appear).

Any idea of what shoud I implement or any method for marking the editor as "dirty"?

Thanks in advance!
Re: Updating editor after modify an emf model programatically [message #509100 is a reply to message #508991] Thu, 21 January 2010 07:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
You should be sure to use commands executed on the command stack to
modify the model because it's via the command stack's state that
dirtiness is determined. If you can't use fine grained commands such as
AddCommand and so on, you can always wrap your model modifying
processing within a ChangeCommand. Of course either approach as the
added advantage of making the changes undoable.


R.Afonso wrote:
> I have an EMF model´s editor opened and I´m inserting programatically
> some elements into the model.
> Everything is ok, elements are shown but the editor doesn´t realized
> the model has changed, (the typical asterix besides the filename
> doesn´t appear).
>
> Any idea of what shoud I implement or any method for marking the
> editor as "dirty"?
>
> Thanks in advance!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Updating editor after modify an emf model programatically [message #509228 is a reply to message #508991] Thu, 21 January 2010 17:41 Go to previous message
R.Afonso is currently offline R.AfonsoFriend
Messages: 10
Registered: December 2009
Junior Member
Thanks!!, that´s it.
In fact there isn´t so much information about this on the web apart from the API description, so I leave a small example below.


I have a hierarchy of EObjects (like the example about mindmaps and topics...) of a SolutionList with Solution elements, and more levels below.
I´m editing the model using the emf model editor generated from my genmodel...
Before using commands I was inserting all the objects like this...

Model.getSolutionList().add(Model.eInstance.create(Solution. ..)));

resulting in a updated model, but the editor didn´t mark it as "modificated" (thus is, "Save As" button was disabled in my app)

Solution:
do all the stuff the same but in the final object insertion (Solution into SolutionList) , instead using a Command:

EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(model.getSolutionList());
Command command = AddCommand.create(domain, model.getSolutionList(), ModelPackage.Literals.SOLUTION_LIST__SOLUTIONS,  sol);
domain.getCommandStack().execute(command); 


This way the editor is marked as dirty, and as said before, Undo and Redo operations work as usual (undo removes all the operation)
Previous Topic:Using an EMF model for a GEF-based editor
Next Topic:Defining the Java package in the ecore model
Goto Forum:
  


Current Time: Fri Mar 29 10:05:44 GMT 2024

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

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

Back to the top