Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » EObject in non Xtext resource(How to get EObjects (model instances) in some project in non Xtext editor (eg. Java or JSP))
EObject in non Xtext resource [message #535417] Sun, 23 May 2010 10:52 Go to next message
Filip Kis is currently offline Filip KisFriend
Messages: 31
Registered: April 2010
Member
Hi,

I'm having the following situation. I want to write content assist proposals in the Java and JSP editors that would list all model instances that user's project contains.

I've extended the mentioned editors and all that, but I don't know how to get the model instances. I mean I'm doing this in another plug-in project (that will depend on my xtext plugin) and I tried figuring out the globalScope stuff, but that always assumes I have a Resource and Context which I don't (at least not in Xtext sense).

Anyway, hope I was clear and that you can give me guidance.

Thanks

Filip
Re: EObject in non Xtext resource [message #535501 is a reply to message #535417] Mon, 24 May 2010 04:48 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
org.eclipse.xtext.ui.shared.Access provides access to the shared
singleton instances (Which the builder state as well as the shadowing
dirt state is part of).

Access.getIResourceDescriptions() gives you access to the global
information about all available resources in the workspace (already with
the dirty editor state shadowing the persistent state).

If you want to show only what's visible due to some dependency
configuration we provide three different alternatives:

Provider<IAllContainersState> getWorkspaceProjectsState()

-> uses project dependencies

Provider<IAllContainersState> getStrictJavaProjectsState()

-> uses classpath entries

Provider<IAllContainersState> getJavaProjectsState()

-> uses both and is used by default

We usually never access these singletons directly, but obtain the
instances with Guice. That means we do not consider these access class
to be stable API. ;-)

Sven

Filip Kis schrieb:
> Hi,
>
> I'm having the following situation. I want to write content assist
> proposals in the Java and JSP editors that would list all model
> instances that user's project contains.
>
> I've extended the mentioned editors and all that, but I don't know how
> to get the model instances. I mean I'm doing this in another plug-in
> project (that will depend on my xtext plugin) and I tried figuring out
> the globalScope stuff, but that always assumes I have a Resource and
> Context which I don't (at least not in Xtext sense).
>
> Anyway, hope I was clear and that you can give me guidance.
>
> Thanks
>
> Filip


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: EObject in non Xtext resource [message #536886 is a reply to message #535501] Mon, 31 May 2010 11:43 Go to previous messageGo to next message
Filip Kis is currently offline Filip KisFriend
Messages: 31
Registered: April 2010
Member
Thank you for your response.

It looked like it's all I need, but I'm having some more problems.

1) First and more important problem is that when I use
Access.getIResourceDescriptions().get().getAllResourceDescriptions()

and then
resoruceDescription.getExportedObjects(EClass);
exportedObject.getEObjectOrProxy();

the returned EObject doesn't have all the components that it should have. I think I read somewhere that getEObjectOrProxy shouldn't really be used for this purpose. So my question is how can I get the full EObject. I mean I want to check some features and links that the EObject has and that's just not available in the IEObjectDescription.

If the answer is that I should put everything there, then my question is how? I mean if the EObject already exists, why should I do the double work?


2) And the second question is: I tried to use Guice and did:
@Inject
private IResourceDescriptions resourceDescriptions;

but that's always null. I'm in the UIPlugin generated by Xtext, so the injector should be set correctly in the Activator (at least injecting stuff in other classes like lable provider works). How do I do this properly?

Thank you very much

Filip
Re: EObject in non Xtext resource [message #536901 is a reply to message #536886] Mon, 31 May 2010 12:50 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Filip Kis schrieb:
> Thank you for your response.
> It looked like it's all I need, but I'm having some more problems.
>
> 1) First and more important problem is that when I use
> Access.getIResourceDescriptions().get().getAllResourceDescri ptions()
>
> and then
>
> resoruceDescription.getExportedObjects(EClass);
> exportedObject.getEObjectOrProxy();
>
> the returned EObject doesn't have all the components that it should
> have.

It is an EMF proxy. An EMF proxy is a normal EObject, but without any
state (it might have state but it doesn'T need to). The important thing
is that InternalEObject.getProxyURI() is set.

If you want the real object you need to resolve the proxy. To do you
shoudl create a ResourceSet and use
org.eclipse.emf.ecore.util.EcoreUtil.resolve(EObject, ResourceSet)

> 2) And the second question is: I tried to use Guice and did:
>
> @Inject
> private IResourceDescriptions resourceDescriptions;
>
> but that's always null. I'm in the UIPlugin generated by Xtext, so the
> injector should be set correctly in the Activator (at least injecting
> stuff in other classes like lable provider works). How do I do this
> properly?

How is the class containing the @Inject field instantiated?
It needs to be created by guice as well. If it is instantiated by the
means of an extension point you need to use the
IExecutableExtensionFactory (see the generated plugin.xml).

Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: EObject in non Xtext resource [message #537310 is a reply to message #536901] Tue, 01 June 2010 22:06 Go to previous messageGo to next message
Filip Kis is currently offline Filip KisFriend
Messages: 31
Registered: April 2010
Member

So I've managed to do as you instructed.

First of all I added the ExecutableExtensionFactory to my class in the plugin extension and the Injected calsses became available.

Then I got the IResourceDescritpions and resolved the objects I needed more information about.

However I would still need to resolve the following two issues:

1) The injected IResourceDescritiptions gives me all the resources in the workspace, but I want only the ones that are in the current project. Since I'm in a non Xtext resource (working on content assist extension for JSP editor) is there something I can configure for it to automatically know which are the resources of my project or should I filter them by the URI?

2) When I change the object the I get IReourceDescriptions that is updated (reflecting the change), but when I resolve the object against ResourcSet (which I also Injected) the state is not update. How can I resolve against some "dirty" resource set?

Thank you once again for all the replies.

You guys are great and I'm definitely mentioning you in my thesis Smile

Filip
Re: EObject in non Xtext resource [message #537345 is a reply to message #537310] Wed, 02 June 2010 06:30 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Filip Kis schrieb:
>
> So I've managed to do as you instructed.
>
> First of all I added the ExecutableExtensionFactory to my class in the
> plugin extension and the Injected calsses became available.
> Then I got the IResourceDescritpions and resolved the objects I needed
> more information about.
> However I would still need to resolve the following two issues:
>
> 1) The injected IResourceDescritiptions gives me all the resources in
> the workspace, but I want only the ones that are in the current project.
> Since I'm in a non Xtext resource (working on content assist extension
> for JSP editor) is there something I can configure for it to
> automatically know which are the resources of my project or should I
> filter them by the URI?

I already explained how to do this in an earlier post in this thread:

If you want to show only what's visible due to some dependency
configuration (i.e. project and classpath dependencies) we provide three
different alternatives:

Provider<IAllContainersState> getWorkspaceProjectsState()

-> uses project dependencies

Provider<IAllContainersState> getStrictJavaProjectsState()

-> uses classpath entries

Provider<IAllContainersState> getJavaProjectsState()

-> uses both and is used by default


>
> 2) When I change the object the I get IReourceDescriptions that is
> updated (reflecting the change), but when I resolve the object against
> ResourcSet (which I also Injected) the state is not update. How can I
> resolve against some "dirty" resource set?

The three components listed above use the dirty state manager under the
hood, which shadows any saved state by the dirty state in open dirty
Xtext editors. Not sure if you meant that or whether you have your own
resourceset which you modify. The latter is not so easy to accomplish.
I'ld recommend to throw things away once you used them.


> Thank you once again for all the replies.
>
> You guys are great and I'm definitely mentioning you in my thesis :)

You are welcome :-)

Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: EObject in non Xtext resource [message #537372 is a reply to message #537345] Wed, 02 June 2010 08:46 Go to previous messageGo to next message
Filip Kis is currently offline Filip KisFriend
Messages: 31
Registered: April 2010
Member
Sven Efftinge wrote on Wed, 02 June 2010 08:30

I already explained how to do this in an earlier post in this thread:

If you want to show only what's visible due to some dependency
configuration (i.e. project and classpath dependencies) we provide three
different alternatives:

Provider<IAllContainersState> getWorkspaceProjectsState()

-> uses project dependencies

Provider<IAllContainersState> getStrictJavaProjectsState()

-> uses classpath entries

Provider<IAllContainersState> getJavaProjectsState()

-> uses both and is used by default



I know you already mentioned them in the first post. But the problem is that I don't know what to do with them. I tried changing the one that is used in the Module to the strictJava one and I still get all the resources. Other then this I don't know how to go from IAllContainerStates to IResourceDescriptions. I am probably missing some basic understanding of how these things work.

Sven Efftinge wrote on Wed, 02 June 2010 08:30

The three components listed above use the dirty state manager under the
hood, which shadows any saved state by the dirty state in open dirty
Xtext editors. Not sure if you meant that or whether you have your own
resourceset which you modify. The latter is not so easy to accomplish.
I'ld recommend to throw things away once you used them.



I don't have my own resource set. So in the Xtext editor I used what is default. But when I'm in my JSP Editor, from what user enters there I get an name of the EObject, then I find it in the ResourceDescription and then I resolve it against the resourceSet injected by guice. So it's here that the state is not updated. So somehow the injected resourceSet stays at some older state.

Filip
Re: EObject in non Xtext resource [message #537627 is a reply to message #537372] Thu, 03 June 2010 06:44 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Filip Kis schrieb:
> Sven Efftinge wrote on Wed, 02 June 2010 08:30
>> I already explained how to do this in an earlier post in this thread:
>>
>> If you want to show only what's visible due to some dependency
>> configuration (i.e. project and classpath dependencies) we provide
>> three different alternatives:
>>
>> Provider<IAllContainersState> getWorkspaceProjectsState()
>>
>> -> uses project dependencies
>>
>> Provider<IAllContainersState> getStrictJavaProjectsState()
>>
>> -> uses classpath entries
>>
>> Provider<IAllContainersState> getJavaProjectsState()
>>
>> -> uses both and is used by default
>
>
> I know you already mentioned them in the first post. But the problem is
> that I don't know what to do with them. I tried changing the one that is
> used in the Module to the strictJava one and I still get all the
> resources. Other then this I don't know how to go from
> IAllContainerStates to IResourceDescriptions. I am probably missing some
> basic understanding of how these things work.

I see that this is not obvious. Sorry for being terse.

If you have the following two methods (which i copied from
StateBasedContainerManager)...

protected List<IContainer> getVisibleContainers(List<String> handles,
IResourceDescriptions resourceDescriptions) {
if (handles.isEmpty())
return Collections.emptyList();
List<IContainer> result =
Lists.newArrayListWithExpectedSize(handles.size());
for(String handle: handles) {
result.add(createContainer(handle, resourceDescriptions));
}
return result;
}

protected IContainer createContainer(final String handle,
IResourceDescriptions resourceDescriptions) {
IContainerState containerState =
new ContainerState(handle, getState(resourceDescriptions));
StateBasedContainer result =
new StateBasedContainer(resourceDescriptions, containerState);
return result;
}

.... you can call them, like this:

@Inject
private IAllContainersState.Provider stateProvider;

..... {
List<String> handles = stateProvider.get(resourceDescriptions)
.getVisibleContainerHandles(nameOfContainerYourJspFileIsCont ained);
List<IContainer> visibleContainers =
getVisibleContainers(handles, resourceDescriptions);

The IContainers are provided in the right order (i.e. like the
classparth entries), and each represents one entry and only provides the
ResourceDescriptions contained there in.

Note that all this is not considered API, so you might have minor
migration effort even in service releases.

In case I missed something look into StateBasedContainerManager, which
can't use directly becaus it expects you have a resourcedescription for
the file your are in, which you obviously don't have.

>
> Sven Efftinge wrote on Wed, 02 June 2010 08:30
>> The three components listed above use the dirty state manager under
>> the hood, which shadows any saved state by the dirty state in open
>> dirty Xtext editors. Not sure if you meant that or whether you have
>> your own resourceset which you modify. The latter is not so easy to
>> accomplish.
>> I'ld recommend to throw things away once you used them.
>
>
> I don't have my own resource set. So in the Xtext editor I used what is
> default. But when I'm in my JSP Editor, from what user enters there I
> get an name of the EObject, then I find it in the ResourceDescription
> and then I resolve it against the resourceSet injected by guice. So it's
> here that the state is not updated. So somehow the injected resourceSet
> stays at some older state.

You should use a Provider<ResourceSet> and throw the ResourceSet away
once you used it.

Sven


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:Imported resource could not be found
Next Topic:Opening file fails with NullPointerException
Goto Forum:
  


Current Time: Thu Apr 18 16:27:01 GMT 2024

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

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

Back to the top