|
Re: ComposedAdapterFactory - documentation ? [message #416190 is a reply to message #416189] |
Mon, 21 January 2008 16:42 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Stefan,
Comments below.
Stefan Winkler wrote:
> Hi,
>
> I am trying to understand a bit, what is going on behind the scenes of
> EMF. I managed to initialize an editing domain and a table viewer.
> At first I used:
>
>
> <--------->
>
> adapterFactory = new ComposedAdapterFactory(
> new AdapterFactory[] {
> new ResourceItemProviderAdapterFactory(),
> new MyOwnModelAdapterFactory ()
> });
Don't you have a generated item provider adapter factory in your model
(like what wold appear in the generated editor for your model)?
>
>
> TableViewer t = new TableViewer(parent, SWT.BORDER);
> t.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
> t.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
> t.setInput(resource);
>
> <--------->
>
> Which did not work, because the LabelProvider could not adapt
> MyObjectItemProvider. I got MyObject.toString() as a fallback label.
>
> Then I looked into the generated editor and tried to copy everything
> applicable from there including:
>
> <--------->
> adapterFactory = new ComposedAdapterFactory(
> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>
> adapterFactory.addAdapterFactory(new
> ResourceItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> MyOwnModelAdapterFactory ());
> <--------->
>
> With this change, the labels are displayed correctly. Why?
Using the above, the item providers registered for your plugin in the
plugin.xml for the *.edit project will be found.
>
> What is the difference between the first and the second initialization?
> Why does it only affect the LabelProvider but not the ContentProvider?
You probably never got a far as showing children of the resource's contents.
> What is that Descriptor-Registry?
If you look in the plugin.xml for your generated *.edit project, you'll
see the registration of your item provider there.
>
> Also, is there any documentation on how the proxy-mechanism and the
> Resource unloading mechanism is works?
Not so much. Just the working code in the generated editor... The gist
is that a cross resource reference is represented as a proper object of
the right type but for which EObject.eIsProxy is true and for which
InternalEObject.eProxyURI returns the URI that needs to be passed to
ResourceSet.getEObject to find the object. Such proxies are resolved as
you fetch the data, so you generally won't notice they exist.
Resource.unload will turn all objects back into proxies...
>
> Thanks for enlightening me ;-)
>
> Cheers,
> Stefan
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: ComposedAdapterFactory - documentation ? [message #416242 is a reply to message #416190] |
Wed, 23 January 2008 10:35 |
Stefan Winkler Messages: 307 Registered: July 2009 Location: Germany |
Senior Member |
|
|
Ed,
thanks for you quick responses in this newsgroup!
Comments below.
Ed Merks schrieb:
> Stefan,
>
> Comments below.
>
> Stefan Winkler wrote:
>> Hi,
>>
>> I am trying to understand a bit, what is going on behind the scenes of
>> EMF. I managed to initialize an editing domain and a table viewer.
>> At first I used:
>>
>>
>> <--------->
>>
>> adapterFactory = new ComposedAdapterFactory(
>> new AdapterFactory[] {
>> new ResourceItemProviderAdapterFactory(),
>> new MyOwnModelAdapterFactory ()
>> });
> Don't you have a generated item provider adapter factory in your model
> (like what wold appear in the generated editor for your model)?
Yes, that is what I meant with MyOwnModelAdapterFactory (i.e.
MyOwnModelItemProviderAdapterFactory). This is the generated adapter
factory for MyOwnModel.
>>
>>
>> TableViewer t = new TableViewer(parent, SWT.BORDER);
>> t.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
>> t.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
>> t.setInput(resource);
>>
>> <--------->
>> Which did not work, because the LabelProvider could not adapt
>> MyObjectItemProvider. I got MyObject.toString() as a fallback label.
>>
>> Then I looked into the generated editor and tried to copy everything
>> applicable from there including:
>>
>> <--------->
>> adapterFactory = new ComposedAdapterFactory(
>> ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>> adapterFactory.addAdapterFactory(new
>> ResourceItemProviderAdapterFactory());
>> adapterFactory.addAdapterFactory(new
>> MyOwnModelAdapterFactory ());
>> <--------->
>>
>> With this change, the labels are displayed correctly. Why?
> Using the above, the item providers registered for your plugin in the
> plugin.xml for the *.edit project will be found.
The adapter factory registered there is the same as mentioned above
(MyOwnModelItemProviderAdapterFactory).
Anyway, the second snippet is the one given in The Book (1st ed., sec.
10.3). So I was surprised that it didn't work.
>> What is the difference between the first and the second initialization?
>> Why does it only affect the LabelProvider but not the ContentProvider?
> You probably never got a far as showing children of the resource's
> contents.
That I don't know as I only have a TableViewer.
Anyway, it seems to work now as desired.
Thanks again,
Stefan
|
|
|
Powered by
FUDForum. Page generated in 0.03286 seconds