Skip to main content



      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 11:19 Go to next message
Eclipse UserFriend
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?

	@Override
	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();
			newMenu.getItems().clear();

                       // 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,
								ExtendedResourceFactory.eINSTANCE.create(id));
						command.execute();
						eventBroker.post(new EventContext<>(EventTopic.COMMAND_STACK_REFRESH, command));
						treeItem.setExpanded(true);
					});
					newMenu.getItems().add(item);
				}
			}
		}
	}


Hope this is clear enough.

Best regards
lam
Re: How to get the ItemProvider of a element [message #1807520 is a reply to message #1807513] Fri, 31 May 2019 14:02 Go to previous message
Eclipse UserFriend
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...
Previous Topic:Java model package name
Next Topic:Disable or Hide the font options from Menubar
Goto Forum:
  


Current Time: Fri Jul 25 01:40:54 EDT 2025

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

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

Back to the top