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?

enter image description here

i had similar problem, , ended doing implementing own property tester. easiest way, because predefined selection variable point global selection.

roughly, need follow steps below.

  1. add org.eclipse.core.expressions plug-in dependency.

  2. define extension org.eclipse.core.expressions.propertytesters extension 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> 
  3. implement propertytester code. above documentation says, class should public , should extend org.eclipse.core.expressions.propertytester class.

    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...         }          // ...     } } 
  4. use implemented property tester in enabledwhen clause.

     <enabledwhen>     <test           property="your.namespace.itemselected">     </test>  </enabledwhen> 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -