How to get the ItemProvider of a element [message #1807513] |
Fri, 31 May 2019 15:19 |
Dimg Cim Messages: 59 Registered: December 2015 |
Member |
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02336 seconds