Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Retrieve ItemProvider based on the EClass
Retrieve ItemProvider based on the EClass [message #425524] Sun, 30 November 2008 15:55 Go to next message
Yigal Spinner is currently offline Yigal SpinnerFriend
Messages: 127
Registered: July 2009
Senior Member
I would like to use the item provider in a custom property page.
Since the property page is for a specific class I have the EClass
definition from the domain package.
I now you can get the ItemProvider if you have an instance of a class.

How can I get the item provider based on the EClass without creating an
instance first?

Thanks
Yigal
Re: Retrieve ItemProvider based on the EClass [message #425525 is a reply to message #425524] Sun, 30 November 2008 17:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Yigal,

There isn't a way to do that.


Yigal wrote:
> I would like to use the item provider in a custom property page.
> Since the property page is for a specific class I have the EClass
> definition from the domain package.
> I now you can get the ItemProvider if you have an instance of a class.
>
> How can I get the item provider based on the EClass without creating
> an instance first?
>
> Thanks
> Yigal


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Retrieve ItemProvider based on the EClass [message #425575 is a reply to message #425525] Mon, 01 December 2008 21:09 Go to previous messageGo to next message
Yigal Spinner is currently offline Yigal SpinnerFriend
Messages: 127
Registered: July 2009
Senior Member
Hi Ed,
I edited the ItemProviderAdapterFactory class manually and added a
method that looks like that:
public Adapter getAdapterItemProvider (EClass eclass) {
if (eclass.equals(DomainPackage.eINSTANCE.getJob()))
return createJobAdapter();
else if (eclass.equals(DomainPackage.eINSTANCE.getStep())) {
return createStepAdapter();
}
else if (eclass.equals(DomainPackage.eINSTANCE.getItemReader())) {
return createItemReaderAdapter();
}
else return null;
}
This method uses the already generated methods that create the item
provider.

Is there a way for me to modify the EMF generation and generate this
method instead of manual add it each time the model changes?
I remember you talked about this before. Can you point me to the
article the explain how to do that.

Thanks
Yigal

Ed Merks wrote:
> Yigal,
>
> There isn't a way to do that.
>
>
> Yigal wrote:
>> I would like to use the item provider in a custom property page.
>> Since the property page is for a specific class I have the EClass
>> definition from the domain package.
>> I now you can get the ItemProvider if you have an instance of a class.
>>
>> How can I get the item provider based on the EClass without creating
>> an instance first?
>>
>> Thanks
>> Yigal
Re: Retrieve ItemProvider based on the EClass [message #425577 is a reply to message #425575] Mon, 01 December 2008 21:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Yigal,

Perhaps I should take a step back and ask what you do with this item
provider? After all, all the methods you can call require you to pass
in an instance object of a type suitable for that adapter so how is the
adapter useful without an instance?


Yigal wrote:
> Hi Ed,
> I edited the ItemProviderAdapterFactory class manually and added a
> method that looks like that:
> public Adapter getAdapterItemProvider (EClass eclass) {
> if (eclass.equals(DomainPackage.eINSTANCE.getJob()))
Note that eClass == DomainPackage.Literals.JOB is more efficient.
> return createJobAdapter();
> else if (eclass.equals(DomainPackage.eINSTANCE.getStep())) {
> return createStepAdapter();
> }
> else if
> (eclass.equals(DomainPackage.eINSTANCE.getItemReader())) {
> return createItemReaderAdapter();
> }
> else return null;
> }
> This method uses the already generated methods that create the item
> provider.
>
> Is there a way for me to modify the EMF generation and generate this
> method instead of manual add it each time the model changes?
It's possible to use dynamic templates, but I think it would be good for
me to understand what your actually trying to achieve with this type of
code...
> I remember you talked about this before. Can you point me to the
> article the explain how to do that.
>
> Thanks
> Yigal
>
> Ed Merks wrote:
>> Yigal,
>>
>> There isn't a way to do that.
>>
>>
>> Yigal wrote:
>>> I would like to use the item provider in a custom property page.
>>> Since the property page is for a specific class I have the EClass
>>> definition from the domain package.
>>> I now you can get the ItemProvider if you have an instance of a class.
>>>
>>> How can I get the item provider based on the EClass without creating
>>> an instance first?
>>>
>>> Thanks
>>> Yigal


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Retrieve ItemProvider based on the EClass [message #425596 is a reply to message #425575] Tue, 02 December 2008 22:31 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Yigal wrote:
> I edited the ItemProviderAdapterFactory class manually and added a
> method that looks like that:
> public Adapter getAdapterItemProvider (EClass eclass) {
> if (eclass.equals(DomainPackage.eINSTANCE.getJob()))
> return createJobAdapter();
> else if (eclass.equals(DomainPackage.eINSTANCE.getStep())) {
> return createStepAdapter();
> }
> else if (eclass.equals(DomainPackage.eINSTANCE.getItemReader())) {
> return createItemReaderAdapter();
> }
> else return null;
> }

This looks like an anti-pattern. Why don't you just let the
ItemProviderAdapterFactory decide which ItemProvider to use? It does so
on the fly, i.e. at the moment you want to display your object. No
hassle then. And btw, one of the most delightful software patterns I've
seen so far :-)

Did you read

http://help.eclipse.org/ganymede/topic/org.eclipse.emf.doc/r eferences/overview/EMF.Edit.html

Felix
Previous Topic:[CDO] "Auto commit"
Next Topic:Problem using SimpleAnyType
Goto Forum:
  


Current Time: Fri Apr 19 18:32:23 GMT 2024

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

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

Back to the top