Eclipse RCP obtain toolbar contributions programmatically

前端 未结 3 1264
天涯浪人
天涯浪人 2021-01-22 16:22

I have an RCP application and I want disable/enable some elements of the toolbar when I perform some actions. My extension:



        
相关标签:
3条回答
  • 2021-01-22 16:34

    No, there's no way to get access to the main toolbar. The IActionBars toolbar returns the view toolbar (right next to the view tab).

    But you enable/disable a command based on the enablement of the active handler. Your handler is responsible for determining its enabled state.

    Programmaticly, if you subclass org.eclipse.core.commands.AbstractHandler you would call setBaseEnabled(boolean state) to make sure it fires the correct event.

    Declaratively, when contributed via org.eclipse.ui.handlers it has support for an enabledWhen element as well. That has access to the application state listed in org.eclipse.ui.ISources

    0 讨论(0)
  • 2021-01-22 16:40

    I just found that the following activity pattern removes the External tools menu contribution. This one was quite difficult to figure out.

           <activity id="org.eclipse.ui.navigator.resources.unwanted" name="unwanted"/> 
    
           <activityPatternBinding
           activityId="org.eclipse.ui.navigator.resources.unwanted"
           pattern=".*ExternalTool.*">
           </activityPatternBinding>
    
    0 讨论(0)
  • 2021-01-22 16:53

    If you want to access your items on the main toolbar, once an IHandler implements the interface IElementUpdater Eclipse’s command framework will use that class to update the label, tooltip, or even images of a command. See this for more details :

    http://www.robertwloch.net/2011/01/eclipse-tips-tricks-label-updating-command-handler/

    0 讨论(0)
提交回复
热议问题