Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » An EMF databinding problem(How to bind a multi-root tree structure)
An EMF databinding problem [message #631737] Fri, 08 October 2010 15:00 Go to next message
Patrick is currently offline PatrickFriend
Messages: 17
Registered: August 2010
Location: Rome
Junior Member
Hi All,

I would like to have some expert hints on how to solve a problem I'm facing with EMF databinding.

I have a datamodel with the following structure:

http://dl.dropbox.com/u/4830862/samplemodel.png

A 'Container' instance is what I set as input to the TreeViewer

I would like to have the following items showed in the tree:

Hierarchy1
|__Node1.1
| |__Node1.1.1
|__Node1.2
Hierarchy2
|__Node2.1
| |__Node2.1.1
| |__Node2.1.2
|__Node2.2
|__Node2.3


But all what I was able to obtain is a tree representation of the nodes, without the root Hierarchy# nodes:


Node1.1
|__Node1.1.1
|__Node1.2
Node2.1
|__Node2.1.1
|__Node2.1.2
Node2.2
Node2.3


This is the snippet of code I used to obtain this representation:

	ObservableListTreeContentProvider cp = new ObservableListTreeContentProvider(
		new TreeFactoryImpl(), new TreeStructureAdvisorImpl());
	viewer.setContentProvider(cp);

	IObservableSet set = cp.getKnownElements();

	IObservableMap[] map = new IObservableMap[3];
	map[0] = EMFProperties.value(
		ModelPackage.Literals.HIERARCHY__NAME).observeDetail(set);		
	map[1] = EMFProperties.value(
		ModelPackage.Literals.HIERARCHY__CHILD).observeDetail(set);		
	map[2] = EMFProperties.value(FeaturePath.fromList(
		ModelPackage.Literals.HIERARCHY__CHILD, ModelPackage.Literals.HIERARCHY_NODE__NAME)).observeDetail(set);
		
	viewer.setLabelProvider(new TreeLabelProviderImpl(map));

	IEMFListProperty container = EMFProperties.multiList(
		FeaturePath.fromList(
				GroupsPackage.Literals.CONTAINER__FIRST_HIERARCHY, GroupsPackage.Literals.HIERARCHY__CHILD),
		FeaturePath.fromList(
				GroupsPackage.Literals.CONTAINER__SECOND_HIERARCHY, GroupsPackage.Literals.HIERARCHY__CHILD)
	);
	viewer.setInput(metadata.observe(gmd));



where the TreeFactoryImpl and TreeStructureAdvisorImpl are defined as follow:

private static class TreeFactoryImpl implements IObservableFactory {

	private IEMFListProperty multi = EMFProperties.list(
		GroupsPackage.Literals.HIERARCHY__CHILD
	);
	    
	public IObservable createObservable(final Object target) {
		if (target instanceof IObservableList) {
			return (IObservable) target;
		} else if (target instanceof Node) {
			return multi.observe(target);
		}
		return null;
	}

}

private static class TreeStructureAdvisorImpl extends TreeStructureAdvisor {
		
	@Override
	public Object getParent(Object element) {
		if (element instanceof Node) {
			return ((Node) element).getParent();
		}
		return null;
	}

	@Override
	public Boolean hasChildren(Object element) {
		if (element instanceof Node && ((Node)element).getChild().size() > 0) {
			return Boolean.TRUE;
		}
		return super.hasChildren(element);
	}
}


Thanks a lot for any suggestion

Best Regards,
Patrick


Re: An EMF databinding problem [message #631740 is a reply to message #631737] Fri, 08 October 2010 15:11 Go to previous messageGo to next message
Patrick is currently offline PatrickFriend
Messages: 17
Registered: August 2010
Location: Rome
Junior Member
Patrick wrote on Fri, 08 October 2010 11:00

Sorry, I made a mistake when quoting the code, here are the two corrections:
map[2] = EMFProperties.value(FeaturePath.fromList(
ModelPackage.Literals.HIERARCHY__CHILD, ModelPackage.Literals.NODE__NAME)).observeDetail(set);

		
viewer.setInput(metadata.observe(container));

Regards,
Patrick


Re: An EMF databinding problem [message #631742 is a reply to message #631737] Fri, 08 October 2010 15:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6505
Registered: July 2009
Senior Member
Can you give us your .ecore? I'm not yet how this looks like.

Tom

Am 08.10.10 17:00, schrieb Patrick:
> Hi All,
> I would like to have some expert hints on how to solve a problem I'm
> facing with EMF databinding.
>
> I have a datamodel with the following structure:
>
>
>
> A 'Container' instance is what I set as input to the TreeViewer
>
> I would like to have the following items showed in the tree:
>
> Hierarchy1
> |__Node1.1
> | |__Node1.1.1
> |__Node1.2
> Hierarchy2
> |__Node2.1
> | |__Node2.1.1
> | |__Node2.1.2
> |__Node2.2
> |__Node2.3
>
>
> But all what I was able to obtain is a tree representation of the nodes,
> without the root Hierarchy# nodes:
>
>
> Node1.1
> |__Node1.1.1
> |__Node1.2
> Node2.1
> |__Node2.1.1
> |__Node2.1.2
> Node2.2
> Node2.3
>
>
> This is the snippet of code I used to obtain this representation:
>
>
> ObservableListTreeContentProvider cp = new
> ObservableListTreeContentProvider(
> new TreeFactoryImpl(), new TreeStructureAdvisorImpl());
> viewer.setContentProvider(cp);
>
> IObservableSet set = cp.getKnownElements();
>
> IObservableMap[] map = new IObservableMap[3];
> map[0] = EMFProperties.value(
> ModelPackage.Literals.HIERARCHY__NAME).observeDetail(set);
> map[1] = EMFProperties.value(
> ModelPackage.Literals.HIERARCHY__CHILD).observeDetail(set);
> map[2] = EMFProperties.value(FeaturePath.fromList(
> ModelPackage.Literals.HIERARCHY__CHILD,
> ModelPackage.Literals.HIERARCHY_NODE__NAME)).observeDetail(s et);
>
> viewer.setLabelProvider(new TreeLabelProviderImpl(map));
>
> IEMFListProperty container = EMFProperties.multiList(
> FeaturePath.fromList(
> GroupsPackage.Literals.CONTAINER__FIRST_HIERARCHY,
> GroupsPackage.Literals.HIERARCHY__CHILD),
> FeaturePath.fromList(
> GroupsPackage.Literals.CONTAINER__SECOND_HIERARCHY,
> GroupsPackage.Literals.HIERARCHY__CHILD)
> );
> viewer.setInput(metadata.observe(gmd));
>
>
>
> where the TreeFactoryImpl and TreeStructureAdvisorImpl are defined as
> follow:
>
>
> private static class TreeFactoryImpl implements IObservableFactory {
>
> private IEMFListProperty multi = EMFProperties.list(
> GroupsPackage.Literals.HIERARCHY__CHILD
> );
> public IObservable createObservable(final Object target) {
> if (target instanceof IObservableList) {
> return (IObservable) target;
> } else if (target instanceof Node) {
> return multi.observe(target);
> }
> return null;
> }
>
> }
>
> private static class TreeStructureAdvisorImpl extends
> TreeStructureAdvisor {
>
> @Override
> public Object getParent(Object element) {
> if (element instanceof Node) {
> return ((Node) element).getParent();
> }
> return null;
> }
>
> @Override
> public Boolean hasChildren(Object element) {
> if (element instanceof Node && ((Node)element).getChild().size()
>> 0) {
> return Boolean.TRUE;
> }
> return super.hasChildren(element);
> }
> }
>
>
> Thanks a lot for any suggestion
>
> Best Regards,
> Patrick
>
>
>
Re: An EMF databinding problem [message #631769 is a reply to message #631742] Fri, 08 October 2010 16:52 Go to previous message
Patrick is currently offline PatrickFriend
Messages: 17
Registered: August 2010
Location: Rome
Junior Member
Hi,

I've posted here the ecore model, in the case you have time to experiment with it

http://dl.dropbox.com/u/4830862/model.ecore

Thanks a lot,

Patrick

Previous Topic:Complex Model Relationships
Next Topic:ChangeRecorder: Ignore Notifications of Transient EStructuralFeatures
Goto Forum:
  


Current Time: Sun Oct 20 00:24:12 GMT 2019

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

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

Back to the top