Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Namespace Imports in Embedded Editor(How does the IEditedResourceProvider work?)
Namespace Imports in Embedded Editor [message #1067901] Thu, 11 July 2013 07:57 Go to next message
Dennis Stampfer is currently offline Dennis StampferFriend
Messages: 23
Registered: April 2013
Junior Member
Hi,

after having no success by adapting an embedded editor from papyrus (http://www.eclipse.org/forums/index.php/m/1058998/), I started working with the embedded xtext editor. We reference elements from other files using importUri mechanism.

However, the importURI mechanism is not practical in our use case. We need to import files with namespaces. Here is how I launch the embedded editor:

IEditedResourceProvider resourceProvider3 = new IEditedResourceProvider() {
    @Override
    public XtextResource createResource() {
        try {
        	//ParameterStandaloneSetup.doSetup();
            ResourceSet resourceSet = new ResourceSetImpl();
            Resource resource = resourceSet.createResource(URI.createURI("somefile.param")); //fictional resource
            return (XtextResource) resource;
        } catch (Exception e) {
            return null;
        }
    }
};

ParameterActivator activator = ParameterActivator.getInstance();
Injector injector = activator.getInjector(ParameterActivator.ORG_XTEXT_PARAMETER_PARAMETER);
EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
handle = factory.newEditor(resourceProvider3).showErrorAndWarningAnnotations().withParent(parent);
EmbeddedEditorModelAccess partialEditor = handle.createPartialEditor(true); // allow r/w access
// handle.getDocument().set("");
// handle.getViewer().setEditable(true);
partialEditor.updateModel("",  "//content", "");


index.php/fa/15566/0/

Upper left: Example package definition in a file.
Upper right: Example package use in a file. Referencing/importing elements from simple.param works.
Lower: Using the same code as use.param in an embedded editor does not work.

Changing the infrastructure to use importURI, I can get the example working with "import 'platform:/resource/..../simple.param'".

I have come upon several different implementations of the IEditedResourceProvider and think that it is the problem. However, I do not understand what that resource provider has to provide to make namespace import work?

Has anyone used the embedded editor with references using namespace imports before and what am I getting wrong here?

I've seen a lot of resource providers, but that did not help, e.g.:
http://www.eclipse.org/forums/index.php/m/987864/
http://www.eclipse.org/forums/index.php/mv/msg/366574/
http://www.eclipse.org/forums/index.php/t/153702/
http://stackoverflow.com/questions/6460535/has-anybody-fully-implemented-an-xtext-editor-in-an-iviewpart
http://stackoverflow.com/questions/15324481/xtext-dsl-embedded-editor-in-a-dialog

I appreciate any hints...

thanks,
dennis
Re: Namespace Imports in Embedded Editor [message #1067902 is a reply to message #1067901] Thu, 11 July 2013 08:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the resourseset should know about the project

(here is mine)

public class ModelQueryLanguageEditedResourceProvider implements IEditedResourceProvider {

@Inject
IResourceSetProvider rsp;

private IProject project;

public IProject getProject() {
return project;
}

public void setProject(IProject project) {
this.project = project;
}

public XtextResource createResource() {
return (XtextResource) rsp.get(project).createResource(URI.createURI("test.mql"));
}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Namespace Imports in Embedded Editor [message #1067904 is a reply to message #1067902] Thu, 11 July 2013 08:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S: in your case you might have to use platform:/resource/yourproject/xxx.mydsl" as uri

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Namespace Imports in Embedded Editor [message #1067935 is a reply to message #1067901] Thu, 11 July 2013 10:48 Go to previous message
Dennis Stampfer is currently offline Dennis StampferFriend
Messages: 23
Registered: April 2013
Junior Member
Hi Christian,

thank you very much for your comments. I tried your provider without success. But your PS did the trick: As fictional resource, I added the path to my project: platform:/resource/myproject/xxx.param

It now works both with my initial and your resource provider. - It just was too obvious...

Danke!
Dennis
Previous Topic:Rewrite Action Problem
Next Topic:Content Assist for JvmTypeReference stops working when redefining its syntax
Goto Forum:
  


Current Time: Fri Apr 26 11:11:54 GMT 2024

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

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

Back to the top