Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » TreeItem problem in JavaxFX with EMF Edit (Different behavior when creating an TreeItem object insteand of creating one as parameter.)
icon5.gif  TreeItem problem in JavaxFX with EMF Edit [message #1729143] Mon, 11 April 2016 13:55 Go to next message
Fabian Kopatschek is currently offline Fabian KopatschekFriend
Messages: 4
Registered: April 2016
Junior Member
Hallo together,

i set up an project, in which in want to use an EMF Model for an JavaFX Application.

Sadly i got stuck at different points in that project.

The first one is very confusing me and i hope you can help.

Following Code is working:

...
        ComposedAdapterFactory adapterFactory;
    	adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    	adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    	adapterFactory.addAdapterFactory(new FinanceAppItemProviderAdapterFactory());
	adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
        
    	EditingDomain editingDomain;
    	BasicCommandStack commandStack = new BasicCommandStack();
    	editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);
    	TreeView<Object> treeView = new TreeView<>();
    	treeView.setRoot(new AdapterFactoryTreeItem(modelData.get(0), adapterFactory));
    	treeView.getRoot().setExpanded(true);
    	AdapterFactoryTreeCellFactory cellFact;
    	cellFact = new AdapterFactoryTreeCellFactory(adapterFactory);   	
    	
    	treeView.setCellFactory(cellFact);
...


And this try gives me an exception:

...
        ComposedAdapterFactory adapterFactory;
    	adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    	adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    	adapterFactory.addAdapterFactory(new FinanceAppItemProviderAdapterFactory());
	adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
        
	EditingDomain editingDomain;
    	BasicCommandStack commandStack = new BasicCommandStack();
    	editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack);
    	TreeView<Object> treeView = new TreeView<>();
    	TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0), adapterFactory);
    	System.out.println(rootItem.getValue().getClass());
    	treeView.setRoot(new AdapterFactoryTreeItem(rootItem, adapterFactory));
    	treeView.getRoot().setExpanded(true);
    	AdapterFactoryTreeCellFactory cellFact;
    	cellFact = new AdapterFactoryTreeCellFactory(adapterFactory);   	
    	
    	treeView.setCellFactory(cellFact);
...


The difference in one box:

treeView.setRoot(new AdapterFactoryTreeItem(modelData.get(0), adapterFactory)); // is working

-------------------------------------------------------------------------------------------------------------------------------

TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0), adapterFactory);
treeView.setRoot(new AdapterFactoryTreeItem(rootItem, adapterFactory));  // throws an exception


The exception is:
java.lang.IllegalArgumentException: Provided root object cannot be adapted.




If you need more information please let me know.

Thanks and regards
Fabian
Re: TreeItem problem in JavaxFX with EMF Edit [message #1729172 is a reply to message #1729143] Mon, 11 April 2016 18:44 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6313
Registered: July 2009
Senior Member
Not sure what you expect in the case not working you have wrapped your
root object into a TreeItem and pass that on but AdapterFactoryTreeItem
expects EObjects hence it fails.

Tom

On 11.04.16 16:51, Fabian Kopatschek wrote:
> Hallo together,
>
> i set up an project, in which in want to use an EMF Model for an JavaFX
> Application.
>
> Sadly i got stuck at different points in that project.
>
> The first one is very confusing me and i hope you can help.
>
> Following Code is working:
>
>
> ..
> ComposedAdapterFactory adapterFactory;
> adapterFactory = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>
> adapterFactory.addAdapterFactory(new
> ResourceItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> FinanceAppItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
> EditingDomain editingDomain;
> BasicCommandStack commandStack = new BasicCommandStack();
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack);
> TreeView<Object> treeView = new TreeView<>();
> treeView.setRoot(new AdapterFactoryTreeItem(modelData.get(0),
> adapterFactory));
> treeView.getRoot().setExpanded(true);
> AdapterFactoryTreeCellFactory cellFact;
> cellFact = new AdapterFactoryTreeCellFactory(adapterFactory);
>
> treeView.setCellFactory(cellFact);
> ..
>
>
> And this try gives me an exception:
>
>
> ..
> ComposedAdapterFactory adapterFactory;
> adapterFactory = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>
> adapterFactory.addAdapterFactory(new
> ResourceItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> FinanceAppItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
> EditingDomain editingDomain;
> BasicCommandStack commandStack = new BasicCommandStack();
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack);
> TreeView<Object> treeView = new TreeView<>();
> TreeItem<Object> rootItem = new
> AdapterFactoryTreeItem(modelData.get(0), adapterFactory);
> System.out.println(rootItem.getValue().getClass());
> treeView.setRoot(new AdapterFactoryTreeItem(rootItem,
> adapterFactory));
> treeView.getRoot().setExpanded(true);
> AdapterFactoryTreeCellFactory cellFact;
> cellFact = new AdapterFactoryTreeCellFactory(adapterFactory);
>
> treeView.setCellFactory(cellFact);
> ..
>
>
> The difference in one box:
>
>
> treeView.setRoot(new AdapterFactoryTreeItem(modelData.get(0),
> adapterFactory)); // is working
>
> -------------------------------------------------------------------------------------------------------------------------------
>
>
> TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0),
> adapterFactory);
> treeView.setRoot(new AdapterFactoryTreeItem(rootItem, adapterFactory));
> // throws an exception
>
>
> The exception is:
>
> java.lang.IllegalArgumentException: Provided root object cannot be adapted.
>
>
>
>
> If you need more information please let me know.
>
> Thanks and regards
> Fabian
Re: TreeItem problem in JavaxFX with EMF Edit [message #1729174 is a reply to message #1729172] Mon, 11 April 2016 19:03 Go to previous messageGo to next message
Fabian Kopatschek is currently offline Fabian KopatschekFriend
Messages: 4
Registered: April 2016
Junior Member
Just found the mistake.

instead of:
TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0), adapterFactory);
treeView.setRoot(new AdapterFactoryTreeItem(rootItem, adapterFactory));


it should be:
TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0), adapterFactory);
treeView.setRoot(rootItem);


Now is my problem, that only the rootItem is displayed. How can i get a tree with it's children?

The class of the rootItem has a list of objects from another class. Both classes has the abstract class ModelItem as SuperType.

Regards Fabian
Re: TreeItem problem in JavaxFX with EMF Edit [message #1729176 is a reply to message #1729174] Mon, 11 April 2016 19:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6313
Registered: July 2009
Senior Member
So has your "modelData.get(0)" containment children? Your setup looks
like the one I see in
http://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/demos/org.eclipse.fx.demo.contacts.app/src/org/eclipse/fx/demo/contacts
so it should work.

Tom

On 11.04.16 21:03, Fabian Kopatschek wrote:
> Just found the mistake.
>
> instead of:
>
> TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0),
> adapterFactory);
> treeView.setRoot(new AdapterFactoryTreeItem(rootItem, adapterFactory));
>
>
> it should be:
>
> TreeItem<Object> rootItem = new AdapterFactoryTreeItem(modelData.get(0),
> adapterFactory);
> treeView.setRoot(rootItem);
>
>
> Now is my problem, that only the rootItem is displayed. How can i get a
> tree with it's children?
>
> The class of the rootItem has a list of objects from another class. Both
> classes has the abstract class ModelItem as SuperType.
>
> Regards Fabian
Re: TreeItem problem in JavaxFX with EMF Edit [message #1729178 is a reply to message #1729176] Mon, 11 April 2016 19:44 Go to previous messageGo to next message
Fabian Kopatschek is currently offline Fabian KopatschekFriend
Messages: 4
Registered: April 2016
Junior Member
Thanks Tom,

the containment was the key. I missed that part.

I have one other question. The tree only appears in the scene if i add it via code to the layout.
If i try to map it with the SceneBuilder via fx:id in the menu "Code". The tree does not appear.

Fabian
Re: TreeItem problem in JavaxFX with EMF Edit [message #1729179 is a reply to message #1729178] Mon, 11 April 2016 19:49 Go to previous message
Fabian Kopatschek is currently offline Fabian KopatschekFriend
Messages: 4
Registered: April 2016
Junior Member
Okay,

i found my mistake. I did create a new TreeView object instead of using the connected object.

Now i can go on with my learning.
Thanks for the help.

Fabian
Previous Topic:Error rendering menu
Next Topic:Bundle org.eclipse.fx.osgi not found :-(
Goto Forum:
  


Current Time: Thu May 25 16:24:39 GMT 2017

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

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