Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Retrieve info from EMF model in UI action and then use it to modify the model itself
Retrieve info from EMF model in UI action and then use it to modify the model itself [message #1006055] Tue, 29 January 2013 16:13 Go to next message
Marco Naddeo is currently offline Marco Naddeo
Messages: 62
Registered: November 2012
Member
Hi. Smile

In an UI action in my DSL editor, I want to retrieve some information from the EMF model and then use it later to modify the model itself.

My code is something like this:

public class MyHandler extends AbstractHandler implements IHandler {

  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {

    final XtextEditor xtextEditor = (XtextEditor) HandlerUtil.getActiveEditor(event);

    final String info = xtextEditor.getDocument().readOnly(new IUnitOfWork<String,XtextResource>() {
			
      @Override
      public String exec(XtextResource state) throws Exception {

        TreeIterator<EObject> iter = state.getAllContents();
        String res = "";

        while (iter.hasNext()) {

	  EObject obj = iter.next();

	  if (...) {

            res = obj.getMyFeature();

          }

        }
        return res;

      }
			
    });


    //do some work here...

    //and then:
    xtextEditor.getDocument().modify(new IUnitOfWork.Void<XtextResource>() {

      @Override
      public void process(XtextResource state) throws Exception {

        TreeIterator<EObject> iter = state.getAllContents();

        while (iter.hasNext()) {

	  EObject obj = iter.next();

	  if (...) {

            obj.setMyFeature(info);

          }

        }

      }

    });

  }

}


The setting of the model element feature with the previous retrieved string *seems* to work, but to the next call of the UI action, the feature turns out to be actually set to null! Shocked

Do you have any idea of why? Confused

Note that I'm forced to declare the info string variable as final because the compiler says that I cannot refer to a non-final variable inside an inner class defined in a different method. Is it possible that this affects the result?


Thanks in advance,
Marco Rolling Eyes
Re: Retrieve info from EMF model in UI action and then use it to modify the model itself [message #1006322 is a reply to message #1006055] Wed, 30 January 2013 20:16 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
HI,

i cannot reproduce this. (the final problem would be avoided using the holder pattern anyway)

~Christian

[Updated on: Wed, 30 January 2013 20:16]

Report message to a moderator

Previous Topic:References from other file not working
Next Topic:IIncompatible implicit return type on short or byte with numeric constants
Goto Forum:
  


Current Time: Wed Oct 22 15:30:25 GMT 2014

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

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