I am trying to make a menu item active when a certain part becomes active. In e3 I used the activeEditorId. I have been trying to use the e4ActivePart variable but from looking at the code using it in an injection it always returns an MPart which in turn contains an object of the type I want.
So a core expression such as with="e4ActivePart" and an instanceOf="MyClass" does not work as the class is always org.eclipse.e4.ui.model.application.ui.basic.MPart.
so
<definition id="activepart">
<with variable="e4ActivePart">
<instanceof value="swb3.quotes.QuoteEditor"></instanceof>
</with>
</definition>
is never true, I tried iterating over the active part in case it contained a collection of user classes.
but
<definition id="activepart">
<with variable="e4ActivePart">
<instanceof value="org.eclipse.e4.ui.model.application.ui.basic.MPart"></instanceof>
</with>
</definition>
is always true.
Is there another way to display a menu item only for certain parts.
That works fine for disabling but I don't want the handler menu item to be displayed at all so need to hide it with a visible when rather than have it showing but disabled. The can execute won't hide it only disable it. Given the number of different editors and commands I would have something like 25 disabled commands under a menu as opposed to 4-5 visible ones relevant to the editor in question. So I really need a core expression to control the visibility based on the active part.
Paul Webster Messages: 6813 Registered: July 2009 Location: Ottawa
Senior Member
so far in Eclipse4 we publish the MPart that's active. If you want to check if your editor part is active, for now you could try writing a property tester that could check
I added it as a property tester in the manifest
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester class="swb3.PartPropertytester" id="swb3.PartPropertytester" namespace="swb3" properties="part" type="java.lang.Object">
</propertyTester>
</extension>
I then created a definition for use by the menu
<definition id="activepart">
<with variable="e4ActivePart">
<test forcePluginActivation="true" property="swb3.part">
</test>
</with>
</definition>
The menu now appears whenever a QuoteEditor is the active part.
I tried injecting an MPart into the property tester but it was always null. Now to make the tester more generic by passing in a class name rather than using an instanceof test.