Domanda

I am having a problem modifying EMF's automatically created "New Child" menu to create submenus for certain kinds of items. I found that, by default, the pipe symbol is used as a separator, so a child object with the name Hamburger | Megaplusbig results in a Hamburger submenu appearing. This page seems to suggest that overriding getCreateChildText() in the relevant item provider is a good option.

What I want is for certain types of model items to appear in a submenu, and to achieve this I'd just make sure that MySubmenu | gets prepended to the name. My problem is that classes for the model which I'm editing in Eclipse are in a separate Jar file that I can't (or rather really shouldn't) modify.

And I have not had much luck trying to achieve this in another way. My other attempt was extending BasicModelEditActionProvider and overriding its fillContextMenu() and updateActions() methods. The latter does create submenus through another call to BasicActionProvider.extractSubmenuActions(), which I again could override, but by then the information about my model objects is lost in the abstraction. That method works on IAction lists and even if I cast the action to StaticSelectionCommandAction (which it always is), the command field has no public getter, and it's only through fields of command that I see the actual EMF EObject somewhere.

I'm looking for a not-too-ugly solution that doesn't involve modifying the item providers in the Jar file, unless I really have to do it that way.

È stato utile?

Soluzione

So in the end, the only solution that worked is unfortunately a hack. I went with overriding extractSubmenuActions() in my BasicModelEditActionProvider, changing it to give me the submenus I wanted. The ugly part is finding the EMF object to-be-added, for which I unfortunately used reflection to forcefully read the protected command field of the normally abstracted IAction.

This forcefully breaks the encapsulation but due to external constraints on my code, I was unable to modify the item providers of the model. The reflective solution is not pretty, but works perfectly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top