Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to get the ItemProvider of a element(A way to read out the image and text of an element)
How to get the ItemProvider of a element [message #1807513] Fri, 31 May 2019 15:19 Go to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 48
Registered: December 2015
Hello together,

I have made a small JavaFX application with a TreeView for Editing the Emf Model. Further I have create a context menu for the tree with the following code part. Are there better way to create the MenuItems of the children? The second question is about to get the icons of the children in ".edit" plugin of the selected item. I think there is a way to access the xxxItemProvider, isn't it?

	public void changed(ObservableValue<? extends Object> arg0, Object arg1, Object newValue) {
		if (newValue instanceof TreeItem<?>) {
			TreeItem<?> treeItem = (TreeItem<?>) newValue;
                      // EMF Object
			Object value = treeItem.getValue();

                       // Get all children of the selected object and create the MenuItem
			Collection<?> collection = editingDomain.getNewChildDescriptors(value, null);
			for (Object object : collection) {
				if (object instanceof CommandParameter) {
					CommandParameter commandParameter = (CommandParameter) object;
					String name = commandParameter.getValue().getClass().getSimpleName().replace("Impl", "");
					MenuItem item = new MenuItem(name);
                                        // Todo: How can I get the Image of the current eobject, maybe via the ItemProvider?
                                        item.setGraphic(new ImageView(""));
					item.setOnAction(event -> {
						int id = EmfUtil.getValueByName(ResourcePackage.eINSTANCE, name);
						Command command = AddCommand.create(editingDomain, value, id,
						command.execute(); EventContext<>(EventTopic.COMMAND_STACK_REFRESH, command));

Hope this is clear enough.

Best regards
Re: How to get the ItemProvider of a element [message #1807520 is a reply to message #1807513] Fri, 31 May 2019 18:02 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31362
Registered: July 2009
Senior Member
I would suggest generating the editor for your model and looking at (with the debugger) how the menu is populated in the XyzActionBarContributor's generateCreateChildActions. All the infrastructure needed to produce the menu items is already available and is portable to different rendering engines...

Ed Merks
Professional Support:
Previous Topic:Java model package name
Next Topic:Disable or Hide the font options from Menubar
Goto Forum:

Current Time: Sun Aug 09 15:15:57 GMT 2020

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

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

Back to the top