Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Virtual Nodes in TreeViewer based on EMF
Virtual Nodes in TreeViewer based on EMF [message #1015262] Wed, 27 February 2013 17:38 Go to next message
Julien S is currently offline Julien S
Messages: 2
Registered: February 2013
Junior Member
Hi,

I made a TreeViewer based on EMF model. It's a simple model i have an EClass project and an EClass dependencies with aggregation between the both.

I'm able to display a tree like this :

|--> Project 1
     |
     |--> dependency1
     |--> dependency2


it works fine. But what i want to do is to have a virtual node between project and dependency like this :

|--> Project 1
   |--> Project Dependencies (virtual node)
     |--> dependency1
     |--> dependency2


But i dont know how to add "project dependencies" node WITHOUT modify my EMF model.

My tree is based on ObservableListTreeContentProvider

ObservableListTreeContentProvider lCp = new ObservableListTreeContentProvider(
				new ProjectTreeFactory(), new ProjectTreeStructureAdvisor());


And a factory like this :
public class ProjectTreeFactory implements IObservableFactory {
	private final IEMFListProperty inputsProp = EMFProperties
			.list(ModelPackage.Literals.PROJECT_DEPEN);

	@Override
	public IObservable createObservable(Object target) {
		if (target instanceof IObservable) {
			return (IObservable) target;
		} else if (target instanceof Project) {
			return inputsProp.observe(target);
		}
		return null;
	}
}


I have to add something in my factory ? With a content provider we have just to add a Children to the method getChildren but i dont know how it works with IObservableFactory.

Thanks for any help.



Re: Virtual Nodes in TreeViewer based on EMF [message #1015332 is a reply to message #1015262] Thu, 28 February 2013 04:29 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 895
Registered: July 2009
Senior Member
On 28-02-13 03:09, Julien S wrote:
> Hi,
>
> I made a TreeViewer based on EMF model. It's a simple model i have an
> EClass project and an EClass dependencies with aggregation between the
> both.
>
> I'm able to display a tree like this :
>
> |--> Project 1
> |
> |--> dependency1
> |--> dependency2
>
> it works fine. But what i want to do is to have a virtual node between
> project and dependency like this :
>
> |--> Project 1
> |--> Project Dependencies (virtual node)
> |--> dependency1
> |--> dependency2
>
> But i dont know how to add "project dependencies" node WITHOUT modify my
> EMF model.
>


I think it starts with the TreeStructureAdvisor. This tells which nodes
has children, then IObservableFactory should return an observable for
the parent of the virtual node, which can produce the children. This is
the tricky part, as the Virtual node is not in the model Hierarchy, so
you would need to fake it somehow, perhaps a ComputedList/Set would do
the trick? It could return a collection of children representing the
virtual node.(Which I assume is a POJO?). For the POJO virtual node, you
could do the same, but it would then hook in to your Model hierarchy
(The real children of the parent).

It's a bit of out-loud thinking, not trialed and proved, but could
perhaps help you a bit?

Cheers Christophe



> My tree is based on ObservableListTreeContentProvider
>
> ObservableListTreeContentProvider lCp = new
> ObservableListTreeContentProvider(
> new ProjectTreeFactory(), new
> ProjectTreeStructureAdvisor());
>
> And a factory like this :
>
> public class ProjectTreeFactory implements IObservableFactory {
> private final IEMFListProperty inputsProp = EMFProperties
> .list(ModelPackage.Literals.PROJECT_DEPEN);
>
> @Override
> public IObservable createObservable(Object target) {
> if (target instanceof IObservable) {
> return (IObservable) target;
> } else if (target instanceof Project) {
> return inputsProp.observe(target);
> }
> return null;
> }
> }
>
> I have to add something in my factory ? With a content provider we have
> just to add a Children to the method getChildren but i dont know how it
> works with IObservableFactory.
>
> Thanks for any help.
>
>
>
>
Re: Virtual Nodes in TreeViewer based on EMF [message #1015609 is a reply to message #1015332] Fri, 01 March 2013 06:15 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5251
Registered: July 2009
Senior Member
Take a look at E4-XMI-Editor code it produces virtual nodes. It is part
of the e4.tools repo.

Tom

Am 28.02.13 10:29, schrieb Christophe Bouhier:
> On 28-02-13 03:09, Julien S wrote:
>> Hi,
>>
>> I made a TreeViewer based on EMF model. It's a simple model i have an
>> EClass project and an EClass dependencies with aggregation between the
>> both.
>>
>> I'm able to display a tree like this :
>>
>> |--> Project 1
>> |
>> |--> dependency1
>> |--> dependency2
>>
>> it works fine. But what i want to do is to have a virtual node between
>> project and dependency like this :
>>
>> |--> Project 1
>> |--> Project Dependencies (virtual node)
>> |--> dependency1
>> |--> dependency2
>>
>> But i dont know how to add "project dependencies" node WITHOUT modify my
>> EMF model.
>>
>
>
> I think it starts with the TreeStructureAdvisor. This tells which nodes
> has children, then IObservableFactory should return an observable for
> the parent of the virtual node, which can produce the children. This is
> the tricky part, as the Virtual node is not in the model Hierarchy, so
> you would need to fake it somehow, perhaps a ComputedList/Set would do
> the trick? It could return a collection of children representing the
> virtual node.(Which I assume is a POJO?). For the POJO virtual node, you
> could do the same, but it would then hook in to your Model hierarchy
> (The real children of the parent).
>
> It's a bit of out-loud thinking, not trialed and proved, but could
> perhaps help you a bit?
>
> Cheers Christophe
>
>
>
>> My tree is based on ObservableListTreeContentProvider
>>
>> ObservableListTreeContentProvider lCp = new
>> ObservableListTreeContentProvider(
>> new ProjectTreeFactory(), new
>> ProjectTreeStructureAdvisor());
>>
>> And a factory like this :
>>
>> public class ProjectTreeFactory implements IObservableFactory {
>> private final IEMFListProperty inputsProp = EMFProperties
>> .list(ModelPackage.Literals.PROJECT_DEPEN);
>>
>> @Override
>> public IObservable createObservable(Object target) {
>> if (target instanceof IObservable) {
>> return (IObservable) target;
>> } else if (target instanceof Project) {
>> return inputsProp.observe(target);
>> }
>> return null;
>> }
>> }
>>
>> I have to add something in my factory ? With a content provider we have
>> just to add a Children to the method getChildren but i dont know how it
>> works with IObservableFactory.
>>
>> Thanks for any help.
>>
>>
>>
>>
>
Re: Virtual Nodes in TreeViewer based on EMF [message #1015675 is a reply to message #1015609] Fri, 01 March 2013 11:26 Go to previous message
Julien S is currently offline Julien S
Messages: 2
Registered: February 2013
Junior Member
I implemented a similar concept thanks to the Christophe Idea.

But i think i will redo this with VirtualEntry defined in e4. Thanks for the tips Thomas.
Previous Topic:Very odd issue with multiple schemaLocations
Next Topic:Ecore Diagram Editor - how to have split diagram files
Goto Forum:
  


Current Time: Mon Jul 28 12:43:42 EDT 2014

Powered by FUDForum. Page generated in 0.03388 seconds