eclipse plugin - Enabling/Disabling Toolbar-Command based on selection in ViewPart, not Perspective -
i have perspective consisting of multiple viewparts. 1 of these viewparts has command assigned using menucontribution locationuri="toolbar:...".
the viewpart toolbar-command contains 1 child (a treeview) , this.getsite().setselectionprovider(child) in it's createpartcontrol(composite)-method.
the problem is, when click 1 of other viewparts in perspective command gets disabled, selection resist in treeview-component. guess enabledwhen-condition not valid anymore, because selection-variable points stuff resists in viewpart.
this distracts, because toolbar-button should activated, when valid row in treeview selected.
how tell core expression, should check selection of viewpart toolbar resists in , not global-selection?

i had similar problem, , ended doing implementing own property tester. easiest way, because predefined selection variable point global selection.
roughly, need follow steps below.
add
org.eclipse.core.expressionsplug-in dependency.define extension
org.eclipse.core.expressions.propertytestersextension point. following (documentation link):<extension point="org.eclipse.core.expressions.propertytesters"> <propertytester class="your.package.treeitemselectionpropertytester" id="your.package.treeitemselectionpropertytester" namespace="your.namespace" properties="itemselected" type="java.lang.object"> </propertytester> </extension>implement propertytester code. above documentation says, class should public , should extend
org.eclipse.core.expressions.propertytesterclass.public class codeselectionpropertytester extends propertytester { @override public boolean test(object receiver, string property, object[] args, object expectedvalue) { if (property.equals("itemselected")) { // write own code test // whether there valid selection... } // ... } }use implemented property tester in enabledwhen clause.
<enabledwhen> <test property="your.namespace.itemselected"> </test> </enabledwhen>
Comments
Post a Comment