How to use AdapterFactoryObservableList ? [message #1462366] |
Wed, 05 November 2014 13:55  |
Eclipse User |
|
|
|
Hello,
I'm trying out the demo about EMF Edit in efxclipse but with my own (extremely simple) ecore model : I only have one class in it, Employer.
So I want to bind this model to an ObservableList, like this :
@PostConstruct
public void init(BorderPane parent, MApplication application)
{
EditingDomain domain = modelservice.getEditingDomain() ;
AdapterFactory factory = modelservice.getAdapterFactory() ;
listView.setItems(new AdapterFactoryObservableList<Object>(factory, modelservice.getRoot()));
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
parent.setCenter(listView);
}
As root element, I thought of just providing the first element of my resource, as follows :
@Override
public Object getRoot()
{
return resource.getContents().get(0) ;
}
When I run this code, I get an IllegalArgumentException : Provided root object cannot be adapted.
But what other root could I provide ? In the demo, the (contact)Group is used for this, but I don't have one in my own model.
The demo would have the same problem anyhow if we would try to have a ListView of contact groups.
I can't come up with some useful alternative, a fortiori because I can't figure out the semantics of a rootelement in a listview? I should just layout independent elements, or am I getting this wrong ?
Thomas
|
|
|
Re: How to use AdapterFactoryObservableList ? [message #1462435 is a reply to message #1462366] |
Wed, 05 November 2014 15:15   |
Eclipse User |
|
|
|
How did you setup your adapter-factory? Have you tried simply pushing
your resource?
Tom
On 05.11.14 14:55, Thomas Elskens wrote:
> Hello,
>
> I'm trying out the demo about EMF Edit in efxclipse but with my own
> (extremely simple) ecore model : I only have one class in it, Employer.
> So I want to bind this model to an ObservableList, like this :
>
>
> @PostConstruct
> public void init(BorderPane parent, MApplication application)
> {
> EditingDomain domain = modelservice.getEditingDomain() ;
> AdapterFactory factory = modelservice.getAdapterFactory() ;
> listView.setItems(new
> AdapterFactoryObservableList<Object>(factory, modelservice.getRoot()));
>
> listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
> parent.setCenter(listView);
> }
>
>
> As root element, I thought of just providing the first element of my
> resource, as follows :
>
> @Override
> public Object getRoot()
> {
> return resource.getContents().get(0) ;
> }
>
>
> When I run this code, I get an IllegalArgumentException : Provided root
> object cannot be adapted.
> But what other root could I provide ? In the demo, the (contact)Group is
> used for this, but I don't have one in my own model.
>
> The demo would have the same problem anyhow if we would try to have a
> ListView of contact groups.
> I can't come up with some useful alternative, a fortiori because I can't
> figure out the semantics of a rootelement in a listview? I should just
> layout independent elements, or am I getting this wrong ?
>
> Thomas
|
|
|
Re: How to use AdapterFactoryObservableList ? [message #1462542 is a reply to message #1462435] |
Wed, 05 November 2014 17:41   |
Eclipse User |
|
|
|
You could also look how the generated SWT-Editor works. I've never
really used EMF-Edit so I'm not of great help in this regard but from my
EMF-Projects I normally always create a Root-Element which holds my
domain model, the reason is simply you can only serialize to XML (I'm
not talking about XMI) if you have exactly 1 root-element.
Tom
On 05.11.14 16:15, Tom Schindl wrote:
> How did you setup your adapter-factory? Have you tried simply pushing
> your resource?
>
> Tom
>
> On 05.11.14 14:55, Thomas Elskens wrote:
>> Hello,
>>
>> I'm trying out the demo about EMF Edit in efxclipse but with my own
>> (extremely simple) ecore model : I only have one class in it, Employer.
>> So I want to bind this model to an ObservableList, like this :
>>
>>
>> @PostConstruct
>> public void init(BorderPane parent, MApplication application)
>> {
>> EditingDomain domain = modelservice.getEditingDomain() ;
>> AdapterFactory factory = modelservice.getAdapterFactory() ;
>> listView.setItems(new
>> AdapterFactoryObservableList<Object>(factory, modelservice.getRoot()));
>>
>> listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
>> parent.setCenter(listView);
>> }
>>
>>
>> As root element, I thought of just providing the first element of my
>> resource, as follows :
>>
>> @Override
>> public Object getRoot()
>> {
>> return resource.getContents().get(0) ;
>> }
>>
>>
>> When I run this code, I get an IllegalArgumentException : Provided root
>> object cannot be adapted.
>> But what other root could I provide ? In the demo, the (contact)Group is
>> used for this, but I don't have one in my own model.
>>
>> The demo would have the same problem anyhow if we would try to have a
>> ListView of contact groups.
>> I can't come up with some useful alternative, a fortiori because I can't
>> figure out the semantics of a rootelement in a listview? I should just
>> layout independent elements, or am I getting this wrong ?
>>
>> Thomas
>
|
|
|
Re: How to use AdapterFactoryObservableList ? [message #1463261 is a reply to message #1462542] |
Thu, 06 November 2014 11:24   |
Eclipse User |
|
|
|
Okay there is some progress: my Adapterfactory indeed was no good. It now looks like this :
private ComposedAdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) ;
private EditingDomain domain = new AdapterFactoryEditingDomain(factory, new BasicCommandStack()) ;
//...
factory.addAdapterFactory(new EmployerItemProviderAdapterFactory());
factory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
factory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
With all the provideradapterfactories having there standard (generated) implementation.
Error no longer shows, but the listview remains empty... And I have two Employers in my resource.
About the root : when I serialize my resource to XMI, the root tag is <xmi:XMI></xmi:XMI>... No useful rootelement can be obtained with that ?
Thomas
|
|
|
Re: How to use AdapterFactoryObservableList ? [message #1463316 is a reply to message #1463261] |
Thu, 06 November 2014 12:41   |
Eclipse User |
|
|
|
XMI allows multiple "root-elements", an XML-File would not allow that.
Maybe you should ask at the EMF-List about EMF-Edit. Did you try your
code with EMF+SWT?
Tom
On 06.11.14 12:24, Thomas Elskens wrote:
> Okay there is some progress: my Adapterfactory indeed was no good. It
> now looks like this :
>
>
> private ComposedAdapterFactory factory = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)
> ;
> private EditingDomain domain = new AdapterFactoryEditingDomain(factory,
> new BasicCommandStack()) ;
> //...
> factory.addAdapterFactory(new EmployerItemProviderAdapterFactory());
> factory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
> factory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
>
> With all the provideradapterfactories having there standard (generated)
> implementation.
> Error no longer shows, but the listview remains empty... And I have two
> Employers in my resource.
> About the root : when I serialize my resource to XMI, the root tag is
> <xmi:XMI></xmi:XMI>... No useful rootelement can be obtained with that ?
>
> Thomas
|
|
|
|
Powered by
FUDForum. Page generated in 0.04268 seconds