Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » How to use AdapterFactoryObservableList ?(Problem with the provided root)
How to use AdapterFactoryObservableList ? [message #1462366] Wed, 05 November 2014 13:55 Go to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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
Re: How to use AdapterFactoryObservableList ? [message #1463347 is a reply to message #1463316] Thu, 06 November 2014 13:27 Go to previous message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
You're right, that is the problem ! I added a real root element, regenerated everything, and now it works.

Thanks a lot,

Thomas
Previous Topic:e(fx)clipse 1.1.0 is released
Next Topic:javafx.embed.swt not found?
Goto Forum:
  


Current Time: Fri Apr 26 14:05:16 GMT 2024

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

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

Back to the top