Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Additional diagram initialization code
Additional diagram initialization code [message #204394] Thu, 04 September 2008 15:44 Go to next message
Eclipse UserFriend
Originally posted by: martin.divbyzero.net

I'm trying to extend ???CreationWizard.performFinish() to add additional
diagram initialization code right after a new diagram has been created.
To be precise, I want to call the method setFoo() on the model element.

My current approach is to add the following code at the bottom of
performFinish():

> TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
> .getEditingDomain(diagram.getResourceSet());
>
> Diagram d = (Diagram)(diagram.getContents().get(0));
> final MyModel model = (MyModel)(d.getElement());
>
> editingDomain.getCommandStack().execute(
> new RecordingCommand(editingDomain) {
> protected void doExecute() {
> model.setFoo("abc");
> }
> });
>
> System.out.println(model.getFoo());

The print statement in the last prints the correct value "abc", but
neither in the properties view of the graphical editor nor in the XMI
file the value for the Foo attribute shows up. Can someone spot my
mistake? Am I using the wrong editing domain?

When I call setFoo() in ???DiagramEditorUtil.createInitialModel()
instead, the value persists as expected. Unfortunately I'd like to
avoid going this route because extending performFinish() seems to be a
much cleaner approach.

Martin
Re: Additional diagram initialization code [message #204997 is a reply to message #204394] Wed, 10 September 2008 11:10 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Martin,

> When I call setFoo() in ???DiagramEditorUtil.createInitialModel()
> instead, the value persists as expected. Unfortunately I'd like to
> avoid going this route because extending performFinish() seems to be a
> much cleaner approach.
Well, ???DiagramEditorUtil.createInitialModel() was designed exactly for
this.. In any case, you have to call model.eResource().save() to persist
changes.

-----------------
Alex Shatalin
Previous Topic:update models and redraw editor at runtime
Next Topic:Domain model and figure hierarchy out of sync
Goto Forum:
  


Current Time: Fri Apr 26 12:01:29 GMT 2024

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

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

Back to the top