Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Element Binding to TreeViewer
EMF Element Binding to TreeViewer [message #1806175] Sun, 05 May 2019 00:14 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member
Hello,

I am using the below code snippet to show the model contents in a treeviewer. This works fine as I give the whole eResource as the input! However, I need to show only some part of the model, so I don't wanna start from the root of the model! I tried to give the element as the input but it doesn't work when I input an element in treeviewer's setinput (). Any idea would be appreciated.

Thanks,
Parsa

		composedAdapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
		composedAdapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
		composedAdapterFactory.addAdapterFactory(new FormlItemProviderAdapterFactory());
		composedAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

		Tree tree = new Tree(this, SWT.SINGLE);
		TreeViewer tv = new TreeViewer(tree);
		tv.setContentProvider(new AdapterFactoryContentProvider(composedAdapterFactory));
		tv.setLabelProvider(new AdapterFactoryLabelProvider(composedAdapterFactory));

           //HOW TO GIVE AN ELEMENT AND NOT THE RESOURCE HERE ?
		tv.setInput(FPC_SingletonData.getCurrentRoleable().eResource());

[Updated on: Sun, 05 May 2019 00:15]

Report message to a moderator

Re: EMF Element Binding to TreeViewer [message #1806177 is a reply to message #1806175] Sun, 05 May 2019 03:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30457
Registered: July 2009
Senior Member
I'm not sure what you mean by "it doesn't work" but likely the issue is that the input object x itself is not displayed in the tree but only result of the content provider's getElements(x). So if x is a resource, as in your case, resource.getContents() are shown in the tree. A handy trick is to use viewer.setInput(new ItemProvider(Collections.singleton(x))), so that x itself is displayed in the viewer.
Re: EMF Element Binding to TreeViewer [message #1806195 is a reply to message #1806177] Mon, 06 May 2019 00:16 Go to previous message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 210
Registered: February 2014
Senior Member
Great help. Thanks Ed.
Previous Topic:Eclipse crashes when editing Ecore models
Next Topic:How to find if two model elements have the same children?
Goto Forum:
  


Current Time: Sat Sep 21 06:49:19 GMT 2019

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

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

Back to the top