Namespace Imports in Embedded Editor [message #1067901] |
Thu, 11 July 2013 07:57 |
Dennis Stampfer 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", "");
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 |
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05219 seconds